public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Tudor Ambarus <tudor.ambarus@linaro.org>
Cc: tytso@mit.edu, adilger.kernel@dilger.ca,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
	joneslee@google.com,
	syzbot+0827b4b52b5ebf65f219@syzkaller.appspotmail.com,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] ext4: Fix possible use-after-free in ext4_find_extent
Date: Thu, 29 Dec 2022 22:56:16 -0800	[thread overview]
Message-ID: <Y66LkPumQjHC2U7d@sol.localdomain> (raw)
In-Reply-To: <20221230062931.2344157-1-tudor.ambarus@linaro.org>

On Fri, Dec 30, 2022 at 08:29:31AM +0200, Tudor Ambarus wrote:
> syzbot reported a use-after-free Read in ext4_find_extent that is hit when
> using a corrupted file system. The bug was reported on Android 5.15, but
> using the same reproducer triggers the bug on v6.2-rc1 as well.
> 
> Fix the use-after-free by checking the extent header magic. An alternative
> would be to check the values of EXT4_{FIRST,LAST}_{EXTENT,INDEX} used in
> ext4_ext_binsearch() and ext4_ext_binsearch_idx(), so that we make sure
> that pointers returned by EXT4_{FIRST,LAST}_{EXTENT,INDEX} don't exceed the
> bounds of the extent tree node. But this alternative will not squash
> the bug for the cases where eh->eh_entries fit into eh->eh_max. We could
> also try to check the sanity of the path, but costs more than checking just
> the header magic, so stick to the header magic sanity check.
> 
> Link: https://syzkaller.appspot.com/bug?id=be6e90ce70987950e6deb3bac8418344ca8b96cd
> Reported-by: syzbot+0827b4b52b5ebf65f219@syzkaller.appspotmail.com
> Cc: stable@vger.kernel.org
> Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
> ---
> v2: drop wrong/uneeded le16_to_cpu() conversion for eh->eh_magic
> 
>  fs/ext4/extents.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 9de1c9d1a13d..bedc8c098449 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -894,6 +894,12 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block,
>  		gfp_flags |= __GFP_NOFAIL;
>  
>  	eh = ext_inode_hdr(inode);
> +	if (eh->eh_magic != EXT4_EXT_MAGIC) {
> +		EXT4_ERROR_INODE(inode, "Extent header has invalid magic.");
> +		ret = -EFSCORRUPTED;
> +		goto err;
> +	}
> +

This is (incompletely) validating the extent header in the inode.  Isn't that
supposed to happen when the inode is loaded?  See how __ext4_iget() calls
ext4_ext_check_inode().  Why isn't that working here?

- Eric

  reply	other threads:[~2022-12-30  6:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-30  6:29 [PATCH v2] ext4: Fix possible use-after-free in ext4_find_extent Tudor Ambarus
2022-12-30  6:56 ` Eric Biggers [this message]
2022-12-30 11:42   ` Tudor Ambarus
2022-12-30 20:07     ` Eric Biggers
2023-01-02  5:41       ` Tudor Ambarus
2022-12-30 20:22     ` Theodore Ts'o

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=Y66LkPumQjHC2U7d@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=adilger.kernel@dilger.ca \
    --cc=joneslee@google.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+0827b4b52b5ebf65f219@syzkaller.appspotmail.com \
    --cc=tudor.ambarus@linaro.org \
    --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