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 B814EA0471 for ; Tue, 18 Jun 2019 18:17:50 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 784FB1C24A; Tue, 18 Jun 2019 18:17:02 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id EB65E1C228 for ; Tue, 18 Jun 2019 18:16:52 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id a186so7937411pfa.5 for ; Tue, 18 Jun 2019 09:16:52 -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=9ZfM4adtNVrF7wT1Mjc0z707Ax+G9osFiWtI1ekyG9E=; b=ZMHakhQf5KELU5sXzAUmwXch86SYWOSu+YGD0oC0n72PII0TOME1gEElqu0aLoKQAU 0BOwvUhFdOt6KpC5nUCIIzWADk147cOh0QwK5aTpczXmVbmpdZQ9uWFOLzcV46Jp0O3w kkM4j0bNngd67DXE2QzSIKjJ7p5VAAMvhnuRwf//8yyy4lGfYhYUbE/zF5K4K8gziiGu LVaOaJd14qqABVrAfO2UH83PrPaNaomqHkguhCg8Y6JhRjptsRA6AjoNuMVTuuZBWr9i WvXeqmiBUekrPfoww/gbQfHUsPyULTQQdlWCN7yBl5DBKTwpvggW0AFzZ9+GRMiHucmV RQTQ== 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=9ZfM4adtNVrF7wT1Mjc0z707Ax+G9osFiWtI1ekyG9E=; b=Yh54tjXILvdDFQPPoB3a2fKmjDvgkCu57+RoowV3zaXcpwFWoRVT3wvds/FvpcG566 Rt8UX/SRUQSe3TGD2CVL3n9SAQBLdWBYRsIp2+Zk+FbWA7mC9ZR1tt7P4kFdYn+VWFpu geQcnR7tQJ4BeWdvSg2C7F6tW/WbkjGSNQVSj4EckPTasR80Cw67GenwKZ3jgmcMlzoM hkBFx93JfEFKQixNQNc4TWAA6UHHXL8Rtu4jYW31osdTsGD1IQUrrx/r/c5b3ssbonBo x+D2zcapLfzdGTrCzn0LmMAij13OXoPkurhtelL+y3WuwdRQMtLbx0fbPgtF2siYiiJU mJ1Q== X-Gm-Message-State: APjAAAXdHw6L4+sHXEIAtdRV+eFau8aMtt47FZnDvW3HVUO9gBTijYZZ BxwlyBOmFY6nmGLjDJZm1zEOxwKi5uc= X-Google-Smtp-Source: APXvYqxM8qTvsSPWZio7USnIoJ6DdTbeVFwaLkvsQSKmvxLnSK3zp+59Km92DDfb0eauVUNXULRHDA== X-Received: by 2002:a63:d415:: with SMTP id a21mr3320829pgh.229.1560874611773; Tue, 18 Jun 2019 09:16:51 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 3sm15485385pfp.114.2019.06.18.09.16.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 18 Jun 2019 09:16:50 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 18 Jun 2019 09:16:34 -0700 Message-Id: <20190618161636.23748-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190618161636.23748-1-stephen@networkplumber.org> References: <20190610175155.21374-1-stephen@networkplumber.org> <20190618161636.23748-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" 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