From: Ming Lei <tom.leiming@gmail.com>
To: Hongling Zeng <zhongling0719@126.com>
Cc: Hongling Zeng <zenghongling@kylinos.cn>,
axboe@kernel.dk, ming.lei@canonical.com,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Subject: Re: [PATCH] block/loop: Fix NULL pointer dereference in lo_rw_aio()
Date: Tue, 19 May 2026 19:28:53 +0800 [thread overview]
Message-ID: <agxJdUf1b0JSDAux@fedora> (raw)
In-Reply-To: <6A0C29F6.5080704@126.com>
On Tue, May 19, 2026 at 05:14:30PM +0800, Hongling Zeng wrote:
> Hi Ming,
>
> Tetsuo’s syzkaller trace confirms the root cause:
>
> Timeline:
> T6142: lo_rw_aio(loop3) starting read with raw_refcnt=0x0, refcnt=1
> T44: lo_rw_aio(loop3) starting read with raw_refcnt=0x0, refcnt=1
> T6148: __loop_clr_fd(loop3) clearing lo_backing_file with raw_refcnt=0x0,
> refcnt=1
> T180: lo_rw_aio(loop3) starting write with NULL file (already cleared?)
> T180: CRASH - null-ptr-deref
IO could be from writeback or early close, so the following patch should help:
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 0000913f7efc..24654a03db71 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1118,6 +1118,8 @@ static void __loop_clr_fd(struct loop_device *lo)
struct file *filp;
gfp_t gfp = lo->old_gfp_mask;
+ drain_workqueue(lo->workqueue);
+
spin_lock_irq(&lo->lo_lock);
filp = lo->lo_backing_file;
lo->lo_backing_file = NULL;
@@ -1857,9 +1859,6 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
blk_mq_start_request(rq);
- if (data_race(READ_ONCE(lo->lo_state)) != Lo_bound)
- return BLK_STS_IOERR;
-
switch (req_op(rq)) {
case REQ_OP_FLUSH:
case REQ_OP_DISCARD:
@@ -1901,6 +1900,11 @@ static void loop_handle_cmd(struct loop_cmd *cmd)
int ret = 0;
struct mem_cgroup *old_memcg = NULL;
+ if (data_race(READ_ONCE(lo->lo_state)) != Lo_bound) {
+ ret = -EIO;
+ goto failed;
+ }
+
if (write && (lo->lo_flags & LO_FLAGS_READ_ONLY)) {
ret = -EIO;
goto failed;
>
> Key anomaly: |raw_refcnt=0|while |refcnt=1|.
> This means |__loop_clr_fd()|runs while I/O is still active.
> Regression introduced by:
> 6050fa4c84cc ("loop: don't hold lo_mutex during __loop_clr_fd()")
Why do you conclude it is caused by above commit?
Thanks,
Ming
next prev parent reply other threads:[~2026-05-19 11:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 4:01 [PATCH] block/loop: Fix NULL pointer dereference in lo_rw_aio() Hongling Zeng
2026-05-19 4:42 ` Ming Lei
2026-05-19 6:06 ` Hongling Zeng
2026-05-19 8:33 ` Ming Lei
[not found] ` <6A0C29F6.5080704@126.com>
2026-05-19 11:28 ` Ming Lei [this message]
2026-05-19 12:37 ` Tetsuo Handa
2026-05-20 3:20 ` Hongling Zeng
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=agxJdUf1b0JSDAux@fedora \
--to=tom.leiming@gmail.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@canonical.com \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=zenghongling@kylinos.cn \
--cc=zhongling0719@126.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