lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_0974B3778967163D1736C0971436F24B5C09@qq.com>
Date: Mon,  8 Dec 2025 19:05:26 +0800
From: Edward Adam Davis <eadavis@...com>
To: syzbot+b44d4a4885bc82af2a06@...kaller.appspotmail.com
Cc: clm@...com,
	dsterba@...e.com,
	josef@...icpanda.com,
	linux-btrfs@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	syzkaller-bugs@...glegroups.com
Subject: [PATCH] btrfs: Optimize the timing of prealloc memory allocation

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

Fixes: 252877a87015 ("btrfs: add ASSERTs on prealloc in qgroup functions")
Reported-by: syzbot+b44d4a4885bc82af2a06@...kaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=b44d4a4885bc82af2a06
Tested-by: syzbot+b44d4a4885bc82af2a06@...kaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@...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);
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