]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/configfs-fix-possible-use-after-free-in-configfs_reg.patch
Linux 5.1.10
[thirdparty/kernel/stable-queue.git] / queue-4.19 / configfs-fix-possible-use-after-free-in-configfs_reg.patch
1 From 5a9168e8fe444a960f0085e350c50222f3ad0daa Mon Sep 17 00:00:00 2001
2 From: YueHaibing <yuehaibing@huawei.com>
3 Date: Sun, 5 May 2019 11:03:12 +0800
4 Subject: configfs: fix possible use-after-free in configfs_register_group
5
6 [ Upstream commit 35399f87e271f7cf3048eab00a421a6519ac8441 ]
7
8 In configfs_register_group(), if create_default_group() failed, we
9 forget to unlink the group. It will left a invalid item in the parent list,
10 which may trigger the use-after-free issue seen below:
11
12 BUG: KASAN: use-after-free in __list_add_valid+0xd4/0xe0 lib/list_debug.c:26
13 Read of size 8 at addr ffff8881ef61ae20 by task syz-executor.0/5996
14
15 CPU: 1 PID: 5996 Comm: syz-executor.0 Tainted: G C 5.0.0+ #5
16 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
17 Call Trace:
18 __dump_stack lib/dump_stack.c:77 [inline]
19 dump_stack+0xa9/0x10e lib/dump_stack.c:113
20 print_address_description+0x65/0x270 mm/kasan/report.c:187
21 kasan_report+0x149/0x18d mm/kasan/report.c:317
22 __list_add_valid+0xd4/0xe0 lib/list_debug.c:26
23 __list_add include/linux/list.h:60 [inline]
24 list_add_tail include/linux/list.h:93 [inline]
25 link_obj+0xb0/0x190 fs/configfs/dir.c:759
26 link_group+0x1c/0x130 fs/configfs/dir.c:784
27 configfs_register_group+0x56/0x1e0 fs/configfs/dir.c:1751
28 configfs_register_default_group+0x72/0xc0 fs/configfs/dir.c:1834
29 ? 0xffffffffc1be0000
30 iio_sw_trigger_init+0x23/0x1000 [industrialio_sw_trigger]
31 do_one_initcall+0xbc/0x47d init/main.c:887
32 do_init_module+0x1b5/0x547 kernel/module.c:3456
33 load_module+0x6405/0x8c10 kernel/module.c:3804
34 __do_sys_finit_module+0x162/0x190 kernel/module.c:3898
35 do_syscall_64+0x9f/0x450 arch/x86/entry/common.c:290
36 entry_SYSCALL_64_after_hwframe+0x49/0xbe
37 RIP: 0033:0x462e99
38 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
39 RSP: 002b:00007f494ecbcc58 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
40 RAX: ffffffffffffffda RBX: 000000000073bf00 RCX: 0000000000462e99
41 RDX: 0000000000000000 RSI: 0000000020000180 RDI: 0000000000000003
42 RBP: 00007f494ecbcc70 R08: 0000000000000000 R09: 0000000000000000
43 R10: 0000000000000000 R11: 0000000000000246 R12: 00007f494ecbd6bc
44 R13: 00000000004bcefa R14: 00000000006f6fb0 R15: 0000000000000004
45
46 Allocated by task 5987:
47 set_track mm/kasan/common.c:87 [inline]
48 __kasan_kmalloc.constprop.3+0xa0/0xd0 mm/kasan/common.c:497
49 kmalloc include/linux/slab.h:545 [inline]
50 kzalloc include/linux/slab.h:740 [inline]
51 configfs_register_default_group+0x4c/0xc0 fs/configfs/dir.c:1829
52 0xffffffffc1bd0023
53 do_one_initcall+0xbc/0x47d init/main.c:887
54 do_init_module+0x1b5/0x547 kernel/module.c:3456
55 load_module+0x6405/0x8c10 kernel/module.c:3804
56 __do_sys_finit_module+0x162/0x190 kernel/module.c:3898
57 do_syscall_64+0x9f/0x450 arch/x86/entry/common.c:290
58 entry_SYSCALL_64_after_hwframe+0x49/0xbe
59
60 Freed by task 5987:
61 set_track mm/kasan/common.c:87 [inline]
62 __kasan_slab_free+0x130/0x180 mm/kasan/common.c:459
63 slab_free_hook mm/slub.c:1429 [inline]
64 slab_free_freelist_hook mm/slub.c:1456 [inline]
65 slab_free mm/slub.c:3003 [inline]
66 kfree+0xe1/0x270 mm/slub.c:3955
67 configfs_register_default_group+0x9a/0xc0 fs/configfs/dir.c:1836
68 0xffffffffc1bd0023
69 do_one_initcall+0xbc/0x47d init/main.c:887
70 do_init_module+0x1b5/0x547 kernel/module.c:3456
71 load_module+0x6405/0x8c10 kernel/module.c:3804
72 __do_sys_finit_module+0x162/0x190 kernel/module.c:3898
73 do_syscall_64+0x9f/0x450 arch/x86/entry/common.c:290
74 entry_SYSCALL_64_after_hwframe+0x49/0xbe
75
76 The buggy address belongs to the object at ffff8881ef61ae00
77 which belongs to the cache kmalloc-192 of size 192
78 The buggy address is located 32 bytes inside of
79 192-byte region [ffff8881ef61ae00, ffff8881ef61aec0)
80 The buggy address belongs to the page:
81 page:ffffea0007bd8680 count:1 mapcount:0 mapping:ffff8881f6c03000 index:0xffff8881ef61a700
82 flags: 0x2fffc0000000200(slab)
83 raw: 02fffc0000000200 ffffea0007ca4740 0000000500000005 ffff8881f6c03000
84 raw: ffff8881ef61a700 000000008010000c 00000001ffffffff 0000000000000000
85 page dumped because: kasan: bad access detected
86
87 Memory state around the buggy address:
88 ffff8881ef61ad00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
89 ffff8881ef61ad80: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
90 >ffff8881ef61ae00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
91 ^
92 ffff8881ef61ae80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
93 ffff8881ef61af00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
94
95 Fixes: 5cf6a51e6062 ("configfs: allow dynamic group creation")
96 Reported-by: Hulk Robot <hulkci@huawei.com>
97 Signed-off-by: YueHaibing <yuehaibing@huawei.com>
98 Signed-off-by: Christoph Hellwig <hch@lst.de>
99 Signed-off-by: Sasha Levin <sashal@kernel.org>
100 ---
101 fs/configfs/dir.c | 17 ++++++++++++-----
102 1 file changed, 12 insertions(+), 5 deletions(-)
103
104 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
105 index 39843fa7e11b..920d350df37b 100644
106 --- a/fs/configfs/dir.c
107 +++ b/fs/configfs/dir.c
108 @@ -1755,12 +1755,19 @@ int configfs_register_group(struct config_group *parent_group,
109
110 inode_lock_nested(d_inode(parent), I_MUTEX_PARENT);
111 ret = create_default_group(parent_group, group);
112 - if (!ret) {
113 - spin_lock(&configfs_dirent_lock);
114 - configfs_dir_set_ready(group->cg_item.ci_dentry->d_fsdata);
115 - spin_unlock(&configfs_dirent_lock);
116 - }
117 + if (ret)
118 + goto err_out;
119 +
120 + spin_lock(&configfs_dirent_lock);
121 + configfs_dir_set_ready(group->cg_item.ci_dentry->d_fsdata);
122 + spin_unlock(&configfs_dirent_lock);
123 + inode_unlock(d_inode(parent));
124 + return 0;
125 +err_out:
126 inode_unlock(d_inode(parent));
127 + mutex_lock(&subsys->su_mutex);
128 + unlink_group(group);
129 + mutex_unlock(&subsys->su_mutex);
130 return ret;
131 }
132 EXPORT_SYMBOL(configfs_register_group);
133 --
134 2.20.1
135