Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH 0/2] ext4: fix race conditions and clean up locking of inline data writes
@ 2026-06-30 15:28 Aditya Srivastava
  2026-06-30 15:28 ` [PATCH 1/2] ext4: use fsdata to track inline data write state Aditya Srivastava
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Aditya Srivastava @ 2026-06-30 15:28 UTC (permalink / raw)
  To: Theodore Ts'o
  Cc: Andreas Dilger, Jan Kara, Baokun Li, Ojaswin Mujoo,
	Ritesh Harjani, Zhang Yi, Tao Ma, syzbot+0c89d865531d053abb2d,
	linux-ext4, linux-fsdevel, linux-kernel,
	Aditya Prakash Srivastava

From: Aditya Prakash Srivastava <aditya.ansh182@gmail.com>

This patch series addresses the remaining race conditions and locking
issues involved with inline data writes, implementing the clean
state-communication design suggested by Jan Kara.

Previously, `ext4_write_end()`, `ext4_journalled_write_end()`, and
`ext4_da_write_end()` checked the inode state and the inline data flag
directly to decide whether to finish writing inline data or to fall
back to block writes. This is highly susceptible to TOCTOU race
conditions where concurrent memory-mapped page faults
(`ext4_page_mkwrite()`) can convert the inline data to an extent
between `write_begin` and `write_end`. Since block buffers were not
allocated in the inline path during `write_begin`, such fallbacks
resulted in kernel crashes and NULL pointer dereferences because
`folio_buffers(folio)` was NULL.

The series cleans up and resolves these issues in two distinct steps:

1) Patch 1 introduces state tracking via the standard `fsdata`
   parameter. By marking whether a write was prepared as inline
   (`EXT4_WRITE_DATA_INLINE`) directly in the private per-write
   `fsdata` during `write_begin`, the corresponding `write_end`
   handlers can reliably decide whether to call
   `ext4_write_inline_data_end()` or complete a normal extent write.
   This eliminates the race-prone checks on the live inode state and
   gets rid of crude fallback/retry hacks.

2) Patch 2 replaces a potential kernel panic
   (`BUG_ON(!ext4_has_inline_data(inode))`) inside
   `ext4_write_inline_data_end()` with a graceful retry error path.
   If a concurrent conversion clears the inline flag right after the
   `write_end` checks pass but before the xattr semaphore is acquired,
   we gracefully release all held resources and return 0 (VFS retry) to
   let the VFS safely retry the write from scratch.

The series compiles clean against the latest linux-next/ext4 tree.

Thanks,
Aditya

Aditya Prakash Srivastava (2):
  ext4: use fsdata to track inline data write state
  ext4: replace BUG_ON with graceful retry in ext4_write_inline_data_end

 fs/ext4/ext4.h   |  1 +
 fs/ext4/inline.c | 14 +++++++++++++-
 fs/ext4/inode.c  | 22 +++++++++++++---------
 3 files changed, 27 insertions(+), 10 deletions(-)

-- 
2.47.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-07-01  9:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30 15:28 [PATCH 0/2] ext4: fix race conditions and clean up locking of inline data writes Aditya Srivastava
2026-06-30 15:28 ` [PATCH 1/2] ext4: use fsdata to track inline data write state Aditya Srivastava
2026-07-01  9:26   ` Jan Kara
2026-06-30 15:28 ` [PATCH 2/2] ext4: replace BUG_ON with graceful retry in ext4_write_inline_data_end Aditya Srivastava
2026-07-01  9:03 ` [PATCH 0/2] ext4: fix race conditions and clean up locking of inline data writes Jan Kara
2026-07-01  9:29   ` Aditya Prakash Srivastava
2026-07-01  9:36     ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox