From: Lee Trager <lee@trager.us>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Alexander Duyck <alexanderduyck@fb.com>,
Jakub Kicinski <kuba@kernel.org>,
kernel-team@meta.com, Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH net-next] eth: fbnic: fix memory corruption in fbnic_tlv_attr_get_string()
Date: Fri, 7 Mar 2025 14:59:13 -0800 [thread overview]
Message-ID: <1e5dcc30-47b1-45c7-8cbe-0c72d07b88ed@trager.us> (raw)
In-Reply-To: <2791d4be-ade4-4e50-9b12-33307d8410f6@stanley.mountain>
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>
next prev parent reply other threads:[~2025-03-07 22:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 9:28 Dan Carpenter
2025-03-07 22:59 ` Lee Trager [this message]
2025-03-10 20:40 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1e5dcc30-47b1-45c7-8cbe-0c72d07b88ed@trager.us \
--to=lee@trager.us \
--cc=alexanderduyck@fb.com \
--cc=andrew+netdev@lunn.ch \
--cc=dan.carpenter@linaro.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®