All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hillf Danton <hdanton@sina.com>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Bart Van Assche <bvanassche@acm.org>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	Christoph Hellwig <hch@infradead.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH v8] loop: Fix NULL pointer dereference in lo_rw_aio()
Date: Fri,  4 Sep 2026 09:07:19 +0800	[thread overview]
Message-ID: <20260904010721.2085-1-hdanton@sina.com> (raw)
In-Reply-To: <dc2f1e00-5e10-4e02-9415-c6ecb2cbc6b3@I-love.SAKURA.ne.jp>

On Fri, 4 Sep 2026 08:50:46 +0900 Tetsuo Handa wrote:
> syzbot is reporting NULL pointer dereference in lo_rw_aio() [1][2].
> An analysis by the Gemini AI collaborator [3] considers that this problem
> is caused by a timing shift primarily exposed by commit 65565ca5f99b
> ("block: unify the synchronous bi_end_io callbacks"), along with helper
> refactorings like commit 92c3737a2473 ("block: add a bio_submit_or_kill
> helper").
> 
> But due to difficulty of reproducing this race, discussion about what is
> happening and how to fix this problem is stalling. Also, we haven't
> identified how many filesystems are subjected to this problem.
> 
> Therefore, introduce a grace period for flushing outstanding I/O
> (which should be a good thing from the perspective of defensive
> programming) so that we won't hit NULL pointer dereference problem.
> 
> However, calling drain_workqueue() from __loop_clr_fd() with
> disk->open_mutex held causes lockdep warnings. We need to flush
> outstanding I/O without disk->open_mutex held. But we can't use task work
> context, for there is no way to reliably wait for completion of a task work
> function inside a loadable module when module unloading code for that
> loadable module has started. We need to use a callback function which is
> embedded into a built-in module so that it can reliably wait for completion
> of synchronous teardown for the loop driver module.
> 
> Therefore, add a dedicated callback for the loop module to the block core
> layer, and invoke that callback immediately after disk->open_mutex is
> released. It is possible that multiple threads invoke that callback
> when a teardown work was scheduled because disk->open_mutex was already
> released, but concurrently calling flush_work() in order to wait for
> completion of an outstanding teardown work will be safe.
> 
> Link: https://syzkaller.appspot.com/bug?extid=cd8a9a308e879a4e2c28 [1]
> Link: https://syzkaller.appspot.com/bug?extid=bc273027d5643e48e5b3 [2]
> Link: https://lkml.kernel.org/r/fbb3edda-f108-4e5b-acf2-266f043f8125@I-love.SAKURA.ne.jp [3]
> Link: https://lkml.kernel.org/r/9f8b5ab0-efbc-4cf3-a1f8-b43377416946@I-love.SAKURA.ne.jp [4]
> Fixes: 65565ca5f99b ("block: unify the synchronous bi_end_io callbacks")
> Assisted-by: Gemini-Pro
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> ---
> What this patch does is basically the same with the v6 patch. Can this be
> a possible alternative for Bart's
> 
>   Releasing and reacquiring disk->open_mutex from __loop_clr_fd() seems
>   risky to me. There is plenty of code in block/bdev.c that assumes that
>   disk->open_mutex is not released by lo_release().
> 
> comment?
> 
>  block/bdev.c           |  2 ++
>  drivers/block/loop.c   | 65 +++++++++++++++++++++++++++++++++---------
>  include/linux/blkdev.h |  5 ++++
>  3 files changed, 59 insertions(+), 13 deletions(-)
> 
> diff --git a/block/bdev.c b/block/bdev.c
> index cd8323083740..7ce5acaacf43 100644
> --- a/block/bdev.c
> +++ b/block/bdev.c
> @@ -1188,6 +1188,8 @@ void bdev_release(struct file *bdev_file)
>  	else
>  		blkdev_put_whole(bdev);
>  	mutex_unlock(&disk->open_mutex);
> +	if (bdev->bd_disk->fops->post_release)
> +		bdev->bd_disk->fops->post_release(bdev->bd_disk);
>  
A great leap forward, I like this.

> +
> +static void lo_post_release(struct gendisk *disk)
> +{
> +	struct loop_device *lo = disk->private_data;
> +
> +	/* Wait for __loop_clr_fd() to complete. */
> +	flush_work(&lo->lo_clr_work);
>  }

  reply	other threads:[~2026-09-04  1:07 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
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 [this message]
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=20260904010721.2085-1-hdanton@sina.com \
    --to=hdanton@sina.com \
    --cc=bvanassche@acm.org \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=torvalds@linux-foundation.org \
    /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.