Message ID | 20221121112204.24456-1-yuehaibing@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1526059wrr; Mon, 21 Nov 2022 03:30:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf7BGwKc6SF3cblosvCtpDgKBHe93vHW6651ik8OqX6XLyLY2PFtE0kRTJFPEFv04D+VyWWG X-Received: by 2002:a17:90a:c381:b0:212:bfc3:3271 with SMTP id h1-20020a17090ac38100b00212bfc33271mr19412874pjt.99.1669030218688; Mon, 21 Nov 2022 03:30:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669030218; cv=none; d=google.com; s=arc-20160816; b=lihR7a+TBnHS/pRYUpziba6XUZfNY/5CS0rFVbPzEDk1V9Ix4CxQokuFMiDbSIbcO+ jxLPPtDS/fdVyJfvD2gk/gKRwjtQH+/xZ46PERqxVhSqKb+OJ08SAgn8/r4bqPQbyLEt L5yQGe7drqOHh1ZUF2czry2YphlTXe6leDt3H3D2s97cKk5OmE+oq020GHaLxiZ/UAJm cBBOiV7zyDwDYqrR4di+voFtpktPFBGqp5Z4J+lmDKP6itO9N8bO/+AtTNjNG54fj7wD TeGPBpo2zYXanaWcLZwsNvvt/Zjn66+SQGU8iIMjo3GWzcK3SAsnkkh/B33EBvCVi08E pKhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=G5cdiOsUhrHuCPCoc0oe87HWxgsA8G/xDHKC00MAfMM=; b=up6rmyXPcbRlVK18tuPItlextku3odp1iNX5QkZUNgFvz9bfv8HJnWHR/e7ubCzdGf 87ujbF1RP5eNySidvsT2jpsQBTF4bR4tcOU3WIEZZ1J25qlw8rzlsvYLfzQdmgSkmIf9 tiXHNhliJqoDr8rNoToI0Qa2O399o/Ef5gGhq0plaDqmjAKpWpiEjq6mav7sYPwGMByN U+15ccLQmO0SANId9ce4P6n3QyREfTa9oQnwx74dP3YkN0j9ONL6pC4dRcdeDoS1n1tb zHz0VEJKIJHjRB14pwrkIN3uNp4xHseNnTVj/vPnC+poVgXcNL5SUXz7KQXTVL4wLx9/ +zjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 2-20020a630b02000000b0043941763eadsi10115093pgl.835.2022.11.21.03.30.01; Mon, 21 Nov 2022 03:30:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229758AbiKUL3O (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Mon, 21 Nov 2022 06:29:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230206AbiKUL2r (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 21 Nov 2022 06:28:47 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6029AE03D; Mon, 21 Nov 2022 03:23:07 -0800 (PST) Received: from canpemm500007.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NG4f83FqpzqSYP; Mon, 21 Nov 2022 19:19:12 +0800 (CST) Received: from localhost (10.174.179.215) by canpemm500007.china.huawei.com (7.192.104.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 21 Nov 2022 19:23:05 +0800 From: YueHaibing <yuehaibing@huawei.com> To: <saeedm@nvidia.com>, <leon@kernel.org>, <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>, <moshe@nvidia.com>, <ogerlitz@mellanox.com>, <eli@mellanox.com>, <jackm@dev.mellanox.co.il>, <roland@purestorage.com> CC: <netdev@vger.kernel.org>, <linux-rdma@vger.kernel.org>, <linux-kernel@vger.kernel.org>, YueHaibing <yuehaibing@huawei.com> Subject: [PATCH net] net/mlx5: Fix uninitialized variable bug in outlen_write() Date: Mon, 21 Nov 2022 19:22:04 +0800 Message-ID: <20221121112204.24456-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.179.215] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500007.china.huawei.com (7.192.104.62) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750105030455422378?= X-GMAIL-MSGID: =?utf-8?q?1750105030455422378?= |
Series |
[net] net/mlx5: Fix uninitialized variable bug in outlen_write()
|
|
Commit Message
Yue Haibing
Nov. 21, 2022, 11:22 a.m. UTC
If sscanf() return 0, outlen is uninitialized and used in kzalloc(),
this is unexpected. We should return -EINVAL if the string is invalid.
Fixes: e126ba97dba9 ("mlx5: Add driver for Mellanox Connect-IB adapters")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On Mon, Nov 21, 2022 at 07:22:04PM +0800, YueHaibing wrote: > If sscanf() return 0, outlen is uninitialized and used in kzalloc(), > this is unexpected. We should return -EINVAL if the string is invalid. > > Fixes: e126ba97dba9 ("mlx5: Add driver for Mellanox Connect-IB adapters") > Signed-off-by: YueHaibing <yuehaibing@huawei.com> > --- > drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > Thanks, Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
On 21 Nov 19:22, YueHaibing wrote: >If sscanf() return 0, outlen is uninitialized and used in kzalloc(), >this is unexpected. We should return -EINVAL if the string is invalid. > >Fixes: e126ba97dba9 ("mlx5: Add driver for Mellanox Connect-IB adapters") >Signed-off-by: YueHaibing <yuehaibing@huawei.com> > applied to net-mlx5, thanks !
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c index 2e0d59ca62b5..cfb1e9f18a6c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c @@ -1508,8 +1508,8 @@ static ssize_t outlen_write(struct file *filp, const char __user *buf, return -EFAULT; err = sscanf(outlen_str, "%d", &outlen); - if (err < 0) - return err; + if (err != 1) + return -EINVAL; ptr = kzalloc(outlen, GFP_KERNEL); if (!ptr)