From: Ratheesh Kannoth <rkannoth@marvell.com>
To: <linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>
Cc: <andrew+netdev@lunn.ch>, <davem@davemloft.net>,
<donald.hunter@gmail.com>, <edumazet@google.com>,
<horms@kernel.org>, <jiri@resnulli.us>, <kuba@kernel.org>,
<pabeni@redhat.com>, <sgoutham@marvell.com>
Subject: Re: [PATCH v18 net-next 1/8] octeontx2-af: npc: cn20k: debugfs enhancements
Date: Wed, 3 Jun 2026 11:49:19 +0530 [thread overview]
Message-ID: <ah_HZ56CUNPHO_sa@rkannoth-OptiPlex-7090> (raw)
In-Reply-To: <20260602060359.1894952-2-rkannoth@marvell.com>
On 2026-06-02 at 11:33:52, Ratheesh Kannoth (rkannoth@marvell.com) wrote:
> Improve MCAM visibility and field debugging for CN20K NPC.
>
> - Extend "mcam_layout" to show enabled (+) or disabled state per entry
> so status can be verified without parsing the full "mcam_entry" dump.
> - Add "dstats" debugfs entry: for enabled MCAM indices, print hit deltas
> since the prior read by comparing hardware counters to a per-entry
> software baseline and advancing that baseline after each read (hardware
> counters are not cleared).
> - Add "mismatch" debugfs entry: lists MCAM entries that are enabled
> but not explicitly allocated, helping diagnose allocation/field issues.
>
> Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
https://sashiko.dev/#/patchset/20260602060359.1894952-1-rkannoth%40marvell.com
sashiko says
>> + pf = 0xFFFF;
>> + map = xa_load(&npc_priv->xa_idx2pf_map, mcam_idx);
>> + if (map)
>> + pf = xa_to_value(map);
>> +
>> + delta = stats - dstats[bank][idx];
>> +
>> + snprintf(buff, sizeof(buff), "%u\t%#04x\t%llu\n",
>> + mcam_idx, pf, delta);
>> + seq_puts(s, buff);
>> +
>> + dstats[bank][idx] = stats;
>Does this code allow an out-of-bounds array access?
No.
>In npc_priv_init() (shown below), integer division truncation allows
>a hardware-supplied bank_depth to exceed statically allocated array
>dimensions. Because remainders are truncated, a bank_depth value such
>as 8223 (with num_subbanks = 32) yields subbank_depth = 256.
npc_priv_init() do check against max limit for MAX_BANKDEPTH and bail out on
error.
>I noticed this was fixed later in the series in commit "octeontx2-af: npc:
>cn20k: Allocate npc_priv and dstats dynamically.", but this patch
>introduces a concrete buffer overflow.
These checks are in the current patch itself.
>+update_en_map:
>> + if (enable)
>> + set_bit(index, npc_priv.en_map);
>Can index exceed the bitmap size here?
>Due to the same integer division truncation issue mentioned above, index
>can exceed the expected bounds, causing set_bit() to write beyond the
>statically allocated 16384 bits of npc_priv.en_map.
No. "en_map" bitmap is defined with MAXimum size possible. Check against these max limits
are done during probe (in npc_priv_init()) and returns error.
> subbank_depth = bank_depth / num_subbanks;
>> + if (subbank_depth > MAX_SUBBANK_DEPTH) {
>This is a pre-existing issue, but can this integer division evaluate to 0?
>If hardware reports a banksize (which becomes bank_depth) less than
>num_subbanks (e.g., 16 vs 32), the integer division evaluates to 0.
Pre-existing issue, so not addressing here. We need to check agaist zero, wll post
as a seperate patch to "net" tree, - or may be a hardening series.
next prev parent reply other threads:[~2026-06-03 6:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 6:03 [PATCH v18 net-next 0/8] octeontx2-af: npc: Enhancements Ratheesh Kannoth
2026-06-02 6:03 ` [PATCH v18 net-next 1/8] octeontx2-af: npc: cn20k: debugfs enhancements Ratheesh Kannoth
2026-06-03 6:19 ` Ratheesh Kannoth [this message]
2026-06-04 2:19 ` Ratheesh Kannoth
2026-06-04 14:45 ` Jakub Kicinski
2026-06-05 2:07 ` Ratheesh Kannoth
2026-06-02 6:03 ` [PATCH v18 net-next 2/8] devlink: heap-allocate param fill buffers in devlink_nl_param_fill Ratheesh Kannoth
2026-06-02 6:03 ` [PATCH v18 net-next 3/8] devlink: Implement devlink param multi attribute nested data values Ratheesh Kannoth
2026-06-02 6:03 ` [PATCH v18 net-next 4/8] octeontx2-af: npc: cn20k: add subbank search order control Ratheesh Kannoth
2026-06-04 2:34 ` Ratheesh Kannoth
2026-06-02 6:03 ` [PATCH v18 net-next 5/8] octeontx2: cn20k: Coordinate default rules with NIX LF lifecycle Ratheesh Kannoth
2026-06-03 6:37 ` Ratheesh Kannoth
2026-06-04 2:41 ` Ratheesh Kannoth
2026-06-02 6:03 ` [PATCH v18 net-next 6/8] octeontx2-af: npc: Support for custom KPU profile from filesystem Ratheesh Kannoth
2026-06-03 6:46 ` Ratheesh Kannoth
2026-06-04 3:07 ` Ratheesh Kannoth
2026-06-02 6:03 ` [PATCH v18 net-next 7/8] octeontx2: cn20k: Respect NPC MCAM X2/X4 profile in flows and DFT alloc Ratheesh Kannoth
2026-06-03 6:54 ` Ratheesh Kannoth
2026-06-04 3:16 ` Ratheesh Kannoth
2026-06-02 6:03 ` [PATCH v18 net-next 8/8] octeontx2-af: npc: cn20k: Allocate npc_priv and dstats dynamically Ratheesh Kannoth
2026-06-03 7:03 ` Ratheesh Kannoth
2026-06-04 3:21 ` Ratheesh Kannoth
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=ah_HZ56CUNPHO_sa@rkannoth-OptiPlex-7090 \
--to=rkannoth@marvell.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sgoutham@marvell.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