lkml.org 
[lkml]   [2017]   [Apr]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
Subjectnet/ipv6: warning in inet6_ifa_finish_destroy
Hi,

I've got the following error report while fuzzing the kernel with syzkaller.

On commit 5a7ad1146caa895ad718a534399e38bd2ba721b7 (4.11-rc8).

C reproducer and .config are attached.
It takes 1-2 minutes of running the reproducer to trigger the issue.

------------[ cut here ]------------
WARNING: CPU: 0 PID: 21 at net/ipv6/addrconf.c:894
inet6_ifa_finish_destroy+0x12e/0x190
Modules linked in:
CPU: 0 PID: 21 Comm: kworker/0:1 Not tainted 4.11.0-rc8+ #296
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
Workqueue: ipv6_addrconf addrconf_dad_work
Call Trace:
__dump_stack lib/dump_stack.c:16
dump_stack+0x292/0x398 lib/dump_stack.c:52
__warn+0x19f/0x1e0 kernel/panic.c:549
warn_slowpath_null+0x2c/0x40 kernel/panic.c:584
inet6_ifa_finish_destroy+0x12e/0x190 c:894
in6_ifa_put ./include/net/addrconf.h:330
addrconf_dad_work+0x4e9/0x1040 net/ipv6/addrconf.c:3963
process_one_work+0xc04/0x1c10 kernel/workqueue.c:2097
worker_thread+0x223/0x19c0 kernel/workqueue.c:2231
kthread+0x35e/0x430 kernel/kthread.c:231
ret_from_fork+0x31/0x40 arch/x86/entry/entry_64.S:430
---[ end trace 64f7dae275ec6e42 ]---
IPv6: Freeing alive inet6 address ffff88006383a000
[unhandled content-type:application/octet-stream]// 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_ioctl
#define __NR_ioctl 16
#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 || e == EAGAIN) ? 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; \
}

struct csum_inet {
uint32_t acc;
};

void csum_inet_init(struct csum_inet* csum)
{
csum->acc = 0;
}

void csum_inet_update(struct csum_inet* csum, const uint8_t* data,
size_t length)
{
if (length == 0)
return;

size_t i;
for (i = 0; i < length - 1; i += 2)
csum->acc += *(uint16_t*)&data[i];

if (length & 1)
csum->acc += (uint16_t)data[length - 1];

while (csum->acc > 0xffff)
csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16);
}

uint16_t csum_inet_digest(struct csum_inet* csum)
{
return ~csum->acc;
}

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 real_uid;
static int real_gid;
static int epid;
static bool etun;
__attribute__((aligned(64 << 10))) static char sandbox_stack[1 << 20];

static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);

int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
close(fd);
return false;
}
close(fd);
return true;
}

static int namespace_sandbox_proc(void* arg)
{
sandbox_common();

write_file("/proc/self/setgroups", "deny");
if (!write_file("/proc/self/uid_map", "0 %d 1\n", real_uid))
fail("write of /proc/self/uid_map failed");
if (!write_file("/proc/self/gid_map", "0 %d 1\n", real_gid))
fail("write of /proc/self/gid_map failed");

if (mkdir("./syz-tmp", 0777))
fail("mkdir(syz-tmp) failed");
if (mount("", "./syz-tmp", "tmpfs", 0, NULL))
fail("mount(tmpfs) failed");
if (mkdir("./syz-tmp/newroot", 0777))
fail("mkdir failed");
if (mkdir("./syz-tmp/newroot/dev", 0700))
fail("mkdir failed");
if (mount("/dev", "./syz-tmp/newroot/dev", NULL,
MS_BIND | MS_REC | MS_PRIVATE, NULL))
fail("mount(dev) failed");
if (mkdir("./syz-tmp/pivot", 0777))
fail("mkdir failed");
if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) {
debug("pivot_root failed");
if (chdir("./syz-tmp"))
fail("chdir failed");
} else {
if (chdir("/"))
fail("chdir failed");
if (umount2("./pivot", MNT_DETACH))
fail("umount failed");
}
if (chroot("./newroot"))
fail("chroot failed");
if (chdir("/"))
fail("chdir failed");

