reiserfs-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shreyansh Chouhan <chouhan.shreyansh630@gmail.com>
To: rkovhaev@gmail.com, jack@suse.cz
Cc: reiserfs-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+c31a48e6702ccb3d64c9@syzkaller.appspotmail.com
Subject: Re: [PATCH] reiserfs: check directry items on read from disk
Date: Tue, 20 Jul 2021 13:01:25 +0530	[thread overview]
Message-ID: <YPZ7zUVAedCkx3IQ@fedora> (raw)
In-Reply-To: <20210709152929.766363-1-chouhan.shreyansh630@gmail.com>

Hi,

Just a ping for reviews/merge since there has been no activity on this patch.

Thank you,
Shreyansh Chouhan

On Fri, Jul 09, 2021 at 08:59:29PM +0530, Shreyansh Chouhan wrote:
> 
> While verifying the leaf item that we read from the disk, reiserfs
> doesn't check the directory items, this could cause a crash when we
> read a directory item from the disk that has an invalid deh_location.
> 
> This patch adds a check to the directory items read from the disk that
> does a bounds check on deh_location for the directory entries. Any
> directory entry header with a directory entry offset greater than the
> item length is considered invalid.
> 
> Reported-by: syzbot+c31a48e6702ccb3d64c9@syzkaller.appspotmail.com
> Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh630@gmail.com>
> ---
>  fs/reiserfs/stree.c | 31 ++++++++++++++++++++++++++-----
>  1 file changed, 26 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
> index 476a7ff49482..ef42729216d1 100644
> --- a/fs/reiserfs/stree.c
> +++ b/fs/reiserfs/stree.c
> @@ -387,6 +387,24 @@ void pathrelse(struct treepath *search_path)
>  	search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
>  }
>  
> +static int has_valid_deh_location(struct buffer_head *bh, struct item_head *ih)
> +{
> +	struct reiserfs_de_head *deh;
> +	int i;
> +
> +	deh = B_I_DEH(bh, ih);
> +	for (i = 0; i < ih_entry_count(ih); i++) {
> +		if (deh_location(&deh[i]) > ih_item_len(ih)) {
> +			reiserfs_warning(NULL, "reiserfs-5094",
> +					 "directory entry location seems wrong %h",
> +					 &deh[i]);
> +			return 0;
> +		}
> +	}
> +
> +	return 1;
> +}
> +
>  static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
>  {
>  	struct block_head *blkh;
> @@ -454,11 +472,14 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
>  					 "(second one): %h", ih);
>  			return 0;
>  		}
> -		if (is_direntry_le_ih(ih) && (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE))) {
> -			reiserfs_warning(NULL, "reiserfs-5093",
> -					 "item entry count seems wrong %h",
> -					 ih);
> -			return 0;
> +		if (is_direntry_le_ih(ih)) {
> +			if (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE)) {
> +				reiserfs_warning(NULL, "reiserfs-5093",
> +						 "item entry count seems wrong %h",
> +						 ih);
> +				return 0;
> +			}
> +			return has_valid_deh_location(bh, ih);
>  		}
>  		prev_location = ih_location(ih);
>  	}
> -- 
> 2.31.1
> 

  reply	other threads:[~2021-07-20  7:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-09 15:29 [PATCH] reiserfs: check directry items on read from disk Shreyansh Chouhan
2021-07-20  7:31 ` Shreyansh Chouhan [this message]
2021-07-26  8:20   ` Jan Kara
2021-07-29  5:06     ` Shreyansh Chouhan

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=YPZ7zUVAedCkx3IQ@fedora \
    --to=chouhan.shreyansh630@gmail.com \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=reiserfs-devel@vger.kernel.org \
    --cc=rkovhaev@gmail.com \
    --cc=syzbot+c31a48e6702ccb3d64c9@syzkaller.appspotmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).