linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>, Kangjie Lu <kjlu@umn.edu>
Cc: pakki001@umn.edu, Chris Mason <clm@fb.com>,
	Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] btrfs: fix a NULL pointer dereference
Date: Thu, 14 Mar 2019 10:03:21 +0200	[thread overview]
Message-ID: <fcdf722f-d128-03c0-99fb-a220f680193c@suse.com> (raw)
In-Reply-To: <50fa02f1-18c0-b039-ec2f-e16b715f53ff@gmx.com>



On 14.03.19 г. 10:02 ч., Qu Wenruo wrote:
> 
> 
> On 2019/3/14 下午3:54, Nikolay Borisov wrote:
>>
>>
>> On 14.03.19 г. 9:50 ч., Kangjie Lu wrote:
>>> btrfs_lookup_block_group may fail and return NULL. The fix goes
>>> to out when it fails to avoid NULL pointer dereference.
>>
>> Actually no, in this case btrfs_lookup_block_group must never fail
>> because if we have an allocated eb then it must have been allocated from
>> a bg.
> 
> Yep, that's the normal case.
> 
> However I'm wondering if it's possible to get a bad eb which is cached.
> 
> Then we could hit such situation.
> 
> So I still believe being safe here still makes sense, especially who
> knows future fuzzed image will be.

Then I'd rather have ASSERT(cache)

> 
> Thanks,
> Qu
> 
>>
>>>
>>> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
>>> ---
>>>  fs/btrfs/extent-tree.c | 2 ++
>>>  1 file changed, 2 insertions(+)
>>>
>>> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
>>> index 994f0cc41799..b1e7985bcb9d 100644
>>> --- a/fs/btrfs/extent-tree.c
>>> +++ b/fs/btrfs/extent-tree.c
>>> @@ -7303,6 +7303,8 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
>>>  
>>>  		pin = 0;
>>>  		cache = btrfs_lookup_block_group(fs_info, buf->start);
>>> +		if (!cache)
>>> +			goto out;
>>>  
>>>  		if (btrfs_header_flag(buf, BTRFS_HEADER_FLAG_WRITTEN)) {
>>>  			pin_down_extent(fs_info, cache, buf->start,
>>>
> 

  reply	other threads:[~2019-03-14  8:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-14  7:50 [PATCH] btrfs: fix a NULL pointer dereference Kangjie Lu
2019-03-14  7:54 ` Nikolay Borisov
2019-03-14  8:02   ` Qu Wenruo
2019-03-14  8:03     ` Nikolay Borisov [this message]
2019-03-14  8:13       ` [PATCH v2] " Kangjie Lu
2019-03-14  8:16         ` Nikolay Borisov
2019-03-14  9:15       ` [PATCH] " Qu Wenruo
2019-03-14  9:18         ` Nikolay Borisov
2019-03-14 15:26         ` Kangjie Lu
2019-03-14 10:23     ` Su Yue
2019-03-14 15:41   ` Josef Bacik
2019-03-14  7:59 ` Qu Wenruo
2019-03-25 16:35 ` 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=fcdf722f-d128-03c0-99fb-a220f680193c@suse.com \
    --to=nborisov@suse.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=kjlu@umn.edu \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pakki001@umn.edu \
    --cc=quwenruo.btrfs@gmx.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).