[BUG] iomap: NULL dereference in iomap_finish_folio_read after deferred failed read

From: Sam Sun

Date: Sat May 23 2026 - 07:02:45 EST


Dear developers and maintainers,

We encountered a NULL pointer dereference in the deferred buffered
read failure path. Unfortunately, no reproducer is available yet.

```
Oops: general protection fault, probably for non-canonical address
0xdffffc0000000000: 0000 [#1] SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
CPU: 0 UID: 0 PID: 10774 Comm: kworker/0:9 Tainted: G L
7.1.0-rc2-g70390501d194-dirty #33 PREEMPT(full)
Tainted: [L]=SOFTLOCKUP
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
Workqueue: events iomap_fail_reads
RIP: 0010:iomap_finish_folio_read+0x12c/0x2c0 fs/iomap/buffered-io.c:415
Code: 48 c1 e1 0c 48 c1 ea 03 4c 01 e9 80 3c 02 00 0f 85 6f 01 00 00
48 b8 00 00 00 00 00 fc ff df 4c 8b 6d 18 4c 89 ea 48 c1 ea 03 <80> 3c
02 00 0f 85 39 01 00 00 48 b8 00 00 00 00 00 fc ff df 49 8b
RSP: 0018:ffa00000058ffb50 EFLAGS: 00010246
RAX: dffffc0000000000 RBX: 00000000fffffffb RCX: 0000000000000000
RDX: 0000000000000000 RSI: ffffffff8263bc9e RDI: ffd40000023aab58
RBP: ffd40000023aab40 R08: 0000000000000001 R09: 0000000000000001
R10: ffffffff90b5ee97 R11: 00000000000009d8 R12: 0000000000000800
R13: 0000000000000000 R14: ff11000076809e80 R15: 0000000000000800
FS: 0000000000000000(0000) GS:ff11000183bb2000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f6637788c38 CR3: 0000000036ca9000 CR4: 0000000000753ef0
DR0: 000000000000007f DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
PKRU: 55555554
Call Trace:
<TASK>
__iomap_read_end_io+0x478/0x940 fs/iomap/bio.c:21
iomap_fail_reads+0xa4/0xe0 fs/iomap/bio.c:43
process_one_work+0xbe6/0x2030 kernel/workqueue.c:3467
process_scheduled_works kernel/workqueue.c:3576 [inline]
worker_thread+0x693/0xeb0 kernel/workqueue.c:3657
kthread+0x38d/0x4a0 kernel/kthread.c:436
ret_from_fork+0xb09/0xdb0 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
```

We analyzed the cause of this report. It seems that failed buffered
read bios are deferred to a global work item "failed_read_work". The
deferred worker still owns the bio/folio, but by the time it calls
`iomap_finish_folio_read()`, the folio may have been truncated,
invalidated, or otherwise detached from its mapping. In that case,
`folio->mapping` is NULL, but the error reporting path unconditionally
dereferences `folio->mapping->host`. This pattern still exists on the
latest kernel commit.

A possible fix could be avoiding the `folio->mapping->host`
dereference in the deferred failure worker, including storing a stable
inode/address_space reference when the read bio is submitted or
completed, or using `folio_mapping(folio)` in
`iomap_finish_folio_read()` and skipping `fserror_report_io()` if the
folio has been detached.

Best regards,
Yue