struct __user_cap_header_struct cap_hdr = {};
struct __user_cap_data_struct cap_data[2] = {};
cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
cap_hdr.pid = getpid();
if (syscall(SYS_capget, &cap_hdr, &cap_data))
fail("capget failed");
cap_data[0].effective &= ~(1 << CAP_SYS_PTRACE);
cap_data[0].permitted &= ~(1 << CAP_SYS_PTRACE);
cap_data[0].inheritable &= ~(1 << CAP_SYS_PTRACE);
if (syscall(SYS_capset, &cap_hdr, &cap_data))
fail("capset failed");

loop();
doexit(1);
}

static int do_sandbox_namespace(int executor_pid, bool enable_tun)
{
real_uid = getuid();
real_gid = getgid();
epid = executor_pid;
etun = enable_tun;
mprotect(sandbox_stack, 4096, PROT_NONE);
return clone(
namespace_sandbox_proc,
&sandbox_stack[sizeof(sandbox_stack) - 64],
CLONE_NEWUSER | CLONE_NEWPID | CLONE_NEWUTS | CLONE_NEWNET, NULL);
}

static void remove_dir(const char* dir)
{
DIR* dp;
struct dirent* ep;
int iter = 0;
retry:
dp = opendir(dir);
if (dp == NULL) {
if (errno == EMFILE) {
exitf("opendir(%s) failed due to NOFILE, exiting");
}
exitf("opendir(%s) failed", dir);
}
while ((ep = readdir(dp))) {
if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
continue;
char filename[FILENAME_MAX];
snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
struct stat st;
if (lstat(filename, &st))
exitf("lstat(%s) failed", filename);
if (S_ISDIR(st.st_mode)) {
remove_dir(filename);
continue;
}
int i;
for (i = 0;; i++) {
debug("unlink(%s)\n", filename);
if (unlink(filename) == 0)
break;
if (errno == EROFS) {
debug("ignoring EROFS\n");
break;
}
if (errno != EBUSY || i > 100)
exitf("unlink(%s) failed", filename);
debug("umount(%s)\n", filename);
if (umount2(filename, MNT_DETACH))
exitf("umount(%s) failed", filename);
}
}
closedir(dp);
int i;
for (i = 0;; i++) {
debug("rmdir(%s)\n", dir);
if (rmdir(dir) == 0)
break;
if (i < 100) {
if (errno == EROFS) {
debug("ignoring EROFS\n");
break;
}
if (errno == EBUSY) {
debug("umount(%s)\n", dir);
if (umount2(dir, MNT_DETACH))
exitf("umount(%s) failed", dir);
continue;
}
if (errno == ENOTEMPTY) {
if (iter < 100) {
iter++;
goto retry;
}
}
}
exitf("rmdir(%s) failed", dir);
}
}

static uint64_t current_time_ms()
{
struct timespec ts;

if (clock_gettime(CLOCK_MONOTONIC, &ts))
fail("clock_gettime failed");
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}

static void test();

void loop()
{
int iter;
for (iter = 0;; iter++) {
char cwdbuf[256];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
fail("failed to mkdir");
int pid = fork();
if (pid < 0)
fail("clone failed");
if (pid == 0) {
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
if (chdir(cwdbuf))
fail("failed to chdir");
test();
doexit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
int res = waitpid(-1, &status, __WALL | WNOHANG);
if (res == pid)
break;
usleep(1000);
if (current_time_ms() - start > 5 * 1000) {
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
while (waitpid(-1, &status, __WALL) != pid) {
}
break;
}
}
remove_dir(cwdbuf);
}
}

