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 v2] ext4: reject a non-regular boot loader inode in EXT4_IOC_SWAP_BOOT
Date: Tue, 17 Nov 2026 07:15:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-218310@kernel.org> (raw)
In-Reply-To: <20261117065645.4409-1-founder@logarcheon.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ext4: unlocked make_bad_inode() in swap_inode_boot_loader()
  races with iget
- [Low] ext4: redundant !S_ISREG() check left in
  swap_inode_boot_loader()
--

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

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

This commit rejects EXT4_IOC_SWAP_BOOT when the boot loader inode is not a
regular file, marking the inode bad before dropping the reference.

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..8990122f585df 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -390,6 +390,26 @@ 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);
> +		/*
> +		 * Drop it as a bad inode, as ext4_get_journal_inode() does:
> +		 * with i_nlink == 0, a plain iput() would try to delete the
> +		 * reserved inode, and otherwise it would stay cached.
> +		 */
> +		make_bad_inode(inode_bl);
> +		iput(inode_bl);
> +		return -EFSCORRUPTED;
> +	}
> +
>  	/* Protect orig inodes against a truncate and make sure,
>  	 * that only 1 swap_inode_boot_loader is running. */
>  	lock_two_nondirectories(inode, inode_bl);

[Severity: Medium]
Can calling make_bad_inode(inode_bl) on a live, unlocked inode race with a
concurrent swap_inode_boot_loader() caller and trick it into treating the
corrupted inode as an unused boot loader inode?

When the on-disk boot loader inode has a valid non-regular mode,
__ext4_iget() unlocks and returns it while it is hashed in the inode cache.
make_bad_inode() overwrites inode_bl->i_mode with S_IFREG and sets
inode_bl->i_op to &bad_inode_ops, which is the same state
swap_inode_boot_loader() uses to identify an unused boot loader inode:

CPU0                                  CPU1
swap_inode_boot_loader()              swap_inode_boot_loader()
  inode_bl = ext4_iget(...)
  !S_ISREG(inode_bl->i_mode)
  EXT4_ERROR_INODE(...)
                                        inode_bl = ext4_iget(...)
                                          /* gets same cached inode_bl */
  make_bad_inode(inode_bl)
    inode_bl->i_mode = S_IFREG
    inode_bl->i_op = &bad_inode_ops
  iput(inode_bl)
                                        !S_ISREG(inode_bl->i_mode) /* false */
                                        ...
                                        if (is_bad_inode(inode_bl) || ...)
                                          /* reinitializes & swaps inode_bl */

CPU1 then bypasses the !S_ISREG(inode_bl->i_mode) check, enters the
is_bad_inode(inode_bl) branch, and swaps the corrupted inode (preserving
its stale i_blocks, i_bytes, and union fields) with the caller's file.

[Severity: Low]
This isn't a bug, but now that non-regular boot loader inodes are rejected
upfront here, is the !S_ISREG(inode_bl->i_mode) check added by
991ed014de08 ("ext4: fix bug_on in __es_tree_search caused by bad boot
loader inode") further down in swap_inode_boot_loader() now redundant?

fs/ext4/ioctl.c:swap_inode_boot_loader() {
    ...
	if (is_bad_inode(inode_bl) || !S_ISREG(inode_bl->i_mode)) {
		/* this inode has never been used as a BOOT_LOADER */
    ...
}

Dropping !S_ISREG(inode_bl->i_mode) from that condition would keep the two
checks consistent.

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

      reply	other threads:[~2026-11-17  7:15 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
2026-11-17  6:56 ` [PATCH v2] " William Chuang
2026-11-17  7:15   ` 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-218310@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