linux/net/devlink
Haishuang Yan c5381ae1cd devlink: fix devlink_rel reference leak when notify work is pending
devlink_rel_nested_in_notify_work_schedule() takes a reference on the
devlink_rel for the notify work and then queues the work, ignoring the
return value of schedule_delayed_work(). If the work is already pending,
nothing new is queued, the work runs only once and drops only one
reference, so the extra one is leaked together with the devlink_rel and
its index in devlink_rels.

This is easy to hit. devl_register() of a nested instance queues the
work, and if the instance is unregistered before the work has run,
devlink_rel_put() queues it again while it is still pending. The work
also keeps rescheduling itself for as long as the parent devlink lock
cannot be taken, which widens the window. Registering and unregistering
a nested devlink instance 100 times while holding the parent lock leaks
all 100 devlink_rel objects.

The reschedule path in devlink_rel_nested_in_notify_work() has the same
problem: if the work was queued again while it was running, the
reference it holds is never dropped.

Drop the reference in both places when the work was already pending.
The pending work holds its own reference, so this can not be the last
one.

Fixes: c137743bce ("devlink: introduce object and nested devlink relationship infra")
Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20261001042232.222987-1-yanhaishuang@cmss.chinamobile.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-10-06 17:16:14 -07:00
..
core.c devlink: fix devlink_rel reference leak when notify work is pending 2026-10-06 17:16:14 -07:00
dev.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2026-08-06 11:53:47 -07:00
devl_internal.h devlink: Add parent dev to devlink API 2026-07-07 11:31:26 +02:00
dpipe.c devlink: Migrate from info->user_ptr to info->ctx 2026-07-07 11:31:26 +02:00
health.c devlink: Migrate from info->user_ptr to info->ctx 2026-07-07 11:31:26 +02:00
linecard.c devlink: Migrate from info->user_ptr to info->ctx 2026-07-07 11:31:26 +02:00
Makefile devlink: introduce shared devlink instance for PFs on same chip 2026-03-14 13:08:50 -07:00
netlink_gen.c devlink: Allow parent dev for rate-set and rate-new 2026-07-07 11:31:26 +02:00
netlink_gen.h devlink: Allow parent dev for rate-set and rate-new 2026-07-07 11:31:26 +02:00
netlink.c treewide: refresh kmalloc_obj() conversions 2026-09-04 21:37:00 -07:00
param.c treewide: refresh kmalloc_obj() conversions 2026-09-04 21:37:00 -07:00
port.c devlink: Expose external flag for PCI SF ports 2026-08-05 16:39:54 -07:00
rate.c devlink: Allow rate node parents from other devlinks 2026-07-07 11:31:26 +02:00
region.c devlink: Migrate from info->user_ptr to info->ctx 2026-07-07 11:31:26 +02:00
resource.c devlink: Migrate from info->user_ptr to info->ctx 2026-07-07 11:31:26 +02:00
sb.c devlink: Migrate from info->user_ptr to info->ctx 2026-07-07 11:31:26 +02:00
sh_dev.c devlink: introduce shared devlink instance for PFs on same chip 2026-03-14 13:08:50 -07:00
trap.c devlink: Migrate from info->user_ptr to info->ctx 2026-07-07 11:31:26 +02:00