mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: Edward Adam Davis <eadavis@qq.com>,
	syzbot+b44d4a4885bc82af2a06@syzkaller.appspotmail.com
Cc: clm@fb.com, dsterba@suse.com, josef@toxicpanda.com,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH] btrfs: Optimize the timing of prealloc memory allocation
Date: Tue, 9 Dec 2025 06:49:06 +1030	[thread overview]
Message-ID: <a9b53a9a-ddcb-4113-8769-40a918223ecf@suse.com> (raw)
In-Reply-To: <tencent_0974B3778967163D1736C0971436F24B5C09@qq.com>



在 2025/12/8 21:35, Edward Adam Davis 写道:
> Too many abnormal exits can cause the prealloc assertion to fail, as
> reported by syzbot in [1].
> 
> Move the prealloc memory allocation to before it is actually used.
> 
> [1]
> assertion failed: prealloc == NULL :: 0, in fs/btrfs/qgroup.c:3529
> kernel BUG at fs/btrfs/qgroup.c:3529!
> Call Trace:
>   <TASK>
>   create_subvol+0x5ad/0x18f0 fs/btrfs/ioctl.c:570
>   btrfs_mksubvol+0x6e4/0x12c0 fs/btrfs/ioctl.c:928
>   __btrfs_ioctl_snap_create+0x2b2/0x730 fs/btrfs/ioctl.c:1201
>   btrfs_ioctl_snap_create+0x131/0x180 fs/btrfs/ioctl.c:1259
>   btrfs_ioctl+0xb4d/0xd00 fs/btrfs/ioctl.c:-1

There is already a full revert, and your fix misses all the other error 
cases.

https://lore.kernel.org/linux-btrfs/20251208195407.GC4859@twin.jikos.cz/T/#t


> 
> Fixes: 252877a87015 ("btrfs: add ASSERTs on prealloc in qgroup functions")
> Reported-by: syzbot+b44d4a4885bc82af2a06@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=b44d4a4885bc82af2a06
> Tested-by: syzbot+b44d4a4885bc82af2a06@syzkaller.appspotmail.com
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
>   fs/btrfs/qgroup.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 9e2b53e90dcb..ac5380520152 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -3289,10 +3289,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
>   	if (!btrfs_qgroup_enabled(fs_info))
>   		return 0;
>   
> -	prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS);
> -	if (!prealloc)
> -		return -ENOMEM;
> -
>   	/*
>   	 * There are only two callers of this function.
>   	 *
> @@ -3388,6 +3384,12 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
>   		}
>   	}
>   
> +	prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS);
> +	if (!prealloc) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
> +
>   	spin_lock(&fs_info->qgroup_lock);
>   
>   	dstgroup = add_qgroup_rb(fs_info, prealloc, objectid);


      reply	other threads:[~2025-12-08 20:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-08  7:52 [syzbot] [btrfs?] kernel BUG in btrfs_qgroup_inherit syzbot
2025-12-08 10:50 ` Edward Adam Davis
2025-12-08 11:06   ` syzbot
2025-12-08 11:05 ` [PATCH] btrfs: Optimize the timing of prealloc memory allocation Edward Adam Davis
2025-12-08 20:19   ` 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=a9b53a9a-ddcb-4113-8769-40a918223ecf@suse.com \
    --to=wqu@suse.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=eadavis@qq.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+b44d4a4885bc82af2a06@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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

all inboxes | Powered by JetHome®