Linux-bcachefs Archive mirror
 help / color / mirror / Atom feed
From: Reed Riley <reed@riley.engineer>
To: "linux-bcachefs@vger.kernel.org" <linux-bcachefs@vger.kernel.org>
Subject: [PATCH] bcachefs: fix overflow in fiemap
Date: Sat, 04 May 2024 22:12:23 +0000	[thread overview]
Message-ID: <7qU8xNKAHxFIkSlLrXO1B6kyf-7DvRoJRgZloXK5qHovOzUFYbbCYhe_9Tzv1J6MgiXcakyIFiovCX3HtotUEE9fsV25jYmifgyMz_wa-Ik=@riley.engineer> (raw)

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>
---
 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 22:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-04 22:12 Reed Riley [this message]
2024-05-04 23:35 ` [PATCH] bcachefs: fix overflow in fiemap Kent Overstreet

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='7qU8xNKAHxFIkSlLrXO1B6kyf-7DvRoJRgZloXK5qHovOzUFYbbCYhe_9Tzv1J6MgiXcakyIFiovCX3HtotUEE9fsV25jYmifgyMz_wa-Ik=@riley.engineer' \
    --to=reed@riley.engineer \
    --cc=linux-bcachefs@vger.kernel.org \
    /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).