* [PATCH net] octeontx2-af: Fix uninitialized variables and bounds in MCS alloc handlers
@ 2026-11-19 17:05 Ian Rogers
2026-11-23 17:38 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Ian Rogers @ 2026-11-19 17:05 UTC (permalink / raw)
To: Sunil Goutham, Ratheesh Kannoth, Geetha sowjanya,
Subbaraya Sundeep, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, llvm, Elkin Cruz, Ian Rogers
In rvu_mbox_handler_mcs_alloc_ctrl_pkt_rule(), switch (req->rule_type) has
no default case; an unrecognized rule_type in a PF/VF mailbox request
leaves 'offset' uninitialized when passed to mcs_alloc_ctrlpktrule(),
allocating rules from the wrong hardware partition or failing spuriously.
In rvu_mbox_handler_mcs_alloc_resources(), 'rsrc_id' is left uninitialized
when !req->all and either req->rsrc_cnt == 0 or req->rsrc_type is not one
of the four handled types. Moreover, req->rsrc_cnt (u8, 0..255) is not
checked against the 128-element rsp->flow_ids, rsp->secy_ids, and
rsp->sc_ids response arrays before writing into them.
Reject invalid rule_type, unrecognized rsrc_type, zero rsrc_cnt when
!req->all, and rsrc_cnt values exceeding the corresponding response array
bounds.
Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
-Wconditional-uninitialized enabled; fix and changelog drafted with an AI
coding assistant. Build-tested under LLVM=1 W=1 and
-Wconditional-uninitialized; not tested on Marvell CN10K hardware.
Fixes: cfc14181d497 ("octeontx2-af: cn10k: mcs: Manage the MCS block hardware resources")
Signed-off-by: Ian Rogers <irogers@google.com>
---
.../ethernet/marvell/octeontx2/af/mcs_rvu_if.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c b/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c
index cd9cca5a9cf5..54c1d9809ae6 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c
@@ -682,12 +682,15 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
{
u16 pcifunc = req->hdr.pcifunc;
struct mcs_rsrc_map *map;
+ int rsrc_id = -EINVAL, i;
struct mcs *mcs;
- int rsrc_id, i;
if (req->mcs_id >= rvu->mcs_blk_cnt)
return MCS_AF_ERR_INVALID_MCSID;
+ if (!req->all && !req->rsrc_cnt)
+ return -EINVAL;
+
mcs = mcs_get_pdata(req->mcs_id);
if (req->dir == MCS_RX)
@@ -709,6 +712,8 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
switch (req->rsrc_type) {
case MCS_RSRC_TYPE_FLOWID:
+ if (req->rsrc_cnt > ARRAY_SIZE(rsp->flow_ids))
+ goto exit;
for (i = 0; i < req->rsrc_cnt; i++) {
rsrc_id = mcs_alloc_rsrc(&map->flow_ids, map->flowid2pf_map, pcifunc);
if (rsrc_id < 0)
@@ -718,6 +723,8 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
}
break;
case MCS_RSRC_TYPE_SECY:
+ if (req->rsrc_cnt > ARRAY_SIZE(rsp->secy_ids))
+ goto exit;
for (i = 0; i < req->rsrc_cnt; i++) {
rsrc_id = mcs_alloc_rsrc(&map->secy, map->secy2pf_map, pcifunc);
if (rsrc_id < 0)
@@ -727,6 +734,8 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
}
break;
case MCS_RSRC_TYPE_SC:
+ if (req->rsrc_cnt > ARRAY_SIZE(rsp->sc_ids))
+ goto exit;
for (i = 0; i < req->rsrc_cnt; i++) {
rsrc_id = mcs_alloc_rsrc(&map->sc, map->sc2pf_map, pcifunc);
if (rsrc_id < 0)
@@ -744,6 +753,8 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
rsp->rsrc_cnt++;
}
break;
+ default:
+ goto exit;
}
rsp->rsrc_type = req->rsrc_type;
@@ -793,6 +804,9 @@ int rvu_mbox_handler_mcs_alloc_ctrl_pkt_rule(struct rvu *rvu,
case MCS_CTRL_PKT_RULE_TYPE_MAC:
offset = MCS_CTRLPKT_MAC_EN_RULE_OFFSET;
break;
+ default:
+ rsrc_id = -EINVAL;
+ goto exit;
}
rsrc_id = mcs_alloc_ctrlpktrule(&map->ctrlpktrule, map->ctrlpktrule2pf_map, offset,
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH net] octeontx2-af: Fix uninitialized variables and bounds in MCS alloc handlers
2026-11-19 17:05 [PATCH net] octeontx2-af: Fix uninitialized variables and bounds in MCS alloc handlers Ian Rogers
@ 2026-11-23 17:38 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 17:38 UTC (permalink / raw)
To: irogers
Cc: sgoutham, rkannoth, gakula, sbhatta, andrew+netdev, davem,
edumazet, kuba, pabeni, netdev, linux-kernel, llvm, elkin
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 (1) · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In rvu_mbox_handler_mcs_alloc_resources(), two of the new
rejection paths still report success over the mailbox.
- [Low] The commit message presents the missing check of req->rsrc_cnt
against the 128-element rsp->flow_ids/secy_ids/sc_ids arrays in…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the sibling
free handler in the same file has the bug class this patch fixes in…
--
octeontx2-af: Fix uninitialized variables and bounds in MCS alloc handlers
This adds a default case to the rule_type switch in
rvu_mbox_handler_mcs_alloc_ctrl_pkt_rule(), so an unknown rule_type no
longer passes an uninitialized offset. In
rvu_mbox_handler_mcs_alloc_resources() it initializes rsrc_id, rejects a
zero rsrc_cnt and an unknown rsrc_type, and checks rsrc_cnt against the
128-entry response arrays.
> In rvu_mbox_handler_mcs_alloc_resources(), 'rsrc_id' is left uninitialized
> when !req->all and either req->rsrc_cnt == 0 or req->rsrc_type is not one
> of the four handled types. Moreover, req->rsrc_cnt (u8, 0..255) is not
> checked against the 128-element rsp->flow_ids, rsp->secy_ids, and
> rsp->sc_ids response arrays before writing into them.
[Severity: Low]
Can the response array overflow described here actually happen today?
Each loop iteration calls mcs_alloc_rsrc()->rvu_alloc_rsrc(), which fails
once the bitmap is full:
rvu_alloc_rsrc() {
...
id = find_first_zero_bit(rsrc->bmap, rsrc->max);
if (id >= rsrc->max)
return -ENOSPC;
...
}
When that happens, the loop does goto exit before it writes rsp->*_ids[i].
mcs_alloc_struct_mem() sets the bitmap sizes from the hardware:
res->flow_ids.max = hw->tcam_entries - MCS_RSRC_RSVD_CNT;
...
res->secy.max = hw->secy_entries - MCS_RSRC_RSVD_CNT;
...
res->sc.max = hw->sc_entries;
That is 127/127/128 on CN10K and 63/63/64 on CNF10KB. These bitmaps are
shared by all PF/VFs, so the index i never goes past 127.
Given that, the new ARRAY_SIZE() checks look like hardening rather than a
fix for an overflow someone can trigger. With the Fixes: tag on the patch,
could the changelog say this more precisely?
The changelog also leaves out a behaviour change. An oversized request
(for example rsrc_cnt = 200) used to get every free entry as a partial
allocation. Now it gets nothing.
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c b/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c
> index cd9cca5a9cf5c..54c1d9809ae69 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c
> @@ -682,12 +682,15 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
> {
> u16 pcifunc = req->hdr.pcifunc;
> struct mcs_rsrc_map *map;
> + int rsrc_id = -EINVAL, i;
> struct mcs *mcs;
> - int rsrc_id, i;
>
> if (req->mcs_id >= rvu->mcs_blk_cnt)
> return MCS_AF_ERR_INVALID_MCSID;
>
> + if (!req->all && !req->rsrc_cnt)
> + return -EINVAL;
> +
> mcs = mcs_get_pdata(req->mcs_id);
>
> if (req->dir == MCS_RX)
> @@ -709,6 +712,8 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
>
> switch (req->rsrc_type) {
> case MCS_RSRC_TYPE_FLOWID:
> + if (req->rsrc_cnt > ARRAY_SIZE(rsp->flow_ids))
> + goto exit;
> for (i = 0; i < req->rsrc_cnt; i++) {
> rsrc_id = mcs_alloc_rsrc(&map->flow_ids, map->flowid2pf_map, pcifunc);
> if (rsrc_id < 0)
[ ... ]
> @@ -744,6 +753,8 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
> rsp->rsrc_cnt++;
> }
> break;
> + default:
> + goto exit;
> }
[Severity: Medium]
Does the requester actually see these rejections as errors?
This default case and the new rsrc_cnt > ARRAY_SIZE() checks both jump to
the exit label, which always returns 0:
exit:
if (rsrc_id < 0)
dev_err(rvu->dev, "Failed to allocate the mcs resources for PCIFUNC:%d\n", pcifunc);
mutex_unlock(&rvu->rsrc_lock);
return 0;
The M() mbox dispatch macro in rvu.c sets rsp->hdr.rc only when the
handler returns non-zero:
if (rsp && err)
rsp->hdr.rc = err;
As a result, the PF/VF gets hdr.rc == 0, rsp->rsrc_cnt == 0, and zeroed
rsrc_type/dir/mcs_id fields.
The new zero-count check earlier in this function returns -EINVAL
directly. The new default case in rvu_mbox_handler_mcs_alloc_ctrl_pkt_rule()
also returns -EINVAL. Should these paths return an error too, so that
invalid input is reported the same way throughout?
cn10k_mcs_alloc_rsrc() in nic/cn10k_macsec.c compares the response fields
with its request, so it would catch this. A requester that checks only
hdr.rc would treat the rejected request as a successful allocation.
[ ... ]
[Severity: High]
This is a pre-existing issue and was not introduced by this patch. The
free handler just above, rvu_mbox_handler_mcs_free_resources(), has the
same kind of problem this patch addresses: a mailbox-supplied index into
fixed-size arrays with no validation.
The handler passes the PF/VF-supplied u8 req->rsrc_id (0..255) straight
through:
case MCS_RSRC_TYPE_FLOWID:
rc = mcs_free_rsrc(&map->flow_ids, map->flowid2pf_map, req->rsrc_id, pcifunc);
mcs_ena_dis_flowid_entry(mcs, req->rsrc_id, req->dir, false);
break;
mcs_free_rsrc() then indexes pf_map without checking against rsrc->max:
int mcs_free_rsrc(struct rsrc_bmap *rsrc, u16 *pf_map, int rsrc_id, u16 pcifunc)
{
/* Check if the rsrc_id is mapped to PF/VF */
if (pf_map[rsrc_id] != pcifunc)
return -EINVAL;
rvu_free_rsrc(rsrc, rsrc_id);
pf_map[rsrc_id] = 0;
return 0;
}
mcs_alloc_struct_mem() sizes the pf_map arrays from the hardware entry
counts:
res->flowid2pf_map = alloc_mem(mcs, hw->tcam_entries);
For flowid/secy/sc that is 128 entries on CN10K and 64 on CNF10KB. SA is
128 entries on CNF10KB.
Can a FLOWID/SECY/SC request with rsrc_id >= 128 (>= 64 on CNF10KB) read
past the end of these allocations?
If the out-of-bounds u16 happens to equal the requester's pcifunc,
rvu_free_rsrc() clears a bit past the end of the bitmap. The
pf_map[rsrc_id] = 0 store then writes past the end of pf_map. Could that
corrupt neighbouring slab objects?
There is also a separate problem. The handler calls
mcs_ena_dis_flowid_entry(), mcs_clear_secy_plcy() and
mcs_ena_dis_sc_cam_entry() no matter what rc is. Suppose mcs_free_rsrc()
returns -EINVAL because the caller doesn't own the entry. Can the PF/VF
still disable another function's flow TCAM entry, clear another
function's SecY policy, or disable another function's RX SC CAM entry?
VF requests reach this handler through otx2_forward_vf_mbox_msgs(), which
only rewrites pcifunc.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119170550.1517634-1-irogers%40google.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 17:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 17:05 [PATCH net] octeontx2-af: Fix uninitialized variables and bounds in MCS alloc handlers Ian Rogers
2026-11-23 17:38 ` netdev-bot+sashiko
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®