From: Danesh Petigara <danesh.petigara@broadcom.com>
To: florian.fainelli@broadcom.com, jonas.gorski@gmail.com,
andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com
Cc: vivien.didelot@gmail.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Justin Chen <justin.chen@broadcom.com>,
Danesh Petigara <danesh.petigara@broadcom.com>
Subject: [PATCH net] net: dsa: bcm_sf2_cfp: fix NULL deref when port_num is out of bounds
Date: Fri, 4 Sep 2026 18:34:04 -0700 [thread overview]
Message-ID: <20260905013404.2712866-1-danesh.petigara@broadcom.com> (raw)
From: Justin Chen <justin.chen@broadcom.com>
bcm_sf2_cfp_rule_insert() validates port_num against
priv->hw_params.num_ports, but the bounds check was placed after the
calls to dsa_is_user_port() and dsa_is_cpu_port():
if (ring_cookie == RX_CLS_FLOW_DISC ||
!(dsa_is_user_port(ds, port_num) ||
dsa_is_cpu_port(ds, port_num)) ||
port_num >= priv->hw_params.num_ports)
Both helpers call dsa_to_port(), which iterates the port list and
returns NULL if no entry matches. With a user-supplied ring_cookie
large enough to produce an out-of-bounds port_num, dsa_to_port()
returns NULL and the immediate ->type dereference faults.
Move the bounds check first so dsa_is_user_port()/dsa_is_cpu_port()
are never reached with an invalid port_num.
Fixes: 4a5b85ffe2a0 ("net: dsa: use dsa_is_user_port everywhere")
Signed-off-by: Justin Chen <justin.chen@broadcom.com>
Assisted-by: Claude:claude-sonnet-4-6 vscode
Signed-off-by: Danesh Petigara <danesh.petigara@broadcom.com>
---
drivers/net/dsa/bcm_sf2_cfp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/dsa/bcm_sf2_cfp.c b/drivers/net/dsa/bcm_sf2_cfp.c
index 84a086c3e99b..6ac5cf154f31 100644
--- a/drivers/net/dsa/bcm_sf2_cfp.c
+++ b/drivers/net/dsa/bcm_sf2_cfp.c
@@ -867,9 +867,9 @@ static int bcm_sf2_cfp_rule_insert(struct dsa_switch *ds, int port,
port_num = ring_cookie / SF2_NUM_EGRESS_QUEUES;
if (ring_cookie == RX_CLS_FLOW_DISC ||
+ port_num >= priv->hw_params.num_ports ||
!(dsa_is_user_port(ds, port_num) ||
- dsa_is_cpu_port(ds, port_num)) ||
- port_num >= priv->hw_params.num_ports)
+ dsa_is_cpu_port(ds, port_num)))
return -EINVAL;
/* If the rule is matching a particular VLAN, make sure that we honor
--
2.54.0
next reply other threads:[~2026-09-05 1:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 1:34 Danesh Petigara [this message]
2026-09-06 10:06 ` [PATCH net] net: dsa: bcm_sf2_cfp: fix NULL deref when port_num is out of bounds Jonas Gorski
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=20260905013404.2712866-1-danesh.petigara@broadcom.com \
--to=danesh.petigara@broadcom.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=florian.fainelli@broadcom.com \
--cc=jonas.gorski@gmail.com \
--cc=justin.chen@broadcom.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=vivien.didelot@gmail.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