Linux I2C development
 help / color / mirror / Atom feed
* [PATCH] i2c: fix use-after-free in debugfs directory during adapter removal
@ 2026-07-29  8:58 Yun Zhou
  2026-07-31 21:55 ` Andi Shyti
  0 siblings, 1 reply; 3+ messages in thread
From: Yun Zhou @ 2026-07-29  8:58 UTC (permalink / raw)
  To: andi.shyti; +Cc: linux-i2c, linux-kernel, yun.zhou

Move debugfs_remove_recursive() after device_unregister() in
i2c_del_adapter() to fix a race condition where a new i2c device probe
can access the adapter's already-freed debugfs dentry.

The race occurs when:
1. i2c_del_adapter() calls debugfs_remove_recursive(adap->debugfs),
   freeing the debugfs dentry.
2. Before device_unregister() completes, another thread writes to the
   sysfs 'new_device' attribute, triggering i2c_device_probe().
3. i2c_device_probe() calls debugfs_create_dir() with the stale
   adapter->debugfs pointer, causing a GPF in start_dirop() when
   trying to lock the freed inode.

Reported-by: syzbot+1e3d934ee3cff1ac188b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=1e3d934ee3cff1ac188b
Fixes: 73febd775bdb ("i2c: create debugfs entry per adapter")
Cc: stable@vger.kernel.org
Signed-off-by: Yun Zhou <yun.zhou@windriver.com>
---
 drivers/i2c/i2c-core-base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 3ec04787a737..9b0f3c783e9c 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1826,8 +1826,6 @@ void i2c_del_adapter(struct i2c_adapter *adap)
 
 	i2c_host_notify_irq_teardown(adap);
 
-	debugfs_remove_recursive(adap->debugfs);
-
 	/* wait until all references to the device are gone
 	 *
 	 * FIXME: This is old code and should ideally be replaced by an
@@ -1839,6 +1837,8 @@ void i2c_del_adapter(struct i2c_adapter *adap)
 	device_unregister(&adap->dev);
 	wait_for_completion(&adap->dev_released);
 
+	debugfs_remove_recursive(adap->debugfs);
+
 	/* free bus id */
 	mutex_lock(&core_lock);
 	idr_remove(&i2c_adapter_idr, adap->nr);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c: fix use-after-free in debugfs directory during adapter removal
  2026-07-29  8:58 [PATCH] i2c: fix use-after-free in debugfs directory during adapter removal Yun Zhou
@ 2026-07-31 21:55 ` Andi Shyti
  2026-08-01  3:49   ` Hillf Danton
  0 siblings, 1 reply; 3+ messages in thread
From: Andi Shyti @ 2026-07-31 21:55 UTC (permalink / raw)
  To: Yun Zhou; +Cc: linux-i2c, linux-kernel

Hi Yun,

On Wed, Jul 29, 2026 at 04:58:53PM +0800, Yun Zhou wrote:
> Move debugfs_remove_recursive() after device_unregister() in
> i2c_del_adapter() to fix a race condition where a new i2c device probe
> can access the adapter's already-freed debugfs dentry.
> 
> The race occurs when:
> 1. i2c_del_adapter() calls debugfs_remove_recursive(adap->debugfs),
>    freeing the debugfs dentry.
> 2. Before device_unregister() completes, another thread writes to the
>    sysfs 'new_device' attribute, triggering i2c_device_probe().
> 3. i2c_device_probe() calls debugfs_create_dir() with the stale
>    adapter->debugfs pointer, causing a GPF in start_dirop() when
>    trying to lock the freed inode.
> 
> Reported-by: syzbot+1e3d934ee3cff1ac188b@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=1e3d934ee3cff1ac188b
> Fixes: 73febd775bdb ("i2c: create debugfs entry per adapter")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yun Zhou <yun.zhou@windriver.com>

This is the third patch of this kind I've reviewed, starting from
the latest. I'm sorry, but I don't need AI to send me patches; I
can do that myself. I don't need intermediaries.

If your goal is to be replaced by AI, you're doing a pretty good
job.

I'm NAKing this patch on principle. Read your second patch to
understand why; read your own patches and understand them before
sending.

Andi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c: fix use-after-free in debugfs directory during adapter removal
  2026-07-31 21:55 ` Andi Shyti
@ 2026-08-01  3:49   ` Hillf Danton
  0 siblings, 0 replies; 3+ messages in thread
From: Hillf Danton @ 2026-08-01  3:49 UTC (permalink / raw)
  To: Andi Shyti, Yun Zhou; +Cc: linux-i2c, linux-kernel

On Fri, 31 Jul 2026 23:55:47 +0200 Andi Shyti wrote:
> Hi Yun,
> 
> On Wed, Jul 29, 2026 at 04:58:53PM +0800, Yun Zhou wrote:
> > Move debugfs_remove_recursive() after device_unregister() in
> > i2c_del_adapter() to fix a race condition where a new i2c device probe
> > can access the adapter's already-freed debugfs dentry.
> > 
> > The race occurs when:
> > 1. i2c_del_adapter() calls debugfs_remove_recursive(adap->debugfs),
> >    freeing the debugfs dentry.
> > 2. Before device_unregister() completes, another thread writes to the
> >    sysfs 'new_device' attribute, triggering i2c_device_probe().
> > 3. i2c_device_probe() calls debugfs_create_dir() with the stale
> >    adapter->debugfs pointer, causing a GPF in start_dirop() when
> >    trying to lock the freed inode.
> > 
> > Reported-by: syzbot+1e3d934ee3cff1ac188b@syzkaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=1e3d934ee3cff1ac188b
> > Fixes: 73febd775bdb ("i2c: create debugfs entry per adapter")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Yun Zhou <yun.zhou@windriver.com>
> 
> This is the third patch of this kind I've reviewed, starting from
> the latest. I'm sorry, but I don't need AI to send me patches; I
> can do that myself. I don't need intermediaries.
> 
> If your goal is to be replaced by AI, you're doing a pretty good
> job.
> 
> I'm NAKing this patch on principle. Read your second patch to
> understand why; read your own patches and understand them before
> sending.
> 
Given no version info in the subject line, can you show links to the
first and second patches to double check AI.

Hillf

> Andi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-01  3:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-29  8:58 [PATCH] i2c: fix use-after-free in debugfs directory during adapter removal Yun Zhou
2026-07-31 21:55 ` Andi Shyti
2026-08-01  3:49   ` Hillf Danton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox