From: sashiko-bot@kernel.org
To: "A. Sverdlin" <alexander.sverdlin@siemens.com>
Cc: linux-leds@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH 3/3] leds: trigger: netdev: serialize mode/interval stores with trigger lock
Date: Mon, 14 Sep 2026 14:21:15 +0000 [thread overview]
Message-ID: <20260914142116.6DAC51F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260914132356.807004-4-alexander.sverdlin@siemens.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Unprotected cancel_delayed_work_sync() allows concurrent execution and UAF of net_device in the worker thread.
--
commit d9c1377958eda5198cea4d7f716e117467e638fb
Author: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Subject: leds: trigger: netdev: serialize mode/interval stores with trigger lock
This patch updates netdev_led_attr_store() and interval_store() to hold
the trigger_data->lock. It prevents concurrent writes from dropping updates,
reading partially-updated device states, and causing data corruption on
shared fields.
> diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
> index 89b48c522c227..6556f6d28547f 100644
> --- a/drivers/leds/trigger/ledtrig-netdev.c
> +++ b/drivers/leds/trigger/ledtrig-netdev.c
> @@ -421,6 +421,16 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
> return -EINVAL;
> }
>
> + /*
> + * Serialize the read-modify-write of ->mode and the dependent
> + * ->hw_control update and set_baseline_state() against concurrent
> + * attribute stores and netdev_trig_notify(). netdev_trig_work() must
> + * never take this lock, otherwise the cancel_delayed_work_sync() below
> + * would deadlock.
> + */
> + guard(mutex)(&trigger_data->lock);
> +
> + mode = trigger_data->mode;
[Severity: Critical]
This is a pre-existing issue, but since this patch discusses lock interactions
with cancel_delayed_work_sync(), does the unprotected call to
cancel_delayed_work_sync() in set_device_name() allow a concurrent thread
to re-arm the work before the old device reference is put?
A sysfs write to device_name triggers set_device_name(), which calls
cancel_delayed_work_sync() locklessly:
drivers/leds/trigger/ledtrig-netdev.c:set_device_name() {
...
cancel_delayed_work_sync(&trigger_data->work);
...
mutex_lock(&trigger_data->lock);
dev_put(trigger_data->net_dev);
...
}
Concurrently, a sysfs write to a mode attribute (e.g., here in
netdev_led_attr_store()) acquires trigger_data->lock and calls
set_baseline_state(), re-arming the workqueue. The delayed work runs
netdev_trig_work() locklessly, accessing trigger_data->net_dev:
drivers/leds/trigger/ledtrig-netdev.c:netdev_trig_work() {
...
dev_stats = dev_get_stats(trigger_data->net_dev, &temp);
...
}
Meanwhile, set_device_name() acquires the lock, assigns a new device, and
calls dev_put() on the old device. Since netdev_trig_work() doesn't hold its
own reference or any locks, this dev_put() can drop the last reference and free
the net_device while the work thread is actively calling dev_get_stats() on it.
A similar race exists in netdev_trig_notify() on the NETDEV_UNREGISTER event.
Can this sequence lead to a Use-After-Free (UAF) of the net_device structure?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260914132356.807004-1-alexander.sverdlin@siemens.com?part=3
prev parent reply other threads:[~2026-09-14 14:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 13:23 [PATCH 0/3] leds: trigger: netdev: fix sysfs_update_group() races A. Sverdlin
2026-09-14 13:23 ` [PATCH 1/3] leds: trigger: netdev: hold lock across sysfs_update_group() in device_name_store() A. Sverdlin
2026-09-14 13:50 ` sashiko-bot
2026-09-14 16:59 ` Andrew Lunn
2026-09-14 13:23 ` [PATCH 2/3] leds: trigger: netdev: fix sysfs_update_group() vs led_trigger_set() races A. Sverdlin
2026-09-14 14:00 ` sashiko-bot
2026-09-14 17:05 ` Andrew Lunn
2026-09-14 13:23 ` [PATCH 3/3] leds: trigger: netdev: serialize mode/interval stores with trigger lock A. Sverdlin
2026-09-14 14:21 ` sashiko-bot [this message]
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=20260914142116.6DAC51F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexander.sverdlin@siemens.com \
--cc=lee@kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.