Skip to content

Commit 0696a18

Browse files
JungerBoyoKent Overstreet
authored andcommitted
bcachefs: memset bounce buffer portion to 0 after key_sort_fix_overlapping
Zero-initialize part of allocated bounce buffer which wasn't touched by subsequent bch2_key_sort_fix_overlapping to mitigate later uinit-value use KMSAN bug[1]. After applying the patch reproducer still triggers stack overflow[2] but it seems unrelated to the uninit-value use warning. After further investigation it was found that stack overflow occurs because KMSAN adds too many function calls[3]. Backtrace of where the stack magic number gets smashed was added as a reply to syzkaller thread[3]. It was confirmed that task's stack magic number gets smashed after the code path where KSMAN detects uninit-value use is executed, so it can be assumed that it doesn't contribute in any way to uninit-value use detection. [1] https://syzkaller.appspot.com/bug?extid=6f655a60d3244d0c6718 [2] https://lore.kernel.org/lkml/[email protected] [3] https://lore.kernel.org/all/rVaWgPULej8K7HqMPNIu8kVNyXNjjCiTB-QBtItLFBmk0alH6fV2tk4joVPk97Evnuv4ZRDd8HB5uDCkiFG6u81xKdzDj-KrtIMJSlF6Kt8=@proton.me Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=6f655a60d3244d0c6718 Fixes: ec4edd7 ("bcachefs: Prep work for variable size btree node buffers") Suggested-by: Kent Overstreet <[email protected]> Signed-off-by: Piotr Zalewski <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent 51b7cc7 commit 0696a18

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/bcachefs/btree_io.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,10 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
11951195
set_btree_bset(b, b->set, &b->data->keys);
11961196

11971197
b->nr = bch2_key_sort_fix_overlapping(c, &sorted->keys, iter);
1198+
memset((uint8_t *)(sorted + 1) + b->nr.live_u64s * sizeof(u64), 0,
1199+
btree_buf_bytes(b) -
1200+
sizeof(struct btree_node) -
1201+
b->nr.live_u64s * sizeof(u64));
11981202

11991203
u64s = le16_to_cpu(sorted->keys.u64s);
12001204
*sorted = *b->data;

0 commit comments

Comments
 (0)