From: Bart Van Assche <bvanassche@acm.org>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
Markus Elfring <Markus.Elfring@web.de>,
linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>,
Damien Le Moal <dlemoal@kernel.org>, Jens Axboe <axboe@kernel.dk>
Cc: linux-kernel@vger.kernel.org, linux-next@vger.kernel.org,
lkp@intel.com, oe-lkp@lists.linux.dev,
Christian Brauner <brauner@kernel.org>,
Christoph Hellwig <hch@infradead.org>,
Christoph Hellwig <hch@lst.de>, Hillf Danton <hdanton@sina.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Mark Brown <broonie@kernel.org>,
Oliver Sang <oliver.sang@intel.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v7] loop: Fix NULL pointer dereference in lo_rw_aio()
Date: Fri, 28 Aug 2026 09:29:44 -0700 [thread overview]
Message-ID: <d0471919-9b71-4d24-9fb8-5f1d7f3792ca@acm.org> (raw)
In-Reply-To: <c2ab2547-63b3-48cf-87c1-fc53219e360a@I-love.SAKURA.ne.jp>
On 8/28/26 8:53 AM, Tetsuo Handa wrote:
> + * wait for already started loop_queue_rq() to complete.
> + */
> + synchronize_rcu();
Calling synchronize_rcu() to wait for ongoing loop_queue_rq() calls to
complete won't work if anyone would set BLK_MQ_F_BLOCKING for the
request queues created by the loop driver. Please use the block-layer
APIs instead of open-coding these. I'm referring to
blk_mq_quiesce_queue() and blk_mq_wait_quiesce_done().
Freezing the request queue must happen before waiting for ongoing
loop_queue_rq() calls to finish.
Calling synchronize_rcu() does not prevent new I/O to be submitted. What
prevents io_uring to submit more I/O asynchronously, e.g. if a file
descriptor that refers to a loop device instance has been registered in
the fixed-file table?
> + /*
> + * Now that no more works are scheduled by loop_queue_rq(),
> + * wait for already scheduled works to complete.
> + */
> + drain_workqueue(lo->workqueue);
> + /*
> + * Now that no more AIO requests are scheduled by lo_rw_aio(),
> + * wait for already started AIO to complete.
> + */
> + blk_mq_unfreeze_queue(lo->lo_queue, blk_mq_freeze_queue(lo->lo_queue));
Freezing the request queue must happen before lo->workqueue is drained.
> + /* Step 2: Perform remaining cleanup, with open_mutex held. */
> + mutex_lock(&disk->open_mutex);
After having obtained disk->open_mutex, lease add something like the
following: WARN_ON_ONCE(lo->lo_state == Lo_bound). Even if this
condition can't be triggered today, this may help with detecting bugs in
future loop driver changes.
> @@ -1168,8 +1186,6 @@ static void __loop_clr_fd(struct loop_device *lo)
> /* let user-space know about this change */
> kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE);
> mapping_set_gfp_mask(filp->f_mapping, gfp);
> - /* This is safe: open() is still holding a reference. */
> - module_put(THIS_MODULE);
>
> disk_force_media_change(lo->lo_disk);
I don't think that it's acceptable to invoke __loop_clr_fd()
asynchronously in its entirety. I think at least the following code
should be executed synchronously from lo_release():
loop_sysfs_exit(lo);
mutex_lock(&lo->lo_mutex);
WRITE_ONCE(lo->lo_state, Lo_unbound);
mutex_unlock(&lo->lo_mutex);
> @@ -1769,8 +1797,20 @@ static void lo_release(struct gendisk *disk)
> need_clear = (lo->lo_state == Lo_rundown);
> mutex_unlock(&lo->lo_mutex);
>
> - if (need_clear)
> - __loop_clr_fd(lo);
> + /*
> + * In order to flush pending I/O requests before clearing the backing
> + * device, defer __loop_clr_fd() to WQ context. The Lo_rundown state
> + * guarantees that lo_open() will fail with -ENXIO.
> + */
> + if (need_clear) {
> + /*
> + * Grab all references that will be dropped as soon as
> + * returning from lo_release() and releasing disk->open_mutex.
> + */
> + get_device(disk_to_dev(disk));
> + __module_get(disk->fops->owner);
> + queue_work(system_long_wq, &lo->lo_clr_work);
> + }
> }
Please convert the above code to the "early return" style that is used
elsewhere in the kernel.
Why system_long_wq instead of lo->workqueue?
Thanks,
Bart.
next prev parent reply other threads:[~2026-08-28 16:30 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-18 0:02 [syzbot] [block?] general protection fault in lo_rw_aio syzbot
2026-04-21 11:05 ` Tetsuo Handa
2026-05-11 11:43 ` [PATCH] loop: Fix NULL pointer dereference by synchronizing lo_release and loop_queue_rq Tetsuo Handa
2026-05-11 15:58 ` Bart Van Assche
2026-05-11 17:43 ` Tetsuo Handa
2026-05-12 11:46 ` Tetsuo Handa
2026-05-15 1:38 ` [PATCH v2] " Tetsuo Handa
2026-05-19 0:40 ` Andrew Morton
2026-05-19 9:27 ` Tetsuo Handa
2026-05-20 3:06 ` Ming Lei
2026-05-20 6:36 ` Tetsuo Handa
2026-05-20 7:49 ` Ming Lei
2026-05-20 8:20 ` Tetsuo Handa
2026-05-20 8:54 ` Ming Lei
2026-05-25 3:40 ` [PATCH v3] loop: Fix NULL pointer dereference in lo_rw_aio() Tetsuo Handa
2026-05-25 15:19 ` Ming Lei
2026-05-26 0:25 ` Tetsuo Handa
2026-05-27 1:20 ` Ming Lei
2026-05-27 1:35 ` Tetsuo Handa
2026-05-27 3:00 ` Ming Lei
2026-05-27 11:29 ` Tetsuo Handa
2026-05-27 18:11 ` Damien Le Moal
2026-05-28 8:38 ` Christoph Hellwig
2026-05-28 10:16 ` Qu Wenruo
2026-06-01 14:40 ` Christoph Hellwig
2026-06-01 16:29 ` Brian Foster
2026-06-01 22:27 ` Qu Wenruo
2026-06-01 15:29 ` Ming Lei
2026-06-01 21:51 ` Hillf Danton
2026-06-01 22:14 ` Ming Lei
2026-06-01 23:17 ` Hillf Danton
2026-06-01 23:36 ` Ming Lei
2026-06-02 2:02 ` Hillf Danton
2026-05-28 5:43 ` Hillf Danton
2026-05-28 23:00 ` Hillf Danton
2026-05-29 0:14 ` Tetsuo Handa
2026-05-29 7:04 ` Hillf Danton
2026-05-29 22:05 ` Hillf Danton
2026-05-30 23:57 ` Tetsuo Handa
2026-06-07 10:54 ` [PATCH v4] " Tetsuo Handa
2026-06-09 17:50 ` Al Viro
2026-06-13 11:00 ` Tetsuo Handa
2026-06-19 14:33 ` Tetsuo Handa
2026-06-20 7:39 ` Al Viro
2026-06-20 9:42 ` Tetsuo Handa
2026-07-13 3:04 ` Hillf Danton
2026-07-13 11:02 ` Tetsuo Handa
2026-07-14 4:38 ` Hillf Danton
2026-07-16 0:05 ` [PATCH v5] " Tetsuo Handa
2026-08-23 11:17 ` [PATCH v6] " Tetsuo Handa
2026-08-23 15:57 ` Markus Elfring
2026-08-24 22:06 ` Tetsuo Handa
2026-08-24 22:53 ` Bart Van Assche
2026-08-24 23:24 ` Bart Van Assche
2026-08-25 15:13 ` Tetsuo Handa
2026-08-25 22:18 ` Bart Van Assche
2026-08-25 23:28 ` Tetsuo Handa
2026-08-25 23:16 ` Bart Van Assche
2026-08-26 10:37 ` Tetsuo Handa
2026-08-26 17:44 ` Bart Van Assche
2026-08-27 15:30 ` Tetsuo Handa
2026-08-27 17:28 ` Bart Van Assche
2026-08-28 15:53 ` [PATCH v7] " Tetsuo Handa
2026-08-28 16:29 ` Bart Van Assche [this message]
2026-08-29 5:17 ` Tetsuo Handa
2026-08-29 5:55 ` Tetsuo Handa
2026-08-31 14:11 ` Tao Cui
2026-08-31 15:49 ` Tetsuo Handa
2026-09-01 13:08 ` Tao Cui
2026-08-31 16:11 ` Bart Van Assche
2026-08-31 16:14 ` Bart Van Assche
2026-09-03 23:15 ` [PATCH v7.1] " Tetsuo Handa
2026-09-03 23:50 ` [PATCH v8] " Tetsuo Handa
2026-09-04 1:07 ` Hillf Danton
2026-09-05 14:25 ` kernel test robot
2026-07-15 16:01 ` [syzbot] [block?] general protection fault in lo_rw_aio Bart Van Assche
2026-07-15 16:02 ` 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=d0471919-9b71-4d24-9fb8-5f1d7f3792ca@acm.org \
--to=bvanassche@acm.org \
--cc=Markus.Elfring@web.de \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=broonie@kernel.org \
--cc=dlemoal@kernel.org \
--cc=hch@infradead.org \
--cc=hch@lst.de \
--cc=hdanton@sina.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=lkp@intel.com \
--cc=oe-lkp@lists.linux.dev \
--cc=oliver.sang@intel.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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.