Skip to contentSkip to conversation

devlink: do not dereference a missing param item or shared buffer

PATCH Applied Linkui Xiao 4 participants 7 messages Nov 2 – Nov 6

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover devlink: do not dereference a missing param item or shared buffer

From: Linkui Xiao <[email protected]>

Two devlink helpers look an object up by id or index, warn when the lookup fails, and then pass the NULL result to code that dereferences it. A driver mistake (a param_id that was never registered, an sb_index that was never registered or is unregistered twice) therefore costs an oops instead of a warning.

1/2 param: devl_param_value_changed() hands the missing param item to

      devlink_param_notify() -> devlink_nl_param_fill(), whose first
      statement dereferences param_item->param.

2/2 sb: devl_sb_unregister() runs list_del() on the missing shared
buffer; list is the first member of struct devlink_sb, so it reads and writes through address 0.

In both cases every other user of the same lookup already returns right after the warning, so the fixes just align the remaining callers; there is no change of behavior beyond avoiding the dereference. The param side follows the example Jiri set for devlink_param_unregister():

Both Fixes: tags point at the commits that introduced the unguarded WARN_ON pattern; the current devl_() functions are pure renames of those originals. No in-tree caller triggers either path today (the audit is part of a defensive hardening pass), so both are aimed at stopping out-of-tree drivers from turning a driver bug into an oops.

v2:
- retargeted from net to net-next, as Simon suggested: with no in-tree caller able to reach either path this is hardening rather than a critical fix. No code change.
- collected Reviewed-by: Simon Horman on both patches.
- the Fixes: tags are kept so that stable can pick the commits up once they are in mainline.

Linkui Xiao (2):
devlink: param: do not dereference a missing param item
devlink: sb: do not dereference a missing shared buffer

 net/devlink/param.c | 3 ++-
 net/devlink/sb.c    | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/2 devlink: param: do not dereference a missing param item

From: Linkui Xiao <[email protected]>

devl_param_value_changed() looks the param item up by id and only warns when the lookup fails. devlink_param_notify() is called with the result regardless, and devlink_nl_param_fill() dereferences param_item->param in its very first statement, so a driver that passes a param_id which is not registered on this instance turns the warning into a NULL pointer dereference.

Every other user of devlink_param_find_by_id() handles the NULL result:
devlink_param_unregister() and devl_param_driverinit_value_set() return right after the same warning, devl_param_driverinit_value_get() returns -EINVAL. Do the same here so that a bogus param_id costs a warning instead of an oops.

---
v2: reposted against net-next at Simon's suggestion; no code change.

 net/devlink/param.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/devlink/param.c +2 -1
index 95ac9db8c993..474fe009f22d 100644
@@ -1008,7 +1008,8 @@ void devl_param_value_changed(struct devlink *devlink, u32 param_id)
 	struct devlink_param_item *param_item;
 
 	param_item = devlink_param_find_by_id(&devlink->params, param_id);
-	WARN_ON(!param_item);
+	if (WARN_ON(!param_item))
+		return;
 
 	devlink_param_notify(devlink, 0, param_item, DEVLINK_CMD_PARAM_NEW);
 }
Signature · 1 line
2.25.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH net-next v2 1/2] devlink: param: do not dereference a missing param item

Quoted 15 lines · Linkui Xiao

From: Linkui Xiao <[email protected]>

devl_param_value_changed() looks the param item up by id and only warns when the lookup fails. devlink_param_notify() is called with the result regardless, and devlink_nl_param_fill() dereferences param_item->param in its very first statement, so a driver that passes a param_id which is not registered on this instance turns the warning into a NULL pointer dereference.

Every other user of devlink_param_find_by_id() handles the NULL result:
devlink_param_unregister() and devl_param_driverinit_value_set() return right after the same warning, devl_param_driverinit_value_get() returns -EINVAL. Do the same here so that a bogus param_id costs a warning instead of an oops.

Quoted 7 lines

---
v2: reposted against net-next at Simon's suggestion; no code change.

#3 lore raw

PATCH v2 2/2 devlink: sb: do not dereference a missing shared buffer

In reply to Linkui Xiao

From: Linkui Xiao <[email protected]>

devl_sb_unregister() looks the shared buffer up by index and only warns when it is not on the list. list_del() and kfree() are then called on the NULL result, so unregistering an index that was never registered, or unregistering the same index twice, turns the warning into a NULL pointer dereference. list is the first member of struct devlink_sb, so list_del() reads the next and prev pointers from address 0 before storing to them.

The register side already fails gracefully: devl_sb_register() returns -EEXIST when the index is taken. Make the unregister side symmetric and return after the warning.

Fixes bf7974710a40 ("devlink: add shared buffer configuration")

---
v2: reposted against net-next at Simon's suggestion; no code change.

 net/devlink/sb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/devlink/sb.c +2 -1
index 129bd016e302..4b444f2ca0f5 100644
@@ -980,7 +980,8 @@ void devl_sb_unregister(struct devlink *devlink, unsigned int sb_index)
 	lockdep_assert_held(&devlink->lock);
 
 	devlink_sb = devlink_sb_get_by_index(devlink, sb_index);
-	WARN_ON(!devlink_sb);
+	if (WARN_ON(!devlink_sb))
+		return;
 	list_del(&devlink_sb->list);
 	kfree(devlink_sb);
 }
Signature · 1 line
2.25.1
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH net-next v2 2/2] devlink: sb: do not dereference a missing shared buffer

Quoted 13 lines · Linkui Xiao

From: Linkui Xiao <[email protected]>

devl_sb_unregister() looks the shared buffer up by index and only warns when it is not on the list. list_del() and kfree() are then called on the NULL result, so unregistering an index that was never registered, or unregistering the same index twice, turns the warning into a NULL pointer dereference. list is the first member of struct devlink_sb, so list_del() reads the next and prev pointers from address 0 before storing to them.

The register side already fails gracefully: devl_sb_register() returns -EEXIST when the index is taken. Make the unregister side symmetric and return after the warning.

Quoted 6 lines
Fixes bf7974710a40 ("devlink: add shared buffer configuration")

---
v2: reposted against net-next at Simon's suggestion; no code change.

maintainer
#5 lore raw
In reply to Linkui Xiao
Quoted 5 lines · On Mon, 2 Nov 2026 21:15:03 +0800 Linkui Xiao wrote:

Two devlink helpers look an object up by id or index, warn when the lookup fails, and then pass the NULL result to code that dereferences it. A driver mistake (a param_id that was never registered, an sb_index that was never registered or is unregistered twice) therefore costs an oops instead of a warning.

This is a very low value contribution.

Please think harder whether the changes you're making are worth community's time.

#6 lore raw
In reply to Linkui Xiao
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Mon, 2 Nov 2026 21:15:03 +0800 you wrote:

From: Linkui Xiao <[email protected]>

Two devlink helpers look an object up by id or index, warn when the lookup fails, and then pass the NULL result to code that dereferences it. A driver mistake (a param_id that was never registered, an sb_index that was never registered or is unregistered twice) therefore costs an oops instead of a warning.

[...]

Here is the summary with links:
- [net-next,v2,1/2] devlink: param: do not dereference a missing param item

    https://git.kernel.org/netdev/net-next/c/944f5b9f00f7
  - [net-next,v2,2/2] devlink: sb: do not dereference a missing shared buffer
    https://git.kernel.org/netdev/net-next/c/0e729906cfee

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html