From: David Sterba <dsterba@suse.cz>
To: WenRuo Qu <wqu@suse.com>
Cc: Nikolay Borisov <nborisov@suse.com>,
"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 1/5] btrfs: extent_io: Do extra check for extent buffer read write functions
Date: Wed, 24 Jul 2019 18:00:29 +0200 [thread overview]
Message-ID: <20190724160029.GQ2868@twin.jikos.cz> (raw)
In-Reply-To: <47b88874-6cef-4eb2-74d8-5a1f51efa99d@suse.com>
On Wed, Jul 10, 2019 at 10:58:40AM +0000, WenRuo Qu wrote:
>
>
> On 2019/7/10 下午6:42, Nikolay Borisov wrote:
> >
> >
> [...]
> >>
> >> +/*
> >> + * Check if the [start, start + len) range is valid before reading/writing
> >> + * the eb.
> >> + *
> >> + * Caller should not touch the dst/src memory if this function returns error.
> >> + */
> >> +static int check_eb_range(const struct extent_buffer *eb, unsigned long start,
> >> + unsigned long len)
> >> +{
> >> + unsigned long end;
> >> +
> >> + /* start, start + len should not go beyond eb->len nor overflow */
> >> + if (unlikely(start > eb->len || start + len > eb->len ||
> >
> > I think your check here is wrong, it should be start + len > start +
> > eb->len. start is the logical address hence it can be a lot bigger than
> > the size of the eb which is 16k by default.
>
> Definitely NO.
>
> [start, start + len) must be in the range of [0, nodesize).
> So think again.
'start' is the logical address, that's always larger than eb->len (16K),
Nikolay is IMO right, the check
start > eb->len
does not make sense, neither does 'start + len > eb->len'.
Your reference to nodesize probably means that the interval
[start, start + len] is subset of [start, start + nodesize].
The test condition in your patch must explode every time the function
is called.
> >> + check_add_overflow(start, len, &end))) {
> >> + WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG), KERN_ERR
> >> +"btrfs: bad eb rw request, eb bytenr=%llu len=%lu rw start=%lu len=%lu\n",
> >> + eb->start, eb->len, start, len);
> >> + btrfs_warn(eb->fs_info,
> >> +"btrfs: bad eb rw request, eb bytenr=%llu len=%lu rw start=%lu len=%lu\n",
> >> + eb->start, eb->len, start, len);
> >
> > If CONFIG_BTRFS_DEBUG is enabled then we will print the warning text
> > twice. Simply make it:
> >
> > WARN_ON(IS_ENABLED()) and leave the btrfs_Warn to always print the text.
>
> WARN_ON() doesn't contain any text to indicate the reason of the stack dump.
> Thus I still prefer to show exact the reason other than takes developer
> several seconds to combine the stack with the following btrfs_warn()
> message.
I agree that a message next to a WARN is a good thing. Plain WARN does
not have the btrfs header (filesystem, device, ...) so we should use our
helpers and do WARN_ON(IS_ENABLED()) after that. Why after? Because with
panic-on-warn enabled the message won't be printed.
Duplicating the message or even the code does not seem like a good
practice to me.
next prev parent reply other threads:[~2019-07-24 15:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-10 8:02 [PATCH 0/5] btrfs: Enhanced runtime defence against fuzzed images Qu Wenruo
2019-07-10 8:02 ` [PATCH 1/5] btrfs: extent_io: Do extra check for extent buffer read write functions Qu Wenruo
2019-07-10 10:42 ` Nikolay Borisov
2019-07-10 10:58 ` WenRuo Qu
2019-07-24 16:00 ` David Sterba [this message]
2019-07-24 22:54 ` Qu Wenruo
2019-07-25 6:39 ` Nikolay Borisov
2019-07-10 8:02 ` [PATCH 2/5] btrfs: extent-tree: Kill BUG_ON() in __btrfs_free_extent() and do better comment Qu Wenruo
2019-07-10 10:48 ` Nikolay Borisov
2019-07-10 11:00 ` WenRuo Qu
2019-07-10 8:02 ` [PATCH 3/5] btrfs: Detect unbalanced tree with empty leaf before crashing btree operations Qu Wenruo
2019-07-10 10:54 ` Nikolay Borisov
2019-07-10 8:02 ` [PATCH 4/5] btrfs: extent-tree: Kill the BUG_ON() in insert_inline_extent_backref() Qu Wenruo
2019-07-10 11:12 ` Nikolay Borisov
2019-07-10 8:02 ` [PATCH 5/5] btrfs: ctree: Checking key orders before merged tree blocks Qu Wenruo
2019-07-10 11:19 ` Nikolay Borisov
2019-07-10 12:02 ` Qu Wenruo
2019-07-10 12:12 ` Nikolay Borisov
2019-07-24 16:24 ` David Sterba
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=20190724160029.GQ2868@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.com \
--cc=wqu@suse.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