mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: William Chuang <founder@logarcheon.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>,
	Jan Kara <jack@suse.cz>, Ojaswin Mujoo <ojaswin@linux.ibm.com>,
	Ritesh Harjani <ritesh.list@gmail.com>,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+e8180f5590685cbc9037@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com
Subject: [PATCH 2/2] ext4: reserve an orphan credit for inline data writes
Date: Tue, 17 Nov 2026 05:28:11 +0000	[thread overview]
Message-ID: <20261117052750.2955-3-founder@logarcheon.com> (raw)
In-Reply-To: <20261117052750.2955-1-founder@logarcheon.com>

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



      parent reply	other threads:[~2026-11-17  5:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=20261117052750.2955-3-founder@logarcheon.com \
    --to=founder@logarcheon.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=syzbot+e8180f5590685cbc9037@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=tytso@mit.edu \
    /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

all inboxes | Powered by JetHome®