* net/ipv6: use-after-free in sock_wfree
@ 2017-01-09 17:08 Andrey Konovalov
2017-01-09 17:11 ` Andrey Konovalov
0 siblings, 1 reply; 7+ messages in thread
From: Andrey Konovalov @ 2017-01-09 17:08 UTC (permalink / raw)
To: David S. Miller, Alexey Kuznetsov, James Morris,
Hideaki YOSHIFUJI, Patrick McHardy, netdev, LKML
Cc: Dmitry Vyukov, Kostya Serebryany, Eric Dumazet, syzkaller
[-- Attachment #1: Type: text/plain, Size: 5712 bytes --]
Hi!
I've got the following error report while running the syzkaller fuzzer.
On commit a121103c922847ba5010819a3f250f1f7fc84ab8 (4.10-rc3).
A reproducer is attached.
==================================================================
BUG: KASAN: use-after-free in sock_wfree+0x118/0x120
Read of size 8 at addr ffff880062da0060 by task a.out/4140
page:ffffea00018b6800 count:1 mapcount:0 mapping: (null)
index:0x0 compound_mapcount: 0
flags: 0x100000000008100(slab|head)
raw: 0100000000008100 0000000000000000 0000000000000000 0000000180130013
raw: dead000000000100 dead000000000200 ffff88006741f140 0000000000000000
page dumped because: kasan: bad access detected
CPU: 0 PID: 4140 Comm: a.out Not tainted 4.10.0-rc3+ #59
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:15
dump_stack+0x292/0x398 lib/dump_stack.c:51
describe_address mm/kasan/report.c:262
kasan_report_error+0x121/0x560 mm/kasan/report.c:370
kasan_report mm/kasan/report.c:392
__asan_report_load8_noabort+0x3e/0x40 mm/kasan/report.c:413
sock_flag ./arch/x86/include/asm/bitops.h:324
sock_wfree+0x118/0x120 net/core/sock.c:1631
skb_release_head_state+0xfc/0x250 net/core/skbuff.c:655
skb_release_all+0x15/0x60 net/core/skbuff.c:668
__kfree_skb+0x15/0x20 net/core/skbuff.c:684
kfree_skb+0x16e/0x4e0 net/core/skbuff.c:705
inet_frag_destroy+0x121/0x290 net/ipv4/inet_fragment.c:304
inet_frag_put ./include/net/inet_frag.h:133
nf_ct_frag6_gather+0x1125/0x38b0 net/ipv6/netfilter/nf_conntrack_reasm.c:617
ipv6_defrag+0x21b/0x350 net/ipv6/netfilter/nf_defrag_ipv6_hooks.c:68
nf_hook_entry_hookfn ./include/linux/netfilter.h:102
nf_hook_slow+0xc3/0x290 net/netfilter/core.c:310
nf_hook ./include/linux/netfilter.h:212
__ip6_local_out+0x52c/0xaf0 net/ipv6/output_core.c:160
ip6_local_out+0x2d/0x170 net/ipv6/output_core.c:170
ip6_send_skb+0xa1/0x340 net/ipv6/ip6_output.c:1722
ip6_push_pending_frames+0xb3/0xe0 net/ipv6/ip6_output.c:1742
rawv6_push_pending_frames net/ipv6/raw.c:613
rawv6_sendmsg+0x2cff/0x4130 net/ipv6/raw.c:927
inet_sendmsg+0x164/0x5b0 net/ipv4/af_inet.c:744
sock_sendmsg_nosec net/socket.c:635
sock_sendmsg+0xca/0x110 net/socket.c:645
sock_write_iter+0x326/0x620 net/socket.c:848
new_sync_write fs/read_write.c:499
__vfs_write+0x483/0x760 fs/read_write.c:512
vfs_write+0x187/0x530 fs/read_write.c:560
SYSC_write fs/read_write.c:607
SyS_write+0xfb/0x230 fs/read_write.c:599
entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
RIP: 0033:0x7ff26e6f5b79
RSP: 002b:00007ff268e0ed98 EFLAGS: 00000206 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007ff268e0f9c0 RCX: 00007ff26e6f5b79
RDX: 0000000000000010 RSI: 0000000020f50fe1 RDI: 0000000000000003
RBP: 00007ff26ebc1220 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000
R13: 00007ff268e0f9c0 R14: 00007ff26efec040 R15: 0000000000000003
The buggy address belongs to the object at ffff880062da0000
which belongs to the cache RAWv6 of size 1504
The buggy address ffff880062da0060 is located 96 bytes inside
of 1504-byte region [ffff880062da0000, ffff880062da05e0)
Freed by task 4113:
save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57
save_stack+0x43/0xd0 mm/kasan/kasan.c:502
set_track mm/kasan/kasan.c:514
kasan_slab_free+0x73/0xc0 mm/kasan/kasan.c:578
slab_free_hook mm/slub.c:1352
slab_free_freelist_hook mm/slub.c:1374
slab_free mm/slub.c:2951
kmem_cache_free+0xb2/0x2c0 mm/slub.c:2973
sk_prot_free net/core/sock.c:1377
__sk_destruct+0x49c/0x6e0 net/core/sock.c:1452
sk_destruct+0x47/0x80 net/core/sock.c:1460
__sk_free+0x57/0x230 net/core/sock.c:1468
sk_free+0x23/0x30 net/core/sock.c:1479
sock_put ./include/net/sock.h:1638
sk_common_release+0x31e/0x4e0 net/core/sock.c:2782
rawv6_close+0x54/0x80 net/ipv6/raw.c:1214
inet_release+0xed/0x1c0 net/ipv4/af_inet.c:425
inet6_release+0x50/0x70 net/ipv6/af_inet6.c:431
sock_release+0x8d/0x1e0 net/socket.c:599
sock_close+0x16/0x20 net/socket.c:1063
__fput+0x332/0x7f0 fs/file_table.c:208
____fput+0x15/0x20 fs/file_table.c:244
task_work_run+0x19b/0x270 kernel/task_work.c:116
exit_task_work ./include/linux/task_work.h:21
do_exit+0x186b/0x2800 kernel/exit.c:839
do_group_exit+0x149/0x420 kernel/exit.c:943
SYSC_exit_group kernel/exit.c:954
SyS_exit_group+0x1d/0x20 kernel/exit.c:952
entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
Allocated by task 4115:
save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57
save_stack+0x43/0xd0 mm/kasan/kasan.c:502
set_track mm/kasan/kasan.c:514
kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:605
kasan_slab_alloc+0x12/0x20 mm/kasan/kasan.c:544
slab_post_alloc_hook mm/slab.h:432
slab_alloc_node mm/slub.c:2708
slab_alloc mm/slub.c:2716
kmem_cache_alloc+0x1af/0x250 mm/slub.c:2721
sk_prot_alloc+0x65/0x2a0 net/core/sock.c:1334
sk_alloc+0x105/0x1010 net/core/sock.c:1396
inet6_create+0x44d/0x1150 net/ipv6/af_inet6.c:183
__sock_create+0x4f6/0x880 net/socket.c:1199
sock_create net/socket.c:1239
SYSC_socket net/socket.c:1269
SyS_socket+0xf9/0x230 net/socket.c:1249
entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
Memory state around the buggy address:
ffff880062d9ff00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff880062d9ff80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff880062da0000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff880062da0080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff880062da0100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
[-- Attachment #2: ipv6-wfree-uaf-poc.c --]
[-- Type: text/x-csrc, Size: 9719 bytes --]
// autogenerated by syzkaller (http://github.com/google/syzkaller)
#ifndef __NR_ioctl
#define __NR_ioctl 16
#endif
#ifndef __NR_mmap
#define __NR_mmap 9
#endif
#ifndef __NR_socket
#define __NR_socket 41
#endif
#ifndef __NR_connect
#define __NR_connect 42
#endif
#ifndef __NR_bind
#define __NR_bind 49
#endif
#ifndef __NR_sendto
#define __NR_sendto 44
#endif
#ifndef __NR_recvfrom
#define __NR_recvfrom 45
#endif
#ifndef __NR_write
#define __NR_write 1
#endif
#define _GNU_SOURCE
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <linux/capability.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <linux/sched.h>
#include <net/if_arp.h>
#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <pthread.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
const int kFailStatus = 67;
const int kErrorStatus = 68;
const int kRetryStatus = 69;
__attribute__((noreturn)) void doexit(int status)
{
syscall(__NR_exit_group, status);
volatile unsigned i = 0;
for (i = 0;; i++) {
}
}
__attribute__((noreturn)) void fail(const char* msg, ...)
{
int e = errno;
fflush(stdout);
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, " (errno %d)\n", e);
doexit(e == ENOMEM ? kRetryStatus : kFailStatus);
}
__attribute__((noreturn)) void exitf(const char* msg, ...)
{
int e = errno;
fflush(stdout);
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, " (errno %d)\n", e);
doexit(kRetryStatus);
}
static int flag_debug;
void debug(const char* msg, ...)
{
if (!flag_debug)
return;
va_list args;
va_start(args, msg);
vfprintf(stdout, msg, args);
va_end(args);
fflush(stdout);
}
__thread int skip_segv;
__thread jmp_buf segv_env;
static void segv_handler(int sig, siginfo_t* info, void* uctx)
{
if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED))
_longjmp(segv_env, 1);
doexit(sig);
for (;;) {
}
}
static void install_segv_handler()
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
}
#define NONFAILING(...) \
{ \
__atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
if (_setjmp(segv_env) == 0) { \
__VA_ARGS__; \
} \
__atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \
}
static uintptr_t execute_syscall(int nr, uintptr_t a0, uintptr_t a1,
uintptr_t a2, uintptr_t a3,
uintptr_t a4, uintptr_t a5,
uintptr_t a6, uintptr_t a7,
uintptr_t a8)
{
switch (nr) {
default:
return syscall(nr, a0, a1, a2, a3, a4, a5);
}
}
static void setup_main_process(uint64_t pid, bool enable_tun)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
install_segv_handler();
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
if (!tmpdir)
fail("failed to mkdtemp");
if (chmod(tmpdir, 0777))
fail("failed to chmod");
if (chdir(tmpdir))
fail("failed to chdir");
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = 128 << 20;
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
unshare(CLONE_NEWNS);
unshare(CLONE_NEWIPC);
unshare(CLONE_IO);
}
static int do_sandbox_none()
{
int pid = fork();
if (pid)
return pid;
sandbox_common();
loop();
doexit(1);
}
long r[56];
void* thr(void* arg)
{
switch ((long)arg) {
case 0:
r[0] =
execute_syscall(__NR_mmap, 0x20000000ul, 0xf55000ul, 0x3ul,
0x32ul, 0xfffffffffffffffful, 0x0ul, 0, 0, 0);
break;
case 1:
r[1] = execute_syscall(__NR_socket, 0xaul, 0x3ul, 0x2cul, 0, 0, 0,
0, 0, 0);
break;
case 2:
NONFAILING(*(uint16_t*)0x20016000 = (uint16_t)0xa);
NONFAILING(*(uint16_t*)0x20016002 = (uint16_t)0x204e);
NONFAILING(*(uint32_t*)0x20016004 = (uint32_t)0x0);
NONFAILING(*(uint64_t*)0x20016008 = (uint64_t)0x0);
NONFAILING(*(uint64_t*)0x20016010 = (uint64_t)0x0);
NONFAILING(*(uint32_t*)0x20016018 = (uint32_t)0x0);
r[8] = execute_syscall(__NR_connect, r[1], 0x20016000ul, 0x20ul, 0,
0, 0, 0, 0, 0);
break;
case 3:
NONFAILING(*(uint16_t*)0x20373000 = (uint16_t)0x2);
NONFAILING(*(uint16_t*)0x20373002 = (uint16_t)0x204e);
NONFAILING(*(uint8_t*)0x20373004 = (uint8_t)0xc0);
NONFAILING(*(uint8_t*)0x20373005 = (uint8_t)0xa8);
NONFAILING(*(uint8_t*)0x20373006 = (uint8_t)0xda);
NONFAILING(*(uint8_t*)0x20373007 = (uint8_t)0xaa);
NONFAILING(*(uint8_t*)0x20373008 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20373009 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2037300a = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2037300b = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2037300c = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2037300d = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2037300e = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2037300f = (uint8_t)0x0);
r[23] = execute_syscall(__NR_bind, 0xfffffffffffffffful,
0x20373000ul, 0x10ul, 0, 0, 0, 0, 0, 0);
break;
case 4:
NONFAILING(*(uint16_t*)0x20f4a000 = (uint16_t)0x0);
NONFAILING(*(uint16_t*)0x20f4a002 = (uint16_t)0x204e);
NONFAILING(*(uint32_t*)0x20f4a004 = (uint32_t)0x0);
NONFAILING(*(uint8_t*)0x20f4a008 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20f4a009 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20f4a00a = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20f4a00b = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20f4a00c = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20f4a00d = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20f4a00e = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20f4a00f = (uint8_t)0x0);
r[35] = execute_syscall(__NR_connect, 0xfffffffffffffffful,
0x20f4a000ul, 0x10ul, 0, 0, 0, 0, 0, 0);
break;
case 5:
NONFAILING(*(uint16_t*)0x20f4cfe0 = (uint16_t)0xa);
NONFAILING(*(uint16_t*)0x20f4cfe2 = (uint16_t)0x204e);
NONFAILING(*(uint32_t*)0x20f4cfe4 = (uint32_t)0x0);
NONFAILING(*(uint64_t*)0x20f4cfe8 = (uint64_t)0x0);
NONFAILING(*(uint64_t*)0x20f4cff0 = (uint64_t)0x100000000000000);
NONFAILING(*(uint32_t*)0x20f4cff8 = (uint32_t)0x5);
r[42] =
execute_syscall(__NR_sendto, 0xfffffffffffffffful, 0x20006000ul,
0x0ul, 0x0ul, 0x20f4cfe0ul, 0x20ul, 0, 0, 0);
break;
case 6:
r[43] = execute_syscall(__NR_recvfrom, 0xfffffffffffffffful,
0x20144f28ul, 0x0ul, 0x10000ul,
0x20f4e000ul, 0x0ul, 0, 0, 0);
break;
case 7:
r[44] = execute_syscall(__NR_socket, 0x1ful, 0x5ul, 0x2ul, 0, 0, 0,
0, 0, 0);
break;
case 8:
r[45] = execute_syscall(__NR_write, r[1], 0x20aa4fdaul, 0xfffful, 0,
0, 0, 0, 0, 0);
break;
case 9:
NONFAILING(*(uint32_t*)0x20f54000 = (uint32_t)0x0);
NONFAILING(*(uint32_t*)0x20f54004 = (uint32_t)0x0);
NONFAILING(*(uint64_t*)0x20f54008 = (uint64_t)0x0);
r[49] =
execute_syscall(__NR_ioctl, 0xfffffffffffffffful, 0xc010640bul,
0x20f54000ul, 0, 0, 0, 0, 0, 0);
break;
case 10:
NONFAILING(*(uint32_t*)0x20f54000 = (uint32_t)0x0);
NONFAILING(*(uint32_t*)0x20f54004 = (uint32_t)0x0);
NONFAILING(*(uint64_t*)0x20f54008 = (uint64_t)0xfc51);
r[53] =
execute_syscall(__NR_ioctl, 0xfffffffffffffffful, 0xc010640bul,
0x20f54000ul, 0, 0, 0, 0, 0, 0);
break;
case 11:
NONFAILING(memcpy((void*)0x20f50fe1, "\x1f\x00\x00\x80\x01\x00\x00"
"\x16\x00\x00\x00\x9a\xc7\x00"
"\x00\x06",
16));
r[55] = execute_syscall(__NR_write, r[1], 0x20f50fe1ul, 0x10ul, 0,
0, 0, 0, 0, 0);
break;
}
return 0;
}
void loop()
{
long i;
pthread_t th[24];
memset(r, -1, sizeof(r));
srand(getpid());
for (i = 0; i < 12; i++) {
pthread_create(&th[i], 0, thr, (void*)i);
usleep(10000);
}
for (i = 0; i < 12; i++) {
pthread_create(&th[12 + i], 0, thr, (void*)i);
if (rand() % 2)
usleep(rand() % 10000);
}
usleep(100000);
}
int main()
{
setup_main_process(0, false);
int pid = do_sandbox_none();
int status = 0;
while (waitpid(pid, &status, __WALL) != pid) {
}
return 0;
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: net/ipv6: use-after-free in sock_wfree
2017-01-09 17:08 net/ipv6: use-after-free in sock_wfree Andrey Konovalov
@ 2017-01-09 17:11 ` Andrey Konovalov
2017-01-09 17:21 ` Eric Dumazet
0 siblings, 1 reply; 7+ messages in thread
From: Andrey Konovalov @ 2017-01-09 17:11 UTC (permalink / raw)
To: David S. Miller, Alexey Kuznetsov, James Morris,
Hideaki YOSHIFUJI, Patrick McHardy, netdev, LKML
Cc: Dmitry Vyukov, Kostya Serebryany, Eric Dumazet, syzkaller
On Mon, Jan 9, 2017 at 6:08 PM, Andrey Konovalov <andreyknvl@google.com> wrote:
> Hi!
>
> I've got the following error report while running the syzkaller fuzzer.
>
> On commit a121103c922847ba5010819a3f250f1f7fc84ab8 (4.10-rc3).
>
> A reproducer is attached.
>
> ==================================================================
> BUG: KASAN: use-after-free in sock_wfree+0x118/0x120
> Read of size 8 at addr ffff880062da0060 by task a.out/4140
>
> page:ffffea00018b6800 count:1 mapcount:0 mapping: (null)
> index:0x0 compound_mapcount: 0
> flags: 0x100000000008100(slab|head)
> raw: 0100000000008100 0000000000000000 0000000000000000 0000000180130013
> raw: dead000000000100 dead000000000200 ffff88006741f140 0000000000000000
> page dumped because: kasan: bad access detected
>
> CPU: 0 PID: 4140 Comm: a.out Not tainted 4.10.0-rc3+ #59
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
> Call Trace:
> __dump_stack lib/dump_stack.c:15
> dump_stack+0x292/0x398 lib/dump_stack.c:51
> describe_address mm/kasan/report.c:262
> kasan_report_error+0x121/0x560 mm/kasan/report.c:370
> kasan_report mm/kasan/report.c:392
> __asan_report_load8_noabort+0x3e/0x40 mm/kasan/report.c:413
> sock_flag ./arch/x86/include/asm/bitops.h:324
> sock_wfree+0x118/0x120 net/core/sock.c:1631
> skb_release_head_state+0xfc/0x250 net/core/skbuff.c:655
> skb_release_all+0x15/0x60 net/core/skbuff.c:668
> __kfree_skb+0x15/0x20 net/core/skbuff.c:684
> kfree_skb+0x16e/0x4e0 net/core/skbuff.c:705
> inet_frag_destroy+0x121/0x290 net/ipv4/inet_fragment.c:304
> inet_frag_put ./include/net/inet_frag.h:133
> nf_ct_frag6_gather+0x1125/0x38b0 net/ipv6/netfilter/nf_conntrack_reasm.c:617
> ipv6_defrag+0x21b/0x350 net/ipv6/netfilter/nf_defrag_ipv6_hooks.c:68
> nf_hook_entry_hookfn ./include/linux/netfilter.h:102
> nf_hook_slow+0xc3/0x290 net/netfilter/core.c:310
> nf_hook ./include/linux/netfilter.h:212
> __ip6_local_out+0x52c/0xaf0 net/ipv6/output_core.c:160
> ip6_local_out+0x2d/0x170 net/ipv6/output_core.c:170
> ip6_send_skb+0xa1/0x340 net/ipv6/ip6_output.c:1722
> ip6_push_pending_frames+0xb3/0xe0 net/ipv6/ip6_output.c:1742
> rawv6_push_pending_frames net/ipv6/raw.c:613
> rawv6_sendmsg+0x2cff/0x4130 net/ipv6/raw.c:927
> inet_sendmsg+0x164/0x5b0 net/ipv4/af_inet.c:744
> sock_sendmsg_nosec net/socket.c:635
> sock_sendmsg+0xca/0x110 net/socket.c:645
> sock_write_iter+0x326/0x620 net/socket.c:848
> new_sync_write fs/read_write.c:499
> __vfs_write+0x483/0x760 fs/read_write.c:512
> vfs_write+0x187/0x530 fs/read_write.c:560
> SYSC_write fs/read_write.c:607
> SyS_write+0xfb/0x230 fs/read_write.c:599
> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
> RIP: 0033:0x7ff26e6f5b79
> RSP: 002b:00007ff268e0ed98 EFLAGS: 00000206 ORIG_RAX: 0000000000000001
> RAX: ffffffffffffffda RBX: 00007ff268e0f9c0 RCX: 00007ff26e6f5b79
> RDX: 0000000000000010 RSI: 0000000020f50fe1 RDI: 0000000000000003
> RBP: 00007ff26ebc1220 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000
> R13: 00007ff268e0f9c0 R14: 00007ff26efec040 R15: 0000000000000003
>
> The buggy address belongs to the object at ffff880062da0000
> which belongs to the cache RAWv6 of size 1504
> The buggy address ffff880062da0060 is located 96 bytes inside
> of 1504-byte region [ffff880062da0000, ffff880062da05e0)
>
> Freed by task 4113:
> save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57
> save_stack+0x43/0xd0 mm/kasan/kasan.c:502
> set_track mm/kasan/kasan.c:514
> kasan_slab_free+0x73/0xc0 mm/kasan/kasan.c:578
> slab_free_hook mm/slub.c:1352
> slab_free_freelist_hook mm/slub.c:1374
> slab_free mm/slub.c:2951
> kmem_cache_free+0xb2/0x2c0 mm/slub.c:2973
> sk_prot_free net/core/sock.c:1377
> __sk_destruct+0x49c/0x6e0 net/core/sock.c:1452
> sk_destruct+0x47/0x80 net/core/sock.c:1460
> __sk_free+0x57/0x230 net/core/sock.c:1468
> sk_free+0x23/0x30 net/core/sock.c:1479
> sock_put ./include/net/sock.h:1638
> sk_common_release+0x31e/0x4e0 net/core/sock.c:2782
> rawv6_close+0x54/0x80 net/ipv6/raw.c:1214
> inet_release+0xed/0x1c0 net/ipv4/af_inet.c:425
> inet6_release+0x50/0x70 net/ipv6/af_inet6.c:431
> sock_release+0x8d/0x1e0 net/socket.c:599
> sock_close+0x16/0x20 net/socket.c:1063
> __fput+0x332/0x7f0 fs/file_table.c:208
> ____fput+0x15/0x20 fs/file_table.c:244
> task_work_run+0x19b/0x270 kernel/task_work.c:116
> exit_task_work ./include/linux/task_work.h:21
> do_exit+0x186b/0x2800 kernel/exit.c:839
> do_group_exit+0x149/0x420 kernel/exit.c:943
> SYSC_exit_group kernel/exit.c:954
> SyS_exit_group+0x1d/0x20 kernel/exit.c:952
> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
>
> Allocated by task 4115:
> save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57
> save_stack+0x43/0xd0 mm/kasan/kasan.c:502
> set_track mm/kasan/kasan.c:514
> kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:605
> kasan_slab_alloc+0x12/0x20 mm/kasan/kasan.c:544
> slab_post_alloc_hook mm/slab.h:432
> slab_alloc_node mm/slub.c:2708
> slab_alloc mm/slub.c:2716
> kmem_cache_alloc+0x1af/0x250 mm/slub.c:2721
> sk_prot_alloc+0x65/0x2a0 net/core/sock.c:1334
> sk_alloc+0x105/0x1010 net/core/sock.c:1396
> inet6_create+0x44d/0x1150 net/ipv6/af_inet6.c:183
> __sock_create+0x4f6/0x880 net/socket.c:1199
> sock_create net/socket.c:1239
> SYSC_socket net/socket.c:1269
> SyS_socket+0xf9/0x230 net/socket.c:1249
> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
>
> Memory state around the buggy address:
> ffff880062d9ff00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> ffff880062d9ff80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>>ffff880062da0000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ^
> ffff880062da0080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ffff880062da0100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ==================================================================
Sometimes this reproducer leads to another report:
INFO: rcu_sched self-detected stall on CPU
1-...: (1 GPs behind) idle=ead/140000000000001/0 softirq=8122/8123 fqs=6497
(t=26000 jiffies g=3021 c=3020 q=345)
Task dump for CPU 1:
syz-executor R running task 18904 3943 3941 0x0000000c
Call Trace:
<IRQ>
sched_show_task+0x3fa/0x560 kernel/sched/core.c:5217
dump_cpu_task+0x71/0x90 kernel/sched/core.c:8822
rcu_dump_cpu_stacks+0x318/0x35e kernel/rcu/tree.c:1290
print_cpu_stall+0x39f/0x6e0 kernel/rcu/tree.c:1434
check_cpu_stall.isra.63+0x702/0xe80 kernel/rcu/tree.c:1502
__rcu_pending kernel/rcu/tree.c:3469
rcu_pending kernel/rcu/tree.c:3533
rcu_check_callbacks+0x27f/0xda0 kernel/rcu/tree.c:2867
update_process_times+0x30/0x60 kernel/time/timer.c:1612
tick_sched_handle.isra.18+0xb3/0xe0 kernel/time/tick-sched.c:151
tick_sched_timer+0x72/0x120 kernel/time/tick-sched.c:1158
__run_hrtimer kernel/time/hrtimer.c:1238
__hrtimer_run_queues+0x38c/0xf80 kernel/time/hrtimer.c:1302
hrtimer_interrupt+0x1ab/0x5c0 kernel/time/hrtimer.c:1336
local_apic_timer_interrupt+0x6f/0xe0 arch/x86/kernel/apic/apic.c:936
smp_apic_timer_interrupt+0x71/0xa0 arch/x86/kernel/apic/apic.c:960
apic_timer_interrupt+0x93/0xa0
RIP: 0010:__sanitizer_cov_trace_pc+0x46/0x60 kernel/kcov.c:93
RSP: 0018:ffff88006ad66a98 EFLAGS: 00000216 ORIG_RAX: ffffffffffffff10
RAX: 0000000000004000 RBX: ffff880068f4e500 RCX: ffffc90000e6c000
RDX: 0000000000004000 RSI: ffffffff83d652b7 RDI: ffff880064f09f51
RBP: ffff88006ad66a98 R08: ffffed000d633ca1 R09: ffffed000d633ca1
R10: 0000000000000001 R11: ffffed000d633ca0 R12: ffff880064f00020
R13: ffff88006ad66c28 R14: 0000000000009f38 R15: dffffc0000000000
</IRQ>
_decode_session6+0x8a7/0x13f0 net/ipv6/xfrm6_policy.c:147
__xfrm_decode_session+0x63/0x100 net/xfrm/xfrm_policy.c:2475
xfrm_decode_session_reverse ./include/net/xfrm.h:1117
icmpv6_route_lookup+0x410/0x780 net/ipv6/icmp.c:362
icmp6_send+0x1611/0x29b0 net/ipv6/icmp.c:515
icmpv6_send+0x12e/0x260 net/ipv6/ip6_icmp.c:42
ip6_fragment+0x583/0x3920 net/ipv6/ip6_output.c:864
ip6_finish_output+0x322/0x960 net/ipv6/ip6_output.c:146
NF_HOOK_COND ./include/linux/netfilter.h:246
ip6_output+0x1cb/0x8d0 net/ipv6/ip6_output.c:162
dst_output ./include/net/dst.h:501
ip6_local_out+0x95/0x170 net/ipv6/output_core.c:172
ip6_send_skb+0xa1/0x340 net/ipv6/ip6_output.c:1722
ip6_push_pending_frames+0xb3/0xe0 net/ipv6/ip6_output.c:1742
rawv6_push_pending_frames net/ipv6/raw.c:613
rawv6_sendmsg+0x2cff/0x4130 net/ipv6/raw.c:927
inet_sendmsg+0x164/0x5b0 net/ipv4/af_inet.c:744
sock_sendmsg_nosec net/socket.c:635
sock_sendmsg+0xca/0x110 net/socket.c:645
sock_write_iter+0x326/0x620 net/socket.c:848
new_sync_write fs/read_write.c:499
__vfs_write+0x483/0x760 fs/read_write.c:512
vfs_write+0x187/0x530 fs/read_write.c:560
SYSC_write fs/read_write.c:607
SyS_write+0xfb/0x230 fs/read_write.c:599
entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
RIP: 0033:0x4421d9
RSP: 002b:00007f090e289b58 EFLAGS: 00000296 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 0000000000000005 RCX: 00000000004421d9
RDX: 000000000000ffff RSI: 0000000020aa4fda RDI: 0000000000000005
RBP: 00000000006de8c0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000296 R12: 0000000000700000
R13: ffffffffffffffff R14: 0000000020f4a000 R15: 0000000000000010
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: net/ipv6: use-after-free in sock_wfree
2017-01-09 17:11 ` Andrey Konovalov
@ 2017-01-09 17:21 ` Eric Dumazet
2017-01-09 19:06 ` Andrey Konovalov
2017-02-12 16:53 ` Andrey Konovalov
0 siblings, 2 replies; 7+ messages in thread
From: Eric Dumazet @ 2017-01-09 17:21 UTC (permalink / raw)
To: Andrey Konovalov
Cc: David S. Miller, Alexey Kuznetsov, James Morris,
Hideaki YOSHIFUJI, Patrick McHardy, netdev, LKML, Dmitry Vyukov,
Kostya Serebryany, syzkaller
On Mon, Jan 9, 2017 at 9:11 AM, Andrey Konovalov <andreyknvl@google.com> wrote:
> On Mon, Jan 9, 2017 at 6:08 PM, Andrey Konovalov <andreyknvl@google.com> wrote:
>> Hi!
>>
>> I've got the following error report while running the syzkaller fuzzer.
>>
>> On commit a121103c922847ba5010819a3f250f1f7fc84ab8 (4.10-rc3).
>>
>> A reproducer is attached.
>>
>> ==================================================================
>> BUG: KASAN: use-after-free in sock_wfree+0x118/0x120
>> Read of size 8 at addr ffff880062da0060 by task a.out/4140
>>
>> page:ffffea00018b6800 count:1 mapcount:0 mapping: (null)
>> index:0x0 compound_mapcount: 0
>> flags: 0x100000000008100(slab|head)
>> raw: 0100000000008100 0000000000000000 0000000000000000 0000000180130013
>> raw: dead000000000100 dead000000000200 ffff88006741f140 0000000000000000
>> page dumped because: kasan: bad access detected
>>
>> CPU: 0 PID: 4140 Comm: a.out Not tainted 4.10.0-rc3+ #59
>> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
>> Call Trace:
>> __dump_stack lib/dump_stack.c:15
>> dump_stack+0x292/0x398 lib/dump_stack.c:51
>> describe_address mm/kasan/report.c:262
>> kasan_report_error+0x121/0x560 mm/kasan/report.c:370
>> kasan_report mm/kasan/report.c:392
>> __asan_report_load8_noabort+0x3e/0x40 mm/kasan/report.c:413
>> sock_flag ./arch/x86/include/asm/bitops.h:324
>> sock_wfree+0x118/0x120 net/core/sock.c:1631
>> skb_release_head_state+0xfc/0x250 net/core/skbuff.c:655
>> skb_release_all+0x15/0x60 net/core/skbuff.c:668
>> __kfree_skb+0x15/0x20 net/core/skbuff.c:684
>> kfree_skb+0x16e/0x4e0 net/core/skbuff.c:705
>> inet_frag_destroy+0x121/0x290 net/ipv4/inet_fragment.c:304
>> inet_frag_put ./include/net/inet_frag.h:133
>> nf_ct_frag6_gather+0x1125/0x38b0 net/ipv6/netfilter/nf_conntrack_reasm.c:617
>> ipv6_defrag+0x21b/0x350 net/ipv6/netfilter/nf_defrag_ipv6_hooks.c:68
>> nf_hook_entry_hookfn ./include/linux/netfilter.h:102
>> nf_hook_slow+0xc3/0x290 net/netfilter/core.c:310
>> nf_hook ./include/linux/netfilter.h:212
>> __ip6_local_out+0x52c/0xaf0 net/ipv6/output_core.c:160
>> ip6_local_out+0x2d/0x170 net/ipv6/output_core.c:170
>> ip6_send_skb+0xa1/0x340 net/ipv6/ip6_output.c:1722
>> ip6_push_pending_frames+0xb3/0xe0 net/ipv6/ip6_output.c:1742
>> rawv6_push_pending_frames net/ipv6/raw.c:613
>> rawv6_sendmsg+0x2cff/0x4130 net/ipv6/raw.c:927
>> inet_sendmsg+0x164/0x5b0 net/ipv4/af_inet.c:744
>> sock_sendmsg_nosec net/socket.c:635
>> sock_sendmsg+0xca/0x110 net/socket.c:645
>> sock_write_iter+0x326/0x620 net/socket.c:848
>> new_sync_write fs/read_write.c:499
>> __vfs_write+0x483/0x760 fs/read_write.c:512
>> vfs_write+0x187/0x530 fs/read_write.c:560
>> SYSC_write fs/read_write.c:607
>> SyS_write+0xfb/0x230 fs/read_write.c:599
>> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
>> RIP: 0033:0x7ff26e6f5b79
>> RSP: 002b:00007ff268e0ed98 EFLAGS: 00000206 ORIG_RAX: 0000000000000001
>> RAX: ffffffffffffffda RBX: 00007ff268e0f9c0 RCX: 00007ff26e6f5b79
>> RDX: 0000000000000010 RSI: 0000000020f50fe1 RDI: 0000000000000003
>> RBP: 00007ff26ebc1220 R08: 0000000000000000 R09: 0000000000000000
>> R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000
>> R13: 00007ff268e0f9c0 R14: 00007ff26efec040 R15: 0000000000000003
>>
>> The buggy address belongs to the object at ffff880062da0000
>> which belongs to the cache RAWv6 of size 1504
>> The buggy address ffff880062da0060 is located 96 bytes inside
>> of 1504-byte region [ffff880062da0000, ffff880062da05e0)
>>
>> Freed by task 4113:
>> save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57
>> save_stack+0x43/0xd0 mm/kasan/kasan.c:502
>> set_track mm/kasan/kasan.c:514
>> kasan_slab_free+0x73/0xc0 mm/kasan/kasan.c:578
>> slab_free_hook mm/slub.c:1352
>> slab_free_freelist_hook mm/slub.c:1374
>> slab_free mm/slub.c:2951
>> kmem_cache_free+0xb2/0x2c0 mm/slub.c:2973
>> sk_prot_free net/core/sock.c:1377
>> __sk_destruct+0x49c/0x6e0 net/core/sock.c:1452
>> sk_destruct+0x47/0x80 net/core/sock.c:1460
>> __sk_free+0x57/0x230 net/core/sock.c:1468
>> sk_free+0x23/0x30 net/core/sock.c:1479
>> sock_put ./include/net/sock.h:1638
>> sk_common_release+0x31e/0x4e0 net/core/sock.c:2782
>> rawv6_close+0x54/0x80 net/ipv6/raw.c:1214
>> inet_release+0xed/0x1c0 net/ipv4/af_inet.c:425
>> inet6_release+0x50/0x70 net/ipv6/af_inet6.c:431
>> sock_release+0x8d/0x1e0 net/socket.c:599
>> sock_close+0x16/0x20 net/socket.c:1063
>> __fput+0x332/0x7f0 fs/file_table.c:208
>> ____fput+0x15/0x20 fs/file_table.c:244
>> task_work_run+0x19b/0x270 kernel/task_work.c:116
>> exit_task_work ./include/linux/task_work.h:21
>> do_exit+0x186b/0x2800 kernel/exit.c:839
>> do_group_exit+0x149/0x420 kernel/exit.c:943
>> SYSC_exit_group kernel/exit.c:954
>> SyS_exit_group+0x1d/0x20 kernel/exit.c:952
>> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
>>
>> Allocated by task 4115:
>> save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57
>> save_stack+0x43/0xd0 mm/kasan/kasan.c:502
>> set_track mm/kasan/kasan.c:514
>> kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:605
>> kasan_slab_alloc+0x12/0x20 mm/kasan/kasan.c:544
>> slab_post_alloc_hook mm/slab.h:432
>> slab_alloc_node mm/slub.c:2708
>> slab_alloc mm/slub.c:2716
>> kmem_cache_alloc+0x1af/0x250 mm/slub.c:2721
>> sk_prot_alloc+0x65/0x2a0 net/core/sock.c:1334
>> sk_alloc+0x105/0x1010 net/core/sock.c:1396
>> inet6_create+0x44d/0x1150 net/ipv6/af_inet6.c:183
>> __sock_create+0x4f6/0x880 net/socket.c:1199
>> sock_create net/socket.c:1239
>> SYSC_socket net/socket.c:1269
>> SyS_socket+0xf9/0x230 net/socket.c:1249
>> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
>>
>> Memory state around the buggy address:
>> ffff880062d9ff00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>> ffff880062d9ff80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>>>ffff880062da0000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>> ^
>> ffff880062da0080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>> ffff880062da0100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>> ==================================================================
>
> Sometimes this reproducer leads to another report:
Looks very similar to issue fixed in 8282f27449bf15548cb82c77b6e04ee0ab827bdc
Could you try :
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c
b/net/ipv6/netfilter/nf_conntrack_reasm.c
index 9948b5ce52dad3a823edede517f17069bd7226dc..986d4ca38832b17703b09e50209ec133885c7276
100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -589,6 +589,7 @@ int nf_ct_frag6_gather(struct net *net, struct
sk_buff *skb, u32 user)
hdr = ipv6_hdr(skb);
fhdr = (struct frag_hdr *)skb_transport_header(skb);
+ skb_orphan(skb);
fq = fq_find(net, fhdr->identification, user, &hdr->saddr, &hdr->daddr,
skb->dev ? skb->dev->ifindex : 0, ip6_frag_ecn(hdr));
if (fq == NULL) {
diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 6b78bab27755b2758f3c8ecd5b9c6d61615af4b6..fdec2a4cc559ab956c58d26535bdf010c0a8964a
100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -367,7 +367,6 @@ static int handle_fragments(struct net *net,
struct sw_flow_key *key,
} else if (key->eth.type == htons(ETH_P_IPV6)) {
enum ip6_defrag_users user = IP6_DEFRAG_CONNTRACK_IN + zone;
- skb_orphan(skb);
memset(IP6CB(skb), 0, sizeof(struct inet6_skb_parm));
err = nf_ct_frag6_gather(net, skb, user);
if (err) {
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: net/ipv6: use-after-free in sock_wfree
2017-01-09 17:21 ` Eric Dumazet
@ 2017-01-09 19:06 ` Andrey Konovalov
2017-01-09 19:08 ` Eric Dumazet
2017-02-12 16:53 ` Andrey Konovalov
1 sibling, 1 reply; 7+ messages in thread
From: Andrey Konovalov @ 2017-01-09 19:06 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, Alexey Kuznetsov, James Morris,
Hideaki YOSHIFUJI, Patrick McHardy, netdev, LKML, Dmitry Vyukov,
Kostya Serebryany, syzkaller
On Mon, Jan 9, 2017 at 6:21 PM, Eric Dumazet <edumazet@google.com> wrote:
> On Mon, Jan 9, 2017 at 9:11 AM, Andrey Konovalov <andreyknvl@google.com> wrote:
>> On Mon, Jan 9, 2017 at 6:08 PM, Andrey Konovalov <andreyknvl@google.com> wrote:
>>> Hi!
>>>
>>> I've got the following error report while running the syzkaller fuzzer.
>>>
>>> On commit a121103c922847ba5010819a3f250f1f7fc84ab8 (4.10-rc3).
>>>
>>> A reproducer is attached.
>>>
>>> ==================================================================
>>> BUG: KASAN: use-after-free in sock_wfree+0x118/0x120
>>> Read of size 8 at addr ffff880062da0060 by task a.out/4140
>>>
>>> page:ffffea00018b6800 count:1 mapcount:0 mapping: (null)
>>> index:0x0 compound_mapcount: 0
>>> flags: 0x100000000008100(slab|head)
>>> raw: 0100000000008100 0000000000000000 0000000000000000 0000000180130013
>>> raw: dead000000000100 dead000000000200 ffff88006741f140 0000000000000000
>>> page dumped because: kasan: bad access detected
>>>
>>> CPU: 0 PID: 4140 Comm: a.out Not tainted 4.10.0-rc3+ #59
>>> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
>>> Call Trace:
>>> __dump_stack lib/dump_stack.c:15
>>> dump_stack+0x292/0x398 lib/dump_stack.c:51
>>> describe_address mm/kasan/report.c:262
>>> kasan_report_error+0x121/0x560 mm/kasan/report.c:370
>>> kasan_report mm/kasan/report.c:392
>>> __asan_report_load8_noabort+0x3e/0x40 mm/kasan/report.c:413
>>> sock_flag ./arch/x86/include/asm/bitops.h:324
>>> sock_wfree+0x118/0x120 net/core/sock.c:1631
>>> skb_release_head_state+0xfc/0x250 net/core/skbuff.c:655
>>> skb_release_all+0x15/0x60 net/core/skbuff.c:668
>>> __kfree_skb+0x15/0x20 net/core/skbuff.c:684
>>> kfree_skb+0x16e/0x4e0 net/core/skbuff.c:705
>>> inet_frag_destroy+0x121/0x290 net/ipv4/inet_fragment.c:304
>>> inet_frag_put ./include/net/inet_frag.h:133
>>> nf_ct_frag6_gather+0x1125/0x38b0 net/ipv6/netfilter/nf_conntrack_reasm.c:617
>>> ipv6_defrag+0x21b/0x350 net/ipv6/netfilter/nf_defrag_ipv6_hooks.c:68
>>> nf_hook_entry_hookfn ./include/linux/netfilter.h:102
>>> nf_hook_slow+0xc3/0x290 net/netfilter/core.c:310
>>> nf_hook ./include/linux/netfilter.h:212
>>> __ip6_local_out+0x52c/0xaf0 net/ipv6/output_core.c:160
>>> ip6_local_out+0x2d/0x170 net/ipv6/output_core.c:170
>>> ip6_send_skb+0xa1/0x340 net/ipv6/ip6_output.c:1722
>>> ip6_push_pending_frames+0xb3/0xe0 net/ipv6/ip6_output.c:1742
>>> rawv6_push_pending_frames net/ipv6/raw.c:613
>>> rawv6_sendmsg+0x2cff/0x4130 net/ipv6/raw.c:927
>>> inet_sendmsg+0x164/0x5b0 net/ipv4/af_inet.c:744
>>> sock_sendmsg_nosec net/socket.c:635
>>> sock_sendmsg+0xca/0x110 net/socket.c:645
>>> sock_write_iter+0x326/0x620 net/socket.c:848
>>> new_sync_write fs/read_write.c:499
>>> __vfs_write+0x483/0x760 fs/read_write.c:512
>>> vfs_write+0x187/0x530 fs/read_write.c:560
>>> SYSC_write fs/read_write.c:607
>>> SyS_write+0xfb/0x230 fs/read_write.c:599
>>> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
>>> RIP: 0033:0x7ff26e6f5b79
>>> RSP: 002b:00007ff268e0ed98 EFLAGS: 00000206 ORIG_RAX: 0000000000000001
>>> RAX: ffffffffffffffda RBX: 00007ff268e0f9c0 RCX: 00007ff26e6f5b79
>>> RDX: 0000000000000010 RSI: 0000000020f50fe1 RDI: 0000000000000003
>>> RBP: 00007ff26ebc1220 R08: 0000000000000000 R09: 0000000000000000
>>> R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000
>>> R13: 00007ff268e0f9c0 R14: 00007ff26efec040 R15: 0000000000000003
>>>
>>> The buggy address belongs to the object at ffff880062da0000
>>> which belongs to the cache RAWv6 of size 1504
>>> The buggy address ffff880062da0060 is located 96 bytes inside
>>> of 1504-byte region [ffff880062da0000, ffff880062da05e0)
>>>
>>> Freed by task 4113:
>>> save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57
>>> save_stack+0x43/0xd0 mm/kasan/kasan.c:502
>>> set_track mm/kasan/kasan.c:514
>>> kasan_slab_free+0x73/0xc0 mm/kasan/kasan.c:578
>>> slab_free_hook mm/slub.c:1352
>>> slab_free_freelist_hook mm/slub.c:1374
>>> slab_free mm/slub.c:2951
>>> kmem_cache_free+0xb2/0x2c0 mm/slub.c:2973
>>> sk_prot_free net/core/sock.c:1377
>>> __sk_destruct+0x49c/0x6e0 net/core/sock.c:1452
>>> sk_destruct+0x47/0x80 net/core/sock.c:1460
>>> __sk_free+0x57/0x230 net/core/sock.c:1468
>>> sk_free+0x23/0x30 net/core/sock.c:1479
>>> sock_put ./include/net/sock.h:1638
>>> sk_common_release+0x31e/0x4e0 net/core/sock.c:2782
>>> rawv6_close+0x54/0x80 net/ipv6/raw.c:1214
>>> inet_release+0xed/0x1c0 net/ipv4/af_inet.c:425
>>> inet6_release+0x50/0x70 net/ipv6/af_inet6.c:431
>>> sock_release+0x8d/0x1e0 net/socket.c:599
>>> sock_close+0x16/0x20 net/socket.c:1063
>>> __fput+0x332/0x7f0 fs/file_table.c:208
>>> ____fput+0x15/0x20 fs/file_table.c:244
>>> task_work_run+0x19b/0x270 kernel/task_work.c:116
>>> exit_task_work ./include/linux/task_work.h:21
>>> do_exit+0x186b/0x2800 kernel/exit.c:839
>>> do_group_exit+0x149/0x420 kernel/exit.c:943
>>> SYSC_exit_group kernel/exit.c:954
>>> SyS_exit_group+0x1d/0x20 kernel/exit.c:952
>>> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
>>>
>>> Allocated by task 4115:
>>> save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57
>>> save_stack+0x43/0xd0 mm/kasan/kasan.c:502
>>> set_track mm/kasan/kasan.c:514
>>> kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:605
>>> kasan_slab_alloc+0x12/0x20 mm/kasan/kasan.c:544
>>> slab_post_alloc_hook mm/slab.h:432
>>> slab_alloc_node mm/slub.c:2708
>>> slab_alloc mm/slub.c:2716
>>> kmem_cache_alloc+0x1af/0x250 mm/slub.c:2721
>>> sk_prot_alloc+0x65/0x2a0 net/core/sock.c:1334
>>> sk_alloc+0x105/0x1010 net/core/sock.c:1396
>>> inet6_create+0x44d/0x1150 net/ipv6/af_inet6.c:183
>>> __sock_create+0x4f6/0x880 net/socket.c:1199
>>> sock_create net/socket.c:1239
>>> SYSC_socket net/socket.c:1269
>>> SyS_socket+0xf9/0x230 net/socket.c:1249
>>> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
>>>
>>> Memory state around the buggy address:
>>> ffff880062d9ff00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>>> ffff880062d9ff80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>>>>ffff880062da0000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>>> ^
>>> ffff880062da0080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>>> ffff880062da0100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>>> ==================================================================
>>
>> Sometimes this reproducer leads to another report:
>
> Looks very similar to issue fixed in 8282f27449bf15548cb82c77b6e04ee0ab827bdc
>
> Could you try :
Hi Eric,
This patch fixes the issue.
Thanks!
>
> diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c
> b/net/ipv6/netfilter/nf_conntrack_reasm.c
> index 9948b5ce52dad3a823edede517f17069bd7226dc..986d4ca38832b17703b09e50209ec133885c7276
> 100644
> --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
> +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
> @@ -589,6 +589,7 @@ int nf_ct_frag6_gather(struct net *net, struct
> sk_buff *skb, u32 user)
> hdr = ipv6_hdr(skb);
> fhdr = (struct frag_hdr *)skb_transport_header(skb);
>
> + skb_orphan(skb);
> fq = fq_find(net, fhdr->identification, user, &hdr->saddr, &hdr->daddr,
> skb->dev ? skb->dev->ifindex : 0, ip6_frag_ecn(hdr));
> if (fq == NULL) {
> diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
> index 6b78bab27755b2758f3c8ecd5b9c6d61615af4b6..fdec2a4cc559ab956c58d26535bdf010c0a8964a
> 100644
> --- a/net/openvswitch/conntrack.c
> +++ b/net/openvswitch/conntrack.c
> @@ -367,7 +367,6 @@ static int handle_fragments(struct net *net,
> struct sw_flow_key *key,
> } else if (key->eth.type == htons(ETH_P_IPV6)) {
> enum ip6_defrag_users user = IP6_DEFRAG_CONNTRACK_IN + zone;
>
> - skb_orphan(skb);
> memset(IP6CB(skb), 0, sizeof(struct inet6_skb_parm));
> err = nf_ct_frag6_gather(net, skb, user);
> if (err) {
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: net/ipv6: use-after-free in sock_wfree
2017-01-09 19:06 ` Andrey Konovalov
@ 2017-01-09 19:08 ` Eric Dumazet
2017-01-10 11:52 ` Andrey Konovalov
0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2017-01-09 19:08 UTC (permalink / raw)
To: Andrey Konovalov
Cc: David S. Miller, Alexey Kuznetsov, James Morris,
Hideaki YOSHIFUJI, Patrick McHardy, netdev, LKML, Dmitry Vyukov,
Kostya Serebryany, syzkaller
On Mon, Jan 9, 2017 at 11:06 AM, Andrey Konovalov <andreyknvl@google.com> wrote:
>
> Hi Eric,
>
> This patch fixes the issue.
>
> Thanks!
Thanks Andrey.
Could you please post your .config for next KASAN reports ?
I am asking this because I could not reproduce the issue with my own
builds, so I had to guess but could not test the fix myself.
Thanks !
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: net/ipv6: use-after-free in sock_wfree
2017-01-09 19:08 ` Eric Dumazet
@ 2017-01-10 11:52 ` Andrey Konovalov
0 siblings, 0 replies; 7+ messages in thread
From: Andrey Konovalov @ 2017-01-10 11:52 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, Alexey Kuznetsov, James Morris,
Hideaki YOSHIFUJI, Patrick McHardy, netdev, LKML, Dmitry Vyukov,
Kostya Serebryany, syzkaller
On Mon, Jan 9, 2017 at 8:08 PM, Eric Dumazet <edumazet@google.com> wrote:
> On Mon, Jan 9, 2017 at 11:06 AM, Andrey Konovalov <andreyknvl@google.com> wrote:
>>
>> Hi Eric,
>>
>> This patch fixes the issue.
>>
>> Thanks!
>
> Thanks Andrey.
>
> Could you please post your .config for next KASAN reports ?
Sure, no problem!
>
> I am asking this because I could not reproduce the issue with my own
> builds, so I had to guess but could not test the fix myself.
>
> Thanks !
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: net/ipv6: use-after-free in sock_wfree
2017-01-09 17:21 ` Eric Dumazet
2017-01-09 19:06 ` Andrey Konovalov
@ 2017-02-12 16:53 ` Andrey Konovalov
1 sibling, 0 replies; 7+ messages in thread
From: Andrey Konovalov @ 2017-02-12 16:53 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, Alexey Kuznetsov, Hideaki YOSHIFUJI,
Patrick McHardy, netdev, LKML, Dmitry Vyukov, Kostya Serebryany,
syzkaller
On Mon, Jan 9, 2017 at 6:21 PM, Eric Dumazet <edumazet@google.com> wrote:
> On Mon, Jan 9, 2017 at 9:11 AM, Andrey Konovalov <andreyknvl@google.com> wrote:
>> On Mon, Jan 9, 2017 at 6:08 PM, Andrey Konovalov <andreyknvl@google.com> wrote:
>>> Hi!
>>>
>>> I've got the following error report while running the syzkaller fuzzer.
>>>
>>> On commit a121103c922847ba5010819a3f250f1f7fc84ab8 (4.10-rc3).
>>>
>>> A reproducer is attached.
>>>
>>> ==================================================================
>>> BUG: KASAN: use-after-free in sock_wfree+0x118/0x120
>>> Read of size 8 at addr ffff880062da0060 by task a.out/4140
>>>
>>> page:ffffea00018b6800 count:1 mapcount:0 mapping: (null)
>>> index:0x0 compound_mapcount: 0
>>> flags: 0x100000000008100(slab|head)
>>> raw: 0100000000008100 0000000000000000 0000000000000000 0000000180130013
>>> raw: dead000000000100 dead000000000200 ffff88006741f140 0000000000000000
>>> page dumped because: kasan: bad access detected
>>>
>>> CPU: 0 PID: 4140 Comm: a.out Not tainted 4.10.0-rc3+ #59
>>> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
>>> Call Trace:
>>> __dump_stack lib/dump_stack.c:15
>>> dump_stack+0x292/0x398 lib/dump_stack.c:51
>>> describe_address mm/kasan/report.c:262
>>> kasan_report_error+0x121/0x560 mm/kasan/report.c:370
>>> kasan_report mm/kasan/report.c:392
>>> __asan_report_load8_noabort+0x3e/0x40 mm/kasan/report.c:413
>>> sock_flag ./arch/x86/include/asm/bitops.h:324
>>> sock_wfree+0x118/0x120 net/core/sock.c:1631
>>> skb_release_head_state+0xfc/0x250 net/core/skbuff.c:655
>>> skb_release_all+0x15/0x60 net/core/skbuff.c:668
>>> __kfree_skb+0x15/0x20 net/core/skbuff.c:684
>>> kfree_skb+0x16e/0x4e0 net/core/skbuff.c:705
>>> inet_frag_destroy+0x121/0x290 net/ipv4/inet_fragment.c:304
>>> inet_frag_put ./include/net/inet_frag.h:133
>>> nf_ct_frag6_gather+0x1125/0x38b0 net/ipv6/netfilter/nf_conntrack_reasm.c:617
>>> ipv6_defrag+0x21b/0x350 net/ipv6/netfilter/nf_defrag_ipv6_hooks.c:68
>>> nf_hook_entry_hookfn ./include/linux/netfilter.h:102
>>> nf_hook_slow+0xc3/0x290 net/netfilter/core.c:310
>>> nf_hook ./include/linux/netfilter.h:212
>>> __ip6_local_out+0x52c/0xaf0 net/ipv6/output_core.c:160
>>> ip6_local_out+0x2d/0x170 net/ipv6/output_core.c:170
>>> ip6_send_skb+0xa1/0x340 net/ipv6/ip6_output.c:1722
>>> ip6_push_pending_frames+0xb3/0xe0 net/ipv6/ip6_output.c:1742
>>> rawv6_push_pending_frames net/ipv6/raw.c:613
>>> rawv6_sendmsg+0x2cff/0x4130 net/ipv6/raw.c:927
>>> inet_sendmsg+0x164/0x5b0 net/ipv4/af_inet.c:744
>>> sock_sendmsg_nosec net/socket.c:635
>>> sock_sendmsg+0xca/0x110 net/socket.c:645
>>> sock_write_iter+0x326/0x620 net/socket.c:848
>>> new_sync_write fs/read_write.c:499
>>> __vfs_write+0x483/0x760 fs/read_write.c:512
>>> vfs_write+0x187/0x530 fs/read_write.c:560
>>> SYSC_write fs/read_write.c:607
>>> SyS_write+0xfb/0x230 fs/read_write.c:599
>>> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
>>> RIP: 0033:0x7ff26e6f5b79
>>> RSP: 002b:00007ff268e0ed98 EFLAGS: 00000206 ORIG_RAX: 0000000000000001
>>> RAX: ffffffffffffffda RBX: 00007ff268e0f9c0 RCX: 00007ff26e6f5b79
>>> RDX: 0000000000000010 RSI: 0000000020f50fe1 RDI: 0000000000000003
>>> RBP: 00007ff26ebc1220 R08: 0000000000000000 R09: 0000000000000000
>>> R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000
>>> R13: 00007ff268e0f9c0 R14: 00007ff26efec040 R15: 0000000000000003
>>>
>>> The buggy address belongs to the object at ffff880062da0000
>>> which belongs to the cache RAWv6 of size 1504
>>> The buggy address ffff880062da0060 is located 96 bytes inside
>>> of 1504-byte region [ffff880062da0000, ffff880062da05e0)
>>>
>>> Freed by task 4113:
>>> save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57
>>> save_stack+0x43/0xd0 mm/kasan/kasan.c:502
>>> set_track mm/kasan/kasan.c:514
>>> kasan_slab_free+0x73/0xc0 mm/kasan/kasan.c:578
>>> slab_free_hook mm/slub.c:1352
>>> slab_free_freelist_hook mm/slub.c:1374
>>> slab_free mm/slub.c:2951
>>> kmem_cache_free+0xb2/0x2c0 mm/slub.c:2973
>>> sk_prot_free net/core/sock.c:1377
>>> __sk_destruct+0x49c/0x6e0 net/core/sock.c:1452
>>> sk_destruct+0x47/0x80 net/core/sock.c:1460
>>> __sk_free+0x57/0x230 net/core/sock.c:1468
>>> sk_free+0x23/0x30 net/core/sock.c:1479
>>> sock_put ./include/net/sock.h:1638
>>> sk_common_release+0x31e/0x4e0 net/core/sock.c:2782
>>> rawv6_close+0x54/0x80 net/ipv6/raw.c:1214
>>> inet_release+0xed/0x1c0 net/ipv4/af_inet.c:425
>>> inet6_release+0x50/0x70 net/ipv6/af_inet6.c:431
>>> sock_release+0x8d/0x1e0 net/socket.c:599
>>> sock_close+0x16/0x20 net/socket.c:1063
>>> __fput+0x332/0x7f0 fs/file_table.c:208
>>> ____fput+0x15/0x20 fs/file_table.c:244
>>> task_work_run+0x19b/0x270 kernel/task_work.c:116
>>> exit_task_work ./include/linux/task_work.h:21
>>> do_exit+0x186b/0x2800 kernel/exit.c:839
>>> do_group_exit+0x149/0x420 kernel/exit.c:943
>>> SYSC_exit_group kernel/exit.c:954
>>> SyS_exit_group+0x1d/0x20 kernel/exit.c:952
>>> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
>>>
>>> Allocated by task 4115:
>>> save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57
>>> save_stack+0x43/0xd0 mm/kasan/kasan.c:502
>>> set_track mm/kasan/kasan.c:514
>>> kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:605
>>> kasan_slab_alloc+0x12/0x20 mm/kasan/kasan.c:544
>>> slab_post_alloc_hook mm/slab.h:432
>>> slab_alloc_node mm/slub.c:2708
>>> slab_alloc mm/slub.c:2716
>>> kmem_cache_alloc+0x1af/0x250 mm/slub.c:2721
>>> sk_prot_alloc+0x65/0x2a0 net/core/sock.c:1334
>>> sk_alloc+0x105/0x1010 net/core/sock.c:1396
>>> inet6_create+0x44d/0x1150 net/ipv6/af_inet6.c:183
>>> __sock_create+0x4f6/0x880 net/socket.c:1199
>>> sock_create net/socket.c:1239
>>> SYSC_socket net/socket.c:1269
>>> SyS_socket+0xf9/0x230 net/socket.c:1249
>>> entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:203
>>>
>>> Memory state around the buggy address:
>>> ffff880062d9ff00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>>> ffff880062d9ff80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>>>>ffff880062da0000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>>> ^
>>> ffff880062da0080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>>> ffff880062da0100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>>> ==================================================================
>>
>> Sometimes this reproducer leads to another report:
>
> Looks very similar to issue fixed in 8282f27449bf15548cb82c77b6e04ee0ab827bdc
>
> Could you try :
>
> diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c
> b/net/ipv6/netfilter/nf_conntrack_reasm.c
> index 9948b5ce52dad3a823edede517f17069bd7226dc..986d4ca38832b17703b09e50209ec133885c7276
> 100644
> --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
> +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
> @@ -589,6 +589,7 @@ int nf_ct_frag6_gather(struct net *net, struct
> sk_buff *skb, u32 user)
> hdr = ipv6_hdr(skb);
> fhdr = (struct frag_hdr *)skb_transport_header(skb);
>
> + skb_orphan(skb);
> fq = fq_find(net, fhdr->identification, user, &hdr->saddr, &hdr->daddr,
> skb->dev ? skb->dev->ifindex : 0, ip6_frag_ecn(hdr));
> if (fq == NULL) {
> diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
> index 6b78bab27755b2758f3c8ecd5b9c6d61615af4b6..fdec2a4cc559ab956c58d26535bdf010c0a8964a
> 100644
> --- a/net/openvswitch/conntrack.c
> +++ b/net/openvswitch/conntrack.c
> @@ -367,7 +367,6 @@ static int handle_fragments(struct net *net,
> struct sw_flow_key *key,
> } else if (key->eth.type == htons(ETH_P_IPV6)) {
> enum ip6_defrag_users user = IP6_DEFRAG_CONNTRACK_IN + zone;
>
> - skb_orphan(skb);
> memset(IP6CB(skb), 0, sizeof(struct inet6_skb_parm));
> err = nf_ct_frag6_gather(net, skb, user);
> if (err) {
Hi Eric,
I'm still seeing these reports on 926af6273fc683cd98cd0ce7bf0d04a02eed6742.
Did you mail the patch?
Thanks!
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-02-12 16:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-09 17:08 net/ipv6: use-after-free in sock_wfree Andrey Konovalov
2017-01-09 17:11 ` Andrey Konovalov
2017-01-09 17:21 ` Eric Dumazet
2017-01-09 19:06 ` Andrey Konovalov
2017-01-09 19:08 ` Eric Dumazet
2017-01-10 11:52 ` Andrey Konovalov
2017-02-12 16:53 ` Andrey Konovalov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).