KASAN: use-after-free Read in nbd_genl_connect

14 views
Skip to first unread message

syzbot

unread,
Feb 20, 2021, 7:01:20 AM2/20/21
to syzkaller...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 29c52025 Linux 4.14.221
git tree: linux-4.14.y
console output: https://syzkaller.appspot.com/x/log.txt?x=134af912d00000
kernel config: https://syzkaller.appspot.com/x/.config?x=83f668f81cfc5600
dashboard link: https://syzkaller.appspot.com/bug?extid=a435837627201d305e96
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=103bc8b8d00000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14d924a8d00000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+a43583...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: use-after-free in __read_once_size include/linux/compiler.h:183 [inline]
BUG: KASAN: use-after-free in atomic_read arch/x86/include/asm/atomic.h:27 [inline]
BUG: KASAN: use-after-free in refcount_dec_not_one+0x9a/0xc0 lib/refcount.c:270
Read of size 4 at addr ffff8880a3290e18 by task syz-executor217/8077

CPU: 1 PID: 8077 Comm: syz-executor217 Not tainted 4.14.221-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:17 [inline]
dump_stack+0x1b2/0x281 lib/dump_stack.c:58
print_address_description.cold+0x54/0x1d3 mm/kasan/report.c:252
kasan_report_error.cold+0x8a/0x191 mm/kasan/report.c:351
kasan_report mm/kasan/report.c:409 [inline]
__asan_report_load4_noabort+0x68/0x70 mm/kasan/report.c:429
__read_once_size include/linux/compiler.h:183 [inline]
atomic_read arch/x86/include/asm/atomic.h:27 [inline]
refcount_dec_not_one+0x9a/0xc0 lib/refcount.c:270
refcount_dec_and_mutex_lock+0x1a/0x60 lib/refcount.c:309
nbd_put drivers/block/nbd.c:228 [inline]
nbd_genl_connect+0xf94/0x1400 drivers/block/nbd.c:1896
genl_family_rcv_msg+0x572/0xb20 net/netlink/genetlink.c:600
genl_rcv_msg+0xaf/0x140 net/netlink/genetlink.c:625
netlink_rcv_skb+0x125/0x390 net/netlink/af_netlink.c:2433
genl_rcv+0x24/0x40 net/netlink/genetlink.c:636
netlink_unicast_kernel net/netlink/af_netlink.c:1287 [inline]
netlink_unicast+0x437/0x610 net/netlink/af_netlink.c:1313
netlink_sendmsg+0x62e/0xb80 net/netlink/af_netlink.c:1878
sock_sendmsg_nosec net/socket.c:646 [inline]
sock_sendmsg+0xb5/0x100 net/socket.c:656
___sys_sendmsg+0x6c8/0x800 net/socket.c:2062
__sys_sendmsg+0xa3/0x120 net/socket.c:2096
SYSC_sendmsg net/socket.c:2107 [inline]
SyS_sendmsg+0x27/0x40 net/socket.c:2103
do_syscall_64+0x1d5/0x640 arch/x86/entry/common.c:292
entry_SYSCALL_64_after_hwframe+0x46/0xbb
RIP: 0033:0x440869
RSP: 002b:00007fff209981b8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00000000000f4240 RCX: 0000000000440869
RDX: 0000000000000000 RSI: 0000000020000340 RDI: 0000000000000003
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000001
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000000077c7
R13: 00007fff209981cc R14: 00007fff209981e0 R15: 00007fff209981d0

Allocated by task 8067:
save_stack mm/kasan/kasan.c:447 [inline]
set_track mm/kasan/kasan.c:459 [inline]
kasan_kmalloc+0xeb/0x160 mm/kasan/kasan.c:551
kmem_cache_alloc_trace+0x131/0x3d0 mm/slab.c:3618
kmalloc include/linux/slab.h:488 [inline]
kzalloc include/linux/slab.h:661 [inline]
nbd_dev_add+0x7c/0x800 drivers/block/nbd.c:1611
nbd_genl_connect+0x3a4/0x1400 drivers/block/nbd.c:1756
genl_family_rcv_msg+0x572/0xb20 net/netlink/genetlink.c:600
genl_rcv_msg+0xaf/0x140 net/netlink/genetlink.c:625
netlink_rcv_skb+0x125/0x390 net/netlink/af_netlink.c:2433
genl_rcv+0x24/0x40 net/netlink/genetlink.c:636
netlink_unicast_kernel net/netlink/af_netlink.c:1287 [inline]
netlink_unicast+0x437/0x610 net/netlink/af_netlink.c:1313
netlink_sendmsg+0x62e/0xb80 net/netlink/af_netlink.c:1878
sock_sendmsg_nosec net/socket.c:646 [inline]
sock_sendmsg+0xb5/0x100 net/socket.c:656
___sys_sendmsg+0x6c8/0x800 net/socket.c:2062
__sys_sendmsg+0xa3/0x120 net/socket.c:2096
SYSC_sendmsg net/socket.c:2107 [inline]
SyS_sendmsg+0x27/0x40 net/socket.c:2103
do_syscall_64+0x1d5/0x640 arch/x86/entry/common.c:292
entry_SYSCALL_64_after_hwframe+0x46/0xbb

