From patchwork Thu Dec 14 01:25:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13492183 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 2CD5D63DF for ; Thu, 14 Dec 2023 01:25:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CZyJAEoj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7BE7C433C7; Thu, 14 Dec 2023 01:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702517124; bh=RJbgxjN90Xw0L2yrktvCzzxxSnOaDd2Bhyvax9W1sCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZyJAEojK10Sfh7J7LDCsdyzhVq3OeX2JsWhYPyE+++y20Bn0EUHvSVx6iJh0E2fk e/RBpx5Fid4uVGwuK8Wu5DgkN/24egqq9Y04yR9cq3hkyDVBrtTlVC+awzcUnrimTb 5HPXuAYKRin7/TNLM+QG+b3R5nsYMlcIg3YW5gTNHyzWvGjEscGD67GomFsvS1ARJ0 +jICR9TxJ1HxcgZVYM+bQjNaJ0dgSBgBlg6Fi2wkmMrbYUFMlg0OG12FG9z422jVDO rlwYMLamgKLfSLKB1dbtSi/OKdY3RYA13boSGrhAj1q3hoqt7+aHUmRZ7Xua72PsPj JccfP+gHlzkjQ== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Rahul Rameshbabu , Simon Horman Subject: [net 15/15] net/mlx5e: Correct snprintf truncation handling for fw_version buffer used by representors Date: Wed, 13 Dec 2023 17:25:05 -0800 Message-ID: <20231214012505.42666-16-saeed@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231214012505.42666-1-saeed@kernel.org> References: <20231214012505.42666-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. Link: https://docs.kernel.org/core-api/kernel-api.html#c.snprintf Fixes: 1b2bd0c0264f ("net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors") Signed-off-by: Rahul Rameshbabu Reviewed-by: Simon Horman Signed-off-by: Saeed Mahameed --- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c index 1bf7540a65ad..e92d4f83592e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c @@ -78,7 +78,7 @@ static void mlx5e_rep_get_drvinfo(struct net_device *dev, 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));