Netdev List
 help / color / mirror / Atom feed
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 v17 net-next 6/8] octeontx2-af: npc: Support for custom KPU profile from filesystem
Date: Tue, 2 Jun 2026 09:43:08 +0530	[thread overview]
Message-ID: <ah5YVLE6cWu-tyMd@rkannoth-OptiPlex-7090> (raw)
In-Reply-To: <20260601025844.865865-7-rkannoth@marvell.com>

On 2026-06-01 at 08:28:41, Ratheesh Kannoth (rkannoth@marvell.com) wrote:
> Flashing updated firmware on deployed devices is cumbersome. Provide a
> mechanism to load a custom KPU (Key Parse Unit) profile directly from
> the filesystem at module load time.

>> +	struct npc_kpu_profile_adapter *adapter = &rvu->kpu;
>> +	struct npc_kpu_profile *kpu;
>> +
>> +	kpu = &adapter->kpu[kpu_num];
>> +
>> +	kpu->cam2 = devm_kcalloc(rvu->dev, num_entries,
>> +				 sizeof(*kpu->cam2), GFP_KERNEL);
>Is it safe to store devm-allocated pointers into this kpu structure?
>Looking at npc_prepare_default_kpu(), the profile->kpu pointer is
>assigned to npc_kpu_profiles, which is a global static array.
>When memory bounded to a specific device via devm_kcalloc is stored
>in this global array, won't multiple devices race to overwrite these
>pointers? Additionally, if the device unbinds, devres will free the memory,
>leaving dangling pointers in the global array that could cause a
>use-after-free for other devices on the system.

There is only one AF device per system.

>> +	struct npc_kpu_profile_cam *cam;
>> +	struct npc_kpu_fwdata *fw_kpu;
>> +	int entries, entry, kpu;
>>
>> -	if (is_cn20k(rvu->pdev))
>> -		return npc_cn20k_apply_custom_kpu(rvu, profile);
>> +	fw = rvu->kpu_fwdata;
>>
>> +	for (kpu = 0; kpu < fw->kpus; kpu++) {
>> +		if (rvu->kpu_fwdata_sz < hdr_sz + offset) {
>This is a pre-existing issue, but does this bounds check guarantee enough
>space to safely read fw_kpu->entries below?
>The check ensures the offset reaches the start of the fw_kpu structure,
>but it doesn't appear to verify there are at least sizeof(*fw_kpu) bytes
>remaining in the buffer. If the firmware image is truncated exactly
>at this boundary, could dereferencing fw_kpu->entries read out of
>bounds?
Pre existing issue; a seperate bug fix patch will be posted to net tree once this series
is merged.

>> +		if (fw_kpu->entries > KPU_MAX_CST_ENT)
>> +			dev_warn(rvu->dev,
>> +				 "Too many custom entries on KPU%d: %d > %d\n",
>> +				 kpu, fw_kpu->entries, KPU_MAX_CST_ENT);
>> +		entries = min_t(int, fw_kpu->entries, KPU_MAX_CST_ENT);
>> +		cam = (struct npc_kpu_profile_cam *)fw_kpu->data;
>> +		offset += sizeof(*fw_kpu) + fw_kpu->entries * sizeof(*cam);
>> +		action = (struct npc_kpu_profile_action *)(fw->data + offset);
>> +		offset += fw_kpu->entries * sizeof(*action);
>This is a pre-existing issue, but could the offset calculation overflow
>on 32-bit architectures?
Pre existing issue; a seperate bug fix patch will be posted to net tree once this series
is merged.

>The expression sizeof(*fw_kpu) + fw_kpu->entries * sizeof(*cam)
>evaluates as a 32-bit unsigned size_t. If a maliciously large value is
>provided for fw_kpu->entries, the multiplication could wrap around,
>producing a small offset that passes the bounds check below, leading to
>out-of-bounds memory reads when copying the entries.<F11>
>> +		if (rvu->kpu_fwdata_sz < hdr_sz + offset) {
>> +			dev_warn(rvu->dev,
>> +				 "Profile size mismatch on KPU%i parsing.\n",
>> +				 kpu + 1);
>> +			return -EINVAL;
>> +		}
>> +		for (entry = 0; entry < entries; entry++) {
>> +			profile->kpu[kpu].cam[entry] = cam[entry];
>> +			profile->kpu[kpu].action[entry] = action[entry];
>This is a pre-existing issue, but does this permanently corrupt the default
>built-in profile?

Pre existing issue; a seperate bug fix patch will be posted to net tree once this series
is merged.

>> +	/* Binary blob contains ikpu actions entries at start of data[0] */
>> +	profile->ikpu2 = devm_kcalloc(rvu->dev, 1,
>> +				      sizeof(ikpu_action_entries),
>> +				      GFP_KERNEL);
>> +	if (!profile->ikpu2)
>> +		return -ENOMEM;
>> +
>> +	action = (struct npc_kpu_profile_action *)(fw->data + offset);
>> +
>> +	if (rvu->kpu_fwdata_sz < hdr_sz + sizeof(ikpu_action_entries))
>> +		return -EINVAL;
>> +
>> +	/* The firmware layout does dependent on the internal size of
>> +	 * ikpu_action_entries.
>> +	 */
>> +	memcpy((void *)profile->ikpu2, action, sizeof(ikpu_action_entries));
>> +	offset += sizeof(ikpu_action_entries);
>Will tying the firmware binary layout directly to the size of an
>internal kernel compilation constant cause backward compatibility issues?
We can't change ikpu structure to add another field as it will break backward compatability.
So we will keep same number of items in ikpu.

>	mkex_extr = rvu->kpu.mcam_kex_prfl.mkex_extr;
>> +	mkex = rvu->kpu.mcam_kex_prfl.mkex;
>> +
>>  	if (is_cn20k(rvu->pdev)) {
>> -		keyx_cfg = mkex_extr->keyx_cfg;
>> +		keyx_cfg = (u64 *)mkex_extr->keyx_cfg;
>>  	} else {
>> -		keyx_cfg = mkex->keyx_cfg;
>> +		keyx_cfg = (u64 *)mkex->keyx_cfg;
>This is a pre-existing issue, but does this cast away the const
>qualifier and modify read-only data? Both mkex_extr and mkex are typed
>as const, and frequently point to the global static npc_mkex_default profile.

Pre existing issue; a seperate bug fix patch will be posted to net tree once this series
is merged.

  reply	other threads:[~2026-06-02  4:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01  2:58 [PATCH v17 net-next 0/8] octeontx2-af: npc: Enhancements Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 1/8] octeontx2-af: npc: cn20k: debugfs enhancements Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 2/8] devlink: heap-allocate param fill buffers in devlink_nl_param_fill Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 3/8] devlink: Implement devlink param multi attribute nested data values Ratheesh Kannoth
2026-06-02  3:44   ` Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 4/8] octeontx2-af: npc: cn20k: add subbank search order control Ratheesh Kannoth
2026-06-02  4:06   ` Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 5/8] octeontx2: cn20k: Coordinate default rules with NIX LF lifecycle Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 6/8] octeontx2-af: npc: Support for custom KPU profile from filesystem Ratheesh Kannoth
2026-06-02  4:13   ` Ratheesh Kannoth [this message]
2026-06-01  2:58 ` [PATCH v17 net-next 7/8] octeontx2: cn20k: Respect NPC MCAM X2/X4 profile in flows and DFT alloc Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 8/8] octeontx2-af: npc: cn20k: Allocate npc_priv and dstats dynamically Ratheesh Kannoth
2026-06-02  4:20   ` 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=ah5YVLE6cWu-tyMd@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