From: Jens Axboe <axboe@kernel.dk>
To: syzbot <syzbot+01523a0ae5600aef5895@syzkaller.appspotmail.com>,
io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] [io-uring?] KASAN: slab-use-after-free Read in io_poll_remove_entries
Date: Tue, 22 Jul 2025 06:47:39 -0600 [thread overview]
Message-ID: <cf0447d1-3590-4540-932d-4be299edc432@kernel.dk> (raw)
In-Reply-To: <687bd5fe.a70a0220.693ce.0091.GAE@google.com>
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c
index c83fd14dd7ad..58b034e45283 100644
--- a/drivers/comedi/comedi_fops.c
+++ b/drivers/comedi/comedi_fops.c
@@ -782,24 +782,33 @@ void comedi_device_cancel_all(struct comedi_device *dev)
}
}
-static int is_device_busy(struct comedi_device *dev)
+static int start_detach(struct comedi_device *dev)
{
struct comedi_subdevice *s;
- int i;
+ int i, is_busy = 0;
lockdep_assert_held(&dev->mutex);
+ lockdep_assert_held(&dev->attach_lock);
if (!dev->attached)
return 0;
for (i = 0; i < dev->n_subdevices; i++) {
s = &dev->subdevices[i];
- if (s->busy)
- return 1;
- if (s->async && comedi_buf_is_mmapped(s))
- return 1;
+ if (s->busy) {
+ is_busy = 1;
+ break;
+ }
+ if (!s->async)
+ continue;
+ if (comedi_buf_is_mmapped(s) ||
+ wq_has_sleeper(&s->async->wait_head)) {
+ is_busy = 1;
+ break;
+ }
}
-
- return 0;
+ if (!is_busy)
+ dev->detaching = 1;
+ return is_busy;
}
/*
@@ -825,8 +834,13 @@ static int do_devconfig_ioctl(struct comedi_device *dev,
return -EPERM;
if (!arg) {
- if (is_device_busy(dev))
+ /* prevent new polls */
+ down_write(&dev->attach_lock);
+ if (start_detach(dev)) {
+ up_write(&dev->attach_lock);
return -EBUSY;
+ }
+ up_write(&dev->attach_lock);
if (dev->attached) {
struct module *driver_module = dev->driver->module;
@@ -2479,7 +2493,7 @@ static __poll_t comedi_poll(struct file *file, poll_table *wait)
down_read(&dev->attach_lock);
- if (!dev->attached) {
+ if (!dev->attached || dev->detaching) {
dev_dbg(dev->class_dev, "no driver attached\n");
goto done;
}
diff --git a/include/linux/comedi/comedidev.h b/include/linux/comedi/comedidev.h
index 4cb0400ad616..b2bec668785f 100644
--- a/include/linux/comedi/comedidev.h
+++ b/include/linux/comedi/comedidev.h
@@ -545,6 +545,7 @@ struct comedi_device {
const char *board_name;
const void *board_ptr;
unsigned int attached:1;
+ unsigned int detaching:1;
unsigned int ioenabled:1;
spinlock_t spinlock; /* generic spin-lock for low-level driver */
struct mutex mutex; /* generic mutex for COMEDI core */
--
Jens Axboe
next prev parent reply other threads:[~2025-07-22 12:47 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-19 17:29 [syzbot] [io-uring?] KASAN: slab-use-after-free Read in io_poll_remove_entries syzbot
2025-07-20 0:36 ` Hillf Danton
2025-07-20 0:49 ` syzbot
2025-07-20 18:24 ` Jens Axboe
2025-07-20 18:49 ` Jens Axboe
2025-07-20 19:00 ` Jens Axboe
2025-07-20 19:19 ` [syzbot] [kernel] " syzbot
2025-07-22 12:21 ` [syzbot] [io-uring?] " Jens Axboe
2025-07-22 12:30 ` Ian Abbott
2025-07-22 12:43 ` Jens Axboe
2025-07-22 12:31 ` Greg Kroah-Hartman
2025-07-22 12:44 ` Jens Axboe
2025-07-22 12:47 ` Ian Abbott
2025-07-22 13:00 ` Jens Axboe
2025-07-22 13:07 ` Ian Abbott
2025-07-22 13:31 ` Ian Abbott
2025-07-22 13:50 ` Jens Axboe
2025-07-22 14:03 ` Ian Abbott
2025-07-22 13:53 ` Jens Axboe
2025-07-22 14:15 ` Ian Abbott
2025-07-23 14:08 ` Aleksandr Nogikh
2025-07-22 12:47 ` Jens Axboe [this message]
2025-07-22 13:14 ` [syzbot] [kernel] " syzbot
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=cf0447d1-3590-4540-932d-4be299edc432@kernel.dk \
--to=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+01523a0ae5600aef5895@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/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