public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Lukas Czerner <lczerner@redhat.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: "Ext4 Developers List" <linux-ext4@vger.kernel.org>,
	"Nils Bars" <nils.bars@rub.de>,
	"Moritz Schlögel" <moritz.schloegel@rub.de>,
	"Nico Schiller" <nico.schiller@rub.de>
Subject: Re: [PATCH 7/7] libext2fs: check for invalid blocks in ext2fs_punch_blocks()
Date: Tue, 7 Jun 2022 16:22:48 +0200	[thread overview]
Message-ID: <20220607142248.3zp564uieel5zjrb@fedora> (raw)
In-Reply-To: <20220607042444.1798015-8-tytso@mit.edu>

Looks good.

Reviewed-by: Lukas Czerner <lczerner@redhat.com>


Thanks!
-Lukas

On Tue, Jun 07, 2022 at 12:24:44AM -0400, Theodore Ts'o wrote:
> If the extent tree has out-of-range physical block numbers, don't try
> to release them.
> 
> Also add a similar check in ext2fs_block_alloc_stats2() to avoid a
> NULL pointer dereference.
> 
> Reported-by: Nils Bars <nils.bars@rub.de>
> Reported-by: Moritz Schlögel <moritz.schloegel@rub.de>
> Reported-by: Nico Schiller <nico.schiller@rub.de>
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> ---
>  lib/ext2fs/alloc_stats.c | 3 ++-
>  lib/ext2fs/punch.c       | 4 ++++
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/ext2fs/alloc_stats.c b/lib/ext2fs/alloc_stats.c
> index 3949f618..6f98bcc7 100644
> --- a/lib/ext2fs/alloc_stats.c
> +++ b/lib/ext2fs/alloc_stats.c
> @@ -62,7 +62,8 @@ void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse)
>  {
>  	int	group = ext2fs_group_of_blk2(fs, blk);
>  
> -	if (blk >= ext2fs_blocks_count(fs->super)) {
> +	if (blk < fs->super->s_first_data_block ||
> +	    blk >= ext2fs_blocks_count(fs->super)) {
>  #ifndef OMIT_COM_ERR
>  		com_err("ext2fs_block_alloc_stats", 0,
>  			"Illegal block number: %lu", (unsigned long) blk);
> diff --git a/lib/ext2fs/punch.c b/lib/ext2fs/punch.c
> index effa1e2d..e2543e1e 100644
> --- a/lib/ext2fs/punch.c
> +++ b/lib/ext2fs/punch.c
> @@ -200,6 +200,10 @@ static errcode_t punch_extent_blocks(ext2_filsys fs, ext2_ino_t ino,
>  	__u32		cluster_freed;
>  	errcode_t	retval = 0;
>  
> +	if (free_start < fs->super->s_first_data_block ||
> +	    (free_start + free_count) >= ext2fs_blocks_count(fs->super))
> +		return EXT2_ET_BAD_BLOCK_NUM;
> +
>  	/* No bigalloc?  Just free each block. */
>  	if (EXT2FS_CLUSTER_RATIO(fs) == 1) {
>  		*freed += free_count;
> -- 
> 2.31.0
> 


      reply	other threads:[~2022-06-07 14:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07  4:24 [PATCH 0/7] Fix various bugs found via a fuzzing campaign Theodore Ts'o
2022-06-07  4:24 ` [PATCH 1/7] e2fsck: sanity check the journal inode number Theodore Ts'o
2022-06-07 13:12   ` Lukas Czerner
2022-06-07  4:24 ` [PATCH 2/7] e2fsck: fix potential out-of-bounds read in inc_ea_inode_refs() Theodore Ts'o
2022-06-07 13:30   ` Lukas Czerner
2022-06-07  4:24 ` [PATCH 3/7] libext2fs: add check for too-short directory blocks Theodore Ts'o
2022-06-07 13:31   ` Lukas Czerner
2022-06-07  4:24 ` [PATCH 4/7] e2fsck: check for xattr value size integer wraparound Theodore Ts'o
2022-06-07 13:33   ` Lukas Czerner
2022-06-07  4:24 ` [PATCH 5/7] e2fsck: avoid out-of-bounds write for very deep extent trees Theodore Ts'o
2022-06-07 13:53   ` Lukas Czerner
2022-06-07  4:24 ` [PATCH 6/7] libext2fs: check for cyclic loops in the extent tree Theodore Ts'o
2022-06-07 14:11   ` Lukas Czerner
2022-06-07  4:24 ` [PATCH 7/7] libext2fs: check for invalid blocks in ext2fs_punch_blocks() Theodore Ts'o
2022-06-07 14:22   ` Lukas Czerner [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=20220607142248.3zp564uieel5zjrb@fedora \
    --to=lczerner@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=moritz.schloegel@rub.de \
    --cc=nico.schiller@rub.de \
    --cc=nils.bars@rub.de \
    --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