From: sashiko-bot@kernel.org
To: "Charles Keepax" <ckeepax@opensource.cirrus.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v4 3/4] soundwire: bus: Expose a helper to remove devices from the bus
Date: Tue, 24 Nov 2026 16:29:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-231567@kernel.org> (raw)
In-Reply-To: <20261124161001.702882-4-ckeepax@opensource.cirrus.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] soundwire: bus: UAF and disposed IRQ access after
sdw_bus_slaves_delete()
- [Medium] soundwire: bus: unlocked list traversal in
sdw_bus_slaves_put()
--
commit 5d1d7079438eb055e1748b6f548e146aa51c7a6c
Author: Charles Keepax <ckeepax@opensource.cirrus.com>
soundwire: bus: Expose a helper to remove devices from the bus
This commit splits peripheral device removal out of sdw_bus_master_delete()
into a new exported sdw_bus_slaves_delete() helper while deferring slave
list removal, device number release, and put_device() to a new
sdw_bus_slaves_put() helper.
> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
> index eddff9a5fd35d..c97f6c27fa854 100644
> --- a/drivers/soundwire/bus.c
> +++ b/drivers/soundwire/bus.c
> @@ -169,7 +169,6 @@ EXPORT_SYMBOL(sdw_bus_master_add);
> static int sdw_delete_slave(struct device *dev, void *data)
> {
> struct sdw_slave *slave = dev_to_sdw_dev(dev);
> - struct sdw_bus *bus = slave->bus;
>
> pm_runtime_disable(dev);
>
> @@ -186,18 +185,38 @@ static int sdw_delete_slave(struct device *dev, void *data)
> */
> device_del(dev);
>
> - mutex_lock(&bus->bus_lock);
> - if (slave->dev_num) { /* clear dev_num if assigned */
> - clear_bit(slave->dev_num, bus->assigned);
> - if (bus->ops && bus->ops->put_device_num)
> - bus->ops->put_device_num(bus, slave);
> - }
> - list_del_init(&slave->node);
> - mutex_unlock(&bus->bus_lock);
> + return 0;
> +}
>
> - put_device(dev);
> +/**
> + * sdw_bus_slaves_delete() - delete all peripherals on a bus
> + * @bus: bus with peripherals to be deleted
> + *
> + * Delete the child devices.
> + */
> +void sdw_bus_slaves_delete(struct sdw_bus *bus)
> +{
> + device_for_each_child(bus->dev, NULL, sdw_delete_slave);
> +}
> +EXPORT_SYMBOL(sdw_bus_slaves_delete);
[Severity: High]
Can deferring the bus->assigned and bus->slaves cleanup until
sdw_bus_slaves_put() cause a NULL pointer dereference or use-after-free
when a status update arrives after sdw_delete_slave()?
device_del(dev) runs devres_release_all(&slave->dev), which invokes
sdw_irq_dispose_mapping() to free slave->irq's descriptor (leaving
slave->irq non-zero) and frees devm-allocated slave->prop.dp0_prop.
Because the slave remains in bus->slaves and bus->assigned until the
controller later calls sdw_bus_master_delete(), a concurrent status
update can still reach the deleted slave:
CPU0 CPU1 (status workqueue)
sdw_bus_slaves_delete(bus)
sdw_delete_slave(&slave->dev)
device_del(&slave->dev)
devres_release_all(&slave->dev)
irq_dispose_mapping(slave->irq)
sdw_handle_slave_status(bus, ...)
sdw_handle_slave_alerts(slave)
handle_nested_irq(slave->irq)
<-- NULL irq_desc dereference
Similarly, if a peripheral re-attaches during teardown,
sdw_initialize_slave() runs without checking slave->probed and
dereferences the freed slave->prop.dp0_prop.
> - return 0;
> +static void sdw_bus_slaves_put(struct sdw_bus *bus)
> +{
> + struct sdw_slave *slave, *tmp;
> +
> + list_for_each_entry_safe(slave, tmp, &bus->slaves, node) {
> + mutex_lock(&bus->bus_lock);
> + if (slave->dev_num) { /* clear dev_num if assigned */
> + clear_bit(slave->dev_num, bus->assigned);
> + if (bus->ops && bus->ops->put_device_num)
> + bus->ops->put_device_num(bus, slave);
> + }
> + list_del_init(&slave->node);
> + mutex_unlock(&bus->bus_lock);
> +
> + /* See comment in sdw_delete_slave() */
> + put_device(&slave->dev);
> + }
> }
[Severity: Medium]
Is it safe for list_for_each_entry_safe() to traverse bus->slaves
without holding bus->bus_lock across the iteration?
On controllers whose interrupt handler remains active during
sdw_bus_master_delete() (such as qcom_swrm_remove(), where the IRQ is
managed with devm), a concurrent enumeration interrupt can call
sdw_slave_add(), which modifies bus->slaves under bus->bus_lock via
list_add_tail() and list_del(). Reading the list pointers outside
bus->bus_lock can race with those updates and miss a newly added slave
or follow a removed node. Holding bus->bus_lock around a
while (!list_empty(&bus->slaves)) loop and dropping it only around
put_device(&slave->dev) would avoid the unlocked traversal.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124161001.702882-1-ckeepax@opensource.cirrus.com?part=3
next prev parent reply other threads:[~2026-11-24 16:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 16:09 [PATCH v4 0/4] Allow SoundWire devices to communicate during remove Charles Keepax
2026-11-24 16:09 ` [PATCH v4 1/4] ASoC: SOF: Intel: Add IRQ chip to distribute the SoundWire IRQ Charles Keepax
2026-11-24 16:36 ` sashiko-bot
2026-11-24 16:49 ` Pierre-Louis Bossart
2026-11-24 17:06 ` Charles Keepax
2026-11-24 18:33 ` Pierre-Louis Bossart
2026-11-24 16:09 ` [PATCH v4 2/4] soundwire: bus: Don't unassign dev_num before unregistering device Charles Keepax
2026-11-24 16:10 ` [PATCH v4 3/4] soundwire: bus: Expose a helper to remove devices from the bus Charles Keepax
2026-11-24 16:29 ` sashiko-bot [this message]
2026-11-24 16:10 ` [PATCH v4 4/4] soundwire: intel_auxdevice: Don't disable IRQs before removing children Charles Keepax
2026-11-24 16:27 ` sashiko-bot
2026-11-24 18:27 ` Pierre-Louis Bossart
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=sashiko-outbox-231567@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ckeepax@opensource.cirrus.com \
--cc=linux-sound@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.