bisecting cause commit starting from fb33c6510d5595144d585aa194d377cf74d31911 building syzkaller on 749688d22abef3f3cb9a0480e15c19a3f2ed8e13 testing commit fb33c6510d5595144d585aa194d377cf74d31911 with gcc (GCC) 8.1.0 kernel signature: a449ffc3176ba3a845923b711150008f6084a920b21fdc7817836837dbe96d1b run #0: crashed: general protection fault in tcf_action_destroy run #1: crashed: KASAN: use-after-free Write in tcindex_set_parms run #2: crashed: KASAN: use-after-free Write in tcindex_set_parms run #3: crashed: KASAN: use-after-free Write in tcindex_set_parms run #4: crashed: WARNING in kfree run #5: crashed: KASAN: use-after-free Write in tcindex_set_parms run #6: crashed: KASAN: use-after-free Write in tcindex_set_parms run #7: crashed: KASAN: invalid-free in tcf_exts_destroy run #8: crashed: KASAN: use-after-free Write in tcindex_set_parms run #9: crashed: KASAN: use-after-free Write in tcindex_set_parms testing release v5.5 testing commit d5226fa6dbae0569ee43ecfc08bdcd6770fc4755 with gcc (GCC) 8.1.0 kernel signature: 4f0aace708d3fbdd4644f615643fecc6f5c87426a4267306e07a6cedc8b81943 all runs: OK # git bisect start fb33c6510d5595144d585aa194d377cf74d31911 d5226fa6dbae0569ee43ecfc08bdcd6770fc4755 Bisecting: 5626 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: 36d9d92f4605afb95b7f99fd423449d4a59b8e7578491fe7401828f1fa9dc9be all runs: OK # git bisect good 9f68e3655aae6d49d6ba05dd263f99f33c2567af Bisecting: 2872 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: 2171b282b14051bfed408d89c6f9453928962858a8fecd1ffe5069de9a57e162 run #0: crashed: KASAN: invalid-free in tcf_exts_destroy run #1: crashed: KASAN: use-after-free Write in tcindex_set_parms run #2: crashed: KASAN: use-after-free Write in tcindex_set_parms run #3: crashed: KASAN: invalid-free in tcf_exts_destroy run #4: crashed: BUG: unable to handle kernel paging request in cache_grow_end run #5: crashed: KASAN: use-after-free Write in tcindex_set_parms run #6: crashed: KASAN: use-after-free Write in tcindex_set_parms run #7: crashed: general protection fault in tcf_action_destroy run #8: crashed: KASAN: use-after-free 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: 0ed2438e217aebe4e780ecdec2768ac5f734a272019ad69ef7727e8677b09c6a 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: 4b0eabb71f7e5da7b84b0fe6a999f431d7ad5b7a2829aaec9b34310583c4a70d run #0: crashed: general protection fault in tcf_action_destroy run #1: crashed: KASAN: use-after-free Write in tcindex_set_parms run #2: crashed: KASAN: invalid-free in tcf_exts_destroy run #3: crashed: KASAN: use-after-free Write in tcindex_set_parms run #4: crashed: KASAN: use-after-free Write in tcindex_set_parms run #5: crashed: KASAN: use-after-free Write in tcindex_set_parms run #6: crashed: KASAN: use-after-free Write in tcindex_set_parms run #7: crashed: KASAN: use-after-free Write in tcindex_set_parms run #8: crashed: general protection fault in tcf_action_destroy run #9: boot failed: can't ssh into the instance # 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: e226e6b129a67f12f793417948b005d18293219d4f1d4ceb0a28bd95d1aa8456 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: 0df3bfac038f683c33a4c49caeca42b6e3b8efd6dc0c77306168d0470d7a8b7a run #0: crashed: KASAN: invalid-free in tcf_exts_destroy run #1: crashed: general protection fault in tcf_action_destroy run #2: crashed: KASAN: use-after-free Write in tcindex_set_parms run #3: crashed: KASAN: use-after-free Write in tcindex_set_parms run #4: crashed: KASAN: use-after-free Write in tcindex_set_parms run #5: crashed: general protection fault in tcf_action_destroy run #6: crashed: KASAN: use-after-free Write in tcindex_set_parms run #7: crashed: KASAN: use-after-free Write in tcindex_set_parms run #8: crashed: KASAN: use-after-free Write in tcindex_set_parms run #9: crashed: KASAN: invalid-free in tcf_exts_destroy # 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: 8964284cab9b46e24492842a6cfacff03f6f1f076e09fd46b4de48da94cf3abb run #0: crashed: general protection fault in tcf_action_destroy run #1: crashed: KASAN: use-after-free Write in tcindex_set_parms run #2: crashed: general protection fault in tcf_action_destroy run #3: crashed: KASAN: use-after-free Write in tcindex_set_parms run #4: crashed: KASAN: invalid-free in tcf_exts_destroy run #5: crashed: KASAN: use-after-free Write in tcindex_set_parms run #6: crashed: WARNING in kfree run #7: crashed: KASAN: invalid-free in tcf_exts_destroy run #8: crashed: KASAN: slab-out-of-bounds Read in tcindex_set_parms run #9: crashed: KASAN: invalid-free in tcf_exts_destroy # 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: bf678dede81527b2bf11b46394b8a69b6da34eff8e381a8151bfcb075c8e6e32 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: c213bfefeab52df91311e47500a14207234d9dca4c5d57499f782e39a2ff2543 run #0: crashed: KASAN: invalid-free in tcf_exts_destroy run #1: crashed: KASAN: invalid-free in tcf_exts_destroy run #2: crashed: KASAN: use-after-free Write in tcindex_set_parms run #3: crashed: KASAN: use-after-free Write in tcindex_set_parms run #4: crashed: KASAN: use-after-free Write in tcindex_set_parms run #5: crashed: KASAN: use-after-free Write in tcindex_set_parms run #6: crashed: KASAN: use-after-free Write in tcindex_set_parms run #7: crashed: KASAN: use-after-free Write in tcindex_set_parms run #8: crashed: KASAN: use-after-free Write in tcindex_set_parms run #9: crashed: KASAN: use-after-free 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: 952c00fb2fe5dd5405df6492732728068a574be97abc9347e16dd946e2bbde20 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: 81ad87b6b4b7a2585ea21e1509be5c2620c7109543fb3160638f3cec6a0fc408 run #0: crashed: KASAN: use-after-free Write in tcindex_set_parms run #1: crashed: KASAN: use-after-free Write in tcindex_set_parms run #2: crashed: KASAN: use-after-free Write in tcindex_set_parms run #3: crashed: KASAN: use-after-free Write in tcindex_set_parms run #4: crashed: KASAN: slab-out-of-bounds Write in tcindex_filter_result_init run #5: crashed: KASAN: invalid-free in tcf_exts_destroy run #6: crashed: KASAN: use-after-free Write in tcindex_set_parms run #7: crashed: KASAN: use-after-free 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 # 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: 18a5e1d730215b5afb4d5e14605dca12ef462b8766adb4e7cea088c7c691a3de run #0: crashed: KASAN: use-after-free Write in tcindex_set_parms run #1: crashed: KASAN: invalid-free in tcf_exts_destroy run #2: crashed: KASAN: use-after-free Write in tcindex_set_parms run #3: crashed: KASAN: use-after-free Write in tcindex_set_parms run #4: crashed: KASAN: use-after-free Write in tcindex_set_parms run #5: crashed: general protection fault in tcf_action_destroy run #6: crashed: KASAN: use-after-free Write in tcindex_set_parms run #7: crashed: KASAN: use-after-free Write in tcindex_set_parms run #8: crashed: KASAN: use-after-free Write in tcindex_set_parms run #9: crashed: general protection fault in tcf_action_destroy # 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: 8663d4b60e971a7c3e822f4e9c457c15c77747fb40ee420d6048ea1bbbc14537 run #0: crashed: KASAN: use-after-free Write in tcindex_set_parms run #1: crashed: KASAN: use-after-free Write in tcindex_set_parms run #2: crashed: general protection fault in tcf_action_destroy run #3: crashed: WARNING in kfree run #4: crashed: KASAN: use-after-free Write in tcindex_set_parms run #5: crashed: KASAN: use-after-free Write in tcindex_set_parms run #6: crashed: general protection fault in tcf_action_destroy run #7: crashed: KASAN: invalid-free in tcf_exts_destroy run #8: crashed: KASAN: use-after-free Write in tcindex_set_parms run #9: crashed: KASAN: use-after-free 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: 0c3c01069fb106f28e5687e9685feef09ed15cf44f5086b5207dad6f264c0659 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: 8663d4b60e971a7c3e822f4e9c457c15c77747fb40ee420d6048ea1bbbc14537 parent signature: 0c3c01069fb106f28e5687e9685feef09ed15cf44f5086b5207dad6f264c0659 revisions tested: 16, total time: 3h49m18.081126074s (build: 1h46m25.384744616s, test: 2h1m32.036695902s) 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: use-after-free Write in tcindex_set_parms ================================================================== BUG: KASAN: use-after-free in tcindex_set_parms+0x1690/0x1b90 net/sched/cls_tcindex.c:455 Write of size 16 at addr ffff888096f7dc30 by task syz-executor.1/8580 CPU: 0 PID: 8580 Comm: syz-executor.1 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:0x45c849 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:00007f2e88624c78 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007f2e886256d4 RCX: 000000000045c849 RDX: 0000000000000000 RSI: 00000000200001c0 RDI: 0000000000000003 RBP: 000000000076c040 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff R13: 00000000000009fa R14: 00000000004ccb28 R15: 000000000076c04c Allocated by task 8446: 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 __do_kmalloc mm/slab.c:3656 [inline] __kmalloc+0x164/0x7b0 mm/slab.c:3665 kmalloc include/linux/slab.h:561 [inline] kzalloc include/linux/slab.h:670 [inline] lsm_cred_alloc security/security.c:532 [inline] security_prepare_creds+0xbf/0x140 security/security.c:1586 prepare_kernel_cred+0x3a2/0x630 kernel/cred.c:718 call_usermodehelper_exec_async+0xa5/0x680 kernel/umh.c:85 ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352 Freed by task 8458: save_stack+0x19/0x80 mm/kasan/common.c:72 set_track mm/kasan/common.c:80 [inline] kasan_set_free_info mm/kasan/common.c:335 [inline] __kasan_slab_free+0xf7/0x140 mm/kasan/common.c:474 __cache_free mm/slab.c:3426 [inline] kfree+0x107/0x2b0 mm/slab.c:3757 security_cred_free+0xa2/0x100 security/security.c:1580 put_cred_rcu+0xe6/0x430 kernel/cred.c:114 rcu_do_batch kernel/rcu/tree.c:2186 [inline] rcu_core+0x584/0x1290 kernel/rcu/tree.c:2410 __do_softirq+0x26e/0x9b2 kernel/softirq.c:292 The buggy address belongs to the object at ffff888096f7dc00 which belongs to the cache kmalloc-192 of size 192 The buggy address is located 48 bytes inside of 192-byte region [ffff888096f7dc00, ffff888096f7dcc0) The buggy address belongs to the page: page:ffffea00025bdf40 refcount:1 mapcount:0 mapping:ffff8880aa400000 index:0xffff888096f7dd00 raw: 00fffe0000000200 ffffea000280b948 ffffea00026706c8 ffff8880aa400000 raw: ffff888096f7dd00 ffff888096f7d000 000000010000000b 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff888096f7db00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffff888096f7db80: 00 fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc >ffff888096f7dc00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff888096f7dc80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc ffff888096f7dd00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ==================================================================