Re: KASAN: use-after-free Read in tcf_action_init

2020-09-28 Thread Cong Wang
#syz fix: net_sched: commit action insertions together


KASAN: use-after-free Read in tcf_action_init

2020-09-28 Thread syzbot
Hello,

syzbot found the following issue on:

HEAD commit:171d4ff7 Merge tag 'mmc-v5.9-rc4-2' of git://git.kernel.or..
git tree:   upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=105fbac590
kernel config:  https://syzkaller.appspot.com/x/.config?x=af502ec9a451c9fc
dashboard link: https://syzkaller.appspot.com/bug?extid=9f43bb6a66ff96a21931
compiler:   clang version 10.0.0 (https://github.com/llvm/llvm-project/ 
c2443155a0fb245c8f17f2c1c72b6ea391e86e81)
syz repro:  https://syzkaller.appspot.com/x/repro.syz?x=13cb8f8b90
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=12af2c8190

The issue was bisected to:

commit 974e6f02e27e1b46c6c5e600e70ced25079f73eb
Author: Enric Balletbo i Serra 
Date:   Mon Aug 1 09:54:35 2016 +

iio: cros_ec_sensors_core: Add common functions for the ChromeOS EC Sensor 
Hub.

bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=11fe49d390
final oops: https://syzkaller.appspot.com/x/report.txt?x=13fe49d390
console output: https://syzkaller.appspot.com/x/log.txt?x=15fe49d390

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+9f43bb6a66ff96a21...@syzkaller.appspotmail.com
Fixes: 974e6f02e27e ("iio: cros_ec_sensors_core: Add common functions for the 
ChromeOS EC Sensor Hub.")

netlink: 32 bytes leftover after parsing attributes in process 
`syz-executor211'.
==
BUG: KASAN: use-after-free in tcf_action_destroy net/sched/act_api.c:724 
[inline]
BUG: KASAN: use-after-free in tcf_action_init+0x231/0x3d0 
net/sched/act_api.c:1058
Read of size 8 at addr 888097225c00 by task syz-executor211/7086

CPU: 0 PID: 7086 Comm: syz-executor211 Not tainted 5.9.0-rc6-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+0x1d6/0x29e lib/dump_stack.c:118
 print_address_description+0x66/0x620 mm/kasan/report.c:383
 __kasan_report mm/kasan/report.c:513 [inline]
 kasan_report+0x132/0x1d0 mm/kasan/report.c:530
 tcf_action_destroy net/sched/act_api.c:724 [inline]
 tcf_action_init+0x231/0x3d0 net/sched/act_api.c:1058
 tcf_action_add net/sched/act_api.c:1451 [inline]
 tc_ctl_action+0x2c7/0x7e0 net/sched/act_api.c:1504
 rtnetlink_rcv_msg+0x889/0xd40 net/core/rtnetlink.c:5563
 netlink_rcv_skb+0x190/0x3a0 net/netlink/af_netlink.c:2470
 netlink_unicast_kernel net/netlink/af_netlink.c:1304 [inline]
 netlink_unicast+0x786/0x940 net/netlink/af_netlink.c:1330
 netlink_sendmsg+0xa57/0xd70 net/netlink/af_netlink.c:1919
 sock_sendmsg_nosec net/socket.c:651 [inline]
 sock_sendmsg net/socket.c:671 [inline]
 sys_sendmsg+0x519/0x800 net/socket.c:2353
 ___sys_sendmsg net/socket.c:2407 [inline]
 __sys_sendmsg+0x2b1/0x360 net/socket.c:2440
 do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x44abe9
Code: e8 dc 13 03 00 48 83 c4 18 c3 0f 1f 80 00 00 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 0f 83 
cb 0b fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:7f842a305ce8 EFLAGS: 0246 ORIG_RAX: 002e
RAX: ffda RBX: 006e0c48 RCX: 0044abe9
RDX:  RSI: 20002980 RDI: 0003
RBP: 006e0c40 R08:  R09: 
R10:  R11: 0246 R12: 006e0c4c
R13: 7ffcf73121ef R14: 7f842a3069c0 R15: 006e0c4c

Allocated by task 7086:
 kasan_save_stack mm/kasan/common.c:48 [inline]
 kasan_set_track mm/kasan/common.c:56 [inline]
 __kasan_kmalloc+0x100/0x130 mm/kasan/common.c:461
 __do_kmalloc mm/slab.c:3655 [inline]
 __kmalloc+0x205/0x300 mm/slab.c:3664
 kmalloc include/linux/slab.h:559 [inline]
 kzalloc+0x16/0x30 include/linux/slab.h:666
 tcf_idr_create+0x56/0x5e0 net/sched/act_api.c:408
 tcf_connmark_init+0x230/0x7d0 net/sched/act_connmark.c:126
 tcf_action_init_1+0x7dc/0xce0 net/sched/act_api.c:984
 tcf_action_init+0x114/0x3d0 net/sched/act_api.c:1043
 tcf_action_add net/sched/act_api.c:1451 [inline]
 tc_ctl_action+0x2c7/0x7e0 net/sched/act_api.c:1504
 rtnetlink_rcv_msg+0x889/0xd40 net/core/rtnetlink.c:5563
 netlink_rcv_skb+0x190/0x3a0 net/netlink/af_netlink.c:2470
 netlink_unicast_kernel net/netlink/af_netlink.c:1304 [inline]
 netlink_unicast+0x786/0x940 net/netlink/af_netlink.c:1330
 netlink_sendmsg+0xa57/0xd70 net/netlink/af_netlink.c:1919
 sock_sendmsg_nosec net/socket.c:651 [inline]
 sock_sendmsg net/socket.c:671 [inline]
 sys_sendmsg+0x519/0x800 net/socket.c:2353
 ___sys_sendmsg net/socket.c:2407 [inline]
 __sys_sendmsg+0x2b1/0x360 net/socket.c:2440
 do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 7088:
 kasan_save_stack mm/kasan/common.c:48 [inline]
 kasan_set_track+0x3d/0x70 mm/kasan/common.c:56