Skip to contentSkip to conversation

net: fbnic: validate mailbox TLV extents

PATCH Applied Pengpeng Hou 2 participants 2 messages Aug 30 – Sep 2

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: fbnic: validate mailbox TLV extents

The mailbox path warns when a message claims more bytes than the descriptor but still parses it. The attribute walkers also validate a child TLV before proving that its declared span fits in the parent remainder.

Reject invalid mailbox message extents and bound each child attribute before type-specific validation.

Fixes da3cde08209e ("eth: fbnic: Add FW communication mechanism")
---
 drivers/net/ethernet/meta/fbnic/fbnic_fw.c  |  9 ++++++---
 drivers/net/ethernet/meta/fbnic/fbnic_tlv.c | 15 ++++++++++-----
 2 files changed, 16 insertions(+), 8 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +6 -3
index 283d25fae79e7..ff1674eff7ad5 100644
@@ -1677,16 +1677,19 @@ static void fbnic_mbx_process_rx_msgs(struct fbnic_dev *fbd)
 		if (!length)
 			goto next_page;
 
-		/* Report descriptors with length greater than page size */
-		if (length > PAGE_SIZE) {
+		/* Report descriptors with invalid message extents. */
+		if (length < sizeof(msg->hdr) || length > PAGE_SIZE) {
 			dev_warn(fbd->dev,
 				 "Invalid mailbox descriptor length: %lld\n",
 				 length);
 			goto next_page;
 		}
 
-		if (le16_to_cpu(msg->hdr.len) * sizeof(u32) > length)
+		if (!le16_to_cpu(msg->hdr.len) ||
+		    le16_to_cpu(msg->hdr.len) * sizeof(u32) > length) {
 			dev_warn(fbd->dev, "Mailbox message length mismatch\n");
+			goto next_page;
+		}
 
 		/* If parsing fails dump contents of message to dmesg */
 		err = fbnic_tlv_msg_parse(fbd, msg, fbnic_fw_tlv_parser);
drivers/net/ethernet/meta/fbnic/fbnic_tlv.c +10 -5
index c55d4f76a5fc0..639f90664d982 100644
@@ -427,9 +427,12 @@ int fbnic_tlv_attr_parse_array(struct fbnic_tlv_msg *attr, int len,
 	/* Work through list of attributes, parsing them as necessary */
 	while (len > 0) {
 		u16 attr_id = attr->hdr.type;
-		u16 attr_len;
+		u16 attr_len = FBNIC_TLV_MSG_SIZE(le16_to_cpu(attr->hdr.len));
 		int err;
 
+		if (!attr_len || attr_len > len)
+			return -EINVAL;
+
 		if (tlv_attr_id != attr_id)
 			return -EINVAL;
 
@@ -443,7 +446,6 @@ int fbnic_tlv_attr_parse_array(struct fbnic_tlv_msg *attr, int len,
 
 		results[i++] = attr;
 
-		attr_len = FBNIC_TLV_MSG_SIZE(le16_to_cpu(attr->hdr.len));
 		len -= attr_len;
 		attr += attr_len;
 	}
@@ -476,11 +478,15 @@ int fbnic_tlv_attr_parse(struct fbnic_tlv_msg *attr, int len,
 
 	/* Work through list of attributes, parsing them as necessary */
 	while (len > 0) {
-		int err = fbnic_tlv_attr_validate(attr, tlv_index);
 		u16 attr_id = attr->hdr.type;
-		u16 attr_len;
+		u16 attr_len = FBNIC_TLV_MSG_SIZE(le16_to_cpu(attr->hdr.len));
+		int err;
+
+		if (!attr_len || attr_len > len)
+			return -EINVAL;
 
 		/* Stop parsing on full error */
+		err = fbnic_tlv_attr_validate(attr, tlv_index);
 		if (err < 0)
 			return err;
 
@@ -493,7 +499,6 @@ int fbnic_tlv_attr_parse(struct fbnic_tlv_msg *attr, int len,
 			results[attr_id] = attr;
 		}
 
-		attr_len = FBNIC_TLV_MSG_SIZE(le16_to_cpu(attr->hdr.len));
 		len -= attr_len;
 		attr += attr_len;
 	}

base-commit: 08dbfad3f5040f5bdb6c529da20d6d4e81fefd72

Signature · 1 line
2.50.1
#1 lore raw
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Sun, 30 Aug 2026 22:24:58 +0800 you wrote:

The mailbox path warns when a message claims more bytes than the descriptor but still parses it. The attribute walkers also validate a child TLV before proving that its declared span fits in the parent remainder.

Reject invalid mailbox message extents and bound each child attribute before type-specific validation.

[...]

Here is the summary with links:
- net: fbnic: validate mailbox TLV extents

    https://git.kernel.org/netdev/net-next/c/c29b37ed7a4d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html