From: sashiko-bot@kernel.org
To: "Sam Agazaryan" <samagazaryan@google.com>, linux-i3c@lists.infradead.org
Cc: Frank.Li@kernel.org, "Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH RFC 1/2] i3c: master: Drain IBI slot pool before freeing
Date: Wed, 02 Dec 2026 02:44:57 +0000 [thread overview]
Message-ID: <sashiko-outbox-244716@kernel.org> (raw)
In-Reply-To: <20261202022502.3661797-2-samagazaryan@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] i3c: master: UAF on checked-out IBI slot in
i3c_generic_ibi_free_pool()
--
commit 992daa004ac4d4fb63c601d96cf2c13eec0369d4
Author: Sam Agazaryan <samagazaryan@google.com>
i3c: master: Drain IBI slot pool before freeing
This commit records the pool and target device metadata on each generic
IBI slot so slots can be recycled directly into their pool, and defers
destroying the pool onto the device IBI workqueue when IBIs have been
queued.
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 01e05bad8661e..75c44c45bd08c 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
[ ... ]
> @@ -3629,14 +3649,32 @@ static void i3c_master_unregister_i3c_devs(struct i3c_master_controller *master)
> */
> void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot)
> {
> - if (!dev->ibi || !slot)
> + struct i3c_generic_ibi_slot *gslot;
> + struct i3c_generic_ibi_pool *pool;
> + unsigned long flags;
> +
> + if (!slot)
> return;
>
> + gslot = container_of(slot, struct i3c_generic_ibi_slot, base);
> + pool = gslot->pool;
> +
> + spin_lock_irqsave(&pool->lock, flags);
> + if (pool->stopping || !dev->ibi || !dev->ibi->wq) {
> + spin_unlock_irqrestore(&pool->lock, flags);
> + i3c_generic_ibi_recycle_slot(pool, slot);
> + return;
> + }
> +
> if (device_may_wakeup(&dev->dev->dev))
> pm_wakeup_event(&dev->dev->dev, I3C_WAKEUP_PROCESSING_TIME_MS);
>
> + gslot->ibi = dev->ibi;
> + gslot->i3cdev = READ_ONCE(dev->dev);
> + pool->wq = dev->ibi->wq;
> atomic_inc(&dev->ibi->pending_ibis);
> queue_work(dev->ibi->wq, &slot->work);
> + spin_unlock_irqrestore(&pool->lock, flags);
> }
[ ... ]
> @@ -3706,6 +3733,56 @@ void i3c_generic_ibi_free_pool(struct i3c_generic_ibi_pool *pool)
> kfree(pool->payload_buf);
> kfree(pool);
> }
> +
> +static void i3c_generic_ibi_free_pool_work(struct work_struct *work)
> +{
> + struct i3c_generic_ibi_pool *pool =
> + container_of(work, struct i3c_generic_ibi_pool, free_work);
> +
> + i3c_generic_ibi_destroy_pool(pool);
> +}
> +
> +/**
> + * i3c_generic_ibi_free_pool() - Free a generic IBI pool
> + * @pool: the IBI pool to free
> + *
> + * Free all IBI slots allocated by a generic IBI pool. If IBIs were ever
> + * queued, IBI work that has not started yet is cancelled and the pool is
> + * freed from the device IBI workqueue, after any handler that is still
> + * running has returned its slot.
> + */
> +void i3c_generic_ibi_free_pool(struct i3c_generic_ibi_pool *pool)
> +{
> + struct i3c_generic_ibi_slot *slot;
> + struct i3c_device_ibi_info *ibi;
> + struct workqueue_struct *wq;
> + unsigned long flags;
> + unsigned int i;
> +
> + spin_lock_irqsave(&pool->lock, flags);
> + pool->stopping = true;
> + wq = pool->wq;
> + if (!wq) {
> + /* No IBI was ever queued, so none can be in flight. */
> + spin_unlock_irqrestore(&pool->lock, flags);
> + i3c_generic_ibi_destroy_pool(pool);
> + return;
> + }
> +
> + for (i = 0; i < pool->num_slots; i++) {
> + slot = &pool->slots[i];
> + if (cancel_work(&slot->base.work)) {
> + ibi = slot->ibi;
> + slot->ibi = NULL;
> + list_add_tail(&slot->node, &pool->free_slots);
> + if (ibi && atomic_dec_and_test(&ibi->pending_ibis))
> + complete(&ibi->all_ibis_handled);
> + }
> + }
> + spin_unlock_irqrestore(&pool->lock, flags);
> +
> + queue_work(wq, &pool->free_work);
> +}
[Severity: High]
Can i3c_generic_ibi_free_pool() destroy the pool while a slot checked out
via i3c_generic_ibi_get_free_slot() has not yet reached
i3c_master_queue_ibi() or i3c_generic_ibi_recycle_slot()?
Controller drivers check out a slot with i3c_generic_ibi_get_free_slot(),
populate slot->data outside pool->lock, and only then pass the slot to
i3c_master_queue_ibi() (which the pool->stopping check in
i3c_master_queue_ibi() anticipates). For example, the MIPI I3C HCI PIO
driver holds a checked-out slot in pio->ibi.slot across multiple segment
interrupts before queueing it, and svc_i3c_master_ibi_isr() checks out a
slot under master->xferqueue.lock while svc_i3c_master_free_ibi() only
takes master->ibi.lock before calling i3c_generic_ibi_free_pool().
CPU0 CPU1
i3c_generic_ibi_get_free_slot(pool)
list_del(&slot->node)
i3c_generic_ibi_free_pool(pool)
pool->stopping = true
/* pool->wq is still NULL */
i3c_generic_ibi_destroy_pool(pool)
WARN_ON(nslots != pool->num_slots)
kfree(pool->payload_buf)
kfree(pool)
memcpy(slot->data, ...)
<-- use-after-free on payload_buf
i3c_master_queue_ibi(dev, slot)
spin_lock_irqsave(&pool->lock, ...)
<-- use-after-free on pool
Even when pool->wq is non-NULL from an earlier IBI, cancel_work() returns
false for a checked-out slot that has not been queued yet, and
pool->free_work can run on wq and free pool->payload_buf and pool before
the controller finishes filling or recycling the slot. In addition, when
i3c_master_queue_ibi() sees pool->stopping, it drops pool->lock before
calling i3c_generic_ibi_recycle_slot(), leaving a window where the slot is
still off pool->free_slots while i3c_generic_ibi_destroy_pool() runs.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202022502.3661797-1-samagazaryan@google.com?part=1
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
next prev parent reply other threads:[~2026-12-02 2:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 2:25 [PATCH RFC 0/2] i3c: master: Fix IBI teardown when DAA re-adds a device Sam Agazaryan
2026-12-02 2:25 ` [PATCH RFC 1/2] i3c: master: Drain IBI slot pool before freeing Sam Agazaryan
2026-12-02 2:44 ` sashiko-bot [this message]
2026-12-02 2:25 ` [PATCH RFC 2/2] i3c: master: Preserve IBI workqueue across DAA Sam Agazaryan
2026-12-02 2:48 ` sashiko-bot
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-244716@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-i3c@lists.infradead.org \
--cc=samagazaryan@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox