From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id EAF74A0471 for ; Wed, 19 Jun 2019 20:58:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DCD4A1D139; Wed, 19 Jun 2019 20:58:14 +0200 (CEST) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by dpdk.org (Postfix) with ESMTP id D80251D0F0 for ; Wed, 19 Jun 2019 20:58:02 +0200 (CEST) Received: by mail-pg1-f194.google.com with SMTP id n2so159496pgp.11 for ; Wed, 19 Jun 2019 11:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FievvR3qZSVV1KBq32+9xb9nuDdD0v5bxhQau2jtXi0=; b=YCxE4LL7OzQR6IWHbuG7zyC53UcHX6TrI4IRMihFu2qswr9BN6cCzhRM1nFO/PRSC9 yHoTgPIAm63rGx+5Su0Yb11XGAj5GZGXeZUvJNy4NWsnPoTknL12ztaG9O72oJ8TrWjL O+m2J5w1/iYJNUYwo3KkcJYb1meGXa9kuxCW3Mszr5J3TLw8ouINKWtDxXkXjNEepmBM vXdFzEgdAn8/RUdJjoSzUIUHX1+aEGbNW8k7vTTs7je2MnocPYExCrkYxr9hTeMJYsUo DJZJBvDO5wD9xUc+u8Sm7MdMPbfs+ucUhAOU6nCUGmJs+2Yqtn16UFLmh/Mg3keEGGhW UENA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FievvR3qZSVV1KBq32+9xb9nuDdD0v5bxhQau2jtXi0=; b=RhEo3/seAWBX0w7IhtcTfTGuFEM4cOn5yj5bLKwvHINluym9DRnYT2LphoeNgWj1lw xOOwIsDcgTl+JKX8Vdl1tVx/mxFGusFBDzmDPVDQPGo0nB6qC07p9eZZYjTmGqBjj4Du e+duZJUoSqtu9NMBPxsAeaaCzbvkZYc0UKOKrwPIw14FavrYsINNj6D8ul7AWL1klrGJ KjWkU1XoxjxNHwe5yZpNm1Oc64OBCtyEITGOHkgnOaj42Chpx1RzjIEqnlBjdGGrzmzW Upo8AyPF918dpyqvH/6jYAeoWZHqC2m4hwi0dHz02FEK9hHDBjEI/jPEUwQf6NG1uWWL viGw== X-Gm-Message-State: APjAAAW6L8qrFhhFSqGmVbNfdnkI1k9j1ARXSH9Vrf5t66qISDI+2KOX 9mmpD4aN0vYoXScU+kBPVu0YknlmbgA= X-Google-Smtp-Source: APXvYqw68h78Cn0vH+9LS1CItOCPGomQ/lxJxFNwohP7Bap8V4FAc6XrRIuiMXxq6+ktag82kzfQrg== X-Received: by 2002:a17:90a:2525:: with SMTP id j34mr13081468pje.11.1560970681757; Wed, 19 Jun 2019 11:58:01 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id b8sm24774858pff.20.2019.06.19.11.58.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 11:58:00 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Stephen Hemminger Date: Wed, 19 Jun 2019 11:57:44 -0700 Message-Id: <20190619185746.26866-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190619185746.26866-1-stephen@networkplumber.org> References: <20190610175155.21374-1-stephen@networkplumber.org> <20190619185746.26866-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 6/8] kni: return -EFAULT if copy_from_user fails X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Stephen Hemminger The correct thing to return if user gives a bad data is to return -EFAULT. Logging is also discouraged because it could be used as a DoS attack. Signed-off-by: Stephen Hemminger --- kernel/linux/kni/kni_misc.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c index b59cf24c2184..be45f823408f 100644 --- a/kernel/linux/kni/kni_misc.c +++ b/kernel/linux/kni/kni_misc.c @@ -301,11 +301,8 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num, return -EINVAL; /* Copy kni info from user space */ - ret = copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info)); - if (ret) { - pr_err("copy_from_user in kni_ioctl_create"); - return -EIO; - } + if (copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info))) + return -EFAULT; /* Check if name is zero-ended */ if (strnlen(dev_info.name, sizeof(dev_info.name)) == sizeof(dev_info.name)) { @@ -427,15 +424,12 @@ kni_ioctl_release(struct net *net, uint32_t ioctl_num, if (_IOC_SIZE(ioctl_num) > sizeof(dev_info)) return -EINVAL; - ret = copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info)); - if (ret) { - pr_err("copy_from_user in kni_ioctl_release"); - return -EIO; - } + if (copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info))) + return -EFAULT; /* Release the network device according to its name */ if (strlen(dev_info.name) == 0) - return ret; + return -EINVAL; down_write(&knet->kni_list_lock); list_for_each_entry_safe(dev, n, &knet->kni_list_head, list) { -- 2.20.1