From: Josef Bacik <josef@toxicpanda.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Cc: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Subject: Re: [PATCH 3/3] btrfs: relocation: Fix a KASAN report on btrfs_reloc_pre_snapshot() due to extended reloc root lifespan
Date: Wed, 11 Dec 2019 09:55:52 -0500 [thread overview]
Message-ID: <e95ea11b-304a-92b7-b2ab-b244a17fa7ce@toxicpanda.com> (raw)
In-Reply-To: <20191211050004.18414-4-wqu@suse.com>
On 12/11/19 12:00 AM, Qu Wenruo wrote:
> [BUG]
> When running workload with balance start/cancel, snapshot
> creation/deletion and fsstress, we can hit the following KASAN report:
> ==================================================================
> BUG: KASAN: use-after-free in btrfs_reloc_pre_snapshot+0x85/0xc0 [btrfs]
> Read of size 4 at addr ffff888157140100 by task btrfs/1822
>
> CPU: 2 PID: 1822 Comm: btrfs Tainted: G O 5.5.0-rc1-custom+ #40
> Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015
> Call Trace:
> dump_stack+0xc2/0x11a
> print_address_description.constprop.0+0x20/0x210
> __kasan_report.cold+0x1b/0x41
> kasan_report+0x12/0x20
> check_memory_region+0x13c/0x1b0
> __asan_loadN+0xf/0x20
> btrfs_reloc_pre_snapshot+0x85/0xc0 [btrfs]
> create_pending_snapshot+0x209/0x15f0 [btrfs]
> create_pending_snapshots+0x111/0x140 [btrfs]
> btrfs_commit_transaction+0x7a6/0x1360 [btrfs]
> btrfs_mksubvol+0x915/0x960 [btrfs]
> btrfs_ioctl_snap_create_transid+0x1d5/0x1e0 [btrfs]
> btrfs_ioctl_snap_create_v2+0x1d3/0x270 [btrfs]
> btrfs_ioctl+0x241b/0x3e60 [btrfs]
> do_vfs_ioctl+0x831/0xb10
> ksys_ioctl+0x67/0x90
> __x64_sys_ioctl+0x43/0x50
> do_syscall_64+0x79/0xe0
> entry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> [CAUSE]
> Again, we try to access root->reloc_root without verify if that reloc
> root is already dead (being freed).
>
> [FIX]
> Check if the root has dead reloc root before accessing it.
>
> Reported-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
> Fixes: d2311e698578 ("btrfs: relocation: Delay reloc tree deletion after merge_reloc_roots")
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> fs/btrfs/relocation.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 619ccb183515..2d2cd1596ec9 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -4721,7 +4721,8 @@ void btrfs_reloc_pre_snapshot(struct btrfs_pending_snapshot *pending,
> struct btrfs_root *root = pending->root;
> struct reloc_control *rc = root->fs_info->reloc_ctl;
>
> - if (!root->reloc_root || !rc)
> + if (!root->reloc_root || !rc || test_bit(BTRFS_ROOT_DEAD_RELOC_TREE,
> + &root->state))
> return;
>
Same comment here as the other one, you can add
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Once it's fixed. Thanks,
Josef
next prev parent reply other threads:[~2019-12-11 14:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-11 5:00 [PATCH 0/3] btrfs: fixes for relocation to avoid KASAN reports Qu Wenruo
2019-12-11 5:00 ` [PATCH 1/3] btrfs: relocation: Fix a KASAN use-after-free bug due to extended reloc tree lifespan Qu Wenruo
2019-12-11 14:53 ` Josef Bacik
2019-12-11 5:00 ` [PATCH 2/3] btrfs: relocation: Fix KASAN report on create_reloc_tree due to extended reloc tree lifepsan Qu Wenruo
2019-12-11 14:55 ` Josef Bacik
2019-12-11 15:15 ` David Sterba
2019-12-11 5:00 ` [PATCH 3/3] btrfs: relocation: Fix a KASAN report on btrfs_reloc_pre_snapshot() due to extended reloc root lifespan Qu Wenruo
2019-12-11 14:55 ` Josef Bacik [this message]
2019-12-11 15:34 ` [PATCH 0/3] btrfs: fixes for relocation to avoid KASAN reports David Sterba
2019-12-12 0:39 ` Qu Wenruo
2019-12-12 14:28 ` David Sterba
2020-01-03 15:52 ` David Sterba
2020-01-03 16:15 ` David Sterba
2020-01-04 9:37 ` Qu Wenruo
2020-01-04 13:18 ` Qu Wenruo
2020-01-06 7:04 ` Qu Wenruo
2020-01-06 18:23 ` David Sterba
2020-01-04 1:32 ` Qu Wenruo
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=e95ea11b-304a-92b7-b2ab-b244a17fa7ce@toxicpanda.com \
--to=josef@toxicpanda.com \
--cc=ce3g8jdj@umail.furryterror.org \
--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