Freed by task 8077:
save_stack mm/kasan/kasan.c:447 [inline]
set_track mm/kasan/kasan.c:459 [inline]
kasan_slab_free+0xc3/0x1a0 mm/kasan/kasan.c:524
__cache_free mm/slab.c:3496 [inline]
kfree+0xc9/0x250 mm/slab.c:3815
nbd_dev_remove drivers/block/nbd.c:223 [inline]
nbd_put.part.0+0x100/0x140 drivers/block/nbd.c:231
nbd_put drivers/block/nbd.c:267 [inline]
nbd_config_put+0x62a/0x810 drivers/block/nbd.c:1172
nbd_genl_connect+0xf6c/0x1400 drivers/block/nbd.c:1894
genl_family_rcv_msg+0x572/0xb20 net/netlink/genetlink.c:600
genl_rcv_msg+0xaf/0x140 net/netlink/genetlink.c:625
netlink_rcv_skb+0x125/0x390 net/netlink/af_netlink.c:2433
genl_rcv+0x24/0x40 net/netlink/genetlink.c:636
netlink_unicast_kernel net/netlink/af_netlink.c:1287 [inline]
netlink_unicast+0x437/0x610 net/netlink/af_netlink.c:1313
netlink_sendmsg+0x62e/0xb80 net/netlink/af_netlink.c:1878
sock_sendmsg_nosec net/socket.c:646 [inline]
sock_sendmsg+0xb5/0x100 net/socket.c:656
___sys_sendmsg+0x6c8/0x800 net/socket.c:2062
__sys_sendmsg+0xa3/0x120 net/socket.c:2096
SYSC_sendmsg net/socket.c:2107 [inline]
SyS_sendmsg+0x27/0x40 net/socket.c:2103
do_syscall_64+0x1d5/0x640 arch/x86/entry/common.c:292
entry_SYSCALL_64_after_hwframe+0x46/0xbb

The buggy address belongs to the object at ffff8880a3290d40
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 216 bytes inside of
512-byte region [ffff8880a3290d40, ffff8880a3290f40)
The buggy address belongs to the page:
page:ffffea00028ca400 count:1 mapcount:0 mapping:ffff8880a32900c0 index:0x0
flags: 0xfff00000000100(slab)
raw: 00fff00000000100 ffff8880a32900c0 0000000000000000 0000000100000006
raw: ffffea0002ab23e0 ffffea0002a316a0 ffff88813fe80940 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8880a3290d00: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb
ffff8880a3290d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880a3290e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880a3290e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880a3290f00: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches

syzbot

unread,
Feb 21, 2021, 9:36:20 AM2/21/21
to syzkaller...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 255b58a2 Linux 4.19.176
git tree: linux-4.19.y
console output: https://syzkaller.appspot.com/x/log.txt?x=1007ab04d00000
kernel config: https://syzkaller.appspot.com/x/.config?x=b270830ae46c1d6f
dashboard link: https://syzkaller.appspot.com/bug?extid=b049c9d787af4256e919
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=11437322d00000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=147f0b04d00000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+b049c9...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: use-after-free in atomic_read include/asm-generic/atomic-instrumented.h:21 [inline]
BUG: KASAN: use-after-free in refcount_dec_not_one+0x71/0x1d0 lib/refcount.c:269
Read of size 4 at addr ffff8880a3625d58 by task syz-executor665/8248

