linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Filipe Manana <fdmanana@kernel.org>
To: Goldwyn Rodrigues <rgoldwyn@suse.de>
Cc: linux-btrfs@vger.kernel.org, Goldwyn Rodrigues <rgoldwyn@suse.com>
Subject: Re: [PATCH 01/16] btrfs: check for range correctness while locking or setting extent bits
Date: Wed, 23 Nov 2022 13:12:16 +0000	[thread overview]
Message-ID: <CAL3q7H7F-7njGV4tZJ8arcqwfzMO3_0_7qvpaWRCw1AhH6-55g@mail.gmail.com> (raw)
In-Reply-To: <07534e31d822b5c08609c72e5a2e8054604765d9.1668530684.git.rgoldwyn@suse.com>

On Tue, Nov 15, 2022 at 6:13 PM Goldwyn Rodrigues <rgoldwyn@suse.de> wrote:
>
> Since we will be working at the mercy of userspace, check if the range
> is valid and proceed to lock or set bits only if start < end.

At the mercy of user space, how? Can you be more detailed about what you mean?

Is this something you ran into, or is this just to prevent such cases
from happening?

>
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
> ---
>  fs/btrfs/extent-io-tree.c | 6 ++++++
>  fs/btrfs/ordered-data.c   | 3 +++
>  2 files changed, 9 insertions(+)
>
> diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c
> index 21fa15123af8..80657c820df4 100644
> --- a/fs/btrfs/extent-io-tree.c
> +++ b/fs/btrfs/extent-io-tree.c
> @@ -557,6 +557,9 @@ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
>         int wake;
>         int delete = (bits & EXTENT_CLEAR_ALL_BITS);
>
> +       if (unlikely(start > end))
> +               return 0;

Having a start > end indicates a bug somewhere else, which should be
fixed in the caller.

That happened a few times in a distant past, one example:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ccccf3d67294714af2d72a6fd6fd7d73b01c9329

And that leads to nasty side effects much later on (inode eviction),
as described in that changelog.

If anything, we should assert here, and if assertions are disabled,
trigger a warning and return an error, not silently ignoring it.
Something like:

ASSERT(start < end);
if (WARN_ON(start >= end))
     return -WHAT_EVER_ERRNO;

Thanks.

> +
>         btrfs_debug_check_extent_io_range(tree, start, end);
>         trace_btrfs_clear_extent_bit(tree, start, end - start + 1, bits);
>
> @@ -979,6 +982,9 @@ static int __set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
>         u64 last_end;
>         u32 exclusive_bits = (bits & EXTENT_LOCKED);
>
> +       if (unlikely(start > end))
> +               return 0;
> +
>         btrfs_debug_check_extent_io_range(tree, start, end);
>         trace_btrfs_set_extent_bit(tree, start, end - start + 1, bits);
>
> diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
> index 4bed0839b640..0a5512ed9a21 100644
> --- a/fs/btrfs/ordered-data.c
> +++ b/fs/btrfs/ordered-data.c
> @@ -1043,6 +1043,9 @@ void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start,
>         struct extent_state *cache = NULL;
>         struct extent_state **cachedp = &cache;
>
> +       if (unlikely(start > end))
> +               return;
> +
>         if (cached_state)
>                 cachedp = cached_state;
>
> --
> 2.35.3
>

  parent reply	other threads:[~2022-11-23 13:31 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1668530684.git.rgoldwyn@suse.com>
2022-11-15 18:00 ` [PATCH 01/16] btrfs: check for range correctness while locking or setting extent bits Goldwyn Rodrigues
2022-11-17 11:09   ` Johannes Thumshirn
2022-11-22 17:17     ` Goldwyn Rodrigues
2022-11-23  8:48       ` Johannes Thumshirn
2022-11-23 13:12   ` Filipe Manana [this message]
2022-11-23 14:35     ` Goldwyn Rodrigues
2022-12-13 16:25   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 02/16] btrfs: qgroup flush responsibility of the caller Goldwyn Rodrigues
2022-12-13 16:30   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 03/16] btrfs: wait ordered range before locking during truncate Goldwyn Rodrigues
2022-11-17 11:22   ` Johannes Thumshirn
2022-12-13 18:14   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 04/16] btrfs: lock extents while truncating Goldwyn Rodrigues
2022-12-13 18:29   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 05/16] btrfs: No need to lock extent while performing invalidate_folio() Goldwyn Rodrigues
2022-12-13 18:30   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 06/16] btrfs: Lock extents before pages in writepages Goldwyn Rodrigues
2022-12-13 18:39   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 07/16] btrfs: Lock extents before folio for read()s Goldwyn Rodrigues
2022-11-21 13:31   ` kernel test robot
2022-11-22 17:11     ` Goldwyn Rodrigues
2022-11-27  8:48   ` kernel test robot
2022-12-13 18:57   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 08/16] btrfs: Lock extents before pages for buffered write() Goldwyn Rodrigues
2022-12-13 19:01   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 09/16] btrfs: lock/unlock extents while creation/end of async_chunk Goldwyn Rodrigues
2022-12-13 19:05   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 10/16] btrfs: decide early if range should be async Goldwyn Rodrigues
2022-12-13 19:07   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 11/16] btrfs: lock extents before pages - defrag Goldwyn Rodrigues
2022-12-13 19:08   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 12/16] btrfs: Perform memory faults under locked extent Goldwyn Rodrigues
2022-12-13 19:12   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 13/16] btrfs: writepage fixup lock rearrangement Goldwyn Rodrigues
2022-12-13 19:13   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 14/16] btrfs: lock extent before pages for encoded read ioctls Goldwyn Rodrigues
2022-12-13 19:14   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 15/16] btrfs: lock extent before pages in encoded write Goldwyn Rodrigues
2022-12-13 19:19   ` Josef Bacik
2022-11-15 18:00 ` [PATCH 16/16] btrfs: btree_writepages lock extents before pages Goldwyn Rodrigues
2022-12-13 19:20   ` Josef Bacik

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=CAL3q7H7F-7njGV4tZJ8arcqwfzMO3_0_7qvpaWRCw1AhH6-55g@mail.gmail.com \
    --to=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=rgoldwyn@suse.com \
    --cc=rgoldwyn@suse.de \
    /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).