From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D646EC48BC2 for ; Mon, 21 Jun 2021 17:59:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC61160698 for ; Mon, 21 Jun 2021 17:59:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232888AbhFUSB7 (ORCPT ); Mon, 21 Jun 2021 14:01:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:45148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232014AbhFUSAE (ORCPT ); Mon, 21 Jun 2021 14:00:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E640E61374; Mon, 21 Jun 2021 17:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624298060; bh=mgXBEowT5e3mMtfgwzguw5gUbGsyEEO5SLKXkbKh3QI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NAmEJHJYBJ46RV5ADrlXyx4pChlowsd+gyM0LzhVRA85Q2ZrhqaQfkbQAVMZPZei6 s/q0BtEUxBTID6ZCZoSSBIf3DzQpb+LIElAaBHLI6GqkF9WyqxcIjupM3+V2AntsyB wRc8ckE05RyhmWEK0A4NGfCIXB3tQfjmq5Yj5JIeV9Jjvt95RSPpuyCdge0ILUwuQC k0LO19HODagDsZy6eRbsAw3Wd8+1lcxgmgXDzNOMgxk44Kpz/dUs573JGeQ1lRE1Yw Diioh2uxWgeX24AYsQYvUxkkMynxyKUy6TtdwunlmmKR/fSoFWT8Knr2zUMFU6lxHE wL9H4a/Pvty6g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Austin Kim , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 11/26] net: ethtool: clear heap allocations for ethtool function Date: Mon, 21 Jun 2021 13:53:44 -0400 Message-Id: <20210621175400.735800-11-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210621175400.735800-1-sashal@kernel.org> References: <20210621175400.735800-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Austin Kim [ Upstream commit 80ec82e3d2c1fab42eeb730aaa7985494a963d3f ] Several ethtool functions leave heap uncleared (potentially) by drivers. This will leave the unused portion of heap unchanged and might copy the full contents back to userspace. Signed-off-by: Austin Kim Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/core/ethtool.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 76506975d59a..cbd1885f2459 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -1508,7 +1508,7 @@ static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr, if (eeprom.offset + eeprom.len > total_len) return -EINVAL; - data = kmalloc(PAGE_SIZE, GFP_USER); + data = kzalloc(PAGE_SIZE, GFP_USER); if (!data) return -ENOMEM; @@ -1573,7 +1573,7 @@ static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) return -EINVAL; - data = kmalloc(PAGE_SIZE, GFP_USER); + data = kzalloc(PAGE_SIZE, GFP_USER); if (!data) return -ENOMEM; @@ -1764,7 +1764,7 @@ static int ethtool_self_test(struct net_device *dev, char __user *useraddr) return -EFAULT; test.len = test_len; - data = kmalloc_array(test_len, sizeof(u64), GFP_USER); + data = kcalloc(test_len, sizeof(u64), GFP_USER); if (!data) return -ENOMEM; @@ -2295,7 +2295,7 @@ static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr) ret = ethtool_tunable_valid(&tuna); if (ret) return ret; - data = kmalloc(tuna.len, GFP_USER); + data = kzalloc(tuna.len, GFP_USER); if (!data) return -ENOMEM; ret = ops->get_tunable(dev, &tuna, data); @@ -2481,7 +2481,7 @@ static int get_phy_tunable(struct net_device *dev, void __user *useraddr) ret = ethtool_phy_tunable_valid(&tuna); if (ret) return ret; - data = kmalloc(tuna.len, GFP_USER); + data = kzalloc(tuna.len, GFP_USER); if (!data) return -ENOMEM; mutex_lock(&phydev->lock); -- 2.30.2