mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] eth: fbnic: fix memory corruption in fbnic_tlv_attr_get_string()
@ 2025-03-07  9:28 Dan Carpenter
  2025-03-07 22:59 ` Lee Trager
  2025-03-10 20:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-03-07  9:28 UTC (permalink / raw)
  To: Lee Trager
  Cc: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
	David S. Miller, Eric Dumazet, Paolo Abeni, netdev, linux-kernel,
	kernel-janitors

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) {
-- 
2.47.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] eth: fbnic: fix memory corruption in fbnic_tlv_attr_get_string()
  2025-03-07  9:28 [PATCH net-next] eth: fbnic: fix memory corruption in fbnic_tlv_attr_get_string() Dan Carpenter
@ 2025-03-07 22:59 ` Lee Trager
  2025-03-10 20:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Trager @ 2025-03-07 22:59 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
	David S. Miller, Eric Dumazet, Paolo Abeni, netdev, linux-kernel,
	kernel-janitors

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>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] eth: fbnic: fix memory corruption in fbnic_tlv_attr_get_string()
  2025-03-07  9:28 [PATCH net-next] eth: fbnic: fix memory corruption in fbnic_tlv_attr_get_string() Dan Carpenter
  2025-03-07 22:59 ` Lee Trager
@ 2025-03-10 20:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-03-10 20:40 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: lee, alexanderduyck, kuba, kernel-team, andrew+netdev, davem,
	edumazet, pabeni, netdev, linux-kernel, kernel-janitors

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-10 20:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-07  9:28 [PATCH net-next] eth: fbnic: fix memory corruption in fbnic_tlv_attr_get_string() Dan Carpenter
2025-03-07 22:59 ` Lee Trager
2025-03-10 20:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®