From: Weigang He <geoffreyhe2@gmail.com>
To: Madalin Bucur <madalin.bucur@nxp.com>
Cc: Sean Anderson <sean.anderson@linux.dev>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Weigang He <geoffreyhe2@gmail.com>
Subject: [PATCH net] fsl/fman: validate the port id in fman_set_port_params()
Date: Sat, 26 Sep 2026 15:39:57 +1000 [thread overview]
Message-ID: <20260926053957.1628730-1-geoffreyhe2@gmail.com> (raw)
fman_set_port_params() uses the port id, which comes from the device
tree "cell-index" property, to index fixed-size tables without
validating it:
set_port_liodn(fman, port_id, fman->liodn_base[port_id],
fman->liodn_offset[port_id]);
...
mac_id = hw_port_id_to_sw_port_id(fman->state->rev_info.major, port_id);
if (port_params->max_frame_length >= fman->state->mac_mfl[mac_id]) {
fman->state->port_mfl[mac_id] = port_params->max_frame_length;
liodn_base[] and liodn_offset[] have FMAN_LIODN_TBL (64) entries, and
set_port_liodn() also accesses fmbm_spliodn[port_id - 1]. mac_mfl[] and
port_mfl[] have MAX_NUM_OF_MACS (10) entries, but
hw_port_id_to_sw_port_id() maps, for example, RX port id 0x12 to 10 and
TX port id 0x3f to 23. fman_port_probe() truncates the property to a u8
and does not otherwise check it, so a device tree with a bad cell-index
can cause out-of-bounds accesses.
Reject a port id of 0, a port id outside the LIODN table, and a port id
that does not map to a MAC, before any state or register is changed. A
cell-index above 0xff that aliases a valid id after the u8 truncation
is not caught here.
Found by static analysis tool CodeQL.
Fixes: 414fd46e7762 ("fsl/fman: Add FMan support")
Assisted-by: LLM codeql
Signed-off-by: Weigang He <geoffreyhe2@gmail.com>
---
Notes:
Compile-tested only (ARCH=arm64 and ARCH=x86_64 allmodconfig, W=1). Not
tested on hardware, and there is no reproducer.
The CodeQL query behind this report was synthesized with LLM assistance,
and the fix and changelog were drafted with LLM assistance; I have
reviewed them.
drivers/net/ethernet/freescale/fman/fman.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/freescale/fman/fman.c b/drivers/net/ethernet/freescale/fman/fman.c
index 46cc28895e565..e25050189b1f3 100644
--- a/drivers/net/ethernet/freescale/fman/fman.c
+++ b/drivers/net/ethernet/freescale/fman/fman.c
@@ -2103,6 +2103,18 @@ int fman_set_port_params(struct fman *fman,
unsigned long flags;
u8 port_id = port_params->port_id, mac_id;
+ /*
+ * port_id comes from the device tree: reject ids outside the LIODN
+ * table and ids that do not map to a MAC.
+ */
+ mac_id = hw_port_id_to_sw_port_id(fman->state->rev_info.major, port_id);
+ if (port_id == 0 || port_id >= FMAN_LIODN_TBL ||
+ mac_id >= MAX_NUM_OF_MACS) {
+ dev_err(fman->dev, "%s: invalid port id %u\n", __func__,
+ port_id);
+ return -EINVAL;
+ }
+
spin_lock_irqsave(&fman->spinlock, flags);
err = set_num_of_tasks(fman, port_params->port_id,
@@ -2170,8 +2182,6 @@ int fman_set_port_params(struct fman *fman,
if (fman->state->rev_info.major < 6)
set_port_order_restoration(fman->fpm_regs, port_id);
- mac_id = hw_port_id_to_sw_port_id(fman->state->rev_info.major, port_id);
-
if (port_params->max_frame_length >= fman->state->mac_mfl[mac_id]) {
fman->state->port_mfl[mac_id] = port_params->max_frame_length;
} else {
base-commit: 165768bb70265b5c38cf0b73fafd75be235f8b14
--
2.43.0
next reply other threads:[~2026-09-26 5:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 5:39 Weigang He [this message]
2026-09-30 12:41 ` netdev-bot+sashiko
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=20260926053957.1628730-1-geoffreyhe2@gmail.com \
--to=geoffreyhe2@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=madalin.bucur@nxp.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sean.anderson@linux.dev \
/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®