From: syzbot <syzbot+09bec78ee77613a3efdd@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org
Subject: Forwarded: [PATCH] ext4: don't append a directory block already mapped in the inode
Date: Sun, 04 Oct 2026 11:49:48 -0700 [thread overview]
Message-ID: <6ac29fcc.01314a6c.556a8.0008.GAE@google.com> (raw)
In-Reply-To: <6abae226.69bd487b.a6f8c.000a.GAE@google.com>
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] ext4: don't append a directory block already mapped in the inode
Author: adrianox@gmail.com
#syz test: upstream master
---
fs/ext4/namei.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 3b9740c1c16d..7b356baf7bd4 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -83,6 +83,36 @@ static struct buffer_head *ext4_append(handle_t *handle,
bh = ext4_bread(handle, inode, *block, EXT4_GET_BLOCKS_CREATE);
if (IS_ERR(bh))
return bh;
+
+ /*
+ * The logical block was a hole, but a corrupt block bitmap can make
+ * the allocator hand out a physical block that is already in use,
+ * possibly by another block of this very inode. Callers such as
+ * do_split()/make_indexed_dir() assume the newly appended block is
+ * distinct from the blocks they are about to modify; if it aliases
+ * one of them, moving directory entries between the two buffers
+ * corrupts the directory. Make sure the new block is not already
+ * mapped by this inode.
+ */
+ for (map.m_lblk = 0; map.m_lblk < *block; ) {
+ map.m_len = *block - map.m_lblk;
+ err = ext4_map_blocks(NULL, inode, &map, 0);
+ if (err < 0)
+ goto out;
+ if (err == 0) {
+ map.m_lblk++;
+ continue;
+ }
+ if (unlikely(map.m_pblk == bh->b_blocknr)) {
+ EXT4_ERROR_INODE(inode,
+ "new block %llu already mapped",
+ (unsigned long long)bh->b_blocknr);
+ err = -EFSCORRUPTED;
+ goto out;
+ }
+ map.m_lblk += map.m_len;
+ }
+
inode->i_size += inode->i_sb->s_blocksize;
EXT4_I(inode)->i_disksize = inode->i_size;
err = ext4_mark_inode_dirty(handle, inode);
--
2.51.0
next prev parent reply other threads:[~2026-10-04 18:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 21:54 [syzbot] [ext4?] KASAN: slab-use-after-free Write in do_split syzbot
2026-09-29 0:32 ` syzbot
2026-09-29 1:00 ` Qu Wenruo
2026-10-01 19:48 ` Forwarded: [PATCH] ext4: validate dirents before splitting a directory syzbot
2026-10-01 20:34 ` Forwarded: [PATCH] ext4: don't trust on-disk rec_len in dx_move_dirents() syzbot
2026-10-01 21:30 ` syzbot
2026-10-04 18:49 ` syzbot [this message]
2026-10-04 23:01 ` Forwarded: [PATCH] ext4: don't append a directory block already mapped in the inode syzbot
2026-10-05 1:01 ` syzbot
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=6ac29fcc.01314a6c.556a8.0008.GAE@google.com \
--to=syzbot+09bec78ee77613a3efdd@syzkaller.appspotmail.com \
--cc=linux-kernel@vger.kernel.org \
/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®