From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90D2B15C82 for ; Mon, 5 Dec 2022 19:22:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12F1CC433C1; Mon, 5 Dec 2022 19:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1670268126; bh=2mUxD8qeq97aRPeJbMuT8Zvqaw9f07LCPRMdsEK6qWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fpz5dtPh2w6QQfttx1lvH2Jr5/kt6HvnYcA6Dsw7udU4M61aE3Y/FioeCZFddxuTd CdD2VQdlwYWr/YoRYW7U0OA58uqb4K91Zk6n8XXCV7jXQvLc6j3loAap1Q+JkTx+UC TXMmtaDVH8EvwRom/WFVuhQf+q2eRrF3b2c4ikso= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, YueHaibing , Leon Romanovsky , Saeed Mahameed , Sasha Levin Subject: [PATCH 4.19 068/105] net/mlx5: Fix uninitialized variable bug in outlen_write() Date: Mon, 5 Dec 2022 20:09:40 +0100 Message-Id: <20221205190805.479590710@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221205190803.124472741@linuxfoundation.org> References: <20221205190803.124472741@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: YueHaibing [ Upstream commit 3f5769a074c13d8f08455e40586600419e02a880 ] 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 Reviewed-by: Leon Romanovsky Signed-off-by: Saeed Mahameed Signed-off-by: Sasha Levin --- drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c index a686082762df..14cdac980520 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c @@ -1324,8 +1324,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) -- 2.35.1