net/llc: bug in llc_pdu_init_as_xid_cmd/skb_over_panic
From: Andrey Konovalov
Date: Fri Feb 10 2017 - 10:40:30 EST
Hi,
I've got the following error report while fuzzing the kernel with syzkaller.
On commit 926af6273fc683cd98cd0ce7bf0d04a02eed6742.
A reproducer and .config are attached
kernel BUG at net/core/skbuff.c:105!
invalid opcode: 0000 [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in:
CPU: 2 PID: 6558 Comm: syz-executor4 Not tainted 4.10.0-rc7+ #126
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
task: ffff88003c49c480 task.stack: ffff88003a5c0000
RIP: 0010:skb_panic+0x16f/0x200 net/core/skbuff.c:101
RSP: 0018:ffff88003a5c77d0 EFLAGS: 00010286
RAX: 0000000000000082 RBX: ffff88006be991c0 RCX: 0000000000000000
RDX: 0000000000000082 RSI: ffffffff814567fc RDI: ffffed00074b8eec
RBP: ffff88003a5c7838 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000002 R11: 0000000000000001 R12: ffffffff85231ee0
R13: ffffffff834a6722 R14: 0000000000000003 R15: ffff88006c81c580
FS: 00007f89298c7700(0000) GS:ffff88006de00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000020ee5000 CR3: 0000000058697000 CR4: 00000000000006e0
Call Trace:
skb_over_panic net/core/skbuff.c:110 [inline]
skb_put+0x18d/0x1d0 net/core/skbuff.c:1437
llc_pdu_init_as_xid_cmd include/net/llc_pdu.h:377 [inline]
llc_sap_action_send_xid_c+0x2a2/0x3b0 net/llc/llc_s_ac.c:82
llc_exec_sap_trans_actions net/llc/llc_sap.c:152 [inline]
llc_sap_next_state net/llc/llc_sap.c:181 [inline]
llc_sap_state_process+0x26b/0x4e0 net/llc/llc_sap.c:212
llc_build_and_send_xid_pkt+0x19f/0x200 net/llc/llc_sap.c:276
llc_ui_sendmsg+0xad9/0x1430 net/llc/af_llc.c:938
sock_sendmsg_nosec net/socket.c:635 [inline]
sock_sendmsg+0xca/0x110 net/socket.c:645
___sys_sendmsg+0x9d2/0xae0 net/socket.c:1985
__sys_sendmsg+0x138/0x320 net/socket.c:2019
SYSC_sendmsg net/socket.c:2030 [inline]
SyS_sendmsg+0x2d/0x50 net/socket.c:2026
entry_SYSCALL_64_fastpath+0x1f/0xc2
RIP: 0033:0x4458b9
RSP: 002b:00007f89298c6b58 EFLAGS: 00000286 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 0000000000000005 RCX: 00000000004458b9
RDX: 0000000000040085 RSI: 0000000020001fc8 RDI: 0000000000000005
RBP: 00000000006e1ae0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000286 R12: 0000000000708000
R13: ffffffffffffffff R14: 00000000c0206434 R15: 00000000201fcfe0
Code: 00 00 00 48 89 54 24 10 48 c7 c7 60 19 23 85 48 89 74 24 08 4c
89 04 24 4c 89 ea 4c 89 7c 24 18 45 89 f0 4c 89 e6 e8 1e c0 38 fe <0f>
0b 4c 89 4d b8 4c 89 45 c0 48 89 75 c8 48 89 55 d0 e8 6a 5e
RIP: skb_panic+0x16f/0x200 net/core/skbuff.c:101 RSP: ffff88003a5c77d0
---[ end trace 89f0ca2ea5bc3ead ]---
Kernel panic - not syncing: Fatal exception
Dumping ftrace buffer:
(ftrace buffer empty)
Kernel Offset: disabled
Rebooting in 86400 seconds..
Attachment:
.config
Description: Binary data
// autogenerated by syzkaller (http://github.com/google/syzkaller)
#ifndef __NR_mmap
#define __NR_mmap 9
#endif
#ifndef __NR_socket
#define __NR_socket 41
#endif
#ifndef __NR_sendmsg
#define __NR_sendmsg 46
#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/kvm.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)
{
volatile unsigned i;
syscall(__NR_exit_group, status);
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)
{
uintptr_t addr = (uintptr_t)info->si_addr;
const uintptr_t prog_start = 1 << 20;
const uintptr_t prog_end = 100 << 20;
if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) &&
(addr < prog_start || addr > prog_end)) {
debug("SIGSEGV on %p, skipping\n", addr);
_longjmp(segv_env, 1);
}
debug("SIGSEGV on %p, exiting\n", addr);
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); \
}
#define BITMASK_LEN(type, bf_len) (type)((1ull << (bf_len)) - 1)
#define BITMASK_LEN_OFF(type, bf_off, bf_len) \
(type)(BITMASK_LEN(type, (bf_len)) << (bf_off))
#define STORE_BY_BITMASK(type, addr, val, bf_off, bf_len) \
if ((bf_off) == 0 && (bf_len) == 0) { \
*(type*)(addr) = (type)(val); \
} else { \
type new_val = *(type*)(addr); \
new_val &= ~BITMASK_LEN_OFF(type, (bf_off), (bf_len)); \
new_val |= ((type)(val)&BITMASK_LEN(type, (bf_len))) << (bf_off); \
*(type*)(addr) = new_val; \
}
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()
{
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 executor_pid, bool enable_tun)
{
int pid = fork();
if (pid)
return pid;
sandbox_common();
loop();
doexit(1);
}
long r[24];
void loop()
{
memset(r, -1, sizeof(r));
r[0] = execute_syscall(__NR_mmap, 0x20000000ul, 0x851000ul, 0x3ul,
0x32ul, 0xfffffffffffffffful, 0x0ul, 0, 0, 0);
r[1] = execute_syscall(__NR_socket, 0x1aul, 0x801ul, 0xcb00ul, 0, 0,
0, 0, 0, 0);
NONFAILING(*(uint64_t*)0x20001fc8 = (uint64_t)0x20004fa0);
NONFAILING(*(uint32_t*)0x20001fd0 = (uint32_t)0x60);
NONFAILING(*(uint64_t*)0x20001fd8 = (uint64_t)0x20003000);
NONFAILING(*(uint64_t*)0x20001fe0 = (uint64_t)0x1);
NONFAILING(*(uint64_t*)0x20001fe8 = (uint64_t)0x20001000);
NONFAILING(*(uint64_t*)0x20001ff0 = (uint64_t)0x10);
NONFAILING(*(uint32_t*)0x20001ff8 = (uint32_t)0x1);
NONFAILING(*(uint16_t*)0x20004fa0 = (uint16_t)0x27);
NONFAILING(*(uint32_t*)0x20004fa4 = (uint32_t)0x800);
NONFAILING(*(uint32_t*)0x20004fa8 = (uint32_t)0x0);
NONFAILING(*(uint32_t*)0x20004fac = (uint32_t)0x0);
NONFAILING(*(uint8_t*)0x20004fb0 = (uint8_t)0xfffffffffffffffd);
NONFAILING(*(uint8_t*)0x20004fb1 = (uint8_t)0x0);
NONFAILING(memcpy(
(void*)0x20004fb2,
"\x4e\xa6\xf0\xe3\x26\x38\x41\x00\x04\xc3\x84\x5a\xd3\xe8\x12\x92"
"\xe2\x97\x1a\x49\xc7\x07\x55\xb5\xa2\x0c\x91\x5b\xe8\xe3\xa2\x1e"
"\x49\x17\x62\x02\x27\x36\xcd\x99\x61\x46\xb6\xa2\xa9\x9e\xfe\x01"
"\xc9\xcb\xf2\xeb\x94\x94\x94\xc2\x85\x56\x30\xea\x2a\x71\xf9",
63));
NONFAILING(*(uint64_t*)0x20004ff8 = (uint64_t)0x0);
NONFAILING(*(uint64_t*)0x20003000 = (uint64_t)0x20002000);
NONFAILING(*(uint64_t*)0x20003008 = (uint64_t)0xa7);
NONFAILING(memcpy(
(void*)0x20002000,
"\x95\x45\x2e\xff\xe1\xb2\xde\xa2\x07\xc7\x4b\xbe\x1d\x19\xd1\x1c"
"\x25\x40\x57\x3d\x31\xa0\xfa\xc5\xaf\xcc\x44\x1d\x21\xaa\x09\xc4"
"\x62\x54\xb9\x46\xcc\x12\x0f\x41\xcc\x99\x90\x8a\x8b\x6e\x1a\x41"
"\x27\xfa\x11\xc5\x6c\x68\xdb\xe6\xbc\x4f\x68\x6e\x8b\xe6\xfe\x9e"
"\xcd\x87\xd9\x7b\x82\xf9\x0d\x28\x3f\xe7\x2a\x69\xc9\x9d\x38\x7c"
"\xcf\x30\x18\xb3\x7a\x2f\xcc\x84\xc2\x0b\x68\x7d\x77\x78\x2a\xd1"
"\xe2\x13\xf6\x64\x89\x5e\x8f\x98\xab\x5c\xce\x7f\xfa\xae\x77\x1c"
"\x14\x41\xb8\x2d\x30\x3a\x0f\x36\x06\x52\x4f\x9f\xdf\x44\xd8\x32"
"\x6b\x28\x91\xde\xa3\x8f\x94\x47\x77\xb0\x1d\xf2\x74\x75\xc5\x53"
"\xa4\x1f\x3f\xba\x7b\x0d\x57\xae\xd6\xfb\x0f\xb1\xbb\xfd\x47\x61"
"\x36\x7a\x1d\x9e\xda\x18\x48",
167));
NONFAILING(*(uint64_t*)0x20001000 = (uint64_t)0x10);
NONFAILING(*(uint32_t*)0x20001008 = (uint32_t)0x1);
NONFAILING(*(uint32_t*)0x2000100c = (uint32_t)0x2);
r[23] = execute_syscall(__NR_sendmsg, r[1], 0x20001fc8ul, 0x40085ul,
0, 0, 0, 0, 0, 0);
}
int main()
{
setup_main_process();
int pid = do_sandbox_none(0, false);
int status = 0;
while (waitpid(pid, &status, __WALL) != pid) {
}
return 0;
}