long r[61];
void* thr(void* arg)
{
switch ((long)arg) {
case 0:
r[0] =
execute_syscall(__NR_mmap, 0x20000000ul, 0x8000ul, 0x3ul,
0x32ul, 0xfffffffffffffffful, 0x0ul, 0, 0, 0);
break;
case 1:
r[1] = execute_syscall(__NR_socket, 0xaul, 0x5ul, 0x0ul, 0, 0, 0, 0,
0, 0);
break;
case 2:
NONFAILING(memcpy((void*)0x20005fd8,
"\x69\x70\x36\x74\x6e\x6c\x30\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00",
16));
NONFAILING(*(uint32_t*)0x20005fe8 = (uint32_t)0x0);
NONFAILING(*(uint8_t*)0x20005fec = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005fed = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005fee = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005fef = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ff0 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ff1 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ff2 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ff3 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ff4 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ff5 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ff6 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ff7 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ff8 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ff9 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ffa = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ffb = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ffc = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ffd = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005ffe = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20005fff = (uint8_t)0x0);
r[24] = execute_syscall(__NR_ioctl, r[1], 0x8933ul, 0x20005fd8ul, 0,
0, 0, 0, 0, 0);
if (r[24] != -1)
NONFAILING(r[25] = *(uint32_t*)0x20005fe8);
break;
case 3:
NONFAILING(*(uint8_t*)0x20001000 = (uint8_t)0xfd);
NONFAILING(*(uint8_t*)0x20001001 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20001002 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20001003 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20001004 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20001005 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20001006 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20001007 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20001008 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20001009 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000100a = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000100b = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000100c = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000100d = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000100e = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000100f = (uint8_t)0xbb);
NONFAILING(*(uint32_t*)0x20001010 = (uint32_t)0x1);
NONFAILING(*(uint32_t*)0x20001014 = r[25]);
r[44] = execute_syscall(__NR_ioctl, r[1], 0x8916ul, 0x20001000ul, 0,
0, 0, 0, 0, 0);
break;
case 4:
NONFAILING(memcpy((void*)0x20000000,
"\x69\x70\x36\x74\x6e\x6c\x30\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00",
16));
NONFAILING(*(uint16_t*)0x20000010 = (uint16_t)0x4001);
r[47] = execute_syscall(__NR_ioctl, r[1], 0x8914ul, 0x20000000ul, 0,
0, 0, 0, 0, 0);
break;
case 5:
NONFAILING(memcpy((void*)0x20000000,
"\x69\x70\x36\x74\x6e\x6c\x30\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00",
16));
NONFAILING(*(uint16_t*)0x20000010 = (uint16_t)0x2);
NONFAILING(*(uint16_t*)0x20000012 = (uint16_t)0x204e);
NONFAILING(*(uint32_t*)0x20000014 = (uint32_t)0x0);
NONFAILING(*(uint8_t*)0x20000018 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x20000019 = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000001a = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000001b = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000001c = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000001d = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000001e = (uint8_t)0x0);
NONFAILING(*(uint8_t*)0x2000001f = (uint8_t)0x0);
r[60] = execute_syscall(__NR_ioctl, r[1], 0x8914ul, 0x20000000ul, 0,
0, 0, 0, 0, 0);
break;
}
return 0;
}

void test()
{
long i;
pthread_t th[12];

memset(r, -1, sizeof(r));
srand(getpid());
for (i = 0; i < 6; i++) {
pthread_create(&th[i], 0, thr, (void*)i);
usleep(10000);
}
for (i = 0; i < 6; i++) {
pthread_create(&th[6 + i], 0, thr, (void*)i);
if (rand() % 2)
usleep(rand() % 10000);
}
usleep(100000);
}

int main()
{
int i;
for (i = 0; i < 8; i++) {
if (fork() == 0) {
setup_main_process();
int pid = do_sandbox_namespace(i, false);
int status = 0;
while (waitpid(pid, &status, __WALL) != pid) {
}
return 0;
}
}
sleep(1000000);
return 0;
}
\
 
 \ /
  Last update: 2017-04-28 15:09    [W:0.118 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site