// https://syzkaller.appspot.com/bug?id=4e947674d10b0fb0cb94d4d723989cee439a71d6 // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include #include const int kFailStatus = 67; const int kRetryStatus = 69; static void fail(const char* msg, ...) { int e = errno; 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); } #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; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static 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); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } 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; } struct ipt_getinfo { char name[32]; unsigned int valid_hooks; unsigned int hook_entry[5]; unsigned int underflow[5]; unsigned int num_entries; unsigned int size; }; struct ipt_get_entries { char name[32]; unsigned int size; void* entrytable[1024 / sizeof(void*)]; }; struct xt_counters { uint64_t pcnt, bcnt; }; struct ipt_replace { char name[32]; unsigned int valid_hooks; unsigned int num_entries; unsigned int size; unsigned int hook_entry[5]; unsigned int underflow[5]; unsigned int num_counters; struct xt_counters* counters; char entrytable[1024]; }; struct ipt_table_desc { const char* name; struct ipt_getinfo info; struct ipt_get_entries entries; struct ipt_replace replace; struct xt_counters counters[10]; }; static struct ipt_table_desc ipv4_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "mangle"}, {.name = "raw"}, {.name = "security"}, }; #define IPT_BASE_CTL 64 #define IPT_SO_SET_REPLACE (IPT_BASE_CTL) #define IPT_SO_GET_INFO (IPT_BASE_CTL) #define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1) static void checkpoint_net_namespace(void) { socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) fail("socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)"); for (i = 0; i < sizeof(ipv4_tables) / sizeof(ipv4_tables[0]); i++) { struct ipt_table_desc* table = &ipv4_tables[i]; strcpy(table->info.name, table->name); strcpy(table->entries.name, table->name); strcpy(table->replace.name, table->name); optlen = sizeof(table->info); if (getsockopt(fd, SOL_IP, IPT_SO_GET_INFO, &table->info, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } fail("getsockopt(IPT_SO_GET_INFO)"); } if (table->info.size > sizeof(table->entries.entrytable)) fail("table size is too large: %u", table->info.size); if (table->info.num_entries > sizeof(table->counters) / sizeof(table->counters[0])) fail("too many counters: %u", table->info.num_entries); table->entries.size = table->info.size; optlen = sizeof(table->entries) - sizeof(table->entries.entrytable) + table->info.size; if (getsockopt(fd, SOL_IP, IPT_SO_GET_ENTRIES, &table->entries, &optlen)) fail("getsockopt(IPT_SO_GET_ENTRIES)"); table->replace.valid_hooks = table->info.valid_hooks; table->replace.num_entries = table->info.num_entries; table->replace.counters = table->counters; table->replace.size = table->info.size; memcpy(table->replace.hook_entry, table->info.hook_entry, sizeof(table->replace.hook_entry)); memcpy(table->replace.underflow, table->info.underflow, sizeof(table->replace.underflow)); memcpy(table->replace.entrytable, table->entries.entrytable, table->info.size); } close(fd); } static void reset_net_namespace(void) { struct ipt_get_entries entries; struct ipt_getinfo info; socklen_t optlen; unsigned i; int fd; memset(&info, 0, sizeof(info)); memset(&entries, 0, sizeof(entries)); fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) fail("socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)"); for (i = 0; i < sizeof(ipv4_tables) / sizeof(ipv4_tables[0]); i++) { struct ipt_table_desc* table = &ipv4_tables[i]; if (table->info.valid_hooks == 0) continue; strcpy(info.name, table->name); optlen = sizeof(info); if (getsockopt(fd, SOL_IP, IPT_SO_GET_INFO, &info, &optlen)) fail("getsockopt(IPT_SO_GET_INFO)"); if (memcmp(&table->info, &info, sizeof(table->info)) == 0) { strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size; if (getsockopt(fd, SOL_IP, IPT_SO_GET_ENTRIES, &entries, &optlen)) fail("getsockopt(IPT_SO_GET_ENTRIES)"); if (memcmp(&table->entries, &entries, optlen) == 0) continue; } table->replace.num_counters = info.num_entries; optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) + table->replace.size; if (setsockopt(fd, SOL_IP, IPT_SO_SET_REPLACE, &table->replace, optlen)) fail("setsockopt(IPT_SO_SET_REPLACE)"); } close(fd); } static void test(); void loop() { int iter; checkpoint_net_namespace(); for (iter = 0;; iter++) { int pid = fork(); if (pid < 0) fail("loop fork failed"); if (pid == 0) { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); 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; } } reset_net_namespace(); } } long r[2]; void test() { memset(r, -1, sizeof(r)); syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0); r[0] = syscall(__NR_socket, 2, 2, 0x88); *(uint16_t*)0x20b9aff0 = 2; *(uint16_t*)0x20b9aff2 = htobe16(0x4e20); *(uint32_t*)0x20b9aff4 = htobe32(0); *(uint8_t*)0x20b9aff8 = 0; *(uint8_t*)0x20b9aff9 = 0; *(uint8_t*)0x20b9affa = 0; *(uint8_t*)0x20b9affb = 0; *(uint8_t*)0x20b9affc = 0; *(uint8_t*)0x20b9affd = 0; *(uint8_t*)0x20b9affe = 0; *(uint8_t*)0x20b9afff = 0; syscall(__NR_bind, r[0], 0x20b9aff0, 0x10); *(uint16_t*)0x20319ff0 = 2; *(uint16_t*)0x20319ff2 = htobe16(0x4e20); *(uint32_t*)0x20319ff4 = htobe32(0); *(uint8_t*)0x20319ff8 = 0; *(uint8_t*)0x20319ff9 = 0; *(uint8_t*)0x20319ffa = 0; *(uint8_t*)0x20319ffb = 0; *(uint8_t*)0x20319ffc = 0; *(uint8_t*)0x20319ffd = 0; *(uint8_t*)0x20319ffe = 0; *(uint8_t*)0x20319fff = 0; syscall(__NR_sendto, r[0], 0x20e7c000, 0, 0x8084, 0x20319ff0, 0x10); *(uint16_t*)0x2082dff0 = 2; *(uint16_t*)0x2082dff2 = 0; *(uint8_t*)0x2082dff4 = 0xac; *(uint8_t*)0x2082dff5 = 0x14; *(uint8_t*)0x2082dff6 = 0; *(uint8_t*)0x2082dff7 = 0xaa; *(uint8_t*)0x2082dff8 = 0; *(uint8_t*)0x2082dff9 = 0; *(uint8_t*)0x2082dffa = 0; *(uint8_t*)0x2082dffb = 0; *(uint8_t*)0x2082dffc = 0; *(uint8_t*)0x2082dffd = 0; *(uint8_t*)0x2082dffe = 0; *(uint8_t*)0x2082dfff = 0; syscall(__NR_sendto, r[0], 0x20f79fff, 0, 0, 0x2082dff0, 0x10); r[1] = syscall(__NR_socket, 0xf, 3, 2); *(uint64_t*)0x20cd0fc8 = 0; *(uint32_t*)0x20cd0fd0 = 0; *(uint64_t*)0x20cd0fd8 = 0x20858ff0; *(uint64_t*)0x20cd0fe0 = 1; *(uint64_t*)0x20cd0fe8 = 0; *(uint64_t*)0x20cd0ff0 = 0; *(uint32_t*)0x20cd0ff8 = 0; *(uint64_t*)0x20858ff0 = 0x20e05000; *(uint64_t*)0x20858ff8 = 0xc0; *(uint8_t*)0x20e05000 = 2; *(uint8_t*)0x20e05001 = 0xd; *(uint8_t*)0x20e05002 = 0; *(uint8_t*)0x20e05003 = 0; *(uint16_t*)0x20e05004 = 0x18; *(uint16_t*)0x20e05006 = 0; *(uint32_t*)0x20e05008 = 0; *(uint32_t*)0x20e0500c = 0; *(uint16_t*)0x20e05010 = 4; *(uint16_t*)0x20e05012 = 3; *(uint32_t*)0x20e05014 = 4; *(uint64_t*)0x20e05018 = 0; *(uint64_t*)0x20e05020 = 0; *(uint64_t*)0x20e05028 = 0; *(uint16_t*)0x20e05030 = 8; *(uint16_t*)0x20e05032 = 0x12; *(uint16_t*)0x20e05034 = 0; *(uint8_t*)0x20e05036 = 1; *(uint8_t*)0x20e05037 = 0; *(uint32_t*)0x20e05038 = 0; *(uint32_t*)0x20e0503c = 0; *(uint16_t*)0x20e05040 = 6; *(uint16_t*)0x20e05042 = 0; *(uint8_t*)0x20e05044 = 0; *(uint8_t*)0x20e05045 = 0; *(uint16_t*)0x20e05046 = 0; *(uint32_t*)0x20e05048 = 0; *(uint32_t*)0x20e0504c = 0; *(uint8_t*)0x20e05050 = 0xac; *(uint8_t*)0x20e05051 = 0x14; *(uint8_t*)0x20e05052 = 0; *(uint8_t*)0x20e05053 = 0xaa; *(uint8_t*)0x20e05060 = -1; *(uint8_t*)0x20e05061 = 2; *(uint8_t*)0x20e05062 = 0; *(uint8_t*)0x20e05063 = 0; *(uint8_t*)0x20e05064 = 0; *(uint8_t*)0x20e05065 = 0; *(uint8_t*)0x20e05066 = 0; *(uint8_t*)0x20e05067 = 0; *(uint8_t*)0x20e05068 = 0; *(uint8_t*)0x20e05069 = 0; *(uint8_t*)0x20e0506a = 0; *(uint8_t*)0x20e0506b = 0; *(uint8_t*)0x20e0506c = 0; *(uint8_t*)0x20e0506d = 0; *(uint8_t*)0x20e0506e = 0; *(uint8_t*)0x20e0506f = 1; *(uint16_t*)0x20e05070 = 5; *(uint16_t*)0x20e05072 = 5; *(uint8_t*)0x20e05074 = 0; *(uint8_t*)0x20e05075 = 0; *(uint16_t*)0x20e05076 = 0; *(uint16_t*)0x20e05078 = 0xa; *(uint16_t*)0x20e0507a = 0; *(uint32_t*)0x20e0507c = 0; *(uint8_t*)0x20e05080 = 0; *(uint8_t*)0x20e05081 = 0; *(uint8_t*)0x20e05082 = 0; *(uint8_t*)0x20e05083 = 0; *(uint8_t*)0x20e05084 = 0; *(uint8_t*)0x20e05085 = 0; *(uint8_t*)0x20e05086 = 0; *(uint8_t*)0x20e05087 = 0; *(uint8_t*)0x20e05088 = 0; *(uint8_t*)0x20e05089 = 0; *(uint8_t*)0x20e0508a = -1; *(uint8_t*)0x20e0508b = -1; *(uint8_t*)0x20e0508c = 0xac; *(uint8_t*)0x20e0508d = 0x14; *(uint8_t*)0x20e0508e = 0; *(uint8_t*)0x20e0508f = 0; *(uint32_t*)0x20e05090 = 0; *(uint16_t*)0x20e05098 = 5; *(uint16_t*)0x20e0509a = 6; *(uint8_t*)0x20e0509c = 0; *(uint8_t*)0x20e0509d = 0; *(uint16_t*)0x20e0509e = 0; *(uint16_t*)0x20e050a0 = 0xa; *(uint16_t*)0x20e050a2 = 0; *(uint32_t*)0x20e050a4 = 0; *(uint8_t*)0x20e050a8 = 0xfe; *(uint8_t*)0x20e050a9 = 0x80; *(uint8_t*)0x20e050aa = 0; *(uint8_t*)0x20e050ab = 0; *(uint8_t*)0x20e050ac = 0; *(uint8_t*)0x20e050ad = 0; *(uint8_t*)0x20e050ae = 0; *(uint8_t*)0x20e050af = 0; *(uint8_t*)0x20e050b0 = 0; *(uint8_t*)0x20e050b1 = 0; *(uint8_t*)0x20e050b2 = 0; *(uint8_t*)0x20e050b3 = 0; *(uint8_t*)0x20e050b4 = 0; *(uint8_t*)0x20e050b5 = 0; *(uint8_t*)0x20e050b6 = 0; *(uint8_t*)0x20e050b7 = 0xbb; *(uint32_t*)0x20e050b8 = 0; syscall(__NR_sendmsg, r[1], 0x20cd0fc8, 0); *(uint8_t*)0x2065afa5 = 0xaa; *(uint8_t*)0x2065afa6 = 0xaa; *(uint8_t*)0x2065afa7 = 0xaa; *(uint8_t*)0x2065afa8 = 0xaa; *(uint8_t*)0x2065afa9 = 0; *(uint8_t*)0x2065afaa = 0xaa; *(uint8_t*)0x2065afab = 0xaa; *(uint8_t*)0x2065afac = 0xaa; *(uint8_t*)0x2065afad = 0xaa; *(uint8_t*)0x2065afae = 0xaa; *(uint8_t*)0x2065afaf = 0; *(uint8_t*)0x2065afb0 = 0; *(uint16_t*)0x2065afb1 = htobe16(0x800); STORE_BY_BITMASK(uint8_t, 0x2065afb3, 7, 0, 4); STORE_BY_BITMASK(uint8_t, 0x2065afb3, 4, 4, 4); STORE_BY_BITMASK(uint8_t, 0x2065afb4, 0, 0, 2); STORE_BY_BITMASK(uint8_t, 0x2065afb4, 0, 2, 6); *(uint16_t*)0x2065afb5 = htobe16(0x38); *(uint16_t*)0x2065afb7 = 0; *(uint16_t*)0x2065afb9 = htobe16(0); *(uint8_t*)0x2065afbb = 0; *(uint8_t*)0x2065afbc = 0; *(uint16_t*)0x2065afbd = 0; *(uint8_t*)0x2065afbf = 0xac; *(uint8_t*)0x2065afc0 = 0x14; *(uint8_t*)0x2065afc1 = 0; *(uint8_t*)0x2065afc2 = 0; *(uint8_t*)0x2065afc3 = 0xac; *(uint8_t*)0x2065afc4 = 0x14; *(uint8_t*)0x2065afc5 = 0; *(uint8_t*)0x2065afc6 = 0xaa; *(uint8_t*)0x2065afc7 = 0x44; *(uint8_t*)0x2065afc8 = 8; *(uint8_t*)0x2065afc9 = 5; STORE_BY_BITMASK(uint8_t, 0x2065afca, 0, 0, 4); STORE_BY_BITMASK(uint8_t, 0x2065afca, 0, 4, 4); *(uint32_t*)0x2065afcb = htobe32(0); *(uint8_t*)0x2065afcf = 3; *(uint8_t*)0x2065afd0 = 0; *(uint16_t*)0x2065afd1 = 0; *(uint8_t*)0x2065afd3 = 0; *(uint8_t*)0x2065afd4 = 0; *(uint16_t*)0x2065afd5 = htobe16(0); STORE_BY_BITMASK(uint8_t, 0x2065afd7, 5, 0, 4); STORE_BY_BITMASK(uint8_t, 0x2065afd7, 4, 4, 4); STORE_BY_BITMASK(uint8_t, 0x2065afd8, 0, 0, 2); STORE_BY_BITMASK(uint8_t, 0x2065afd8, 0, 2, 6); *(uint16_t*)0x2065afd9 = htobe16(0); *(uint16_t*)0x2065afdb = 0; *(uint16_t*)0x2065afdd = htobe16(0); *(uint8_t*)0x2065afdf = 0; *(uint8_t*)0x2065afe0 = 0; *(uint16_t*)0x2065afe1 = htobe16(0); *(uint32_t*)0x2065afe3 = htobe32(-1); *(uint32_t*)0x2065afe7 = htobe32(0xe0000001); *(uint32_t*)0x203b5000 = 0; *(uint32_t*)0x203b5004 = 0; struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x2065afcf, 28); *(uint16_t*)0x2065afd1 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x2065afb3, 28); *(uint16_t*)0x2065afbd = csum_inet_digest(&csum_2); } int main() { for (;;) { loop(); } }