From: sashiko-bot@kernel.org
To: shaos <shawnq1@163.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH] ext2: validate directory entries before rename
Date: Sat, 28 Nov 2026 05:08:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-238466@kernel.org> (raw)
In-Reply-To: <20261128045214.2649994-1-shawnq1@163.com>
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:
- [High] ext2, ufs: i_nlink underflow in ext2_rmdir() and ufs_rmdir()
[1]
--
commit de08d578a699530700ffcced108cd1f48e146ca0
Author: shaos <shawnq1@163.com>
ext2: validate directory entries before rename
This commit validates the '.' and '..' entries in ext2_dotdot() and checks
that '..' points to old_dir in ext2_rename() before updating directory links.
> diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
> index bfb6a463a95e0..a5b5aff1cfb45 100644
> --- a/fs/ext2/namei.c
> +++ b/fs/ext2/namei.c
> @@ -350,6 +350,12 @@ static int ext2_rename (const struct mnt_idmap * idmap,
> dir_de = ext2_dotdot(old_inode, &dir_folio);
> if (!dir_de)
> goto out_old;
> + if (le32_to_cpu(dir_de->inode) != old_dir->i_ino) {
> + ext2_error(old_inode->i_sb, __func__,
> + "directory #%llu has incorrect '..' entry",
> + (unsigned long long)old_inode->i_ino);
> + goto out_dir;
> + }
> }
>
> if (new_inode) {
[Severity: High]
This problem wasn't introduced by this patch, but can new_inode->i_nlink
underflow when overwriting an existing directory in ext2_rename()
[1]?
In the if (new_inode) block just below, overwriting a directory calls
drop_nlink(new_inode) followed immediately by
inode_dec_link_count(new_inode) (and ext2_rmdir() similarly calls
ext2_unlink() followed by inode_dec_link_count()):
fs/ext2/namei.c:ext2_rename() {
...
if (new_inode) {
...
if (old_is_dir)
drop_nlink(new_inode);
inode_dec_link_count(new_inode);
} else {
...
}
On a corrupted filesystem image where a directory inode has an on-disk
i_nlink of 0 or 1, these two unconditional decrements wrap
new_inode->i_nlink to UINT_MAX, triggering kernel warnings and corrupting
inode lifetime tracking.
[1] https://sashiko.dev/#/bug/linux-218ca4cb-3bec-4504-bb15-b7247a83953c
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261128045214.2649994-1-shawnq1@163.com?part=1
prev parent reply other threads:[~2026-11-28 5:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 4:52 [PATCH] ext2: validate directory entries before rename shaos
2026-11-28 5:08 ` sashiko-bot [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=sashiko-outbox-238466@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shawnq1@163.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