map[SimplifiedCRepro:// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef __NR_close_range
#define __NR_close_range 436
#endif
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) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
static int inject_fault(int nth)
{
int fd;
fd = open("/proc/thread-self/fail-nth", O_RDWR);
if (fd == -1)
exit(1);
char buf[16];
sprintf(buf, "%d", nth);
if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf))
exit(1);
return fd;
}
static const char* setup_fault()
{
int fd = open("/proc/self/make-it-fail", O_WRONLY);
if (fd == -1)
return "CONFIG_FAULT_INJECTION is not enabled";
close(fd);
fd = open("/proc/thread-self/fail-nth", O_WRONLY);
if (fd == -1)
return "kernel does not have systematic fault injection support";
close(fd);
static struct {
const char* file;
const char* val;
bool fatal;
} files[] = {
{"/sys/kernel/debug/failslab/ignore-gfp-wait", "N", true},
{"/sys/kernel/debug/fail_futex/ignore-private", "N", false},
{"/sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem", "N", false},
{"/sys/kernel/debug/fail_page_alloc/ignore-gfp-wait", "N", false},
{"/sys/kernel/debug/fail_page_alloc/min-order", "0", false},
};
unsigned i;
for (i = 0; i < sizeof(files) / sizeof(files[0]); i++) {
if (!write_file(files[i].file, files[i].val)) {
if (files[i].fatal)
return "failed to write fault injection file";
}
}
return NULL;
}
uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
if ((reason = setup_fault()))
printf("the reproducer may not work as expected: fault injection setup failed: %s\n", reason);
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// mmap$auto arguments: [
// addr: intptr = 0x0 (8 bytes)
// len: intptr = 0x1 (8 bytes)
// prot: intptr = 0xdf (8 bytes)
// flags: intptr = 0x9b72 (8 bytes)
// fd: fd (resource)
// off: intptr = 0x8000 (8 bytes)
// ]
syscall(__NR_mmap, /*addr=*/0ul, /*len=*/1ul, /*prot=*/0xdful, /*flags=*/0x9b72ul, /*fd=*/2, /*off=*/0x8000ul);
// openat$auto_kernfs_file_fops_kernfs_internal arguments: [
// fd: const = 0xffffffffffffff9c (8 bytes)
// file: ptr[in, buffer] {
// buffer: {2f 73 79 73 2f 64 65 76 69 63 65 73 2f 76 69 72 74 75 61 6c 2f 77 6f 72 6b 71 75 65 75 65 2f 6e 66 5f 66 74 5f 6f 66 66 6c 6f 61 64 5f 73 74 61 74 73 2f 61 66 66 69 6e 69 74 79 5f 73 63 6f 70 65 00} (length 0x42)
// }
// flags: open_flags = 0x8000 (4 bytes)
// mode: const = 0x0 (2 bytes)
// ]
// returns fd_kernfs_file_fops_kernfs_internal
memcpy((void*)0x2000000000c0, "/sys/devices/virtual/workqueue/nf_ft_offload_stats/affinity_scope\000", 66);
res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x2000000000c0ul, /*flags=O_LARGEFILE*/0x8000, /*mode=*/0);
if (res != -1)
r[0] = res;
// read$auto arguments: [
// fd: fd (resource)
// buf: nil
// count: intptr = 0x20 (8 bytes)
// ]
syscall(__NR_read, /*fd=*/r[0], /*buf=*/0ul, /*count=*/0x20ul);
// close_range$auto arguments: [
// fd: fd (resource)
// max_fd: fd (resource)
// flags: int32 = 0x4000000000002 (4 bytes)
// ]
syscall(__NR_close_range, /*fd=*/0, /*max_fd=*/r[0], /*flags=*/2);
// socket arguments: [
// domain: socket_domain = 0x2 (8 bytes)
// type: socket_type = 0x801 (8 bytes)
// proto: int32 = 0x106 (4 bytes)
// ]
// returns sock
syscall(__NR_socket, /*domain=AF_INET*/2ul, /*type=SOCK_NONBLOCK|SOCK_STREAM*/0x801ul, /*proto=*/0x106);
// socketpair$auto arguments: [
// family: int32 = 0x1a (4 bytes)
// type: int32 = 0x9 (4 bytes)
// protocol: int32 = 0x8000000000000000 (4 bytes)
// usockvec: nil
// ]
// returns fd
syscall(__NR_socketpair, /*family=*/0x1a, /*type=*/9, /*protocol=*/0, /*usockvec=*/0ul);
// openat$auto_mtd_fops_mtdchar arguments: [
// fd: const = 0xffffffffffffff9c (8 bytes)
// file: ptr[in, buffer] {
// buffer: {2f 64 65 76 2f 6d 74 64 30 72 6f 00} (length 0xc)
// }
// flags: open_flags = 0x0 (4 bytes)
// mode: const = 0x0 (2 bytes)
// ]
// returns fd_mtd_fops_mtdchar
memcpy((void*)0x200000000140, "/dev/mtd0ro\000", 12);
res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000140ul, /*flags=*/0, /*mode=*/0);
if (res != -1)
r[1] = res;
// ioctl$auto_BLKPG2 arguments: [
// fd: fd_mtd_fops_mtdchar (resource)
// cmd: const = 0x1269 (4 bytes)
// arg: const = 0x0 (8 bytes)
// ]
inject_fault(8);
syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x1269, /*arg=*/0ul);
return 0;
}
]