Qu Wenruo
19ea40dddf
btrfs: unlock newly allocated extent buffer after error
...
[BUG]
There is a bug report that injected ENOMEM error could leave a tree
block locked while we return to user-space:
BTRFS info (device loop0): enabling ssd optimizations
FAULT_INJECTION: forcing a failure.
name failslab, interval 1, probability 0, space 0, times 0
CPU: 0 PID: 7579 Comm: syz-executor Not tainted 5.15.0-rc1 #16
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
rel-1.12.0-59-gc9ba5276e321-prebuilt.qemu.org 04/01/2014
Call Trace:
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x8d/0xcf lib/dump_stack.c:106
fail_dump lib/fault-inject.c:52 [inline]
should_fail+0x13c/0x160 lib/fault-inject.c:146
should_failslab+0x5/0x10 mm/slab_common.c:1328
slab_pre_alloc_hook.constprop.99+0x4e/0xc0 mm/slab.h:494
slab_alloc_node mm/slub.c:3120 [inline]
slab_alloc mm/slub.c:3214 [inline]
kmem_cache_alloc+0x44/0x280 mm/slub.c:3219
btrfs_alloc_delayed_extent_op fs/btrfs/delayed-ref.h:299 [inline]
btrfs_alloc_tree_block+0x38c/0x670 fs/btrfs/extent-tree.c:4833
__btrfs_cow_block+0x16f/0x7d0 fs/btrfs/ctree.c:415
btrfs_cow_block+0x12a/0x300 fs/btrfs/ctree.c:570
btrfs_search_slot+0x6b0/0xee0 fs/btrfs/ctree.c:1768
btrfs_insert_empty_items+0x80/0xf0 fs/btrfs/ctree.c:3905
btrfs_new_inode+0x311/0xa60 fs/btrfs/inode.c:6530
btrfs_create+0x12b/0x270 fs/btrfs/inode.c:6783
lookup_open+0x660/0x780 fs/namei.c:3282
open_last_lookups fs/namei.c:3352 [inline]
path_openat+0x465/0xe20 fs/namei.c:3557
do_filp_open+0xe3/0x170 fs/namei.c:3588
do_sys_openat2+0x357/0x4a0 fs/open.c:1200
do_sys_open+0x87/0xd0 fs/open.c:1216
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x34/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x46ae99
Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48
89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d
01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f46711b9c48 EFLAGS: 00000246 ORIG_RAX: 0000000000000055
RAX: ffffffffffffffda RBX: 000000000078c0a0 RCX: 000000000046ae99
RDX: 0000000000000000 RSI: 00000000000000a1 RDI: 0000000020005800
RBP: 00007f46711b9c80 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000017
R13: 0000000000000000 R14: 000000000078c0a0 R15: 00007ffc129da6e0
================================================
WARNING: lock held when returning to user space!
5.15.0-rc1 #16 Not tainted
------------------------------------------------
syz-executor/7579 is leaving the kernel with locks still held!
1 lock held by syz-executor/7579:
#0 : ffff888104b73da8 (btrfs-tree-01/1){+.+.}-{3:3}, at:
__btrfs_tree_lock+0x2e/0x1a0 fs/btrfs/locking.c:112
[CAUSE]
In btrfs_alloc_tree_block(), after btrfs_init_new_buffer(), the new
extent buffer @buf is locked, but if later operations like adding
delayed tree ref fail, we just free @buf without unlocking it,
resulting above warning.
[FIX]
Unlock @buf in out_free_buf: label.
Reported-by: Hao Sun <sunhao.th@gmail.com>
Link: https://lore.kernel.org/linux-btrfs/CACkBjsZ9O6Zr0KK1yGn=1rQi6Crh1yeCRdTSBxx9R99L4xdn-Q@mail.gmail.com/
CC: stable@vger.kernel.org # 5.4+
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-07 22:04:20 +02:00
..
2021-08-23 13:19:07 +02:00
2021-06-29 10:53:48 -07:00
2021-06-29 10:53:48 -07:00
2021-07-21 15:11:22 +01:00
2021-03-24 14:14:27 -04:00
2021-03-30 16:54:49 -07:00
2021-06-29 10:53:48 -07:00
2021-10-07 22:04:20 +02:00
2021-04-23 10:14:32 +01:00
2021-08-04 19:20:29 +02:00
2021-08-12 11:29:58 -05:00
2021-04-23 14:42:39 -07:00
2021-08-09 16:56:00 +02:00
2021-01-05 23:02:47 -05:00
2021-06-05 00:52:52 -07:00
2021-06-14 09:07:45 +02:00
2021-06-11 12:44:47 -05:00
2021-06-29 10:53:48 -07:00
2021-04-12 15:04:29 +02:00
2021-06-08 00:41:24 +08:00
2021-07-06 11:06:04 -07:00
2020-12-09 09:39:38 -05:00
2021-07-16 12:36:51 +02:00
2021-08-06 13:00:49 -04:00
2021-07-06 22:05:06 -07:00
2021-06-29 10:53:48 -07:00
2021-04-23 10:14:32 +01:00
2021-08-11 12:04:43 -07:00
2021-06-29 20:23:08 -07:00
2021-07-15 10:13:49 -07:00
2021-07-01 11:06:06 -07:00
2021-05-02 09:14:01 -07:00
2021-06-29 10:53:48 -07:00
2021-07-23 17:43:28 -07:00
2021-07-15 09:58:06 -07:00
2021-06-17 17:11:42 +02:00
2021-07-08 08:37:31 -04:00
2021-05-04 18:08:40 -07:00
2021-07-02 14:25:17 -07:00
2021-07-05 13:51:41 -07:00
2021-07-06 20:14:44 -04:00
2021-06-29 10:53:48 -07:00
2021-06-21 21:24:07 +01:00
2021-07-09 09:43:57 -07:00
2021-07-06 20:14:41 -04:00
2021-07-09 12:05:33 -07:00
2021-07-02 12:08:10 -07:00
2021-08-09 15:45:02 -05:00
2021-07-03 11:30:04 -07:00
2021-07-30 10:14:39 -07:00
2021-06-29 10:53:48 -07:00
2021-03-12 22:15:22 -05:00
2021-06-28 08:40:08 -04:00
2021-08-10 10:21:30 +02:00
2021-07-03 11:41:14 -07:00
2021-06-30 12:21:16 -07:00
2021-06-22 10:40:52 +02:00
2021-06-29 10:53:48 -07:00
2021-07-16 12:36:51 +02:00
2021-06-29 10:53:46 -07:00
2021-01-12 14:26:31 +01:00
2021-06-29 10:53:48 -07:00
2021-03-23 14:08:18 -04:00
2021-06-22 09:21:39 +02:00
2021-07-01 12:06:39 -07:00
2021-06-29 10:53:48 -07:00
2021-05-02 00:43:35 +09:00
2021-06-23 14:36:52 +02:00
2021-04-22 17:31:32 +10:00
2021-08-01 12:07:23 -07:00
2021-07-16 13:45:18 +09:00
2021-04-30 11:20:39 -07:00
2021-01-15 12:17:25 -05:00
2021-01-24 14:27:20 +01:00
2021-01-24 14:27:20 +01:00
2021-06-29 10:53:50 -07:00
2021-06-29 17:29:11 -07:00
2021-06-29 17:29:11 -07:00
2021-06-29 10:53:50 -07:00
2021-03-13 11:27:30 -08:00
2021-07-30 11:08:12 -07:00
2021-06-29 10:53:48 -07:00
2021-01-06 08:42:51 -05:00
2021-07-03 11:41:14 -07:00
2021-05-18 20:15:58 -04:00
2021-08-11 12:04:43 -07:00
2021-04-15 22:36:45 -04:00
2021-04-09 14:54:23 -07:00
2021-05-06 19:24:13 -07:00
2021-07-02 12:08:10 -07:00
2021-07-12 11:09:13 -05:00
2021-04-07 13:56:43 -04:00
2021-05-03 11:05:28 -07:00
2021-07-14 09:19:06 -07:00
2021-04-30 11:20:35 -07:00
2021-08-23 13:19:07 +02:00
2021-01-24 14:27:19 +01:00
2021-05-05 11:27:20 -07:00
2021-07-21 06:39:20 -10:00
2021-08-20 14:59:58 -06:00
2021-08-09 19:59:06 -06:00
2021-06-18 09:22:02 -06:00
2021-04-12 15:04:23 +02:00
2021-06-30 20:47:26 -07:00
2021-07-25 22:33:03 -07:00
2021-04-07 13:56:43 -04:00
2021-06-29 10:53:48 -07:00
2021-05-05 13:44:19 -07:00
2021-07-25 22:33:03 -07:00
2021-01-24 14:29:34 +01:00
2021-03-11 07:47:48 -07:00
2021-08-23 13:19:12 +02:00
2021-08-21 10:50:22 -07:00
2021-07-03 11:41:14 -07:00
2021-08-18 11:39:46 -07:00
2021-03-08 15:18:43 +01:00
2021-01-24 14:27:20 +01:00
2021-01-24 14:43:45 +01:00
2021-01-25 23:29:36 -05:00
2021-04-17 11:39:49 -07:00
2021-01-24 14:27:19 +01:00
2021-03-16 22:13:10 +01:00
2021-07-19 17:18:48 -07:00
2021-05-18 16:20:54 -05:00
2021-02-21 11:02:48 -08:00
2021-04-17 23:03:50 -04:00
2021-02-13 17:17:53 +01:00
2021-06-01 07:44:32 -06:00
2021-07-23 17:43:28 -07:00
2021-01-24 14:27:18 +01:00
2021-03-23 11:20:26 +01:00