mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	BAREBOX <barebox@lists.infradead.org>
Cc: "Claude Opus 4.6 (1M context)" <noreply@anthropic.com>
Subject: Re: [PATCH 2/5] fs: ext4: reject superblocks with zero inodesz, gdsize or inodes_per_group
Date: Fri, 10 Apr 2026 13:51:35 +0200	[thread overview]
Message-ID: <3666e81e-4969-495e-97e2-8c7cbcd1df9f@pengutronix.de> (raw)
In-Reply-To: <20260402-fs-ext4-buffer-overflows-v1-2-b9f8a909fe58@pengutronix.de>

On 4/2/26 12:12 PM, Sascha Hauer wrote:
> The superblock fields inode_size, descriptor_size, and inodes_per_group
> are read from disk and used as divisors without validation:
> 
>   - inodesz == 0: division by zero in ext4fs_read_inode()
>   - gdsize == 0: division by zero in ext4fs_blockgroup()
>   - inodes_per_group == 0: division by zero in ext4fs_read_inode()
> 
> All three are trivially triggered by a crafted filesystem image.
> 
> Validate these fields are non-zero at mount time and reject the
> filesystem if they aren't.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  fs/ext4/ext4_common.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
> index 094293a069..5d252b4a2c 100644
> --- a/fs/ext4/ext4_common.c
> +++ b/fs/ext4/ext4_common.c
> @@ -541,6 +541,15 @@ int ext4fs_mount(struct ext_filesystem *fs)
>  	      le32_to_cpu(data->sblock.revision_level),
>  	      fs->inodesz, fs->gdsize);
>  
> +	if (!fs->inodesz || !fs->gdsize ||
> +	    !le32_to_cpu(data->sblock.inodes_per_group)) {
> +		dev_err(fs->dev, "invalid superblock: inodesz=%u gdsize=%u inodes_per_group=%u\n",
> +			fs->inodesz, fs->gdsize,
> +			le32_to_cpu(data->sblock.inodes_per_group));
> +		ret = -EINVAL;
> +		goto fail;
> +	}
> +
>  	data->diropen.data = data;
>  	data->diropen.ino = 2;
>  	data->diropen.inode_read = 1;
> 

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |




  reply	other threads:[~2026-04-10 11:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-02 10:12 [PATCH 0/5] fs: ext4: protection against corrupted filesystems Sascha Hauer
2026-04-02 10:12 ` [PATCH 1/5] fs: ext4: validate log2_block_size from superblock at mount Sascha Hauer
2026-04-10 11:33   ` Ahmad Fatoum
2026-04-02 10:12 ` [PATCH 2/5] fs: ext4: reject superblocks with zero inodesz, gdsize or inodes_per_group Sascha Hauer
2026-04-10 11:51   ` Ahmad Fatoum [this message]
2026-04-02 10:12 ` [PATCH 3/5] fs: ext4: fix OOB read and infinite loop in ext_iterate() Sascha Hauer
2026-04-02 10:45   ` Sascha Hauer
2026-04-02 10:12 ` [PATCH 4/5] fs: ext4: reject dirents with too-small direntlen to prevent infinite loops Sascha Hauer
2026-04-02 10:12 ` [PATCH 5/5] fs: ext4: validate extent eh_entries against buffer capacity Sascha Hauer
2026-04-13  8:01 ` [PATCH 0/5] fs: ext4: protection against corrupted filesystems Sascha Hauer

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=3666e81e-4969-495e-97e2-8c7cbcd1df9f@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=noreply@anthropic.com \
    --cc=s.hauer@pengutronix.de \
    /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