From: sashiko-bot@kernel.org
To: "Shawn Shao" <shawnq1@163.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH v2] ext2: validate directory entries before rename
Date: Tue, 01 Dec 2026 14:35:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-243496@kernel.org> (raw)
In-Reply-To: <179613469562.187341.6558824516172704292.1796134695.4-1-shawnq1@163.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ext2: lax dot_len check in ext2_check_folio() lets
ext2_add_link() split '.'
- [Low] ext2: commit message formatted as email reply without problem
description
--
commit 9941f46a8139b486ee5aa49e86c4ccf959cce7a4
Author: Shawn Shao <shawnq1@163.com>
> ext2: validate directory entries before rename
>
> Hello Jan,
>
> Thanks for the suggestion. I moved validation of the `.` and `..` records
> to `ext2_check_folio()` for the first directory folio, after the existing
> record-boundary checks. `ext2_get_folio()` runs this validation before a
> caller can use a directory-entry pointer. The `..` inode comparison stays
> in `ext2_rename()`, where `old_dir` is available.
>
> The malformed image still makes cross-directory rename return `-EIO`; the
> valid-image rename control succeeds. I also rebuilt the full x86-64 kernel
> and ran both cases in QEMU.
>
> Tested on Linux 7.4-rc4, commit
> 7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046, tree
> 194227446ae61b4971eea1b7bed06856fe3cc477, with gcc 11.4.0 and QEMU 6.2.0.
> The reproducer, image builder, kernel configuration, and updated console
> logs are collected here:
> https://gist.github.com/shaos26/afcee45e1ee5b8da6bbfdb8b642093a8
>
> Changes in v2:
> - Validate the first two directory entries in `ext2_check_folio()`.
> - Keep the expected-parent check in `ext2_rename()`.
>
> Thanks,
> Shawn Shao
>
> Signed-off-by: Shawn Shao <shawnq1@163.com>
[Severity: Low]
The commit message is formatted as an email reply with v2 changelog notes
rather than a standalone description of the bug being fixed. Conversational
notes and version history belong below the --- separator, while the commit
log should explain why missing or invalid "." and ".." entries cause a
problem in ext2_dotdot() and ext2_rename().
> diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
> index 5de32c221a83b..10f33a2de0acc 100644
> --- a/fs/ext2/dir.c
> +++ b/fs/ext2/dir.c
> @@ -112,9 +112,11 @@ static bool ext2_check_folio(struct folio *folio, int quiet, char *kaddr)
> limit = offset_in_folio(folio, dir->i_size);
> if (limit & (chunk_size - 1))
> goto Ebadsize;
> - if (!limit)
> + if (!limit && folio_pos(folio))
> goto out;
> }
> + if (!limit)
> + goto bad_dot;
> for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
> p = (ext2_dirent *)(kaddr + offs);
> rec_len = ext2_rec_len_from_disk(p->rec_len);
> @@ -132,6 +134,24 @@ static bool ext2_check_folio(struct folio *folio, int quiet, char *kaddr)
> }
> if (offs != limit)
> goto Eend;
> + if (!folio_pos(folio)) {
> + unsigned int dot_len, dotdot_len;
> +
> + p = (ext2_dirent *)kaddr;
> + dot_len = ext2_rec_len_from_disk(p->rec_len);
> + if (p->name_len != 1 || p->name[0] != '.' ||
> + le32_to_cpu(p->inode) != dir->i_ino ||
> + dot_len > chunk_size - EXT2_DIR_REC_LEN(2))
> + goto bad_dot;
[Severity: Medium]
Should dot_len be required to equal EXT2_DIR_REC_LEN(1) instead of only
checking dot_len > chunk_size - EXT2_DIR_REC_LEN(2)?
If a crafted image has "." at offset 0 with dot_len >= 24 and ".." at
kaddr + dot_len, ext2_check_folio() marks the folio checked. When a new
entry is later added to that directory, ext2_add_link() starts scanning at
offset 0, sees rec_len >= name_len + reclen on ".", and splits "." to insert
the new entry at offset 12 ahead of "..". After that, ext2_dotdot() returns
the new entry instead of "..", causing a later cross-directory ext2_rename()
or folio re-read to trigger ext2_error().
--
Sashiko AI review · https://sashiko.dev/#/patchset/179613469562.187341.6558824516172704292.1796134695.4-1-shawnq1@163.com?part=1
next prev parent reply other threads:[~2026-12-01 14:35 UTC|newest]
Thread overview: 6+ 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
2026-11-30 12:58 ` Jan Kara
2026-12-01 14:18 ` [PATCH v2] " Shawn Shao
2026-12-01 14:35 ` sashiko-bot [this message]
2026-12-01 14:42 ` Jan Kara
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-243496@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