drop mbcache-fix-potential-double-count-when-removing-entry
[ext4-patch-queue.git] / mbcache-initialize-e_referenced-in-mb_cache_entry_create
blob13cd8027cd464ffd717aa2acd4d92ac2c9941f48
1 mbcache: initialize entry->e_referenced in mb_cache_entry_create()
3 From: Alexander Potapenko <glider@google.com>
5 KMSAN reported use of uninitialized |entry->e_referenced| in a condition
6 in mb_cache_shrink():
8 ==================================================================
9 BUG: KMSAN: use of uninitialized memory in mb_cache_shrink+0x3b4/0xc50 fs/mbcache.c:287
10 CPU: 2 PID: 816 Comm: kswapd1 Not tainted 4.11.0-rc5+ #2877
11 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs
12 01/01/2011
13 Call Trace:
14  __dump_stack lib/dump_stack.c:16 [inline]
15  dump_stack+0x172/0x1c0 lib/dump_stack.c:52
16  kmsan_report+0x12a/0x180 mm/kmsan/kmsan.c:927
17  __msan_warning_32+0x61/0xb0 mm/kmsan/kmsan_instr.c:469
18  mb_cache_shrink+0x3b4/0xc50 fs/mbcache.c:287
19  mb_cache_scan+0x67/0x80 fs/mbcache.c:321
20  do_shrink_slab mm/vmscan.c:397 [inline]
21  shrink_slab+0xc3d/0x12d0 mm/vmscan.c:500
22  shrink_node+0x208f/0x2fd0 mm/vmscan.c:2603
23  kswapd_shrink_node mm/vmscan.c:3172 [inline]
24  balance_pgdat mm/vmscan.c:3289 [inline]
25  kswapd+0x160f/0x2850 mm/vmscan.c:3478
26  kthread+0x46c/0x5f0 kernel/kthread.c:230
27  ret_from_fork+0x29/0x40 arch/x86/entry/entry_64.S:430
28 chained origin:
29  save_stack_trace+0x37/0x40 arch/x86/kernel/stacktrace.c:59
30  kmsan_save_stack_with_flags mm/kmsan/kmsan.c:302 [inline]
31  kmsan_save_stack mm/kmsan/kmsan.c:317 [inline]
32  kmsan_internal_chain_origin+0x12a/0x1f0 mm/kmsan/kmsan.c:547
33  __msan_store_shadow_origin_1+0xac/0x110 mm/kmsan/kmsan_instr.c:257
34  mb_cache_entry_create+0x3b3/0xc60 fs/mbcache.c:95
35  ext4_xattr_cache_insert fs/ext4/xattr.c:1647 [inline]
36  ext4_xattr_block_set+0x4c82/0x5530 fs/ext4/xattr.c:1022
37  ext4_xattr_set_handle+0x1332/0x20a0 fs/ext4/xattr.c:1252
38  ext4_xattr_set+0x4d2/0x680 fs/ext4/xattr.c:1306
39  ext4_xattr_trusted_set+0x8d/0xa0 fs/ext4/xattr_trusted.c:36
40  __vfs_setxattr+0x703/0x790 fs/xattr.c:149
41  __vfs_setxattr_noperm+0x27a/0x6f0 fs/xattr.c:180
42  vfs_setxattr fs/xattr.c:223 [inline]
43  setxattr+0x6ae/0x790 fs/xattr.c:449
44  path_setxattr+0x1eb/0x380 fs/xattr.c:468
45  SYSC_lsetxattr+0x8d/0xb0 fs/xattr.c:490
46  SyS_lsetxattr+0x77/0xa0 fs/xattr.c:486
47  entry_SYSCALL_64_fastpath+0x13/0x94
48 origin:
49  save_stack_trace+0x37/0x40 arch/x86/kernel/stacktrace.c:59
50  kmsan_save_stack_with_flags mm/kmsan/kmsan.c:302 [inline]
51  kmsan_internal_poison_shadow+0xb1/0x1a0 mm/kmsan/kmsan.c:198
52  kmsan_kmalloc+0x7f/0xe0 mm/kmsan/kmsan.c:337
53  kmem_cache_alloc+0x1c2/0x1e0 mm/slub.c:2766
54  mb_cache_entry_create+0x283/0xc60 fs/mbcache.c:86
55  ext4_xattr_cache_insert fs/ext4/xattr.c:1647 [inline]
56  ext4_xattr_block_set+0x4c82/0x5530 fs/ext4/xattr.c:1022
57  ext4_xattr_set_handle+0x1332/0x20a0 fs/ext4/xattr.c:1252
58  ext4_xattr_set+0x4d2/0x680 fs/ext4/xattr.c:1306
59  ext4_xattr_trusted_set+0x8d/0xa0 fs/ext4/xattr_trusted.c:36
60  __vfs_setxattr+0x703/0x790 fs/xattr.c:149
61  __vfs_setxattr_noperm+0x27a/0x6f0 fs/xattr.c:180
62  vfs_setxattr fs/xattr.c:223 [inline]
63  setxattr+0x6ae/0x790 fs/xattr.c:449
64  path_setxattr+0x1eb/0x380 fs/xattr.c:468
65  SYSC_lsetxattr+0x8d/0xb0 fs/xattr.c:490
66  SyS_lsetxattr+0x77/0xa0 fs/xattr.c:486
67  entry_SYSCALL_64_fastpath+0x13/0x94
68 ==================================================================
70 Signed-off-by: Alexander Potapenko <glider@google.com>
71 Signed-off-by: Eric Biggers <ebiggers@google.com>
72 Cc: stable@vger.kernel.org # v4.6
73 ---
74  fs/mbcache.c | 1 +
75  1 file changed, 1 insertion(+)
77 diff --git a/fs/mbcache.c b/fs/mbcache.c
78 index d818fd236787..49c5b25bfa8c 100644
79 --- a/fs/mbcache.c
80 +++ b/fs/mbcache.c
81 @@ -94,6 +94,7 @@ int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,
82         entry->e_key = key;
83         entry->e_value = value;
84         entry->e_reusable = reusable;
85 +       entry->e_referenced = 0;
86         head = mb_cache_entry_head(cache, key);
87         hlist_bl_lock(head);
88         hlist_bl_for_each_entry(dup, dup_node, head, e_hash_list) {
89 -- 
90 2.15.1