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 D25CCA0471 for ; Wed, 19 Jun 2019 21:01:01 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8A0061D187; Wed, 19 Jun 2019 21:00:20 +0200 (CEST) Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by dpdk.org (Postfix) with ESMTP id A354B1D163 for ; Wed, 19 Jun 2019 21:00:10 +0200 (CEST) Received: by mail-pl1-f194.google.com with SMTP id a93so194962pla.7 for ; Wed, 19 Jun 2019 12:00:10 -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=EBoOLn1f3lR7Oh2FSQiyP0BjOPpi3th438KdVsChFCVp0/XOdNHhgBNtgFSxfNJq2e WnLcfb1nhZ6fOcvncDuJ/Ia8l+AvgadwYCS8vZgCoxJeG3g0rgmFyjqsMSFNBc9ghvCk Uv9yk9WD7s0SmP9X3A9YatZ14m9gyCsikVdiz6hzivWxSmXi9ZCopYiftPla3GTK0Xd3 456Ks12pT5jyc802NquopKfb+Yo/7FHkP3oClBzLMchfYFDHD9mydRSCPYKpy1VG5iiu uALlI4s0FU6Zczk28fOKAV+6TqrDuP0ru2OdkfPGhTQuLmBw36qlaq0oA7fT+M2z00Q0 1HFQ== 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=PKOx/goENcomQ1O9k1MfYH+E5s3IxoH5G2DTcJimhbK5jEk8LhQrd6V24Byd1OkQIk K7SJa2mOcI9H4cyFyWTZ05UOqqicMG/Sj03Q7R49yoMIqe46CqclZXOL27E7Caek4610 9Yb5NL/6nJQkVwsppvo3KYK8h8n95KYFtehmFRDTGcSQIfRWySCMy0aa0k3FYEYsLvIU Z51d2nTJHnCO/WucoH4A3y8Xf9jclEmSm74atT+shRAtpzgNRsPoDz6xqhrG4WXZX1Tz Md7fhfcCF0/GhFVfOnIYajoUrztGdtJjRpzZZ9016dPhy8pd8EaXGPDYL1PRn2DHyjr2 uHDg== X-Gm-Message-State: APjAAAUq5Y/HXjcHN2orLex2wbL91b2J8RPD87N/MMyVHJNnrYyBQTUF +DBvNmmU/wW5wM1CXtK0inorwh7PRPU= X-Google-Smtp-Source: APXvYqzPRbyUyYouS1eKKwXWn4bp2iFCzc7SUo2/3d4uw92yd/a8BM4HnyEzASqVf3Q96K/4HCnBkw== X-Received: by 2002:a17:902:7883:: with SMTP id q3mr119301451pll.89.1560970809624; Wed, 19 Jun 2019 12:00:09 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id g8sm18613397pfi.8.2019.06.19.12.00.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 12:00:08 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Stephen Hemminger Date: Wed, 19 Jun 2019 11:59:56 -0700 Message-Id: <20190619185958.27306-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190619185958.27306-1-stephen@networkplumber.org> References: <20190610175155.21374-1-stephen@networkplumber.org> <20190619185958.27306-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v4 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