Skip to contentSkip to conversation

net: bcmgenet: reject undersized RX classification rule buffers

PATCH Superseded Artemii Mashanov 3 participants 5 messages Nov 21

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: bcmgenet: reject undersized RX classification rule buffers

bcmgenet_get_rxnfc() returns success with an incomplete list of RX classification rules when ETHTOOL_GRXCLSRLALL receives fewer slots than the number of installed rules.

Return -EMSGSIZE when the next rule cannot fit in the caller's buffer. On success, report the actual number of copied rules.

The source-extracted ASan/UBSan regression tests passed.

Fixes 3e370952287c ("net: bcmgenet: add support for ethtool rxnfc flows")
---
 drivers/net/ethernet/broadcom/genet/bcmgenet.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +6 -4
index 4d2be2a..6a4a7fd 100644
@@ -1664,7 +1664,7 @@ static int bcmgenet_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
 	struct bcmgenet_priv *priv = netdev_priv(dev);
 	struct bcmgenet_rxnfc_rule *rule;
 	int err = 0;
-	int i = 0;
+	u32 i = 0;
 
 	switch (cmd->cmd) {
 	case ETHTOOL_GRXCLSRLCNT:
@@ -1675,9 +1675,11 @@ static int bcmgenet_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
 		err = bcmgenet_get_flow(dev, cmd, cmd->fs.location);
 		break;
 	case ETHTOOL_GRXCLSRLALL:
-		list_for_each_entry(rule, &priv->rxnfc_list, list)
-			if (i < cmd->rule_cnt)
-				rule_locs[i++] = rule->fs.location;
+		list_for_each_entry(rule, &priv->rxnfc_list, list) {
+			if (i == cmd->rule_cnt)
+				return -EMSGSIZE;
+			rule_locs[i++] = rule->fs.location;
+		}
 		cmd->rule_cnt = i;
 		cmd->data = MAX_NUM_OF_FS_RULES;
 		break;
Signature · 1 line
2.56.0
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
#2 lore raw

Hi,

A scripted source audit of ETHTOOL_GRXCLSRLALL handlers flagged this path. Reviewing bcmgenet_get_rxnfc() showed that it stops copying rule locations when the caller's buffer fills, then returns success with a partial list.

The original behavior was identified by source inspection. The ASan/UBSan tests exercised the patched handler in a standalone userspace harness. They verified that an undersized buffer returns -EMSGSIZE and that a successful call reports the actual number of locations copied.

An earlier revision built as genet.ko against Linux 7.4-rc2. I did not reproduce the issue through the ioctl on a running kernel or test the patch on GENET hardware.

Thanks,
Artemii

сб, 21 нояб. 2026 г. в 03:17, <[email protected]>:

Quoted 27 lines

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages. --
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

maintainer
#3 lore raw
In reply to Artemii Mashanov

Hi Artemii

Thanks for your patch.

Quoted 6 lines · Artemii Mashanov

bcmgenet_get_rxnfc() returns success with an incomplete list of RX classification rules when ETHTOOL_GRXCLSRLALL receives fewer slots than the number of installed rules.

Return -EMSGSIZE when the next rule cannot fit in the caller's buffer. On success, report the actual number of copied rules.

The loop already stops at rule_cnt, so nothing overflows. The short list only can happen if a rule is added between the count and dump ioctls - and then ethtool -n just shows one rule fewer.

Fine as a cleanup, but please resend for net-next without the Fixes tag.

Quoted 1 line

The source-extracted ASan/UBSan regression tests passed.

Please drop this line, it doesn't apply to the kernel change.

Quoted 1 line

[...]

Thanks,
Nicolai

#4 lore raw

Thanks for the review. I'll resend this for net-next and drop the Fixes tag.

Thanks,
Artemii

сб, 21 нояб. 2026 г. в 23:48, Nicolai Buchwitz <[email protected]>:

Quoted 27 lines

Hi Artemii

Thanks for your patch.

Quoted 6 lines · Artemii Mashanov

bcmgenet_get_rxnfc() returns success with an incomplete list of RX classification rules when ETHTOOL_GRXCLSRLALL receives fewer slots than the number of installed rules.

Return -EMSGSIZE when the next rule cannot fit in the caller's buffer. On success, report the actual number of copied rules.

The loop already stops at rule_cnt, so nothing overflows. The short list only can happen if a rule is added between the count and dump ioctls - and then ethtool -n just shows one rule fewer.

Fine as a cleanup, but please resend for net-next without the Fixes tag.

Quoted 1 line

The source-extracted ASan/UBSan regression tests passed.

Please drop this line, it doesn't apply to the kernel change.

Quoted 1 line

[...]

Thanks,
Nicolai