Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH 0/2] ext4: fix two journal credit shortfalls behind one syzbot report
@ 2026-11-17  5:27 William Chuang
  2026-11-17  5:28 ` [PATCH 1/2] ext4: reserve quota credits in swap_inode_boot_loader() William Chuang
  2026-11-17  5:28 ` [PATCH 2/2] ext4: reserve an orphan credit for inline data writes William Chuang
  0 siblings, 2 replies; 5+ messages in thread
From: William Chuang @ 2026-11-17  5:27 UTC (permalink / raw)
  To: Theodore Ts'o
  Cc: Andreas Dilger, Jan Kara, Ojaswin Mujoo, Ritesh Harjani,
	linux-ext4, linux-kernel, syzbot+e8180f5590685cbc9037,
	syzkaller-bugs

syzbot report e8180f5590685cbc9037 ("WARNING in jbd2_journal_dirty_metadata
(4)") collects crashes from two separate paths. Both hit the same WARN:
a handle dirties a new metadata block after its credits are used up.

1. EXT4_IOC_SWAP_BOOT: swap_inode_boot_loader() reserves 2 credits, then
   updates quota under the same handle (crashes of 15 and 16 Nov).

2. Inline data buffered write with a short user copy:
   ext4_generic_write_inline_data() reserves 1 credit, and
   ext4_write_inline_data_end() then calls ext4_orphan_add() (crashes of
   12-14 Nov, x86_64 and arm64, including data=journal).

Both were reproduced on UML at 666539eec ("Merge tag
'assoc-array-fixes-v2'") with small standalone reproducers, before and
after each fix; details are in each changelog. One patch per path, so
each can be reviewed alone. Both patches carry the same Reported-by
tag, and the report closes only when both are applied.

William Chuang (2):
  ext4: reserve quota credits in swap_inode_boot_loader()
  ext4: reserve an orphan credit for inline data writes

 fs/ext4/inline.c | 7 ++++++-
 fs/ext4/ioctl.c  | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

-- 
2.43.0



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

* [PATCH 1/2] ext4: reserve quota credits in swap_inode_boot_loader()
  2026-11-17  5:27 [PATCH 0/2] ext4: fix two journal credit shortfalls behind one syzbot report William Chuang
@ 2026-11-17  5:28 ` William Chuang
  2026-11-17  6:00   ` sashiko-bot
  2026-11-17  5:28 ` [PATCH 2/2] ext4: reserve an orphan credit for inline data writes William Chuang
  1 sibling, 1 reply; 5+ messages in thread
From: William Chuang @ 2026-11-17  5:28 UTC (permalink / raw)
  To: Theodore Ts'o
  Cc: Andreas Dilger, Jan Kara, Ojaswin Mujoo, Ritesh Harjani,
	linux-ext4, linux-kernel, syzbot+e8180f5590685cbc9037,
	syzkaller-bugs

swap_inode_boot_loader() starts its handle with 2 credits, enough for
the two inode table blocks it dirties.  Since commit aa507b5faf38
("ext4: update quota information while swapping boot loader inode") it
also calls dquot_free_space() or dquot_alloc_space() under the same
handle.  On a filesystem with quota enabled, that marks the dquots
dirty and ext4_write_dquot() writes them to the quota file.  The
nested ext4_journal_start() in ext4_write_dquot() reuses the running
handle and adds no credits, so the quota block write can find the
handle with no credits left:

  WARNING: fs/jbd2/transaction.c:1598 at jbd2_journal_dirty_metadata
  Call Trace:
   __ext4_handle_dirty_metadata
   ext4_quota_write
   qtree_write_dquot
   v2_write_dquot
   dquot_commit
   ext4_write_dquot
   mark_all_dquot_dirty
   __dquot_free_space
   swap_inode_boot_loader
   ext4_ioctl

jbd2 returns -ENOSPC and the journal is aborted.  The ioctl still
returns 0, and the filesystem is left with the wrong i_blocks on the
swapped inode and inconsistent quota usage, which e2fsck reports.

Reserve one quota block per quota type, as ext4_ext_migrate() does.

Tested on UML with a filesystem made by "mke2fs -O quota": write and
sync a file, then issue EXT4_IOC_SWAP_BOOT on it.  Without this patch
the WARN fires ("credits 3/0") and e2fsck -fn reports errors; with it
there is no warning and e2fsck -fn is clean.

Fixes: aa507b5faf38 ("ext4: update quota information while swapping boot loader inode")
Reported-by: syzbot+e8180f5590685cbc9037@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e8180f5590685cbc9037
Signed-off-by: William Chuang <founder@logarcheon.com>
---
 fs/ext4/ioctl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index e8e579498..ae03eb834 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -425,7 +425,12 @@ static long swap_inode_boot_loader(struct super_block *sb,
 	truncate_inode_pages(&inode->i_data, 0);
 	truncate_inode_pages(&inode_bl->i_data, 0);
 
-	handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2);
+	/*
+	 * Two inode table blocks, plus one quota block per quota type for
+	 * the dquot_free_space()/dquot_alloc_space() update below.
+	 */
+	handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS,
+				    2 + EXT4_MAXQUOTAS_TRANS_BLOCKS(sb));
 	if (IS_ERR(handle)) {
 		err = -EINVAL;
 		goto err_out;
-- 
2.43.0



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

* [PATCH 2/2] ext4: reserve an orphan credit for inline data writes
  2026-11-17  5:27 [PATCH 0/2] ext4: fix two journal credit shortfalls behind one syzbot report William Chuang
  2026-11-17  5:28 ` [PATCH 1/2] ext4: reserve quota credits in swap_inode_boot_loader() William Chuang
@ 2026-11-17  5:28 ` William Chuang
  2026-11-17  5:36   ` sashiko-bot
  1 sibling, 1 reply; 5+ messages in thread
From: William Chuang @ 2026-11-17  5:28 UTC (permalink / raw)
  To: Theodore Ts'o
  Cc: Andreas Dilger, Jan Kara, Ojaswin Mujoo, Ritesh Harjani,
	linux-ext4, linux-kernel, syzbot+e8180f5590685cbc9037,
	syzkaller-bugs

ext4_generic_write_inline_data() starts its handle with one credit.
ext4_prepare_inline_data() uses it when it creates or grows the inline
data xattr and dirties the inode table block.

If the copy from user space then comes up short, write_end calls
ext4_write_inline_data_end(), which sees pos + len > i_size and calls
ext4_orphan_add() under the same handle.  That dirties a second block,
the orphan file block or the superblock, and the handle has no credit
left for it:

  WARNING: fs/jbd2/transaction.c:1598 at jbd2_journal_dirty_metadata
  Call Trace:
   __ext4_handle_dirty_metadata
   ext4_orphan_file_add
   ext4_orphan_add
   ext4_write_inline_data_end
   generic_perform_write
   ext4_buffered_write_iter
   ext4_file_write_iter

jbd2 returns -ENOSPC, the journal is aborted and write() fails with
ENOSPC.  An unprivileged user who can write to a file on such a
filesystem can trigger this.  The inode table block must not already
be dirty in the running transaction, which is the case with lazytime,
or when the write is the first change to that block since the last
commit.  The block write path already reserves an extra credit for
this case in ext4_write_begin().

Start the inline handle with two credits.

Tested on UML with filesystems made by "mke2fs -O inline_data", with
and without orphan_file, mounted with lazytime: a write to a new file
whose user buffer runs into an unmapped page after 10 of 21 bytes.
Without this patch the WARN fires ("credits 2/0") and write() fails
with ENOSPC, also when run as uid 65534; with it there is no warning,
write() returns 10, and e2fsck -fn is clean.

Fixes: f19d5870cbf7 ("ext4: add normal write support for inline data")
Reported-by: syzbot+e8180f5590685cbc9037@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e8180f5590685cbc9037
Signed-off-by: William Chuang <founder@logarcheon.com>
---
 fs/ext4/inline.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index ceee69a66..a1ae23888 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -709,7 +709,12 @@ int ext4_generic_write_inline_data(struct address_space *mapping,
 		return ret;
 
 retry_journal:
-	handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
+	/*
+	 * One credit for the inode table block, plus one for the orphan
+	 * file block or superblock that ext4_write_inline_data_end() may
+	 * dirty via ext4_orphan_add() after a short copy.
+	 */
+	handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
 	if (IS_ERR(handle)) {
 		ret = PTR_ERR(handle);
 		goto out_release_bh;
-- 
2.43.0



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

* Re: [PATCH 2/2] ext4: reserve an orphan credit for inline data writes
  2026-11-17  5:28 ` [PATCH 2/2] ext4: reserve an orphan credit for inline data writes William Chuang
@ 2026-11-17  5:36   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-17  5:36 UTC (permalink / raw)
  To: William Chuang; +Cc: linux-ext4, tytso

> ext4_generic_write_inline_data() starts its handle with one credit.
> ext4_prepare_inline_data() uses it when it creates or grows the inline
> data xattr and dirties the inode table block.
> 
> If the copy from user space then comes up short, write_end calls
> ext4_write_inline_data_end(), which sees pos + len > i_size and calls
> ext4_orphan_add() under the same handle.  That dirties a second block,
> the orphan file block or the superblock, and the handle has no credit
> left for it:
> 
>   WARNING: fs/jbd2/transaction.c:1598 at jbd2_journal_dirty_metadata
>   Call Trace:
>    __ext4_handle_dirty_metadata
>    ext4_orphan_file_add
>    ext4_orphan_add
> [ ... ]
> 
> Fixes: f19d5870cbf7 ("ext4: add normal write support for inline data")
> Reported-by: syzbot+e8180f5590685cbc9037@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=e8180f5590685cbc9037
> Signed-off-by: William Chuang <founder@logarcheon.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117052750.2955-1-founder@logarcheon.com?part=2


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

* Re: [PATCH 1/2] ext4: reserve quota credits in swap_inode_boot_loader()
  2026-11-17  5:28 ` [PATCH 1/2] ext4: reserve quota credits in swap_inode_boot_loader() William Chuang
@ 2026-11-17  6:00   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-17  6:00 UTC (permalink / raw)
  To: William Chuang; +Cc: linux-ext4, tytso

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] ext4: missing inode_bl type check in
  swap_inode_boot_loader() [1]
--

commit bcadebc925a37de0440a70c290c23f8fd547aadb
Author: William Chuang <founder@logarcheon.com>

ext4: reserve quota credits in swap_inode_boot_loader()

This commit reserves quota transaction credits in
swap_inode_boot_loader() to prevent running out of journal credits when
updating quota information during EXT4_IOC_SWAP_BOOT.

> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index e8e579498c990..ae03eb834c7ac 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -425,7 +425,12 @@ static long swap_inode_boot_loader(struct super_block *sb,
>  	truncate_inode_pages(&inode->i_data, 0);
>  	truncate_inode_pages(&inode_bl->i_data, 0);
>  
> -	handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2);
> +	/*
> +	 * Two inode table blocks, plus one quota block per quota type for
> +	 * the dquot_free_space()/dquot_alloc_space() update below.
> +	 */
> +	handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS,
> +				    2 + EXT4_MAXQUOTAS_TRANS_BLOCKS(sb));
>  	if (IS_ERR(handle)) {
>  		err = -EINVAL;
>  		goto err_out;

[Severity: Critical]
This problem wasn't introduced by this patch, but can a crafted
filesystem where EXT4_BOOT_LOADER_INO is a directory trigger a warning
and corrupt VFS state in swap_inode_boot_loader() [1]?

fs/ext4/ioctl.c:swap_inode_boot_loader() {
	...
	inode_bl = ext4_iget(sb, EXT4_BOOT_LOADER_INO,
			EXT4_IGET_SPECIAL | EXT4_IGET_BAD);
	if (IS_ERR(inode_bl))
		return PTR_ERR(inode_bl);
	ei_bl = EXT4_I(inode_bl);

	lock_two_nondirectories(inode, inode_bl);
	...
	if (is_bad_inode(inode_bl) || !S_ISREG(inode_bl->i_mode)) {
		...
		inode_bl->i_mode = S_IFREG;
	}
	...
}

inode_bl is passed to lock_two_nondirectories() before its mode is
checked, which triggers WARN_ON_ONCE(S_ISDIR(inode2->i_mode)).  Then the
!S_ISREG() branch overwrites inode_bl->i_mode with S_IFREG instead of
rejecting it, changing the type of a cached directory inode in place.

[1] https://sashiko.dev/#/bug/linux-8cfc8e22-8259-4c89-8a8b-64c16e4481a5

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117052750.2955-1-founder@logarcheon.com?part=1

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

end of thread, other threads:[~2026-11-17  6:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  5:27 [PATCH 0/2] ext4: fix two journal credit shortfalls behind one syzbot report William Chuang
2026-11-17  5:28 ` [PATCH 1/2] ext4: reserve quota credits in swap_inode_boot_loader() William Chuang
2026-11-17  6:00   ` sashiko-bot
2026-11-17  5:28 ` [PATCH 2/2] ext4: reserve an orphan credit for inline data writes William Chuang
2026-11-17  5:36   ` sashiko-bot

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