bisecting cause commit starting from 425c075dcbb2009a526fffb40ada846acc40d2b1 building syzkaller on 2e9971bbbfb4df6ba0118353163a7703f3dbd6ec testing commit 425c075dcbb2009a526fffb40ada846acc40d2b1 with gcc (GCC) 8.1.0 kernel signature: ac4b1212ee74418ea47fb5ea5beb6611881aea4bc16e6c366af88ba46316d324 run #0: crashed: KASAN: use-after-free Write in tcindex_set_parms run #1: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #2: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #3: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #4: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #5: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #6: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #7: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #8: crashed: KASAN: use-after-free Write in tcindex_set_parms run #9: boot failed: can't ssh into the instance testing release v5.5 testing commit d5226fa6dbae0569ee43ecfc08bdcd6770fc4755 with gcc (GCC) 8.1.0 kernel signature: 4b6a12f1b1a200cfd1bab12f05bbd79b325479a98e8e293935a1baee8893bf40 all runs: OK # git bisect start 425c075dcbb2009a526fffb40ada846acc40d2b1 d5226fa6dbae0569ee43ecfc08bdcd6770fc4755 Bisecting: 5831 revisions left to test after this (roughly 13 steps) [9f68e3655aae6d49d6ba05dd263f99f33c2567af] Merge tag 'drm-next-2020-01-30' of git://anongit.freedesktop.org/drm/drm testing commit 9f68e3655aae6d49d6ba05dd263f99f33c2567af with gcc (GCC) 8.1.0 kernel signature: f47bcab51d70e6d1e3404be8a7dbaaa7dec921b27efc39af969fdf5c7a5069f7 all runs: OK # git bisect good 9f68e3655aae6d49d6ba05dd263f99f33c2567af Bisecting: 3077 revisions left to test after this (roughly 12 steps) [469030d454bd1620c7b2651d9ec8cdcbaa74deb9] Merge tag 'armsoc-soc' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc testing commit 469030d454bd1620c7b2651d9ec8cdcbaa74deb9 with gcc (GCC) 8.1.0 kernel signature: 71142ef09ae82ec566de13bd6f7c98f447ddbad81ec3e7d88c27c3315b96c2c7 run #0: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #1: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #2: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #3: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #4: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #5: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #6: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #7: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #8: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #9: crashed: KASAN: use-after-free Write in tcindex_set_parms # git bisect bad 469030d454bd1620c7b2651d9ec8cdcbaa74deb9 Bisecting: 1354 revisions left to test after this (roughly 11 steps) [f4a6365ae88d38528b4eec717326dab877b515ea] Merge tag 'clk-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux testing commit f4a6365ae88d38528b4eec717326dab877b515ea with gcc (GCC) 8.1.0 kernel signature: 08dd855a29d54f50c0402aea86e10577fafec0e4cd8b29be861979d2b8d2be0d all runs: OK # git bisect good f4a6365ae88d38528b4eec717326dab877b515ea Bisecting: 637 revisions left to test after this (roughly 9 steps) [e310396bb8d7db977a0e10ef7b5040e98b89c34c] Merge tag 'trace-v5.6-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace testing commit e310396bb8d7db977a0e10ef7b5040e98b89c34c with gcc (GCC) 8.1.0 kernel signature: 0d7b09a18c6a1294036999599237107dee10af8a828418cf7a1dfc05bded19b9 run #0: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #1: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #2: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #3: crashed: KASAN: use-after-free Write in tcindex_set_parms run #4: crashed: general protection fault in tcf_action_destroy run #5: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #6: crashed: KASAN: use-after-free Write in tcindex_set_parms run #7: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #8: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #9: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms # git bisect bad e310396bb8d7db977a0e10ef7b5040e98b89c34c Bisecting: 359 revisions left to test after this (roughly 9 steps) [d60ddd244215da7c695cba858427094d8e366aa7] Merge tag 'for-linus' of git://git.armlinux.org.uk/~rmk/linux-arm testing commit d60ddd244215da7c695cba858427094d8e366aa7 with gcc (GCC) 8.1.0 kernel signature: 91a5299e69cfc38e5534918e3c433992bbbb44fc876321eaff676d91063d6985 all runs: OK # git bisect good d60ddd244215da7c695cba858427094d8e366aa7 Bisecting: 176 revisions left to test after this (roughly 8 steps) [4fc2ea6a8608d9a649eff5e3c2ee477eb70f0fb6] Merge tag 'iommu-updates-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu testing commit 4fc2ea6a8608d9a649eff5e3c2ee477eb70f0fb6 with gcc (GCC) 8.1.0 kernel signature: c3f9c4550f468bbc80ec2811ed604d0aa1656ab4ba9c66df7ec8541b7e62e968 all runs: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms # git bisect bad 4fc2ea6a8608d9a649eff5e3c2ee477eb70f0fb6 Bisecting: 89 revisions left to test after this (roughly 7 steps) [d271ab29230b1d0ceb426f374c221c4eb2c91c64] Merge tag 'for-linus-5.6-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip testing commit d271ab29230b1d0ceb426f374c221c4eb2c91c64 with gcc (GCC) 8.1.0 kernel signature: 1e28163f3cb0d05d92e5e3bf0585db1607088adb933a80807458cd5ec90578e3 run #0: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #1: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #2: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #3: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #4: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #5: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #6: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #7: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #8: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #9: crashed: KASAN: use-after-free Write in tcindex_set_parms # git bisect bad d271ab29230b1d0ceb426f374c221c4eb2c91c64 Bisecting: 45 revisions left to test after this (roughly 6 steps) [9afe2322cb90a8fbc27e32bfc691100c653cab2a] Merge branch 'unbreak-basic-and-bpf-tdc-testcases' testing commit 9afe2322cb90a8fbc27e32bfc691100c653cab2a with gcc (GCC) 8.1.0 kernel signature: 92ad978a6519510109eada55f60a7c0ee8589698200bd6cad088c3aeb12551cc all runs: OK # git bisect good 9afe2322cb90a8fbc27e32bfc691100c653cab2a Bisecting: 23 revisions left to test after this (roughly 5 steps) [6992ca0dd017ebaa2bf8e9dcc49f1c3b7033b082] Merge branch 'parisc-5.6-1' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux testing commit 6992ca0dd017ebaa2bf8e9dcc49f1c3b7033b082 with gcc (GCC) 8.1.0 kernel signature: 1ae6396ab596e43dd2ef7ed35ac75948747f48bbe1092c746c429c495fba7e9a all runs: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms # git bisect bad 6992ca0dd017ebaa2bf8e9dcc49f1c3b7033b082 Bisecting: 13 revisions left to test after this (roughly 4 steps) [f0f3588f7a95bb8e02b0f8f5138efb7064665730] kernfs: don't bother with timestamp truncation testing commit f0f3588f7a95bb8e02b0f8f5138efb7064665730 with gcc (GCC) 8.1.0 kernel signature: 1e300b1a79d92f7d06f39e5abf97eb6c99f6702fbcb6fd28078635c4cf44c0f8 all runs: OK # git bisect good f0f3588f7a95bb8e02b0f8f5138efb7064665730 Bisecting: 6 revisions left to test after this (roughly 3 steps) [bddea11b1b9385f713006820f16a9fbe5efe6b47] Merge branch 'imm.timestamp' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs testing commit bddea11b1b9385f713006820f16a9fbe5efe6b47 with gcc (GCC) 8.1.0 kernel signature: f9f6f40badf45eebca0602dce61139544041364862b15e996a7f9cbadfb82f9e run #0: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #1: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #2: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #3: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #4: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #5: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #6: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #7: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #8: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #9: boot failed: can't ssh into the instance # git bisect bad bddea11b1b9385f713006820f16a9fbe5efe6b47 Bisecting: 3 revisions left to test after this (roughly 2 steps) [b4b771fd51fda70577dc980429347c41e807c64f] r8152: Add MAC passthrough support to new device testing commit b4b771fd51fda70577dc980429347c41e807c64f with gcc (GCC) 8.1.0 kernel signature: fab359f8c4307301f7d0ba10d46e1ed28ea21a72adcad684166a8a4c27658031 all runs: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms # git bisect bad b4b771fd51fda70577dc980429347c41e807c64f Bisecting: 0 revisions left to test after this (roughly 1 step) [599be01ee567b61f4471ee8078870847d0a11e8e] net_sched: fix an OOB access in cls_tcindex testing commit 599be01ee567b61f4471ee8078870847d0a11e8e with gcc (GCC) 8.1.0 kernel signature: 90f0832754899bf75f054def82353554ab3a124382448915bce7ef002823a01d run #0: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #1: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #2: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #3: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #4: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #5: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #6: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #7: crashed: KASAN: use-after-free Write in tcindex_set_parms run #8: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms run #9: crashed: KASAN: slab-out-of-bounds Write in tcindex_set_parms # git bisect bad 599be01ee567b61f4471ee8078870847d0a11e8e Bisecting: 0 revisions left to test after this (roughly 0 steps) [83b43045308ea0600099830292955f18818f8d5e] qed: Remove set but not used variable 'p_link' testing commit 83b43045308ea0600099830292955f18818f8d5e with gcc (GCC) 8.1.0 kernel signature: 3c94ea759270897ceb8b0fd51cb3970beeb0fbe6781c412a0a0841320249a640 all runs: OK # git bisect good 83b43045308ea0600099830292955f18818f8d5e 599be01ee567b61f4471ee8078870847d0a11e8e is the first bad commit commit 599be01ee567b61f4471ee8078870847d0a11e8e Author: Cong Wang Date: Sun Feb 2 21:14:35 2020 -0800 net_sched: fix an OOB access in cls_tcindex As Eric noticed, tcindex_alloc_perfect_hash() uses cp->hash to compute the size of memory allocation, but cp->hash is set again after the allocation, this caused an out-of-bound access. So we have to move all cp->hash initialization and computation before the memory allocation. Move cp->mask and cp->shift together as cp->hash may need them for computation too. Reported-and-tested-by: syzbot+35d4dea36c387813ed31@syzkaller.appspotmail.com Fixes: 331b72922c5f ("net: sched: RCU cls_tcindex") Cc: Eric Dumazet Cc: John Fastabend Cc: Jamal Hadi Salim Cc: Jiri Pirko Cc: Jakub Kicinski Signed-off-by: Cong Wang Signed-off-by: David S. Miller net/sched/cls_tcindex.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) culprit signature: 90f0832754899bf75f054def82353554ab3a124382448915bce7ef002823a01d parent signature: 3c94ea759270897ceb8b0fd51cb3970beeb0fbe6781c412a0a0841320249a640 revisions tested: 16, total time: 3h51m5.593431891s (build: 1h46m53.676524133s, test: 2h2m59.305148379s) first bad commit: 599be01ee567b61f4471ee8078870847d0a11e8e net_sched: fix an OOB access in cls_tcindex cc: ["davem@davemloft.net" "syzbot+35d4dea36c387813ed31@syzkaller.appspotmail.com" "xiyou.wangcong@gmail.com"] crash: KASAN: slab-out-of-bounds Write in tcindex_set_parms ================================================================== BUG: KASAN: slab-out-of-bounds in tcindex_set_parms+0x1690/0x1b90 net/sched/cls_tcindex.c:455 Write of size 16 at addr ffff88807b6f2eb8 by task syz-executor.4/8473 CPU: 1 PID: 8473 Comm: syz-executor.4 Not tainted 5.5.0-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x128/0x182 lib/dump_stack.c:118 print_address_description.constprop.8.cold.10+0x9/0x317 mm/kasan/report.c:374 __kasan_report.cold.11+0x1c/0x34 mm/kasan/report.c:506 kasan_report+0xe/0x20 mm/kasan/common.c:639 tcindex_set_parms+0x1690/0x1b90 net/sched/cls_tcindex.c:455 tcindex_change+0x1c2/0x280 net/sched/cls_tcindex.c:519 tc_new_tfilter+0xffa/0x1da0 net/sched/cls_api.c:2103 rtnetlink_rcv_msg+0x60c/0x8c0 net/core/rtnetlink.c:5429 netlink_rcv_skb+0x119/0x340 net/netlink/af_netlink.c:2477 netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline] netlink_unicast+0x434/0x630 net/netlink/af_netlink.c:1328 netlink_sendmsg+0x714/0xc60 net/netlink/af_netlink.c:1917 sock_sendmsg_nosec net/socket.c:652 [inline] sock_sendmsg+0xac/0xe0 net/socket.c:672 ____sys_sendmsg+0x54e/0x750 net/socket.c:2343 ___sys_sendmsg+0xe4/0x160 net/socket.c:2397 __sys_sendmsg+0xce/0x170 net/socket.c:2430 do_syscall_64+0xc6/0x5e0 arch/x86/entry/common.c:294 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x45c4a9 Code: ad b6 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 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 0f 83 7b b6 fb ff c3 66 2e 0f 1f 84 00 00 00 00 RSP: 002b:00007f6e44d01c78 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007f6e44d026d4 RCX: 000000000045c4a9 RDX: 0000000000000000 RSI: 00000000200001c0 RDI: 0000000000000003 RBP: 000000000076bf20 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff R13: 00000000000009fa R14: 00000000004cc777 R15: 000000000076bf2c Allocated by task 8473: save_stack+0x19/0x80 mm/kasan/common.c:72 set_track mm/kasan/common.c:80 [inline] __kasan_kmalloc.constprop.17+0xc1/0xd0 mm/kasan/common.c:513 kmem_cache_alloc_trace+0x156/0x780 mm/slab.c:3551 kmalloc include/linux/slab.h:556 [inline] kzalloc include/linux/slab.h:670 [inline] tcindex_set_parms+0x1b7/0x1b90 net/sched/cls_tcindex.c:325 tcindex_change+0x1c2/0x280 net/sched/cls_tcindex.c:519 tc_new_tfilter+0xffa/0x1da0 net/sched/cls_api.c:2103 rtnetlink_rcv_msg+0x60c/0x8c0 net/core/rtnetlink.c:5429 netlink_rcv_skb+0x119/0x340 net/netlink/af_netlink.c:2477 netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline] netlink_unicast+0x434/0x630 net/netlink/af_netlink.c:1328 netlink_sendmsg+0x714/0xc60 net/netlink/af_netlink.c:1917 sock_sendmsg_nosec net/socket.c:652 [inline] sock_sendmsg+0xac/0xe0 net/socket.c:672 ____sys_sendmsg+0x54e/0x750 net/socket.c:2343 ___sys_sendmsg+0xe4/0x160 net/socket.c:2397 __sys_sendmsg+0xce/0x170 net/socket.c:2430 do_syscall_64+0xc6/0x5e0 arch/x86/entry/common.c:294 entry_SYSCALL_64_after_hwframe+0x49/0xbe Freed by task 0: (stack is not available) The buggy address belongs to the object at ffff88807b6f2e00 which belongs to the cache kmalloc-192 of size 192 The buggy address is located 184 bytes inside of 192-byte region [ffff88807b6f2e00, ffff88807b6f2ec0) The buggy address belongs to the page: page:ffffea0001edbc80 refcount:1 mapcount:0 mapping:ffff8880aa400000 index:0x0 raw: 00fffe0000000200 ffffea00028a6108 ffffea0002a2b388 ffff8880aa400000 raw: 0000000000000000 ffff88807b6f2000 0000000100000010 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88807b6f2d80: 00 fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff88807b6f2e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >ffff88807b6f2e80: 00 fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ^ ffff88807b6f2f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffff88807b6f2f80: 00 fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ==================================================================