linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 6/6] btrfs-progs: rescue-super: Don't double free fs_devices
Date: Wed, 29 Aug 2018 18:38:44 +0300	[thread overview]
Message-ID: <c357b98d-3d37-31fe-ad42-df8d7eff0d20@suse.com> (raw)
In-Reply-To: <20180803055022.9816-7-wqu@suse.com>



On  3.08.2018 08:50, Qu Wenruo wrote:
> [BUG]
> During fuzz/007 we hit the following error:
> ------
> ====== RUN MAYFAIL /home/adam/btrfs/btrfs-progs/btrfs rescue super-recover -y -v /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-200409.raw.restored.scratch
> ERROR: tree_root block unaligned: 33554431
> ERROR: superblock checksum matches but it has invalid members
> ERROR: tree_root block unaligned: 33554431
> ERROR: superblock checksum matches but it has invalid members
> ERROR: tree_root block unaligned: 33554431
> ERROR: superblock checksum matches but it has invalid members
> ERROR: failed to add chunk map start=12582912 len=8454144: -17 (File exists)
> Couldn't read chunk tree
> failed (ignored, ret=139): /home/adam/btrfs/btrfs-progs/btrfs rescue super-recover -y -v /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-200409.raw.restored.scratch
> mayfail: returned code 139 (SEGFAULT), not ignored
> test failed for case 007-simple-super-recover
> ------
> 
> [CAUSE]
> In __open_ctree_fd(), if we have valid @open_ctree_flags and
> btrfs_scan_fs_devices() successes without problem, no matter what
> happens we will call btrfs_close_devices(), thus free all related
> devices.

Why do you think it's _always_ going to be called? Looking into that
function it seems this can happen if
btrfs_setup_chunk_tree_and_device_map fails.
> 
> In super-recover, before we call open_ctree(), we have called
> btrfs_scan_fs_devices() already, so btrfs_scan_fs_devices() should not
> fail in open_ctree(), fs_devices will always be freed in open_ctree() or
> close_ctree().

Isn't the actual issue just that we call close_ctree. So the actual life
time of fs_devices is :

1. Create in btrfs_scan_fs_devices called from btrfs_recover_superblocks
2. All other references to those fs_devices will just return the same
reference.
3. Calling close_ctree frees fs_devices.

> 
> [FIX]
> So in super-recover.c, we should not call btrfs_close_devices(), or we
> will find fs_devices->list get poisoned, and trigger segfault when
> exiting.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  super-recover.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/super-recover.c b/super-recover.c
> index 880fd7712546..86b3df9867dc 100644
> --- a/super-recover.c
> +++ b/super-recover.c
> @@ -292,9 +292,6 @@ int btrfs_recover_superblocks(const char *dname,
>  no_recover:
>  	recover_err_str(ret);
>  	free_recover_superblock(&recover);
> -	/* check if we have freed fs_devices in close_ctree() */
> -	if (!root)
> -		btrfs_close_devices(recover.fs_devices);
>  	return ret;
>  }
>  
> 

  reply	other threads:[~2018-08-29 19:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-03  5:50 [PATCH 0/6] btrfs-progs: Variant fixes for fuzz-tests Qu Wenruo
2018-08-03  5:50 ` [PATCH 1/6] btrfs-progs: Exit gracefully if we hit ENOSPC when allocating tree block Qu Wenruo
2018-08-29 14:30   ` Nikolay Borisov
2018-08-03  5:50 ` [PATCH 2/6] btrfs-progs: Exit gracefully when failed to repair root dir item Qu Wenruo
2018-08-29 14:31   ` Nikolay Borisov
2018-08-03  5:50 ` [PATCH 3/6] btrfs-progs: Don't report dirty leaked eb using BUG_ON Qu Wenruo
2018-08-29 14:52   ` Nikolay Borisov
2018-08-30  1:08     ` Qu Wenruo
2018-08-03  5:50 ` [PATCH 4/6] btrfs-progs: Fix infinite loop when failed to repair bad key order Qu Wenruo
2018-08-03  5:50 ` [PATCH 5/6] btrfs-progs: Exit gracefull when we failed to alloc dev extent Qu Wenruo
2018-08-29 14:59   ` Nikolay Borisov
2018-08-03  5:50 ` [PATCH 6/6] btrfs-progs: rescue-super: Don't double free fs_devices Qu Wenruo
2018-08-29 15:38   ` Nikolay Borisov [this message]
2018-08-30  1:16     ` Qu Wenruo
2018-08-29  5:27 ` [PATCH 0/6] btrfs-progs: Variant fixes for fuzz-tests Qu Wenruo
2018-09-11 16:38   ` David Sterba
2018-09-11 23:59     ` Qu Wenruo
2018-09-14 14:25       ` 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=c357b98d-3d37-31fe-ad42-df8d7eff0d20@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).