Linux-bcachefs Archive mirror
 help / color / mirror / Atom feed
From: Kent Overstreet <kent.overstreet@linux.dev>
To: Reed Riley <reed@riley.engineer>
Cc: "linux-bcachefs@vger.kernel.org" <linux-bcachefs@vger.kernel.org>
Subject: Re: [PATCH] bcachefs: fix overflow in fiemap
Date: Sat, 4 May 2024 19:35:13 -0400	[thread overview]
Message-ID: <2x2pkl56bpo6ptinyp6kpjgrazbiwzsccw3qxb3jv7u775eesb@3bqc6om37j6f> (raw)
In-Reply-To: <7qU8xNKAHxFIkSlLrXO1B6kyf-7DvRoJRgZloXK5qHovOzUFYbbCYhe_9Tzv1J6MgiXcakyIFiovCX3HtotUEE9fsV25jYmifgyMz_wa-Ik=@riley.engineer>

On Sat, May 04, 2024 at 10:12:23PM +0000, Reed Riley wrote:
> filefrag (and potentially other utilities that call fiemap) sometimes
> pass ULONG_MAX as the length.  fiemap_prep clamps excessively large
> lengths - but the calculation of end can overflow if it occurs before
> calling fiemap_prep.  When this happens, filefrag assumes it has read to
> the end and exits.
> 
> Signed-off-by: Reed Riley <reed@riley.engineer>

Applied!

> ---
>  fs/bcachefs/fs.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c
> index 4e4442bc71e3..ff01c954bff8 100644
> --- a/fs/bcachefs/fs.c
> +++ b/fs/bcachefs/fs.c
> @@ -996,7 +996,7 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
>         struct btree_iter iter;
>         struct bkey_s_c k;
>         struct bkey_buf cur, prev;
> -       struct bpos end = POS(ei->v.i_ino, (start + len) >> 9);
> +       struct bpos end;
>         unsigned offset_into_extent, sectors;
>         bool have_extent = false;
>         u32 snapshot;
> @@ -1006,6 +1006,7 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
>         if (ret)
>                 return ret;
>  
> +       end = POS(ei->v.i_ino, (start + len) >> 9);
>         if (start + len < start)
>                 return -EINVAL;
>  
> -- 
> 2.44.0
> 

      reply	other threads:[~2024-05-04 23:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-04 22:12 [PATCH] bcachefs: fix overflow in fiemap Reed Riley
2024-05-04 23:35 ` Kent Overstreet [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=2x2pkl56bpo6ptinyp6kpjgrazbiwzsccw3qxb3jv7u775eesb@3bqc6om37j6f \
    --to=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=reed@riley.engineer \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).