[syzbot] KASAN: use-after-free Read in j1939_xtp_rx_dat_one (3)

20 views
Skip to first unread message

syzbot

unread,
Mar 28, 2022, 2:25:27 PM3/28/22
to da...@davemloft.net, ker...@pengutronix.de, ku...@kernel.org, linu...@vger.kernel.org, linux-...@vger.kernel.org, li...@rempel-privat.de, m...@pengutronix.de, net...@vger.kernel.org, pab...@redhat.com, ro...@protonic.nl, sock...@hartkopp.net, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: ae085d7f9365 mm: kfence: fix missing objcg housekeeping fo..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17656105700000
kernel config: https://syzkaller.appspot.com/x/.config?x=6bae4cd50262530e
dashboard link: https://syzkaller.appspot.com/bug?extid=a9dce1ff45c3bbeceb3a
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=12529653700000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14b64ea5700000

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

vcan0: j1939_xtp_rx_dat_one: 0xffff88801fe31400: last 00
vcan0: j1939_xtp_rx_dat_one: 0xffff88801fe31800: last 00
vcan0: j1939_xtp_rx_dat_one: 0xffff88801fe31800: Data of RX-looped back packet (00 ff ff ff ff ff ff) doesn't match TX data (00 00 00 00 00 00 00)!
==================================================================
BUG: KASAN: use-after-free in j1939_xtp_rx_dat_one+0xe15/0xee0 net/can/j1939/transport.c:1877
Read of size 1 at addr ffff88802304ab8e by task ksoftirqd/1/21

CPU: 1 PID: 21 Comm: ksoftirqd/1 Tainted: G W 5.17.0-syzkaller-11407-gae085d7f9365 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
print_address_description.constprop.0.cold+0xeb/0x495 mm/kasan/report.c:313
print_report mm/kasan/report.c:429 [inline]
kasan_report.cold+0xf4/0x1c6 mm/kasan/report.c:491
j1939_xtp_rx_dat_one+0xe15/0xee0 net/can/j1939/transport.c:1877
j1939_xtp_rx_dat net/can/j1939/transport.c:1929 [inline]
j1939_tp_recv+0x6de/0xcb0 net/can/j1939/transport.c:2123
j1939_can_recv+0x6ff/0x9a0 net/can/j1939/main.c:108
deliver net/can/af_can.c:574 [inline]
can_rcv_filter+0x5d4/0x8d0 net/can/af_can.c:608
can_receive+0x31d/0x580 net/can/af_can.c:665
can_rcv+0x120/0x1c0 net/can/af_can.c:696
__netif_receive_skb_one_core+0x114/0x180 net/core/dev.c:5405
__netif_receive_skb+0x24/0x1b0 net/core/dev.c:5519
process_backlog+0x3a0/0x7c0 net/core/dev.c:5847
__napi_poll+0xb3/0x6e0 net/core/dev.c:6413
napi_poll net/core/dev.c:6480 [inline]
net_rx_action+0x8ec/0xc60 net/core/dev.c:6567
__do_softirq+0x29b/0x9c2 kernel/softirq.c:558
run_ksoftirqd kernel/softirq.c:921 [inline]
run_ksoftirqd+0x2d/0x60 kernel/softirq.c:913
smpboot_thread_fn+0x645/0x9c0 kernel/smpboot.c:164
kthread+0x2e9/0x3a0 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298
</TASK>

