linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [bug report] btrfs: locking: Add extra check in btrfs_init_new_buffer() to avoid deadlock
Date: Thu, 21 Feb 2019 22:21:03 +0800	[thread overview]
Message-ID: <cef05cfd-2fdd-3c27-39d2-15d35b61d64a@suse.de> (raw)
In-Reply-To: <20190221141347.GA20330@kadam>


[-- Attachment #1.1: Type: text/plain, Size: 2010 bytes --]



On 2019/2/21 下午10:13, Dan Carpenter wrote:
> [ This one is not actually your fault.  It's the core code which is
>   confusing.  -dan ]
> 
> Hello Qu Wenruo,
> 
> The patch b72c3aba09a5: "btrfs: locking: Add extra check in
> btrfs_init_new_buffer() to avoid deadlock" from Aug 21, 2018, leads
> to the following static checker warning:
> 
> 	fs/btrfs/extent-tree.c:8556 btrfs_init_new_buffer()
> 	warn: possible NULL dereference of 'buf'
> 
> fs/btrfs/extent-tree.c
>     8540 static struct extent_buffer *
>     8541 btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root,
>     8542 		      u64 bytenr, int level, u64 owner)
>     8543 {
>     8544 	struct btrfs_fs_info *fs_info = root->fs_info;
>     8545 	struct extent_buffer *buf;
>     8546 
>     8547 	buf = btrfs_find_create_tree_block(fs_info, bytenr);
> 
> The btrfs_find_create_tree_block() function either returns
> alloc_test_extent_buffer() which returns NULL on error

You caught me!

Indeed that's a possible NULL return case.

The only good news is it shouldn't affect release build which normally
doesn't enabled CONFIG_BTRFS_FS_RUN_SANITY_TESTS.

I'll fix it by unifying the return pointer.

Thanks for pointing this out,
Qu

> or
> alloc_extent_buffer() which returns error pointers on error.  It
> confuses static checkers and me also.
> 
>     8548 	if (IS_ERR(buf))
>     8549 		return buf;
>     8550 
>     8551 	/*
>     8552 	 * Extra safety check in case the extent tree is corrupted and extent
>     8553 	 * allocator chooses to use a tree block which is already used and
>     8554 	 * locked.
>     8555 	 */
> --> 8556 	if (buf->lock_owner == current->pid) {
>     8557 		btrfs_err_rl(fs_info,
>     8558 "tree block %llu owner %llu already locked by pid=%d, extent tree corruption detected",
>     8559 			buf->start, btrfs_header_owner(buf), current->pid);
>     8560 		free_extent_buffer(buf);
> 
> regards,
> dan carpenter
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2019-02-21 14:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21 14:13 [bug report] btrfs: locking: Add extra check in btrfs_init_new_buffer() to avoid deadlock Dan Carpenter
2019-02-21 14:21 ` Qu Wenruo [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=cef05cfd-2fdd-3c27-39d2-15d35b61d64a@suse.de \
    --to=wqu@suse.de \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-btrfs@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 NNTP newsgroup(s).