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 52756A00E6 for ; Mon, 10 Jun 2019 19:52:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 985B71C1B6; Mon, 10 Jun 2019 19:52:15 +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 23DC41C136 for ; Mon, 10 Jun 2019 19:52:07 +0200 (CEST) Received: by mail-pg1-f194.google.com with SMTP id v11so5423029pgl.5 for ; Mon, 10 Jun 2019 10:52:07 -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=1NDmwzHrmZPX3u9NF7x3GeKUDjSznkLaHCXozcreu7g=; b=u1V9T0BQ1st5o44n5rvzwGumdNLUrxJAALPcWLKCX3fgjjeJTmJNqnCIy9X87ERnF/ 1FzSCE346YTcWnTsu/sFIpcuH+PpPydGjEQ/bXGvajrcbWgbk8W0dtM3Fxmc7mGgL47W qqeR1mexu4Ie1KIykWF2ri6mKTtjQqhzRsRtAdXLr5kAuhN/WBMZ9rJ7PdpnLxS7bDPz ZsWsA0rxIxtEwJPYdtN9oiVZgUYsOKwSOjVA13+C5KUIVx+lHsNJIBVkqtMFLyG9l20U bklaC4ftDvUVOysk1QTzjD5PrkWgyYtwHGQ10u9ZhvFsTUrWf63gBns5HPbQPxbujfCC S8FA== 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=1NDmwzHrmZPX3u9NF7x3GeKUDjSznkLaHCXozcreu7g=; b=Mo83NKINMjNPHNC1Gnzwt8gXr/+WUOvWYUKg0zXud7sMgj2niXSS1usKHoJy7ZgzxW /WXkUtCjMvXrG7VF0X/MbXW/r39+zIJ+l6MPBECnnG/ttoFCX7REwmDFy0FSBVyGN0A6 qFsF0jZ6KnzM4jXxw+TQe7b52u17ECYK+gW1l5WCmXtM/KpVtGCt6R9HgEiBEBL4oKQN 06b38yygW6msMvFlUZLIr2ETyN6E2seUHygP8rpX60/RG0T/1QBl4sjOXZOc3gYSnqJX c0IaFv9p3qrWFRcr+5x6afYPv5kPRvXkgXiNeE1nfAA34VCUm36CdwPVb7kFWrOcwK5V lf6Q== X-Gm-Message-State: APjAAAUgbkEUKbHdrpaGWY93Seie1YOpuvml+oATyONiw56nM5crSy1g BHoNEizFQcjt2ClBhYPT2orQ3nqNUNY= X-Google-Smtp-Source: APXvYqyjIF2QMrhwNqJZZukyNJcXHII+yj5VGtDXEq4Vjw1WLWCdDMuIOcyg90/r2An3bHLFLupqFQ== X-Received: by 2002:a63:545a:: with SMTP id e26mr16453089pgm.162.1560189126265; Mon, 10 Jun 2019 10:52:06 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id l38sm131656pje.12.2019.06.10.10.52.05 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 10 Jun 2019 10:52:05 -0700 (PDT) From: Stephen Hemminger To: ferruh.yigit@intel.com Cc: dev@dpdk.org, Stephen Hemminger Date: Mon, 10 Jun 2019 10:51:54 -0700 Message-Id: <20190610175155.21374-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190610175155.21374-1-stephen@networkplumber.org> References: <20190610175155.21374-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 6/7] 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" 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 6a206d883c0d..a67991066cd9 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)) { @@ -433,15 +430,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