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

From
Linkui Xiao <hidden>
Date
2026-11-02 13:16:35
Also in
lkml
Reply to
Linkui Xiao, 2026-11-02
From: Linkui Xiao <redacted>

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.

Fixes: ea601e170988 ("devlink: Add devlink notifications support for params")
Signed-off-by: Linkui Xiao <redacted>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/all/20230126075838.1643665-5-jiri@resnulli.us/ (local)
Link: https://lore.kernel.org/r/20261030033332.3685172-2-xiaolinkui@126.com (local)
---
v2: reposted against net-next at Simon's suggestion; no code change.

 net/devlink/param.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/devlink/param.c b/net/devlink/param.c
index 95ac9db8c993..474fe009f22d 100644
--- a/net/devlink/param.c
+++ b/net/devlink/param.c
@@ -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);
 }
-- 
2.25.1
Thread (7 messages) 7 messages, 4 authors, last reply 9d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help