Article View: linux.kernel.netdev
Article #21195Re: [PATCH net] octeontx2-af: Fix uninitialized variables and bounds in MCS alloc handlers
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 17:38
Date: Mon, 23 Nov 2026 17:38
201 lines
15175 bytes
15175 bytes
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
Technical Details
Message-ID:
<179545553181.3135.4354699424439095142@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369623-linux-kernel-netdev=dewy.ruReferences:
<20261119170550.1517634-1-irogers@google.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369623-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] octeontx2-af: Fix uninitialized variables and bounds in MCS alloc handlers Date: Mon, 23 Nov 2026 17:38:51 +0000 Organization: Usenet Network Message-ID: <179545553181.3135.4354699424439095142@kernel.org> References: <20261119170550.1517634-1-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3942494"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:aN29jcKZq0gPYyWzJPhuGC5jbyc= sha256:G+e7xncPrkQyFjR/674fyPzmZ816UZr2UB3qKd7x0MU= sha1:cSgzs5/1sckfr94jZehYM16+phA= sha256:knN4oxm758VGX3bERro+WX7ROG5a8vdW28+k47wa7ik= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id D0123125DC1; Mon, 23 Nov 2026 20:39:19 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YldwWIPePc7R; Mon, 23 Nov 2026 20:39:11 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-369623-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 3AE73125DC0; Mon, 23 Nov 2026 20:39:02 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id CD808271A6; Mon, 23 Nov 2026 17:38:59 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795455539; b=xR6TMZfKHgc7YYr9pPTGpTjsCiAEGHa9DzC2kJT27Htm45z12fnc3o0sGnBnm+pUSJUs 5JY0TufDAgwHky3Ep6ElVIYKAlX/INi4TbATkEkvUIbedx5J0IkIRatibIDsPXoB1tKGV 3LKLMDNGS7AT9mqHMFk8ZPK5Dl0MJ3+FT/X8LhVEpjtdesMuO6efJ1h2nSn97vjrR9LIP RX9W/tN1NScK2ZdmItqm0IBV05S0QLgtv9EFb0KgVqA3Cnchss80unujseTyhiB6NQtSy tZsxSUHgAJNG6NRrQaUNnHsSnGYL/zF6MRkK+U+CnQa684/E7HYAflXSG0hkq7P+pqw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795455539; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=M1jT+G0VMSaygnsbEE6grX37J+IeCer1lhkCNoYHZC0=; b=UjiDFViQtHpakBrLJTAwCblZ6klsyud8ldZRR7qw4pFa4PWL/VAXSulY018q+knyKy1U y9qcRWyn+DELz0oT0FRMntH4Rcb4+H0rWS76OVVPZ/8IlXhp1au73ah5OdJ4Bt3PfiJFd EAbvDsqWuWImBm5h2mOg9ZUUjvRUQy98SKYSBAh4Y1mKBtf5jY8DHHGmevKbLNA665GSC qKSaAE1aU9yrB8znbr2iD9K1GHMUfK5OMtZY54yKf9ro13zM+R/fAMx3R8DOWehbHagwg 93Q6jCyazVrKDcpXK2tUVkBZx96w9/ZBuml+/rYr6GQXcQ7XesdCkcTXx4GOoOYmMEg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hn5Guuht; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C85A606A330; Mon, 23 Nov 2026 17:38:59 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hn5Guuht X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795455533; b=iElvBbnrhsQZ0pnMZ/McU697ymaicENmF5kt4uo5KHqRq66smgdW1sNtDzBPxPJ9ajrt AKzfjGntjHgxa+1r8jnEqCNRfzwTMASinJrSb+co0SbIs4tNM3z89kbMs8whDI9Fkata3 RcQnzBJnpHslYUU5tnf4aMsP2ieuqblPtLgw70zPSQvRNs/QXYsVt4ZoZS53mYjFq5GK6 hurSDx9tUCpXOrA7zCV0TrDkq7zYjK49qo8TXsLGDyss7ZURzkDgfjNSuhtoo2rPeHJBH DMOoM3faI6OltXWG9MBKqh4GDQ5JBxLA1rUJ+VZqlXbt09cNXRgqdiaD3RdiNSFHyhg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795455533; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=M1jT+G0VMSaygnsbEE6grX37J+IeCer1lhkCNoYHZC0=; b=N9HJ7vec1xQ2OSR+lBo9MPaghVRe2+1XTQUzt5VbF8YNKg3un/aOUoNSrJl8KvIsZc2t Rf66fWNSJiW2S9ArbBnmL4sb31Zk72wLLCQhLPCkjWzM/qo20eKd3JsSEDHClcS5rKR3N 5Ml5SgEK7bPb0mnIYn1755T5SrNo3vSNYJPCKtrXzAKIi0mhsWKFEgcjDUFio98yeslJW Dr5SeDUHsYsmBI8N85WkRfF3oOW99GFzWbKW5M1rGmFKY4C5yssSJbCzWkxLTJCqdr6RE /InbltYstgPoJ6rNEsEHS3YFG25im0PoMQ1p2c5v7qjYicBFIigpTMI9lV+tQ/UuVSQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hn5Guuht; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C903606A31E; Mon, 23 Nov 2026 17:38:53 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E1F81F000EF; Mon, 23 Nov 2026 17:38:52 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795455533; bh=M1jT+G0VMSaygnsbEE6grX37J+IeCer1lhkCNoYHZC0=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=hn5GuuhtF0Nvk2GInTT7DzQmBJO45Vi+1AfuM9SkeHqb+wIg6t/2Y1gu5EVJ5DvL7 uJYxgTWAmJNOmvt2L+h9DX6+N0zCDfrVUAMWLD7woBg17IPPxfn4tBRfDc/7vQzk/M T56Cq7wGNnPyOFqAwk23oW0r+wkyPF8xlOCh3NpwnzwyDxoCUnpT2exnJSuevCw2QX 1d3y+X0mw1Bphf9phmTDJUEwds0m8po7FxjRjjuBZ29QgQqUyjBBG1rpi/SqCcBFLo 4iEkM89mLA3TTWVfAYW5nOGBCV44tNXHQD9oe8rkpCtBpTACr21GwubOjsdLiIhPnS 5BjbIETev9FyQ== X-Cc: sgoutham@marvell.com, rkannoth@marvell.com, gakula@marvell.com, sbhatta@marvell.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, elkin@google.com X-In-Reply-To: <20261119170550.1517634-1-irogers@google.com> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list