Allocated by task 3606:
kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
kasan_set_track mm/kasan/common.c:45 [inline]
set_alloc_info mm/kasan/common.c:436 [inline]
__kasan_slab_alloc+0x90/0xc0 mm/kasan/common.c:469
kasan_slab_alloc include/linux/kasan.h:224 [inline]
slab_post_alloc_hook mm/slab.h:749 [inline]
slab_alloc_node mm/slub.c:3217 [inline]
kmem_cache_alloc_node+0x255/0x3f0 mm/slub.c:3267
__alloc_skb+0x215/0x340 net/core/skbuff.c:414
alloc_skb include/linux/skbuff.h:1300 [inline]
alloc_skb_with_frags+0x93/0x730 net/core/skbuff.c:5988
sock_alloc_send_pskb+0x793/0x920 net/core/sock.c:2600
j1939_sk_alloc_skb net/can/j1939/socket.c:861 [inline]
j1939_sk_send_loop net/can/j1939/socket.c:1118 [inline]
j1939_sk_sendmsg+0x6eb/0x13f0 net/can/j1939/socket.c:1253
sock_sendmsg_nosec net/socket.c:705 [inline]
sock_sendmsg+0xcf/0x120 net/socket.c:725
sock_no_sendpage+0xf6/0x140 net/core/sock.c:3106
kernel_sendpage.part.0+0x1ff/0x7b0 net/socket.c:3492
kernel_sendpage net/socket.c:3489 [inline]
sock_sendpage+0xdf/0x140 net/socket.c:1007
pipe_to_sendpage+0x2ad/0x380 fs/splice.c:364
splice_from_pipe_feed fs/splice.c:418 [inline]
__splice_from_pipe+0x43e/0x8a0 fs/splice.c:562
splice_from_pipe fs/splice.c:597 [inline]
generic_splice_sendpage+0xd4/0x140 fs/splice.c:746
do_splice_from fs/splice.c:767 [inline]
direct_splice_actor+0x110/0x180 fs/splice.c:936
splice_direct_to_actor+0x34b/0x8c0 fs/splice.c:891
do_splice_direct+0x1a7/0x270 fs/splice.c:979
do_sendfile+0xae0/0x1240 fs/read_write.c:1246
__do_sys_sendfile64 fs/read_write.c:1311 [inline]
__se_sys_sendfile64 fs/read_write.c:1297 [inline]
__x64_sys_sendfile64+0x1cc/0x210 fs/read_write.c:1297
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0x80 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae

Freed by task 15:
kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
kasan_set_track+0x21/0x30 mm/kasan/common.c:45
kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
____kasan_slab_free mm/kasan/common.c:366 [inline]
____kasan_slab_free+0x166/0x1a0 mm/kasan/common.c:328
kasan_slab_free include/linux/kasan.h:200 [inline]
slab_free_hook mm/slub.c:1728 [inline]
slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1754
slab_free mm/slub.c:3510 [inline]
kmem_cache_free+0xdd/0x5a0 mm/slub.c:3527
kfree_skbmem+0xef/0x1b0 net/core/skbuff.c:700
kfree_skb_reason+0x85/0x110 include/linux/refcount.h:279
kfree_skb include/linux/skbuff.h:1250 [inline]
j1939_session_skb_drop_old net/can/j1939/transport.c:340 [inline]
j1939_xtp_rx_cts_one net/can/j1939/transport.c:1434 [inline]
j1939_xtp_rx_cts+0xbdb/0x1170 net/can/j1939/transport.c:1473
j1939_tp_cmd_recv net/can/j1939/transport.c:2061 [inline]
j1939_tp_recv+0x83c/0xcb0 net/can/j1939/transport.c:2133
j1939_can_recv+0x6ff/0x9a0 net/can/j1939/main.c:108
deliver net/can/af_can.c:574 [inline]
can_rcv_filter+0x5d4/0x8d0 net/can/af_can.c:608
can_receive+0x31d/0x580 net/can/af_can.c:665
can_rcv+0x120/0x1c0 net/can/af_can.c:696
__netif_receive_skb_one_core+0x114/0x180 net/core/dev.c:5405
__netif_receive_skb+0x24/0x1b0 net/core/dev.c:5519
process_backlog+0x3a0/0x7c0 net/core/dev.c:5847
__napi_poll+0xb3/0x6e0 net/core/dev.c:6413
napi_poll net/core/dev.c:6480 [inline]
net_rx_action+0x8ec/0xc60 net/core/dev.c:6567
__do_softirq+0x29b/0x9c2 kernel/softirq.c:558

The buggy address belongs to the object at ffff88802304ab40
which belongs to the cache skbuff_head_cache of size 232
The buggy address is located 78 bytes inside of
232-byte region [ffff88802304ab40, ffff88802304ac28)

