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: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260714043834.554-1-hdanton@sina.com>
2026-07-16 0:05 ` [PATCH v5] loop: Fix NULL pointer dereference in lo_rw_aio() 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
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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox