Skip to content

block: Wait for inflight requests in bdev_release() - #1427

Open
ghost wants to merge 1 commit into
linus-master_basefrom
series/1183724=>linus-master
Open

ghost wants to merge 1 commit into
linus-master_basefrom
series/1183724=>linus-master

Conversation

@ghost

@ghost ghost commented Oct 12, 2026

Copy link
Copy Markdown

Pull request for series with
subject: block: Wait for inflight requests in bdev_release()
version: 1
url: https://patchwork.kernel.org/series/1183724/

@ghost

ghost commented Oct 12, 2026

Copy link
Copy Markdown
Author

Upstream branch: d5b6dc3
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the linus-master_base branch from ec9266e to 2e69118 Compare October 12, 2026 12:20
@ghost

ghost commented Oct 12, 2026

Copy link
Copy Markdown
Author

Upstream branch: 24a19b9
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from 5050dfb to df573ff Compare October 12, 2026 13:02
@ghost ghost added the V1-ci-pass label Oct 13, 2026
@ghost
ghost force-pushed the linus-master_base branch from 2e69118 to 3cdd51f Compare October 14, 2026 11:11
@ghost

ghost commented Oct 14, 2026

Copy link
Copy Markdown
Author

Upstream branch: 4056b3c
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from df573ff to 4b59038 Compare October 14, 2026 11:24
@ghost
ghost force-pushed the linus-master_base branch from 3cdd51f to e6ca2c1 Compare October 14, 2026 15:40
@ghost

ghost commented Oct 14, 2026

Copy link
Copy Markdown
Author

Upstream branch: 0fcb05b
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from 4b59038 to dcea0fc Compare October 14, 2026 15:54
@ghost
ghost force-pushed the linus-master_base branch from e6ca2c1 to 3d027d5 Compare October 17, 2026 03:32
@ghost

ghost commented Oct 17, 2026

Copy link
Copy Markdown
Author

Upstream branch: 58161ea
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from dcea0fc to fbad3c6 Compare October 17, 2026 03:49
@ghost
ghost force-pushed the linus-master_base branch from 3d027d5 to 90ea7e4 Compare October 19, 2026 00:00
@ghost

ghost commented Oct 19, 2026

Copy link
Copy Markdown
Author

Upstream branch: c03c1a1
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from fbad3c6 to 4953d43 Compare October 19, 2026 00:30
@ghost
ghost force-pushed the linus-master_base branch from 90ea7e4 to 435b194 Compare October 22, 2026 07:21
@ghost

ghost commented Oct 22, 2026

Copy link
Copy Markdown
Author

Upstream branch: 7be4bc5
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from 4953d43 to 94847b1 Compare October 22, 2026 07:56
@ghost
ghost force-pushed the linus-master_base branch from 435b194 to fd67522 Compare October 24, 2026 03:36
@ghost

ghost commented Oct 24, 2026

Copy link
Copy Markdown
Author

Upstream branch: 17bb0e2
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from 94847b1 to e01ff43 Compare October 24, 2026 04:03
@ghost
ghost force-pushed the linus-master_base branch from fd67522 to 3b53a63 Compare October 26, 2026 01:52
@ghost

ghost commented Oct 26, 2026

Copy link
Copy Markdown
Author

Upstream branch: 21a7f44
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from e01ff43 to d0d71bb Compare October 26, 2026 02:26
@ghost
ghost force-pushed the linus-master_base branch from 3b53a63 to 5d84576 Compare October 26, 2026 07:01
@ghost

ghost commented Oct 26, 2026

Copy link
Copy Markdown
Author

Upstream branch: 6b4b543
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from d0d71bb to a960d43 Compare October 26, 2026 07:29
@ghost
ghost force-pushed the linus-master_base branch from 5d84576 to 6582ed2 Compare October 26, 2026 18:11
@ghost

ghost commented Oct 26, 2026

Copy link
Copy Markdown
Author

Upstream branch: fb2c3f4
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from a960d43 to 1a6e10f Compare October 26, 2026 18:56
@ghost
ghost force-pushed the linus-master_base branch from 6582ed2 to b3a1abc Compare October 26, 2026 23:55
@ghost

ghost commented Oct 27, 2026

Copy link
Copy Markdown
Author

Upstream branch: d135ab4
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from 1a6e10f to 168738d Compare October 27, 2026 00:20
@ghost
ghost force-pushed the linus-master_base branch from b3a1abc to 712496f Compare October 28, 2026 23:34
@ghost

ghost commented Oct 29, 2026

Copy link
Copy Markdown
Author

Upstream branch: c339f40
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from 168738d to 410ba27 Compare October 29, 2026 00:00
@ghost
ghost force-pushed the linus-master_base branch from 712496f to a186880 Compare October 30, 2026 13:52
@ghost

ghost commented Oct 30, 2026

Copy link
Copy Markdown
Author

Upstream branch: d89e1d1
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from 410ba27 to 6d4fcd0 Compare October 30, 2026 14:51
@ghost
ghost force-pushed the linus-master_base branch from a186880 to 46206a3 Compare November 2, 2026 17:14
@ghost

ghost commented Nov 2, 2026

Copy link
Copy Markdown
Author

Upstream branch: 6628e7d
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from 6d4fcd0 to 3a83b47 Compare November 2, 2026 18:01
@ghost
ghost force-pushed the linus-master_base branch from 46206a3 to 220bd96 Compare November 3, 2026 23:41
@ghost

ghost commented Nov 4, 2026

Copy link
Copy Markdown
Author

Upstream branch: 05441d6
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from 3a83b47 to f2f1e9a Compare November 4, 2026 00:13
@ghost
ghost force-pushed the linus-master_base branch from 220bd96 to 6c4625e Compare November 6, 2026 08:02
@ghost

ghost commented Nov 6, 2026

Copy link
Copy Markdown
Author

Upstream branch: f66469d
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from f2f1e9a to 5d8eabe Compare November 6, 2026 08:53
@ghost
ghost force-pushed the linus-master_base branch from 6c4625e to c7f678d Compare November 7, 2026 03:08
@ghost

ghost commented Nov 7, 2026

Copy link
Copy Markdown
Author

Upstream branch: d487237
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from 5d8eabe to baefac2 Compare November 7, 2026 03:49
@ghost
ghost force-pushed the linus-master_base branch from c7f678d to 6aa6cd1 Compare November 10, 2026 07:53
syzbot is reporting a NULL pointer dereference [1] and invalid reading of
destroyed "struct file" [2] in lo_rw_aio() within the loop driver. Also,
syzbot-ci is reporting read attempt on a no-longer bound loop device [3].
These reports are caused by current implementation that a block device's
backing storage and associated structures (such as "struct file") are
invalidated before all outstanding asynchronous or file-system-driven I/O
requests have fully completed.

Investigation revealed that filesystems can leak outstanding non-blocking
Read/Write requests during error-rollbacks in the mount failure path or
during standard unmount sequences:

1. Write Leaks via -EIO: When filemap_fdatawrite_range() returns an error
   (such as -EIO due to filesystem errors), filemap_write_and_wait_range()
   skips the subsequent __filemap_fdatawait_range() call. As a result,
   sync_blockdev() returns prematurely without waiting for the completion
   of write requests already sitting in flight.
2. Read Leaks via Readahead: Asynchronous metadata readahead requests are
   entirely ignored by sync_blockdev(), allowing ongoing Read I/O to bypass
   data synchronization entirely.

When these leaked requests later complete or attempt backend processing via
loop's kworker (loop_handle_cmd()), they dereference now-invalid or
nullified fields.

While earlier attempts tried to address this regression inside the loop
driver by temporarily releasing disk->open_mutex [4] or proposing a core
layer post_release() callback [5], these approaches were rejected because
they either introduced invasive driver-specific hooks into the block layer
or broke the core mutual exclusion semantics that the block layer relies
upon.

To fix this comprehensively without introducing deadlocks or altering
driver-specific semantics, enforce an explicit queue freeze in the core
VFS close path inside bdev_release(), right before disk->open_mutex is
acquired:

1. Lock-Free Congestion Clearing: Calling blk_mq_freeze_queue() before
   acquiring disk->open_mutex avoids any circular locking dependencies
   (disk->open_mutex => wq_completion => VFS locks => disk->open_mutex),
   guaranteeing that the lockdep hierarchy remains perfectly undisturbed.
2. Guaranteed Quenching: Freezing the queue ensures that all outstanding
   asynchronous Direct I/O (cmd->use_aio != 0) and page-cache readahead
   requests are physically completed and drained before the loop device
   proceeds to teardown and unbind the backing file via fput().

This architecture-compliant fix should be able to ensure data integrity
and lifecycle synchronization across all virtual block devices without
muddying block layer locks.

Reported-by: syzbot+cd8a9a308e879a4e2c28@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=cd8a9a308e879a4e2c28 [1]
Reported-by: syzbot+bc273027d5643e48e5b3@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=bc273027d5643e48e5b3 [2]
Link: https://lkml.kernel.org/r/6acbe268.8cdf6287.1eb53.00ed.GAE@google.com [3]
Link: https://lkml.kernel.org/r/8dedfc40-9cae-44ff-9960-e0eb1825e963@I-love.SAKURA.ne.jp [4]
Link: https://lkml.kernel.org/r/69960302-1535-441a-be4e-d652766d65c2@I-love.SAKURA.ne.jp [5]
Assisted-by: Gemini-Pro
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
@ghost

ghost commented Nov 10, 2026

Copy link
Copy Markdown
Author

Upstream branch: b3dfbde
series: https://patchwork.kernel.org/series/1183724/
version: 1

@ghost
ghost force-pushed the series/1183724=>linus-master branch from baefac2 to 6eedc2b Compare November 10, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants