From patchwork Tue Dec 5 21:45:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13480810 X-Patchwork-Delegate: kuba@kernel.org 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 432076FCC6 for ; Tue, 5 Dec 2023 21:45:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uU1hJQh6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C6A5C433C8; Tue, 5 Dec 2023 21:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701812750; bh=zKCONBqv5B4WAD0DUxmPeLaCswnYO2/PVLYztXh3QnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uU1hJQh635WtJSmzigaks4JVHRH9i498b5D7lULL+ARFhO/P9KPRVXi9e+ZWUULSW kAWijMV2nK3I/d3w51WKw85musENDvcEJHB9sAxOBtkhsHzdcIGr6DyBqqxLB3nNtQ tpnYpzT0Rg7yzv8jUqeG0GYYf6MpJmuZqofTo6piaJJ47g7WvoBTT+215DoxId3zo8 NVrHKvwzHiGibjRTvEjBRePbepYmMt+2TvLXoaOBVx60fwE2tmqDJPItCr7Jf9eCl5 mHt7st7+DgUAw7K7umrfAnL+O17KXCYjnTGKX1wHwbmF90TKfOSHU9/SvlbkYykpBu wRprQdAsHPqvg== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Rahul Rameshbabu , David Laight , Simon Horman Subject: [net V3 14/15] net/mlx5e: Correct snprintf truncation handling for fw_version buffer Date: Tue, 5 Dec 2023 13:45:33 -0800 Message-ID: <20231205214534.77771-15-saeed@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205214534.77771-1-saeed@kernel.org> References: <20231205214534.77771-1-saeed@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Rahul Rameshbabu snprintf returns the length of the formatted string, excluding the trailing null, without accounting for truncation. This means that is the return value is greater than or equal to the size parameter, the fw_version string was truncated. Reported-by: David Laight Closes: https://lore.kernel.org/netdev/81cae734ee1b4cde9b380a9a31006c1a@AcuMS.aculab.com/ Link: https://docs.kernel.org/core-api/kernel-api.html#c.snprintf Fixes: 41e63c2baa11 ("net/mlx5e: Check return value of snprintf writing to fw_version buffer") Signed-off-by: Rahul Rameshbabu Reviewed-by: Simon Horman Signed-off-by: Saeed Mahameed --- drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c index 792a0ea544cd..c7c1b667b105 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c @@ -49,7 +49,7 @@ void mlx5e_ethtool_get_drvinfo(struct mlx5e_priv *priv, count = snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%04d (%.16s)", fw_rev_maj(mdev), fw_rev_min(mdev), fw_rev_sub(mdev), mdev->board_id); - if (count == sizeof(drvinfo->fw_version)) + if (count >= sizeof(drvinfo->fw_version)) snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%04d", fw_rev_maj(mdev), fw_rev_min(mdev), fw_rev_sub(mdev));