The buggy address belongs to the physical page:
page:ffffea00008c1280 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2304a
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 0000000000000000 dead000000000122 ffff888140b8d500
raw: 0000000000000000 00000000000c000c 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x12a20(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY), pid 3590, tgid 3590 (kworker/1:3), ts 33637485571, free_ts 33296379898
prep_new_page mm/page_alloc.c:2438 [inline]
get_page_from_freelist+0xba2/0x3df0 mm/page_alloc.c:4179
__alloc_pages+0x1b2/0x500 mm/page_alloc.c:5405
alloc_pages+0x1aa/0x310 mm/mempolicy.c:2262
alloc_slab_page mm/slub.c:1799 [inline]
allocate_slab+0x26c/0x3c0 mm/slub.c:1944
new_slab mm/slub.c:2004 [inline]
___slab_alloc+0x8df/0xf20 mm/slub.c:3005
__slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3092
slab_alloc_node mm/slub.c:3183 [inline]
kmem_cache_alloc_node+0x122/0x3f0 mm/slub.c:3267
__alloc_skb+0x215/0x340 net/core/skbuff.c:414
alloc_skb include/linux/skbuff.h:1300 [inline]
ndisc_alloc_skb+0x134/0x320 net/ipv6/ndisc.c:420
ndisc_send_rs+0x37f/0x6f0 net/ipv6/ndisc.c:701
addrconf_dad_completed+0x37a/0xd30 net/ipv6/addrconf.c:4231
addrconf_dad_work+0x79f/0x1340 net/ipv6/addrconf.c:4141
process_one_work+0x996/0x1610 kernel/workqueue.c:2289
worker_thread+0x665/0x1080 kernel/workqueue.c:2436
kthread+0x2e9/0x3a0 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1353 [inline]
free_pcp_prepare+0x549/0xd20 mm/page_alloc.c:1403
free_unref_page_prepare mm/page_alloc.c:3325 [inline]
free_unref_page+0x19/0x690 mm/page_alloc.c:3420
qlink_free mm/kasan/quarantine.c:157 [inline]
qlist_free_all+0x6a/0x170 mm/kasan/quarantine.c:176
kasan_quarantine_reduce+0x180/0x200 mm/kasan/quarantine.c:283
__kasan_slab_alloc+0xa2/0xc0 mm/kasan/common.c:446
kasan_slab_alloc include/linux/kasan.h:224 [inline]
slab_post_alloc_hook mm/slab.h:749 [inline]
slab_alloc_node mm/slub.c:3217 [inline]
kmem_cache_alloc_node+0x255/0x3f0 mm/slub.c:3267
__alloc_skb+0x215/0x340 net/core/skbuff.c:414
alloc_skb include/linux/skbuff.h:1300 [inline]
alloc_skb_with_frags+0x93/0x730 net/core/skbuff.c:5988
sock_alloc_send_pskb+0x793/0x920 net/core/sock.c:2600
mld_newpack.isra.0+0x1be/0x750 net/ipv6/mcast.c:1746
add_grhead+0x283/0x360 net/ipv6/mcast.c:1849
add_grec+0x106a/0x1530 net/ipv6/mcast.c:1987
mld_send_initial_cr.part.0+0xf6/0x230 net/ipv6/mcast.c:2234
mld_send_initial_cr net/ipv6/mcast.c:1232 [inline]
ipv6_mc_dad_complete+0x1d0/0x690 net/ipv6/mcast.c:2245
addrconf_dad_completed+0x9e8/0xd30 net/ipv6/addrconf.c:4211
addrconf_dad_work+0x79f/0x1340 net/ipv6/addrconf.c:4141

Memory state around the buggy address:
ffff88802304aa80: 00 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc
ffff88802304ab00: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
>ffff88802304ab80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88802304ac00: fb fb fb fb fb fc fc fc fc fc fc fc fc fc fc fc
ffff88802304ac80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================


---
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

Hillf Danton

unread,
Mar 31, 2022, 8:57:50 PM3/31/22
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Mon, 28 Mar 2022 11:25:26 -0700
See if the uaf is due to refcount imbalance.

Hillf

