Skip to content

Commit

Permalink
eth: fbnic: fix memory corruption in fbnic_tlv_attr_get_string()
Browse files Browse the repository at this point in the history
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: e5cf510 ("eth: fbnic: Update fbnic_tlv_attr_get_string() to work like nla_strscpy()")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Lee Trager <lee@trager.us>
Link: https://patch.msgid.link/2791d4be-ade4-4e50-9b12-33307d8410f6@stanley.mountain
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Dan Carpenter authored and Jakub Kicinski committed Mar 10, 2025
1 parent 473367a commit 991a1b0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 991a1b0

Please sign in to comment.