RE: net/sctp: use-after-free in __sctp_connect
From: YUAN Jia
Date: Wed Jan 13 2016 - 20:52:55 EST
Hi Dmitry,
I've tested your program, but found nothing happens. So, I suspect it may cause kernel crash only on some special kernel version?
I was just using kernel of 4.2.3. What about you?
Richard
-----Original Message-----
From: linux-sctp-owner@xxxxxxxxxxxxxxx [mailto:linux-sctp-owner@xxxxxxxxxxxxxxx] On Behalf Of Dmitry Vyukov
Sent: 2016å1æ13æ 17:53
To: Vlad Yasevich; Neil Horman; David S. Miller; linux-sctp@xxxxxxxxxxxxxxx; netdev; LKML; Eric Dumazet; Marcelo Ricardo Leitner
Cc: syzkaller; Kostya Serebryany; Alexander Potapenko; Sasha Levin
Subject: net/sctp: use-after-free in __sctp_connect
Hello,
The following program causes use-after-free in __sctp_connect:
// autogenerated by syzkaller (http://github.com/google/syzkaller)
#include <unistd.h>
#include <sys/syscall.h>
#include <string.h>
#include <stdint.h>
#include <pthread.h>
long r[13];
void *thr(void *arg)
{
switch ((long)arg) {
case 0:
r[0] = syscall(SYS_mmap, 0x20000000ul, 0x20000ul, 0x3ul, 0x32ul, 0xfffffffffffffffful, 0x0ul);
break;
case 1:
r[1] = syscall(SYS_socket, 0xaul, 0x1ul, 0x84ul, 0, 0, 0);
break;
case 2:
memcpy((void*)0x2000b000, "\x0a\x00\x33\xe0\x49\xd0\x2e\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x4c\x37\xff\xc4",
28);
r[3] = syscall(SYS_bind, r[1], 0x2000b000ul, 0x1cul, 0, 0, 0);
break;
case 3:
r[4] = syscall(SYS_dup2, r[1], r[1], 0, 0, 0, 0);
break;
case 4:
*(uint64_t*)0x200177ed = (uint64_t)0x0;
*(uint64_t*)0x200177f5 = (uint64_t)0x2710;
r[7] = syscall(SYS_setsockopt, r[4], 0x1ul, 0x15ul, 0x200177edul, 0x10ul, 0);
break;
case 5:
*(uint16_t*)0x2000b008 = (uint16_t)0x2;
*(uint16_t*)0x2000b00a = (uint16_t)0xbab;
*(uint32_t*)0x2000b00c = (uint32_t)0xffffffff;
r[11] = syscall(SYS_setsockopt, r[4], 0x84ul, 0x6eul, 0x2000b000ul, 0x1cul, 0);
break;
case 6:
r[12] = syscall(SYS_shutdown, r[4], 0x1ul, 0, 0, 0, 0);
break;
}
return 0;
}
int main()
{
long i;
pthread_t th[7];
memset(r, -1, sizeof(r));
for (i = 0; i < 7; i++) {
pthread_create(&th[i], 0, thr, (void*)i);
usleep(10000);
}
for (i = 0; i < 7; i++) {
pthread_create(&th[i], 0, thr, (void*)i);
if (i%2==0)
usleep(10000);
}
usleep(100000);
return 0;
}
==================================================================
BUG: KASAN: use-after-free in __sctp_connect+0xb23/0xb90 at addr
ffff8800605febb8
Read of size 4 by task syz-executor/15263
INFO: Allocated in sctp_association_new+0x6f/0x1da0 age=0 cpu=3 pid=15267
[< none >] ___slab_alloc+0x486/0x4e0 mm/slub.c:2468
[< none >] __slab_alloc+0x66/0xc0 mm/slub.c:2497
[< inline >] slab_alloc_node mm/slub.c:2560
[< inline >] slab_alloc mm/slub.c:2602
[< none >] kmem_cache_alloc_trace+0x284/0x310 mm/slub.c:2619
[< inline >] kmalloc include/linux/slab.h:458
[< inline >] kzalloc include/linux/slab.h:602
[< none >] sctp_association_new+0x6f/0x1da0 net/sctp/associola.c:302
[< none >] __sctp_connect+0x4ec/0xb90 net/sctp/socket.c:1161
[< none >] __sctp_setsockopt_connectx+0x198/0x1d0
net/sctp/socket.c:1328
[< inline >] sctp_setsockopt_connectx net/sctp/socket.c:1360
[< none >] sctp_setsockopt+0x226/0x3630 net/sctp/socket.c:3728
[< none >] sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2642
[< inline >] SYSC_setsockopt net/socket.c:1752
[< none >] SyS_setsockopt+0x158/0x240 net/socket.c:1731
[< none >] entry_SYSCALL_64_fastpath+0x16/0x7a
arch/x86/entry/entry_64.S:185
INFO: Freed in sctp_association_put+0x150/0x250 age=0 cpu=3 pid=15267
[< none >] __slab_free+0x1fc/0x320 mm/slub.c:2678
[< inline >] slab_free mm/slub.c:2833
[< none >] kfree+0x2a8/0x2d0 mm/slub.c:3662
[< inline >] sctp_association_destroy net/sctp/associola.c:424
[< none >] sctp_association_put+0x150/0x250 net/sctp/associola.c:860
[< none >] sctp_wait_for_connect+0x37c/0x4f0 net/sctp/socket.c:7067
[< none >] __sctp_connect+0x905/0xb90 net/sctp/socket.c:1215
[< none >] __sctp_setsockopt_connectx+0x198/0x1d0
net/sctp/socket.c:1328
[< inline >] sctp_setsockopt_connectx net/sctp/socket.c:1360
[< none >] sctp_setsockopt+0x226/0x3630 net/sctp/socket.c:3728
[< none >] sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2642
[< inline >] SYSC_setsockopt net/socket.c:1752
[< none >] SyS_setsockopt+0x158/0x240 net/socket.c:1731
[< none >] entry_SYSCALL_64_fastpath+0x16/0x7a
arch/x86/entry/entry_64.S:185
INFO: Slab 0xffffea0001817e00 objects=7 used=3 fp=0xffff8800605fa3b0
flags=0x5fffc0000004080
INFO: Object 0xffff8800605feb10 @offset=27408 fp=0x (null)
CPU: 2 PID: 15263 Comm: syz-executor Tainted: G B 4.4.0+ #237
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 00000000ffffffff ffff88003717f8f0 ffffffff8290ea2d ffff88003e806a00
ffff8800605feb10 ffff8800605f8000 ffff88003717f920 ffffffff81730904
ffff88003e806a00 ffffea0001817e00 ffff8800605feb10 dffffc0000000000 Call Trace:
[<ffffffff81739e1e>] __asan_report_load4_noabort+0x3e/0x40
mm/kasan/report.c:294
[<ffffffff85925803>] __sctp_connect+0xb23/0xb90 net/sctp/socket.c:1217 [<ffffffff85925a08>] __sctp_setsockopt_connectx+0x198/0x1d0
net/sctp/socket.c:1328
[< inline >] sctp_setsockopt_connectx net/sctp/socket.c:1360
[<ffffffff8592bf36>] sctp_setsockopt+0x226/0x3630 net/sctp/socket.c:3728 [<ffffffff84d593a5>] sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2642
[< inline >] SYSC_setsockopt net/socket.c:1752
[<ffffffff84d56548>] SyS_setsockopt+0x158/0x240 net/socket.c:1731 [<ffffffff85e8eb76>] entry_SYSCALL_64_fastpath+0x16/0x7a
arch/x86/entry/entry_64.S:185
==================================================================
On commit 03891f9c853d5c4473224478a1e03ea00d70ff8d (Jan 11).
--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html