#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ ae085d7f9365

--- x/net/can/j1939/transport.c
+++ y/net/can/j1939/transport.c
@@ -336,8 +336,6 @@ static void j1939_session_skb_drop_old(s
__skb_unlink(do_skb, &session->skb_queue);
/* drop ref taken in j1939_session_skb_queue() */
skb_unref(do_skb);
-
- kfree_skb(do_skb);
}
spin_unlock_irqrestore(&session->skb_queue.lock, flags);
}
--

syzbot

unread,
Mar 31, 2022, 9:09:10 PM3/31/22
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in j1939_session_deactivate_activate_next

vcan0: j1939_xtp_rx_abort_one: 0xffff888010f92000: 0x00000: (3) A timeout occurred and this is the connection abort to close the session.
vcan0: j1939_xtp_rx_abort_one: 0xffff88807c1b1000: 0x00000: (3) A timeout occurred and this is the connection abort to close the session.
vcan0: j1939_xtp_rx_abort_one: 0xffff88801af96000: 0x00000: (3) A timeout occurred and this is the connection abort to close the session.
------------[ cut here ]------------
WARNING: CPU: 1 PID: 21 at net/can/j1939/transport.c:1088 j1939_session_deactivate net/can/j1939/transport.c:1088 [inline]
WARNING: CPU: 1 PID: 21 at net/can/j1939/transport.c:1088 j1939_session_deactivate_activate_next+0x95/0xd3 net/can/j1939/transport.c:1098
Modules linked in:
CPU: 1 PID: 21 Comm: ksoftirqd/1 Tainted: G W 5.17.0-syzkaller-08652-gae085d7f9365-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:j1939_session_deactivate net/can/j1939/transport.c:1088 [inline]
RIP: 0010:j1939_session_deactivate_activate_next+0x95/0xd3 net/can/j1939/transport.c:1098
Code: 03 38 d0 7c 0c 84 d2 74 08 4c 89 ef e8 75 69 69 f8 8b 5d 28 bf 01 00 00 00 89 de e8 76 c3 1d f8 83 fb 01 77 07 e8 4c c1 1d f8 <0f> 0b e8 45 c1 1d f8 48 89 ef e8 5d 22 dd fe 4c 89 e7 89 c3 e8 c3
RSP: 0018:ffffc900001b79b0 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000001 RCX: 0000000000000100
RDX: ffff888011a59d00 RSI: ffffffff895adaf4 RDI: 0000000000000003
RBP: ffff88801af96000 R08: 0000000000000001 R09: ffff88801af9602b
R10: ffffffff895adaea R11: 000000000000001d R12: ffff88801e58d070
R13: ffff88801af96028 R14: ffff88807ba16418 R15: ffffffff8ae458c0
FS: 0000000000000000(0000) GS:ffff8880b9d00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000056002b304fe8 CR3: 000000001b125000 CR4: 0000000000350ee0
Call Trace:
<TASK>
j1939_xtp_rx_abort_one.cold+0x20b/0x33c net/can/j1939/transport.c:1338
j1939_xtp_rx_abort net/can/j1939/transport.c:1349 [inline]
j1939_tp_cmd_recv net/can/j1939/transport.c:2098 [inline]
j1939_tp_recv+0xb28/0xcb0 net/can/j1939/transport.c:2131
j1939_can_recv+0x6ff/0x9a0 net/can/j1939/main.c:108
deliver net/can/af_can.c:574 [inline]
can_rcv_filter+0x5d4/0x8d0 net/can/af_can.c:608
can_receive+0x31d/0x580 net/can/af_can.c:665
can_rcv+0x120/0x1c0 net/can/af_can.c:696
__netif_receive_skb_one_core+0x114/0x180 net/core/dev.c:5405
__netif_receive_skb+0x24/0x1b0 net/core/dev.c:5519
process_backlog+0x3a0/0x7c0 net/core/dev.c:5847
__napi_poll+0xb3/0x6e0 net/core/dev.c:6413
napi_poll net/core/dev.c:6480 [inline]
net_rx_action+0x8ec/0xc60 net/core/dev.c:6567
__do_softirq+0x29b/0x9c2 kernel/softirq.c:558
run_ksoftirqd kernel/softirq.c:921 [inline]
run_ksoftirqd+0x2d/0x60 kernel/softirq.c:913
smpboot_thread_fn+0x645/0x9c0 kernel/smpboot.c:164
kthread+0x2e9/0x3a0 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298
</TASK>


