map[SimplifiedCRepro:// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <fcntl.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>
static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2)
{
if (a0 == 0xc || a0 == 0xb) {
char buf[128];
sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2);
return open(buf, O_RDWR, 0);
} else {
unsigned long nb = a1;
char buf[1024];
char* hash;
strncpy(buf, (char*)a0, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = 0;
while ((hash = strchr(buf, '#'))) {
*hash = '0' + (char)(nb % 10);
nb /= 10;
}
return open(buf, a2 & ~O_CREAT, 0);
}
}
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;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_open_dev$ndb arguments: [
// dev: ptr[in, buffer] {
// buffer: {2f 64 65 76 2f 6e 62 64 23 00} (length 0xa)
// }
// id: proc = 0x0 (8 bytes)
// flags: open_flags = 0x0 (8 bytes)
// ]
// returns fd_nbd
memcpy((void*)0x200000000000, "/dev/nbd#\000", 10);
res = -1;
res = syz_open_dev(/*dev=*/0x200000000000, /*id=*/0, /*flags=*/0);
if (res != -1)
r[0] = res;
// socketpair$nbd arguments: [
// domain: const = 0x1 (8 bytes)
// type: const = 0x1 (8 bytes)
// proto: const = 0x0 (4 bytes)
// fds: ptr[out, nbd_sock_pair] {
// nbd_sock_pair {
// client: sock_nbd_client (resource)
// server: sock_nbd_server (resource)
// }
// }
// ]
res = syscall(__NR_socketpair, /*domain=*/1ul, /*type=*/1ul, /*proto=*/0, /*fds=*/0x200000000040ul);
if (res != -1)
r[1] = *(uint32_t*)0x200000000040;
// ioctl$NBD_SET_SIZE_BLOCKS arguments: [
// fd: fd_nbd (resource)
// cmd: const = 0xab07 (4 bytes)
// arg: intptr = 0x83 (8 bytes)
// ]
syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xab07, /*arg=*/0x83ul);
// ioctl$NBD_SET_SOCK arguments: [
// fd: fd_nbd (resource)
// cmd: const = 0xab00 (4 bytes)
// arg: sock_nbd_client (resource)
// ]
syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xab00, /*arg=*/r[1]);
// ioctl$NBD_DO_IT arguments: [
// fd: fd_nbd (resource)
// cmd: const = 0xab03 (4 bytes)
// ]
syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xab03, 0);
return 0;
}
]