CPU: 1 PID: 8248 Comm: syz-executor665 Not tainted 4.19.176-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+0x1fc/0x2ef lib/dump_stack.c:118
print_address_description.cold+0x54/0x219 mm/kasan/report.c:256
kasan_report_error.cold+0x8a/0x1b9 mm/kasan/report.c:354
kasan_report+0x8f/0xa0 mm/kasan/report.c:412
atomic_read include/asm-generic/atomic-instrumented.h:21 [inline]
refcount_dec_not_one+0x71/0x1d0 lib/refcount.c:269
refcount_dec_and_mutex_lock+0x1c/0x80 lib/refcount.c:308
nbd_put drivers/block/nbd.c:228 [inline]
nbd_genl_connect+0x11ee/0x1630 drivers/block/nbd.c:1913
genl_family_rcv_msg+0x642/0xc40 net/netlink/genetlink.c:602
genl_rcv_msg+0xbf/0x160 net/netlink/genetlink.c:627
netlink_rcv_skb+0x160/0x440 net/netlink/af_netlink.c:2455
genl_rcv+0x24/0x40 net/netlink/genetlink.c:638
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x4d5/0x690 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x6bb/0xc40 net/netlink/af_netlink.c:1909
sock_sendmsg_nosec net/socket.c:622 [inline]
sock_sendmsg+0xc3/0x120 net/socket.c:632
___sys_sendmsg+0x7bb/0x8e0 net/socket.c:2115
__sys_sendmsg net/socket.c:2153 [inline]
__do_sys_sendmsg net/socket.c:2162 [inline]
__se_sys_sendmsg net/socket.c:2160 [inline]
__x64_sys_sendmsg+0x132/0x220 net/socket.c:2160
do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x440959
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 14 00 00 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 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd88792008 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00000000000f4240 RCX: 0000000000440959
RDX: 0000000002000800 RSI: 0000000020002580 RDI: 0000000000000003
RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000001
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000000988e
R13: 00007ffd8879201c R14: 00007ffd88792030 R15: 00007ffd88792020

Allocated by task 8238:
kmem_cache_alloc_trace+0x12f/0x380 mm/slab.c:3625
kmalloc include/linux/slab.h:515 [inline]
kzalloc include/linux/slab.h:709 [inline]
nbd_dev_add+0x44/0x890 drivers/block/nbd.c:1627
nbd_genl_connect+0x4cc/0x1630 drivers/block/nbd.c:1773
genl_family_rcv_msg+0x642/0xc40 net/netlink/genetlink.c:602
genl_rcv_msg+0xbf/0x160 net/netlink/genetlink.c:627
netlink_rcv_skb+0x160/0x440 net/netlink/af_netlink.c:2455
genl_rcv+0x24/0x40 net/netlink/genetlink.c:638
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x4d5/0x690 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x6bb/0xc40 net/netlink/af_netlink.c:1909
sock_sendmsg_nosec net/socket.c:622 [inline]
sock_sendmsg+0xc3/0x120 net/socket.c:632
___sys_sendmsg+0x7bb/0x8e0 net/socket.c:2115
__sys_sendmsg net/socket.c:2153 [inline]
__do_sys_sendmsg net/socket.c:2162 [inline]
__se_sys_sendmsg net/socket.c:2160 [inline]
__x64_sys_sendmsg+0x132/0x220 net/socket.c:2160
do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 8248:
__cache_free mm/slab.c:3503 [inline]
kfree+0xcc/0x210 mm/slab.c:3822
nbd_dev_remove drivers/block/nbd.c:223 [inline]
nbd_put.part.0+0xfe/0x140 drivers/block/nbd.c:231
nbd_put drivers/block/nbd.c:275 [inline]
nbd_config_put+0x6a0/0x870 drivers/block/nbd.c:1185
nbd_genl_connect+0x11bb/0x1630 drivers/block/nbd.c:1911
genl_family_rcv_msg+0x642/0xc40 net/netlink/genetlink.c:602
genl_rcv_msg+0xbf/0x160 net/netlink/genetlink.c:627
netlink_rcv_skb+0x160/0x440 net/netlink/af_netlink.c:2455
genl_rcv+0x24/0x40 net/netlink/genetlink.c:638
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x4d5/0x690 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x6bb/0xc40 net/netlink/af_netlink.c:1909
sock_sendmsg_nosec net/socket.c:622 [inline]
sock_sendmsg+0xc3/0x120 net/socket.c:632
___sys_sendmsg+0x7bb/0x8e0 net/socket.c:2115
__sys_sendmsg net/socket.c:2153 [inline]
__do_sys_sendmsg net/socket.c:2162 [inline]
__se_sys_sendmsg net/socket.c:2160 [inline]
__x64_sys_sendmsg+0x132/0x220 net/socket.c:2160
do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
entry_SYSCALL_64_after_hwframe+0x49/0xbe

The buggy address belongs to the object at ffff8880a3625c80
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 216 bytes inside of
512-byte region [ffff8880a3625c80, ffff8880a3625e80)
The buggy address belongs to the page:
page:ffffea00028d8940 count:1 mapcount:0 mapping:ffff88813bff0940 index:0x0
flags: 0xfff00000000100(slab)
raw: 00fff00000000100 ffffea0002a66208 ffffea0002ab52c8 ffff88813bff0940
raw: 0000000000000000 ffff8880a3625000 0000000100000006 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8880a3625c00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff8880a3625c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880a3625d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880a3625d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880a3625e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
Reply all
Reply to author
Forward
0 new messages