diff mbox series

[net-next] eth: fbnic: fix memory corruption in fbnic_tlv_attr_get_string()

Message ID 2791d4be-ade4-4e50-9b12-33307d8410f6@stanley.mountain (mailing list archive)
State Accepted
Commit 991a1b09920bc15c66f64c1e7d15cdabd3816c46
Delegated to: Netdev Maintainers
Headers show
Series [net-next] eth: fbnic: fix memory corruption in fbnic_tlv_attr_get_string() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-03-07--12-00 (tests: 894)

Commit Message

Dan Carpenter March 7, 2025, 9:28 a.m. UTC
This code is trying to ensure that the last byte of the buffer is a NUL
terminator.  However, the problem is that attr->value[] is an array of
__le32, not char, so it zeroes out 4 bytes way beyond the end of the
buffer.  Cast the buffer to char to address this.

Fixes: e5cf5107c9e4 ("eth: fbnic: Update fbnic_tlv_attr_get_string() to work like nla_strscpy()")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/net/ethernet/meta/fbnic/fbnic_tlv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Lee Trager March 7, 2025, 10:59 p.m. UTC | #1
On 3/7/25 1:28 AM, Dan Carpenter wrote:

> This code is trying to ensure that the last byte of the buffer is a NUL
> terminator.  However, the problem is that attr->value[] is an array of
> __le32, not char, so it zeroes out 4 bytes way beyond the end of the
> buffer.  Cast the buffer to char to address this.
>
> Fixes: e5cf5107c9e4 ("eth: fbnic: Update fbnic_tlv_attr_get_string() to work like nla_strscpy()")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>   drivers/net/ethernet/meta/fbnic/fbnic_tlv.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
> index d558d176e0df..517ed8b2f1cb 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
> @@ -261,7 +261,7 @@ ssize_t fbnic_tlv_attr_get_string(struct fbnic_tlv_msg *attr, char *dst,
>   		return -E2BIG;
>   
>   	srclen = le16_to_cpu(attr->hdr.len) - sizeof(*attr);
> -	if (srclen > 0 && attr->value[srclen - 1] == '\0')
> +	if (srclen > 0 && ((char *)attr->value)[srclen - 1] == '\0')
>   		srclen--;
>   
>   	if (srclen >= dstsize) {

Thanks for catching that. While I didn't see any negative effect without 
it I have verified on hardware this patch works.

Reviewed-by: Lee Trager <lee@trager.us>
patchwork-bot+netdevbpf@kernel.org March 10, 2025, 8:40 p.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 7 Mar 2025 12:28:48 +0300 you wrote:
> This code is trying to ensure that the last byte of the buffer is a NUL
> terminator.  However, the problem is that attr->value[] is an array of
> __le32, not char, so it zeroes out 4 bytes way beyond the end of the
> buffer.  Cast the buffer to char to address this.
> 
> Fixes: e5cf5107c9e4 ("eth: fbnic: Update fbnic_tlv_attr_get_string() to work like nla_strscpy()")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> 
> [...]

Here is the summary with links:
  - [net-next] eth: fbnic: fix memory corruption in fbnic_tlv_attr_get_string()
    https://git.kernel.org/netdev/net-next/c/991a1b09920b

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
index d558d176e0df..517ed8b2f1cb 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
@@ -261,7 +261,7 @@  ssize_t fbnic_tlv_attr_get_string(struct fbnic_tlv_msg *attr, char *dst,
 		return -E2BIG;
 
 	srclen = le16_to_cpu(attr->hdr.len) - sizeof(*attr);
-	if (srclen > 0 && attr->value[srclen - 1] == '\0')
+	if (srclen > 0 && ((char *)attr->value)[srclen - 1] == '\0')
 		srclen--;
 
 	if (srclen >= dstsize) {