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 13ADFA046B for ; Mon, 24 Jun 2019 18:48:21 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BAE091BD40; Mon, 24 Jun 2019 18:47:43 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id 2CFE71BCEA for ; Mon, 24 Jun 2019 18:47:29 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id f25so7416354pgv.10 for ; Mon, 24 Jun 2019 09:47:29 -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=jQL7qF7ZN2Zfuv/c+mhKGQXC+rda0uj3KB3CwU29dr5t+5FM+ZmwTLATBhwwSOfQCX MbugYk3le1Zcqn5cQ5sLZ4aSo2J4f7HkVW17Fiu/Qtt4zl7NVIL2j84/c1kjJAQzyI1D wjbm1mpbcm0JA9v1nu2G54pJIWKmNOLQ0XJV5z8saaBgzV0J0ppdUmCTFiVOQyguOKBU tIlnwYo6/RpL3dWREd6qaUO1CQvxUj60OYWCa+cHoacRLKgibK4XyPOqBO4Srgz+sloF NJ0axfCCkB5AxZ32ywsnYf0rU5HmjTb6Se48N2Aqd3ptqHvGlsxCTouMn9yFEKGRAiZn F/cg== 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=AfNEMrsCZnjihX0A82TZuWC2AVLVOO6QyngxkrL4cOcBGx2lMAGo7IcT6vI7zrwRgm y2KO9cWPcBpu/QNls073zriC6zTglpFHAm9NBD6z9njgQntzv+6HClMePuVHFq4bIAcz WSl8YcGUu2EqfAjoxzjZNaq+deJ4bGIG0vDkhePy1jdftycx4HswdiqG5C74y1QYFxuu AfY9U8qDrjGcTNSe21X7NiVZzkI1xhPwvTlKsN/r3iXQADN/nFLz1ZByo/z2nSfV9Q6M NE1XSivb/xdsvnHDDKz3mZwpk8BVDjYm/ISLKXIl0dF85EUiJwGgLI5j1wpUO+sCqFH7 qQNA== X-Gm-Message-State: APjAAAUaZZUeZmB73oGQFMWtVH8Zuu4fYc25pNbWfsE8IvhZT4yF2wCF qlDKz2xQ88pYQGXYevXS8v0C+6lm3EY= X-Google-Smtp-Source: APXvYqwTJqqhduEO1CES7r7GcTpoWkoVa1/N6Kgszp/EvnpoP351orzirH/jGXKHISyCfdz8q3W35w== X-Received: by 2002:a63:80c7:: with SMTP id j190mr16371330pgd.410.1561394848053; Mon, 24 Jun 2019 09:47:28 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id f7sm12814023pfd.43.2019.06.24.09.47.26 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 09:47:26 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 24 Jun 2019 09:47:11 -0700 Message-Id: <20190624164714.6560-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624164714.6560-1-stephen@networkplumber.org> References: <20190610175155.21374-1-stephen@networkplumber.org> <20190624164714.6560-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v6 6/9] 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