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 D3410A0471 for ; Thu, 20 Jun 2019 21:21:53 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C64921D492; Thu, 20 Jun 2019 21:21:18 +0200 (CEST) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id 19F511D467 for ; Thu, 20 Jun 2019 21:21:05 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id f25so2066824pgv.10 for ; Thu, 20 Jun 2019 12:21:05 -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=BsHKJBwl9VUEkFWXS5327E2HSNc3JDo08kdmSflhKcNR/vk+do8O7NwoVxObllrIr4 dR/3V75lo7xfJqGaizCIJPF2Iptm+TkpcMN0TZCHlRVJF+IgkigxogvXH5Z0eFODvM6Q QfX3uZaShjt69gEFYHOzWOJOaQK5gSzl6PtLDje1/KsxqFF1azO8z0c2Wmtaf9H+RwDe N383YNFsyTxoWNVIaTdhPwRJR9y9vQmN2gaB7bqDBgTdlA+j6/obiNRd0PNdSs0Kab1n Sxs2w/rNYf7V4Ml6QNK9UNvjdXvgU0vQvkeasWw+sxU0ARGSaQP5WrI0YU9cHpqE0LLT rXHg== 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=cGycGbewS2Slb2Vqrwc1IiFIQXKZdf9cZl52whJXj1pLbECinTMa80edl6xSMjyCl3 04rcik6QySxST/uTqMTa5dlS2nLSmu+Zf4tSlp8eiMlsVdFDdueoTNu3ImLQC3s5fu2A JEjQzLI+QFT9qKPrWkOknpAKR3k5SNTsFg+MVmUd41LfiLayZQOsNvPjAa131FeobTfV wXxUjR9S4uagFTlK02PQ96ICRDyGQlrLEW7niDBDR/qB5kcZcLcC9gr1aE8nScoSvnG6 P9JTuIugopNs5UsKgQX/mXurF29fHylagtdMcZbrsZ8D2HGxi00biZXA0aB7wkks1Bq5 6loQ== X-Gm-Message-State: APjAAAUbDrHoCkEGuFE4xZ5GL2I5daxfmxlrDirk4IwTeLun6aT2m2hw 0zaN6KJAeZuaF4C99axNSaS2rrhqYOE= X-Google-Smtp-Source: APXvYqweTTjSqy2DX7zzUUPrwsAFkuqExuDAONUbp7+6r5u+mlZamQ8CpSVNd5N5pH2sUgwGYwVY0g== X-Received: by 2002:a17:90a:9291:: with SMTP id n17mr1252663pjo.66.1561058464045; Thu, 20 Jun 2019 12:21:04 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id j11sm255703pfa.2.2019.06.20.12.21.02 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 20 Jun 2019 12:21:03 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 20 Jun 2019 12:20:45 -0700 Message-Id: <20190620192048.13814-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190620192048.13814-1-stephen@networkplumber.org> References: <20190610175155.21374-1-stephen@networkplumber.org> <20190620192048.13814-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v5 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