Linux block layer
 help / color / mirror / Atom feed
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 v6] loop: Fix NULL pointer dereference in lo_rw_aio()
Date: Thu, 27 Aug 2026 10:28:14 -0700	[thread overview]
Message-ID: <c0df5f39-d103-4e36-9807-df0ae0247772@acm.org> (raw)
In-Reply-To: <e5518546-701e-4d3c-a077-18e34aa8c188@I-love.SAKURA.ne.jp>

On 8/27/26 8:30 AM, Tetsuo Handa wrote:
> While Sashiko considers a static blk_mq_freeze_queue() sufficient to avoid
> the NULL pointer dereference, relying on freezing the queue inside __loop_clr_fd()
> while holding `disk->open_mutex` is a dangerous decision.
> 
> It is true that blk_mq_freeze_queue() alone is equivalent to
> synchronize_rcu() + drain_workqueue() + blk_mq_freeze_queue().
> 
> Although omitting drain_workqueue() causes lockdep to stop complaining, not
> using drain_workqueue() does not avoid the runtime deadlock situation shown below.
> As long as there is a possibility of an in-flight I/O holding or waiting on a
> lock that subsequently tries to acquire `disk->open_mutex`, the deadlock
> risk remains. Lockdep will remain silent here simply because it cannot inspect
> the wake-up conditions inside wait_event() during a queue freeze.
> 
> Here is the exact execution timeline that leads to the silent deadlock:
> 
> Thread 1:                         Thread 2:                         Thread 3:
> ========================================================================================
>                                                                      Holds a global lock
>                                                                      (e.g., system_transition_mutex).
> 
>                                    Block core increments
>                                    `q_usage_counter`.
> 
> Block core holds `disk->open_mutex`.
> 
> lo_release() tries to wait for
> `q_usage_counter` to reach 0
> via blk_mq_freeze_queue()
>    => BLOCKED by Thread 2.
>                                    loop_handle_cmd() tries
>                                    to hold the global lock
>                                      => BLOCKED by Thread 3.
>                                                                      Tries to hold
>                                                                      `disk->open_mutex`
>                                                                        => BLOCKED by Thread 1.
> ========================================================================================
> 
> Since Thread 1 will never release `disk->open_mutex`, Thread 3 can never release
> the global lock, and Thread 2 can never reach blk_mq_end_request() to unblock Thread 1.
> 
> I've tried offloading __loop_clr_fd() entirely to task_work context in v3 patch, but
> it did not work due to module lifecycle restrictions
> ( https://sashiko.dev/#/patchset/fda8abc8-6aa2-463b-bf72-865f6b838034@I-love.SAKURA.ne.jp ).
> 
> Therefore, I consider that temporarily releasing `disk->open_mutex` within the process
> context to safely perform flushing/draining before clearing the backing file pointer
> is the most robust architectural solution to break this deadlock chain.

I'm going to drop patch "loop: Serialize I/O and queue limits updates"
from my patch series and leave it to someone else to solve this issue
since none of the proposed fixes that have been discussed so far make me
enthusiast.

Thanks,

Bart.

  reply	other threads:[~2026-08-27 17:28 UTC|newest]

Thread overview: 66+ 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 [this message]
2026-08-28 15:53                                                                                     ` [PATCH v7] " Tetsuo Handa
2026-08-28 16:29                                                                                       ` Bart Van Assche
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=c0df5f39-d103-4e36-9807-df0ae0247772@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