Tested on:

commit: ae085d7f mm: kfence: fix missing objcg housekeeping fo..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
console output: https://syzkaller.appspot.com/x/log.txt?x=16ab36fd700000
kernel config: https://syzkaller.appspot.com/x/.config?x=6bae4cd50262530e
dashboard link: https://syzkaller.appspot.com/bug?extid=a9dce1ff45c3bbeceb3a
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=151c6fbb700000

Hillf Danton

unread,
Mar 31, 2022, 11:23:09 PM3/31/22
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Thu, 31 Mar 2022 18:09:09 -0700
To quiesce the warning, check session aborted after seeing if the uaf is
due to refcount imbalance.

Hillf

#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ ae085d7f9365

--- x/net/can/j1939/transport.c
+++ y/net/can/j1939/transport.c
@@ -336,8 +336,6 @@ static void j1939_session_skb_drop_old(s
__skb_unlink(do_skb, &session->skb_queue);
/* drop ref taken in j1939_session_skb_queue() */
skb_unref(do_skb);
-
- kfree_skb(do_skb);
}
spin_unlock_irqrestore(&session->skb_queue.lock, flags);
}
@@ -1081,14 +1079,19 @@ static bool j1939_session_deactivate_loc
static bool j1939_session_deactivate(struct j1939_session *session)
{
struct j1939_priv *priv = session->priv;
- bool active;
+ bool active = false;

j1939_session_list_lock(priv);
+ if (list_empty(&session->active_session_list_entry)) {
+ /* J1939_SESSION_DONE already */
+ goto out;
+ }
/* This function should be called with a session ref-count of at
* least 2.
*/
WARN_ON_ONCE(kref_read(&session->kref) < 2);
active = j1939_session_deactivate_locked(session);
+out:
j1939_session_list_unlock(priv);

return active;
--

syzbot

unread,
Mar 31, 2022, 11:36:15 PM3/31/22
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+a9dce1...@syzkaller.appspotmail.com

Tested on:

commit: ae085d7f mm: kfence: fix missing objcg housekeeping fo..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
kernel config: https://syzkaller.appspot.com/x/.config?x=6bae4cd50262530e
dashboard link: https://syzkaller.appspot.com/bug?extid=a9dce1ff45c3bbeceb3a
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=11cc67f5700000

Note: testing is done by a robot and is best-effort only.

syzbot

unread,
May 28, 2022, 11:54:07 AM5/28/22
to da...@davemloft.net, el...@google.com, hda...@sina.com, john....@linutronix.de, ker...@pengutronix.de, ku...@kernel.org, linu...@vger.kernel.org, linux-...@vger.kernel.org, li...@rempel-privat.de, m...@pengutronix.de, net...@vger.kernel.org, pab...@redhat.com, pml...@suse.com, ro...@protonic.nl, ros...@goodmis.org, sock...@hartkopp.net, syzkall...@googlegroups.com
syzbot suspects this issue was fixed by commit:

commit 701850dc0c31bfadf75a0a74af7d2c97859945ec
Author: Marco Elver <el...@google.com>
Date: Tue May 3 07:38:44 2022 +0000

printk, tracing: fix console tracepoint

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=153df725f00000
start commit: ae085d7f9365 mm: kfence: fix missing objcg housekeeping fo..
git tree: upstream
If the result looks correct, please mark the issue as fixed by replying with:

#syz fix: printk, tracing: fix console tracepoint

For information about bisection process see: https://goo.gl/tpsmEJ#bisection

syzbot

unread,
Aug 23, 2023, 5:02:47 AM8/23/23
to syzkall...@googlegroups.com
Auto-closing this bug as obsolete.
No recent activity, existing reproducers are no longer triggering the issue.
Reply all
Reply to author
Forward
0 new messages