Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "William Chuang" <founder@logarcheon.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH] ext4: reject a non-regular boot loader inode in EXT4_IOC_SWAP_BOOT
Date: Tue, 17 Nov 2026 06:43:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-218276@kernel.org> (raw)
In-Reply-To: <20261117061822.3826-1-founder@logarcheon.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ext4: missing make_bad_inode() before iput() in
  swap_inode_boot_loader()
--

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

ext4: reject a non-regular boot loader inode in EXT4_IOC_SWAP_BOOT

This commit rejects a boot loader inode (inode 5) in
swap_inode_boot_loader() with -EFSCORRUPTED if its mode after ext4_iget()
is not S_IFREG.

Link: https://lore.kernel.org/all/tencent_DABB2333139E8D1BCF4B5D1B2725FABA9108@qq.com/T/
Link: https://sashiko.dev/#/bug/linux-8cfc8e22-8259-4c89-8a8b-64c16e4481a5

> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index e8e579498c990..cf005fe2da34f 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -390,6 +390,20 @@ static long swap_inode_boot_loader(struct super_block *sb,
>  		return PTR_ERR(inode_bl);
>  	ei_bl = EXT4_I(inode_bl);
>  
> +	/*
> +	 * An unused boot loader inode comes back from ext4_iget() as a bad
> +	 * inode, which make_bad_inode() leaves as S_IFREG.  Any other type
> +	 * means the on-disk inode is corrupted; its type cannot be changed
> +	 * in place below.
> +	 */
> +	if (!S_ISREG(inode_bl->i_mode)) {
> +		EXT4_ERROR_INODE(inode_bl,
> +				 "boot loader inode is not a regular file (mode 0%o)",
> +				 inode_bl->i_mode);
> +		iput(inode_bl);
> +		return -EFSCORRUPTED;
> +	}

[Severity: Medium]
Should this error path call make_bad_inode(inode_bl) before iput(inode_bl),
similar to ext4_get_journal_inode()?

__ext4_iget() exempts EXT4_BOOT_LOADER_INO from the i_nlink == 0 check and
only marks it bad when i_mode is not a recognized file type:

fs/ext4/inode.c:__ext4_iget() {
    ...
	if (inode->i_nlink == 0) {
		if ((inode->i_mode == 0 || flags & EXT4_IGET_SPECIAL ||
		     !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) &&
		    ino != EXT4_BOOT_LOADER_INO) {
    ...
}

When a corrupted inode 5 has a valid non-regular i_mode (such as S_IFDIR or
S_IFCHR) and i_nlink == 0, __ext4_iget() returns a live, non-bad inode.
Under errors=continue, iput(inode_bl) then enters ext4_evict_inode(), which
only skips truncation and on-disk deletion when is_bad_inode(inode) is
true, causing it to truncate inode 5, dirty it on disk, and call
ext4_free_inode() on the reserved inode.  If i_nlink > 0, the corrupted
non-regular inode stays hashed in the inode cache instead of being evicted.

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

  reply	other threads:[~2026-11-17  6:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  6:18 [PATCH] ext4: reject a non-regular boot loader inode in EXT4_IOC_SWAP_BOOT William Chuang
2026-11-17  6:43 ` sashiko-bot [this message]
2026-11-17  6:56 ` [PATCH v2] " William Chuang
2026-11-17  7:15   ` sashiko-bot

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-218276@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=founder@logarcheon.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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