// https://syzkaller.appspot.com/bug?id=9127ca62fb1d66ce49803077aa1c2f5c19941b47
// autogenerated by syzkaller (https://github.com/google/syzkaller)

#define _GNU_SOURCE

#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sched.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 <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/swap.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

#include <linux/capability.h>
#include <linux/falloc.h>
#include <linux/loop.h>
#include <linux/net.h>

#ifndef __NR_memfd_create
#define __NR_memfd_create 319
#endif

static unsigned long long procid;

static void sleep_ms(uint64_t ms)
{
  usleep(ms * 1000);
}

static uint64_t current_time_ms(void)
{
  struct timespec ts;
  if (clock_gettime(CLOCK_MONOTONIC, &ts))
    exit(1);
  return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}

static void use_temporary_dir(void)
{
  char tmpdir_template[] = "./syzkaller.XXXXXX";
  char* tmpdir = mkdtemp(tmpdir_template);
  if (!tmpdir)
    exit(1);
  if (chmod(tmpdir, 0777))
    exit(1);
  if (chdir(tmpdir))
    exit(1);
}

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 runcmdline(char* cmdline)
{
  int ret = system(cmdline);
  if (ret) {
  }
  return ret;
}

#define MAX_FDS 30

//% This code is derived from puff.{c,h}, found in the zlib development. The
//% original files come with the following copyright notice:

//% Copyright (C) 2002-2013 Mark Adler, all rights reserved
//% version 2.3, 21 Jan 2013
//% This software is provided 'as-is', without any express or implied
//% warranty.  In no event will the author be held liable for any damages
//% arising from the use of this software.
//% Permission is granted to anyone to use this software for any purpose,
//% including commercial applications, and to alter it and redistribute it
//% freely, subject to the following restrictions:
//% 1. The origin of this software must not be misrepresented; you must not
//%    claim that you wrote the original software. If you use this software
//%    in a product, an acknowledgment in the product documentation would be
//%    appreciated but is not required.
//% 2. Altered source versions must be plainly marked as such, and must not be
//%    misrepresented as being the original software.
//% 3. This notice may not be removed or altered from any source distribution.
//% Mark Adler    madler@alumni.caltech.edu

//% BEGIN CODE DERIVED FROM puff.{c,h}

#define MAXBITS 15
#define MAXLCODES 286
#define MAXDCODES 30
#define MAXCODES (MAXLCODES + MAXDCODES)
#define FIXLCODES 288

struct puff_state {
  unsigned char* out;
  unsigned long outlen;
  unsigned long outcnt;
  const unsigned char* in;
  unsigned long inlen;
  unsigned long incnt;
  int bitbuf;
  int bitcnt;
  jmp_buf env;
};
static int puff_bits(struct puff_state* s, int need)
{
  long val = s->bitbuf;
  while (s->bitcnt < need) {
    if (s->incnt == s->inlen)
      longjmp(s->env, 1);
    val |= (long)(s->in[s->incnt++]) << s->bitcnt;
    s->bitcnt += 8;
  }
  s->bitbuf = (int)(val >> need);
  s->bitcnt -= need;
  return (int)(val & ((1L << need) - 1));
}
static int puff_stored(struct puff_state* s)
{
  s->bitbuf = 0;
  s->bitcnt = 0;
  if (s->incnt + 4 > s->inlen)
    return 2;
  unsigned len = s->in[s->incnt++];
  len |= s->in[s->incnt++] << 8;
  if (s->in[s->incnt++] != (~len & 0xff) ||
      s->in[s->incnt++] != ((~len >> 8) & 0xff))
    return -2;
  if (s->incnt + len > s->inlen)
    return 2;
  if (s->outcnt + len > s->outlen)
    return 1;
  for (; len--; s->outcnt++, s->incnt++) {
    if (s->in[s->incnt])
      s->out[s->outcnt] = s->in[s->incnt];
  }
  return 0;
}
struct puff_huffman {
  short* count;
  short* symbol;
};
static int puff_decode(struct puff_state* s, const struct puff_huffman* h)
{
  int first = 0;
  int index = 0;
  int bitbuf = s->bitbuf;
  int left = s->bitcnt;
  int code = first = index = 0;
  int len = 1;
  short* next = h->count + 1;
  while (1) {
    while (left--) {
      code |= bitbuf & 1;
      bitbuf >>= 1;
      int count = *next++;
      if (code - count < first) {
        s->bitbuf = bitbuf;
        s->bitcnt = (s->bitcnt - len) & 7;
        return h->symbol[index + (code - first)];
      }
      index += count;
      first += count;
      first <<= 1;
      code <<= 1;
      len++;
    }
    left = (MAXBITS + 1) - len;
    if (left == 0)
      break;
    if (s->incnt == s->inlen)
      longjmp(s->env, 1);
    bitbuf = s->in[s->incnt++];
    if (left > 8)
      left = 8;
  }
  return -10;
}
static int puff_construct(struct puff_huffman* h, const short* length, int n)
{
  int len;
  for (len = 0; len <= MAXBITS; len++)
    h->count[len] = 0;
  int symbol;
  for (symbol = 0; symbol < n; symbol++)
    (h->count[length[symbol]])++;
  if (h->count[0] == n)
    return 0;
  int left = 1;
  for (len = 1; len <= MAXBITS; len++) {
    left <<= 1;
    left -= h->count[len];
    if (left < 0)
      return left;
  }
  short offs[MAXBITS + 1];
  offs[1] = 0;
  for (len = 1; len < MAXBITS; len++)
    offs[len + 1] = offs[len] + h->count[len];
  for (symbol = 0; symbol < n; symbol++)
    if (length[symbol] != 0)
      h->symbol[offs[length[symbol]]++] = symbol;
  return left;
}
static int puff_codes(struct puff_state* s, const struct puff_huffman* lencode,
                      const struct puff_huffman* distcode)
{
  static const short lens[29] = {3,  4,  5,  6,   7,   8,   9,   10,  11, 13,
                                 15, 17, 19, 23,  27,  31,  35,  43,  51, 59,
                                 67, 83, 99, 115, 131, 163, 195, 227, 258};
  static const short lext[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2,
                                 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
  static const short dists[30] = {
      1,    2,    3,    4,    5,    7,    9,    13,    17,    25,
      33,   49,   65,   97,   129,  193,  257,  385,   513,   769,
      1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577};
  static const short dext[30] = {0, 0, 0,  0,  1,  1,  2,  2,  3,  3,
                                 4, 4, 5,  5,  6,  6,  7,  7,  8,  8,
                                 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
  int symbol;
  do {
    symbol = puff_decode(s, lencode);
    if (symbol < 0)
      return symbol;
    if (symbol < 256) {
      if (s->outcnt == s->outlen)
        return 1;
      if (symbol)
        s->out[s->outcnt] = symbol;
      s->outcnt++;
    } else if (symbol > 256) {
      symbol -= 257;
      if (symbol >= 29)
        return -10;
      int len = lens[symbol] + puff_bits(s, lext[symbol]);
      symbol = puff_decode(s, distcode);
      if (symbol < 0)
        return symbol;
      unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]);
      if (dist > s->outcnt)
        return -11;
      if (s->outcnt + len > s->outlen)
        return 1;
      while (len--) {
        if (dist <= s->outcnt && s->out[s->outcnt - dist])
          s->out[s->outcnt] = s->out[s->outcnt - dist];
        s->outcnt++;
      }
    }
  } while (symbol != 256);
  return 0;
}
static int puff_fixed(struct puff_state* s)
{
  static int virgin = 1;
  static short lencnt[MAXBITS + 1], lensym[FIXLCODES];
  static short distcnt[MAXBITS + 1], distsym[MAXDCODES];
  static struct puff_huffman lencode, distcode;
  if (virgin) {
    lencode.count = lencnt;
    lencode.symbol = lensym;
    distcode.count = distcnt;
    distcode.symbol = distsym;
    short lengths[FIXLCODES];
    int symbol;
    for (symbol = 0; symbol < 144; symbol++)
      lengths[symbol] = 8;
    for (; symbol < 256; symbol++)
      lengths[symbol] = 9;
    for (; symbol < 280; symbol++)
      lengths[symbol] = 7;
    for (; symbol < FIXLCODES; symbol++)
      lengths[symbol] = 8;
    puff_construct(&lencode, lengths, FIXLCODES);
    for (symbol = 0; symbol < MAXDCODES; symbol++)
      lengths[symbol] = 5;
    puff_construct(&distcode, lengths, MAXDCODES);
    virgin = 0;
  }
  return puff_codes(s, &lencode, &distcode);
}
static int puff_dynamic(struct puff_state* s)
{
  static const short order[19] = {16, 17, 18, 0, 8,  7, 9,  6, 10, 5,
                                  11, 4,  12, 3, 13, 2, 14, 1, 15};
  int nlen = puff_bits(s, 5) + 257;
  int ndist = puff_bits(s, 5) + 1;
  int ncode = puff_bits(s, 4) + 4;
  if (nlen > MAXLCODES || ndist > MAXDCODES)
    return -3;
  short lengths[MAXCODES];
  int index;
  for (index = 0; index < ncode; index++)
    lengths[order[index]] = puff_bits(s, 3);
  for (; index < 19; index++)
    lengths[order[index]] = 0;
  short lencnt[MAXBITS + 1], lensym[MAXLCODES];
  struct puff_huffman lencode = {lencnt, lensym};
  int err = puff_construct(&lencode, lengths, 19);
  if (err != 0)
    return -4;
  index = 0;
  while (index < nlen + ndist) {
    int symbol;
    int len;
    symbol = puff_decode(s, &lencode);
    if (symbol < 0)
      return symbol;
    if (symbol < 16)
      lengths[index++] = symbol;
    else {
      len = 0;
      if (symbol == 16) {
        if (index == 0)
          return -5;
        len = lengths[index - 1];
        symbol = 3 + puff_bits(s, 2);
      } else if (symbol == 17)
        symbol = 3 + puff_bits(s, 3);
      else
        symbol = 11 + puff_bits(s, 7);
      if (index + symbol > nlen + ndist)
        return -6;
      while (symbol--)
        lengths[index++] = len;
    }
  }
  if (lengths[256] == 0)
    return -9;
  err = puff_construct(&lencode, lengths, nlen);
  if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1]))
    return -7;
  short distcnt[MAXBITS + 1], distsym[MAXDCODES];
  struct puff_huffman distcode = {distcnt, distsym};
  err = puff_construct(&distcode, lengths + nlen, ndist);
  if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1]))
    return -8;
  return puff_codes(s, &lencode, &distcode);
}
static int puff(unsigned char* dest, unsigned long* destlen,
                const unsigned char* source, unsigned long sourcelen)
{
  struct puff_state s = {
      .out = dest,
      .outlen = *destlen,
      .outcnt = 0,
      .in = source,
      .inlen = sourcelen,
      .incnt = 0,
      .bitbuf = 0,
      .bitcnt = 0,
  };
  int err;
  if (setjmp(s.env) != 0)
    err = 2;
  else {
    int last;
    do {
      last = puff_bits(&s, 1);
      int type = puff_bits(&s, 2);
      err = type == 0 ? puff_stored(&s)
                      : (type == 1 ? puff_fixed(&s)
                                   : (type == 2 ? puff_dynamic(&s) : -1));
      if (err != 0)
        break;
    } while (!last);
  }
  *destlen = s.outcnt;
  return err;
}

//% END CODE DERIVED FROM puff.{c,h}

#define ZLIB_HEADER_WIDTH 2

static int puff_zlib_to_file(const unsigned char* source,
                             unsigned long sourcelen, int dest_fd)
{
  if (sourcelen < ZLIB_HEADER_WIDTH)
    return 0;
  source += ZLIB_HEADER_WIDTH;
  sourcelen -= ZLIB_HEADER_WIDTH;
  const unsigned long max_destlen = 132 << 20;
  void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ,
                   MAP_PRIVATE | MAP_ANON, -1, 0);
  if (ret == MAP_FAILED)
    return -1;
  unsigned char* dest = (unsigned char*)ret;
  unsigned long destlen = max_destlen;
  int err = puff(dest, &destlen, source, sourcelen);
  if (err) {
    munmap(dest, max_destlen);
    errno = -err;
    return -1;
  }
  if (write(dest_fd, dest, destlen) != (ssize_t)destlen) {
    munmap(dest, max_destlen);
    return -1;
  }
  return munmap(dest, max_destlen);
}

static int setup_loop_device(unsigned char* data, unsigned long size,
                             const char* loopname, int* loopfd_p)
{
  int err = 0, loopfd = -1;
  int memfd = syscall(__NR_memfd_create, "syzkaller", 0);
  if (memfd == -1) {
    err = errno;
    goto error;
  }
  if (puff_zlib_to_file(data, size, memfd)) {
    err = errno;
    goto error_close_memfd;
  }
  loopfd = open(loopname, O_RDWR);
  if (loopfd == -1) {
    err = errno;
    goto error_close_memfd;
  }
  if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
    if (errno != EBUSY) {
      err = errno;
      goto error_close_loop;
    }
    ioctl(loopfd, LOOP_CLR_FD, 0);
    usleep(1000);
    if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
      err = errno;
      goto error_close_loop;
    }
  }
  close(memfd);
  *loopfd_p = loopfd;
  return 0;

error_close_loop:
  close(loopfd);
error_close_memfd:
  close(memfd);
error:
  errno = err;
  return -1;
}

static void reset_loop_device(const char* loopname)
{
  int loopfd = open(loopname, O_RDWR);
  if (loopfd == -1) {
    return;
  }
  if (ioctl(loopfd, LOOP_CLR_FD, 0)) {
  }
  close(loopfd);
}

static long syz_mount_image(volatile long fsarg, volatile long dir,
                            volatile long flags, volatile long optsarg,
                            volatile long change_dir,
                            volatile unsigned long size, volatile long image)
{
  unsigned char* data = (unsigned char*)image;
  int res = -1, err = 0, need_loop_device = !!size;
  char* mount_opts = (char*)optsarg;
  char* target = (char*)dir;
  char* fs = (char*)fsarg;
  char* source = NULL;
  char loopname[64];
  if (need_loop_device) {
    int loopfd;
    memset(loopname, 0, sizeof(loopname));
    snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
    if (setup_loop_device(data, size, loopname, &loopfd) == -1)
      return -1;
    close(loopfd);
    source = loopname;
  }
  mkdir(target, 0777);
  char opts[256];
  memset(opts, 0, sizeof(opts));
  if (strlen(mount_opts) > (sizeof(opts) - 32)) {
  }
  strncpy(opts, mount_opts, sizeof(opts) - 32);
  if (strcmp(fs, "iso9660") == 0) {
    flags |= MS_RDONLY;
  } else if (strncmp(fs, "ext", 3) == 0) {
    bool has_remount_ro = false;
    char* remount_ro_start = strstr(opts, "errors=remount-ro");
    if (remount_ro_start != NULL) {
      char after = *(remount_ro_start + strlen("errors=remount-ro"));
      char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1);
      has_remount_ro = ((before == '\0' || before == ',') &&
                        (after == '\0' || after == ','));
    }
    if (strstr(opts, "errors=panic") || !has_remount_ro)
      strcat(opts, ",errors=continue");
  } else if (strcmp(fs, "xfs") == 0) {
    strcat(opts, ",nouuid");
  }
  res = mount(source, target, fs, flags, opts);
  if (res == -1) {
    err = errno;
    goto error_clear_loop;
  }
  res = open(target, O_RDONLY | O_DIRECTORY);
  if (res == -1) {
    err = errno;
    goto error_clear_loop;
  }
  if (change_dir) {
    res = chdir(target);
    if (res == -1) {
      err = errno;
    }
  }

error_clear_loop:
  if (need_loop_device)
    reset_loop_device(loopname);
  errno = err;
  return res;
}

#define XT_TABLE_SIZE 1536
#define XT_MAX_ENTRIES 10

struct xt_counters {
  uint64_t pcnt, bcnt;
};

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;
  uint64_t entrytable[XT_TABLE_SIZE / sizeof(uint64_t)];
};

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;
  uint64_t entrytable[XT_TABLE_SIZE / sizeof(uint64_t)];
};

struct ipt_table_desc {
  const char* name;
  struct ipt_getinfo info;
  struct ipt_replace replace;
};

static struct ipt_table_desc ipv4_tables[] = {
    {.name = "filter"}, {.name = "nat"},      {.name = "mangle"},
    {.name = "raw"},    {.name = "security"},
};

static struct ipt_table_desc ipv6_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)

struct arpt_getinfo {
  char name[32];
  unsigned int valid_hooks;
  unsigned int hook_entry[3];
  unsigned int underflow[3];
  unsigned int num_entries;
  unsigned int size;
};

struct arpt_get_entries {
  char name[32];
  unsigned int size;
  uint64_t entrytable[XT_TABLE_SIZE / sizeof(uint64_t)];
};

struct arpt_replace {
  char name[32];
  unsigned int valid_hooks;
  unsigned int num_entries;
  unsigned int size;
  unsigned int hook_entry[3];
  unsigned int underflow[3];
  unsigned int num_counters;
  struct xt_counters* counters;
  uint64_t entrytable[XT_TABLE_SIZE / sizeof(uint64_t)];
};

struct arpt_table_desc {
  const char* name;
  struct arpt_getinfo info;
  struct arpt_replace replace;
};

static struct arpt_table_desc arpt_tables[] = {
    {.name = "filter"},
};

#define ARPT_BASE_CTL 96
#define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL)
#define ARPT_SO_GET_INFO (ARPT_BASE_CTL)
#define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1)

static void checkpoint_iptables(struct ipt_table_desc* tables, int num_tables,
                                int family, int level)
{
  int fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
  if (fd == -1) {
    switch (errno) {
    case EAFNOSUPPORT:
    case ENOPROTOOPT:
    case ENOENT:
      return;
    }
    exit(1);
  }
  for (int i = 0; i < num_tables; i++) {
    struct ipt_table_desc* table = &tables[i];
    strcpy(table->info.name, table->name);
    strcpy(table->replace.name, table->name);
    socklen_t optlen = sizeof(table->info);
    if (getsockopt(fd, level, IPT_SO_GET_INFO, &table->info, &optlen)) {
      switch (errno) {
      case EPERM:
      case ENOENT:
      case ENOPROTOOPT:
        continue;
      }
      exit(1);
    }
    if (table->info.size > sizeof(table->replace.entrytable))
      exit(1);
    if (table->info.num_entries > XT_MAX_ENTRIES)
      exit(1);
    struct ipt_get_entries entries;
    memset(&entries, 0, sizeof(entries));
    strcpy(entries.name, table->name);
    entries.size = table->info.size;
    optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
    if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
      exit(1);
    table->replace.valid_hooks = table->info.valid_hooks;
    table->replace.num_entries = table->info.num_entries;
    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, entries.entrytable, table->info.size);
  }
  close(fd);
}

static void reset_iptables(struct ipt_table_desc* tables, int num_tables,
                           int family, int level)
{
  int fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
  if (fd == -1) {
    switch (errno) {
    case EAFNOSUPPORT:
    case ENOPROTOOPT:
    case ENOENT:
      return;
    }
    exit(1);
  }
  for (int i = 0; i < num_tables; i++) {
    struct ipt_table_desc* table = &tables[i];
    if (table->info.valid_hooks == 0)
      continue;
    struct ipt_getinfo info;
    memset(&info, 0, sizeof(info));
    strcpy(info.name, table->name);
    socklen_t optlen = sizeof(info);
    if (getsockopt(fd, level, IPT_SO_GET_INFO, &info, &optlen))
      exit(1);
    if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
      struct ipt_get_entries entries;
      memset(&entries, 0, sizeof(entries));
      strcpy(entries.name, table->name);
      entries.size = table->info.size;
      optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
      if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
        exit(1);
      if (memcmp(table->replace.entrytable, entries.entrytable,
                 table->info.size) == 0)
        continue;
    }
    struct xt_counters counters[XT_MAX_ENTRIES];
    table->replace.num_counters = info.num_entries;
    table->replace.counters = counters;
    optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
             table->replace.size;
    if (setsockopt(fd, level, IPT_SO_SET_REPLACE, &table->replace, optlen))
      exit(1);
  }
  close(fd);
}

static void checkpoint_arptables(void)
{
  int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (fd == -1) {
    switch (errno) {
    case EAFNOSUPPORT:
    case ENOPROTOOPT:
    case ENOENT:
      return;
    }
    exit(1);
  }
  for (unsigned i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
    struct arpt_table_desc* table = &arpt_tables[i];
    strcpy(table->info.name, table->name);
    strcpy(table->replace.name, table->name);
    socklen_t optlen = sizeof(table->info);
    if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &table->info, &optlen)) {
      switch (errno) {
      case EPERM:
      case ENOENT:
      case ENOPROTOOPT:
        continue;
      }
      exit(1);
    }
    if (table->info.size > sizeof(table->replace.entrytable))
      exit(1);
    if (table->info.num_entries > XT_MAX_ENTRIES)
      exit(1);
    struct arpt_get_entries entries;
    memset(&entries, 0, sizeof(entries));
    strcpy(entries.name, table->name);
    entries.size = table->info.size;
    optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
    if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
      exit(1);
    table->replace.valid_hooks = table->info.valid_hooks;
    table->replace.num_entries = table->info.num_entries;
    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, entries.entrytable, table->info.size);
  }
  close(fd);
}

static void reset_arptables()
{
  int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (fd == -1) {
    switch (errno) {
    case EAFNOSUPPORT:
    case ENOPROTOOPT:
    case ENOENT:
      return;
    }
    exit(1);
  }
  for (unsigned i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
    struct arpt_table_desc* table = &arpt_tables[i];
    if (table->info.valid_hooks == 0)
      continue;
    struct arpt_getinfo info;
    memset(&info, 0, sizeof(info));
    strcpy(info.name, table->name);
    socklen_t optlen = sizeof(info);
    if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &info, &optlen))
      exit(1);
    if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
      struct arpt_get_entries entries;
      memset(&entries, 0, sizeof(entries));
      strcpy(entries.name, table->name);
      entries.size = table->info.size;
      optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
      if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
        exit(1);
      if (memcmp(table->replace.entrytable, entries.entrytable,
                 table->info.size) == 0)
        continue;
    } else {
    }
    struct xt_counters counters[XT_MAX_ENTRIES];
    table->replace.num_counters = info.num_entries;
    table->replace.counters = counters;
    optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
             table->replace.size;
    if (setsockopt(fd, SOL_IP, ARPT_SO_SET_REPLACE, &table->replace, optlen))
      exit(1);
  }
  close(fd);
}

#define NF_BR_NUMHOOKS 6
#define EBT_TABLE_MAXNAMELEN 32
#define EBT_CHAIN_MAXNAMELEN 32
#define EBT_BASE_CTL 128
#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
#define EBT_SO_GET_INFO (EBT_BASE_CTL)
#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO + 1)
#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES + 1)
#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO + 1)

struct ebt_replace {
  char name[EBT_TABLE_MAXNAMELEN];
  unsigned int valid_hooks;
  unsigned int nentries;
  unsigned int entries_size;
  struct ebt_entries* hook_entry[NF_BR_NUMHOOKS];
  unsigned int num_counters;
  struct ebt_counter* counters;
  char* entries;
};

struct ebt_entries {
  unsigned int distinguisher;
  char name[EBT_CHAIN_MAXNAMELEN];
  unsigned int counter_offset;
  int policy;
  unsigned int nentries;
  char data[0] __attribute__((aligned(__alignof__(struct ebt_replace))));
};

struct ebt_table_desc {
  const char* name;
  struct ebt_replace replace;
  char entrytable[XT_TABLE_SIZE];
};

static struct ebt_table_desc ebt_tables[] = {
    {.name = "filter"},
    {.name = "nat"},
    {.name = "broute"},
};

static void checkpoint_ebtables(void)
{
  int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (fd == -1) {
    switch (errno) {
    case EAFNOSUPPORT:
    case ENOPROTOOPT:
    case ENOENT:
      return;
    }
    exit(1);
  }
  for (size_t i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
    struct ebt_table_desc* table = &ebt_tables[i];
    strcpy(table->replace.name, table->name);
    socklen_t optlen = sizeof(table->replace);
    if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_INFO, &table->replace,
                   &optlen)) {
      switch (errno) {
      case EPERM:
      case ENOENT:
      case ENOPROTOOPT:
        continue;
      }
      exit(1);
    }
    if (table->replace.entries_size > sizeof(table->entrytable))
      exit(1);
    table->replace.num_counters = 0;
    table->replace.entries = table->entrytable;
    optlen = sizeof(table->replace) + table->replace.entries_size;
    if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_ENTRIES, &table->replace,
                   &optlen))
      exit(1);
  }
  close(fd);
}

static void reset_ebtables()
{
  int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (fd == -1) {
    switch (errno) {
    case EAFNOSUPPORT:
    case ENOPROTOOPT:
    case ENOENT:
      return;
    }
    exit(1);
  }
  for (unsigned i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
    struct ebt_table_desc* table = &ebt_tables[i];
    if (table->replace.valid_hooks == 0)
      continue;
    struct ebt_replace replace;
    memset(&replace, 0, sizeof(replace));
    strcpy(replace.name, table->name);
    socklen_t optlen = sizeof(replace);
    if (getsockopt(fd, SOL_IP, EBT_SO_GET_INFO, &replace, &optlen))
      exit(1);
    replace.num_counters = 0;
    table->replace.entries = 0;
    for (unsigned h = 0; h < NF_BR_NUMHOOKS; h++)
      table->replace.hook_entry[h] = 0;
    if (memcmp(&table->replace, &replace, sizeof(table->replace)) == 0) {
      char entrytable[XT_TABLE_SIZE];
      memset(&entrytable, 0, sizeof(entrytable));
      replace.entries = entrytable;
      optlen = sizeof(replace) + replace.entries_size;
      if (getsockopt(fd, SOL_IP, EBT_SO_GET_ENTRIES, &replace, &optlen))
        exit(1);
      if (memcmp(table->entrytable, entrytable, replace.entries_size) == 0)
        continue;
    }
    for (unsigned j = 0, h = 0; h < NF_BR_NUMHOOKS; h++) {
      if (table->replace.valid_hooks & (1 << h)) {
        table->replace.hook_entry[h] =
            (struct ebt_entries*)table->entrytable + j;
        j++;
      }
    }
    table->replace.entries = table->entrytable;
    optlen = sizeof(table->replace) + table->replace.entries_size;
    if (setsockopt(fd, SOL_IP, EBT_SO_SET_ENTRIES, &table->replace, optlen))
      exit(1);
  }
  close(fd);
}

static void checkpoint_net_namespace(void)
{
  checkpoint_ebtables();
  checkpoint_arptables();
  checkpoint_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
                      AF_INET, SOL_IP);
  checkpoint_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
                      AF_INET6, SOL_IPV6);
}

static void reset_net_namespace(void)
{
  reset_ebtables();
  reset_arptables();
  reset_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
                 AF_INET, SOL_IP);
  reset_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
                 AF_INET6, SOL_IPV6);
}

static void setup_common()
{
  if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
  }
}

static void setup_binderfs()
{
  if (mkdir("/dev/binderfs", 0777)) {
  }
  if (mount("binder", "/dev/binderfs", "binder", 0, NULL)) {
  }
}

static void loop();

static void sandbox_common()
{
  prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  setsid();
  struct rlimit rlim;
  rlim.rlim_cur = rlim.rlim_max = (200 << 20);
  setrlimit(RLIMIT_AS, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 32 << 20;
  setrlimit(RLIMIT_MEMLOCK, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 136 << 20;
  setrlimit(RLIMIT_FSIZE, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 1 << 20;
  setrlimit(RLIMIT_STACK, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 128 << 20;
  setrlimit(RLIMIT_CORE, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 256;
  setrlimit(RLIMIT_NOFILE, &rlim);
  if (unshare(CLONE_NEWNS)) {
  }
  if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
  }
  if (unshare(CLONE_NEWIPC)) {
  }
  if (unshare(0x02000000)) {
  }
  if (unshare(CLONE_NEWUTS)) {
  }
  if (unshare(CLONE_SYSVSEM)) {
  }
  typedef struct {
    const char* name;
    const char* value;
  } sysctl_t;
  static const sysctl_t sysctls[] = {
      {"/proc/sys/kernel/shmmax", "16777216"},
      {"/proc/sys/kernel/shmall", "536870912"},
      {"/proc/sys/kernel/shmmni", "1024"},
      {"/proc/sys/kernel/msgmax", "8192"},
      {"/proc/sys/kernel/msgmni", "1024"},
      {"/proc/sys/kernel/msgmnb", "1024"},
      {"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
  };
  unsigned i;
  for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
    write_file(sysctls[i].name, sysctls[i].value);
}

static int wait_for_loop(int pid)
{
  if (pid < 0)
    exit(1);
  int status = 0;
  while (waitpid(-1, &status, __WALL) != pid) {
  }
  return WEXITSTATUS(status);
}

static void drop_caps(void)
{
  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))
    exit(1);
  const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE);
  cap_data[0].effective &= ~drop;
  cap_data[0].permitted &= ~drop;
  cap_data[0].inheritable &= ~drop;
  if (syscall(SYS_capset, &cap_hdr, &cap_data))
    exit(1);
}

static int do_sandbox_none(void)
{
  if (unshare(CLONE_NEWPID)) {
  }
  int pid = fork();
  if (pid != 0)
    return wait_for_loop(pid);
  setup_common();
  sandbox_common();
  drop_caps();
  if (unshare(CLONE_NEWNET)) {
  }
  write_file("/proc/sys/net/ipv4/ping_group_range", "0 65535");
  setup_binderfs();
  loop();
  exit(1);
}

#define FS_IOC_SETFLAGS _IOW('f', 2, long)
static void remove_dir(const char* dir)
{
  int iter = 0;
  DIR* dp = 0;
retry:
  const int umount_flags = MNT_FORCE | UMOUNT_NOFOLLOW;
  while (umount2(dir, umount_flags) == 0) {
  }
  dp = opendir(dir);
  if (dp == NULL) {
    if (errno == EMFILE) {
      exit(1);
    }
    exit(1);
  }
  struct dirent* ep = 0;
  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);
    while (umount2(filename, umount_flags) == 0) {
    }
    struct stat st;
    if (lstat(filename, &st))
      exit(1);
    if (S_ISDIR(st.st_mode)) {
      remove_dir(filename);
      continue;
    }
    int i;
    for (i = 0;; i++) {
      if (unlink(filename) == 0)
        break;
      if (errno == EPERM) {
        int fd = open(filename, O_RDONLY);
        if (fd != -1) {
          long flags = 0;
          if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
          }
          close(fd);
          continue;
        }
      }
      if (errno == EROFS) {
        break;
      }
      if (errno != EBUSY || i > 100)
        exit(1);
      if (umount2(filename, umount_flags))
        exit(1);
    }
  }
  closedir(dp);
  for (int i = 0;; i++) {
    if (rmdir(dir) == 0)
      break;
    if (i < 100) {
      if (errno == EPERM) {
        int fd = open(dir, O_RDONLY);
        if (fd != -1) {
          long flags = 0;
          if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
          }
          close(fd);
          continue;
        }
      }
      if (errno == EROFS) {
        break;
      }
      if (errno == EBUSY) {
        if (umount2(dir, umount_flags))
          exit(1);
        continue;
      }
      if (errno == ENOTEMPTY) {
        if (iter < 100) {
          iter++;
          goto retry;
        }
      }
    }
    exit(1);
  }
}

static void kill_and_wait(int pid, int* status)
{
  kill(-pid, SIGKILL);
  kill(pid, SIGKILL);
  for (int i = 0; i < 100; i++) {
    if (waitpid(-1, status, WNOHANG | __WALL) == pid)
      return;
    usleep(1000);
  }
  DIR* dir = opendir("/sys/fs/fuse/connections");
  if (dir) {
    for (;;) {
      struct dirent* ent = readdir(dir);
      if (!ent)
        break;
      if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
        continue;
      char abort[300];
      snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
               ent->d_name);
      int fd = open(abort, O_WRONLY);
      if (fd == -1) {
        continue;
      }
      if (write(fd, abort, 1) < 0) {
      }
      close(fd);
    }
    closedir(dir);
  } else {
  }
  while (waitpid(-1, status, __WALL) != pid) {
  }
}

static void setup_loop()
{
  checkpoint_net_namespace();
}

static void reset_loop()
{
  char buf[64];
  snprintf(buf, sizeof(buf), "/dev/loop%llu", procid);
  int loopfd = open(buf, O_RDWR);
  if (loopfd != -1) {
    ioctl(loopfd, LOOP_CLR_FD, 0);
    close(loopfd);
  }
  reset_net_namespace();
}

static void setup_test()
{
  prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  setpgrp();
  write_file("/proc/self/oom_score_adj", "1000");
  if (symlink("/dev/binderfs", "./binderfs")) {
  }
}

static void close_fds()
{
  for (int fd = 3; fd < MAX_FDS; fd++)
    close(fd);
}

static void setup_binfmt_misc()
{
  if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0)) {
  }
  write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:");
  write_file("/proc/sys/fs/binfmt_misc/register",
             ":syz1:M:1:\x02::./file0:POC");
}

#define SWAP_FILE "./swap-file"
#define SWAP_FILE_SIZE (128 * 1000 * 1000)

static void setup_swap()
{
  swapoff(SWAP_FILE);
  unlink(SWAP_FILE);
  int fd = open(SWAP_FILE, O_CREAT | O_WRONLY | O_CLOEXEC, 0600);
  if (fd == -1) {
    exit(1);
    return;
  }
  fallocate(fd, FALLOC_FL_ZERO_RANGE, 0, SWAP_FILE_SIZE);
  close(fd);
  char cmdline[64];
  sprintf(cmdline, "mkswap %s", SWAP_FILE);
  if (runcmdline(cmdline)) {
    exit(1);
    return;
  }
  if (swapon(SWAP_FILE, SWAP_FLAG_PREFER) == 1) {
    exit(1);
    return;
  }
}

static void execute_one(void);

#define WAIT_FLAGS __WALL

static void loop(void)
{
  setup_loop();
  int iter = 0;
  for (;; iter++) {
    char cwdbuf[32];
    sprintf(cwdbuf, "./%d", iter);
    if (mkdir(cwdbuf, 0777))
      exit(1);
    reset_loop();
    int pid = fork();
    if (pid < 0)
      exit(1);
    if (pid == 0) {
      if (chdir(cwdbuf))
        exit(1);
      setup_test();
      execute_one();
      close_fds();
      exit(0);
    }
    int status = 0;
    uint64_t start = current_time_ms();
    for (;;) {
      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
        break;
      sleep_ms(1);
      if (current_time_ms() - start < 5000)
        continue;
      kill_and_wait(pid, &status);
      break;
    }
    remove_dir(cwdbuf);
  }
}

uint64_t r[1] = {0xffffffffffffffff};

void execute_one(void)
{
  intptr_t res = 0;
  memcpy((void*)0x20000080, "ext3\000", 5);
  memcpy((void*)0x20000440, "./file0\000", 8);
  memcpy((void*)0x20000740, "jqfmt=vfsold,resgid=", 20);
  sprintf((char*)0x20000754, "0x%016llx", (long long)0xee00);
  memcpy(
      (void*)0x20000766,
      "\x2c\x6e\x6f\x62\x6c\x6f\x63\x6b\x5f\x76\x61\x6c\x69\x64\x69\x74\x79\x2c"
      "\x6e\x6f\x6c\x6f\x61\x64\x2c\x64\x61\x74\x61\x5f\x65\x72\x72\x3d\x69\x67"
      "\x6e\x6f\x72\x65\x2c\x75\x73\x72\x6a\x71\x75\x6f\x74\x61\x3d\x2c\x69\x6e"
      "\x69\x74\x5f\x69\x74\x61\x62\x6c\x65\x3d\x30\x78\x30\x30\x30\x30\x30\x30"
      "\x30\x30\x30\x30\x30\x30\x30\x36\x30\x31\x2c\x6d\x61\x78\x5f\x64\x69\x72"
      "\x5f\x73\x69\x7a\x65\x5f\x6b\x62\x3d\x30\x78\x30\x30\x30\x30\x30\x30\x30"
      "\x30\x30\x30\x30\x30\x30\x30\x30\x33\x2c\x00\x00\x80\xa2\xa1\x62\x24\x2f"
      "\x5f\x14\xe2\x7c\xd9\x03\xe7\x52\xde\xaf\x06\x90\x45\xd4\xf4\xb0\x73\xf9"
      "\xcf\xa1\x8c\x6c\x20\x15\x8a\xe1\x3a\x24\xe7\x9b\x65\x4e\xe8\x58\x8b\x67"
      "\x7e\x3b\x0c\xe2\xca\xf6\x52\xe5\xc6\x43\x33\xf7\x47\x21\xb5\xa3\x6a\x10"
      "\x45\xa0\x1e\x15\xc7\xa9\x29\x14\x6b\x16\x2c\x26\xa0\xe6\x1b\x81\x39\x35"
      "\xe3\xce\x71\xa2\x19\x54\xd9\xdc\x4e\x39\x70\x1c\x78\xe3\x89\x27\xc9\xdb"
      "\x9d\x9b\xc3\xaf\x4d\x44\x7a\xa1\x98\x1b\xe8\xf7\x65\x3c\x75\x0a\x90\x3c"
      "\x6f\x7c\x71\xa0\x85\x66\x9f\x96\xee\xf6\x83\x05\x00\x6a\x96\xdd\x79\xc2"
      "\x21\x67\xdb\xa4\x98\x19\x72\xae\x5a\xae\x35\x5b\xe7\x8a\x01\x3f\xe2\x95"
      "\xc7\x82\x56\xa1\x45\xc3\xef\xe6\x94\x05\x76\xa6\x55\xda\xb6\xde\x92\xf1"
      "\xaa\xe8\xa9\xec\xf3\xb9\xb1\x7c\xfe\x50\x78\x24\x3c\xec\xdd\x4a\x7f\x8f"
      "\xaf\x2f\x8f\xb7\xb7\x27\x0f\xc9\x23\x4a\xf8\xa1\xc8\x6d\xc7\xf4\x0d\x65"
      "\xbf\x6d\x42\x47\xb9\x2f\x4c\x3f\xb6\xa3\x4d\xe9\x28\xce\xfa\x87\xf4\x0f"
      "\xc9\xb5\xfc\x3f\xf0\x51\x0d\xbe\x6c\xef\x81\x0c\xf4\x23\x0f\x3e\xee\x9e"
      "\x4b\x6a\x52\x76\x71\x72\x43\xeb\x92\xe3\x62\x8a\xdc\xc4\xf5\xa8\xc5\x19"
      "\x7c\x5e\x9c\x48\xdc\xbc\x52\xed\x01\x22\x8a\x54\x83\xe2",
      392);
  sprintf((char*)0x200008ee, "%020llu", (long long)-1);
  memcpy(
      (void*)0x20000940,
      "\x78\x9c\xec\xdc\xcf\x4f\x1c\x55\x1c\x00\xf0\xef\xec\xf2\xb3\xa5\x82\xb5"
      "\xfe\x28\xb6\x11\xad\x46\xe2\x0f\x28\xf4\x87\x3d\x78\xd1\x68\xe2\x41\x13"
      "\x13\x3d\x68\x3c\x11\xc0\x06\xbb\x2d\xa6\x60\x22\x0d\x51\xf4\x80\x47\x63"
      "\x62\xbc\x1a\x8f\xfe\x0b\x9e\xf4\x62\x8c\x27\x13\xaf\x7a\x37\x26\x8d\x72"
      "\x69\xf5\x60\xd6\xcc\xee\x0c\x5d\x60\x97\x2e\xb0\x65\xdb\xee\xe7\x93\x0c"
      "\xbc\x37\xf3\xe0\xbd\xef\xcc\xbc\xdd\x37\xef\xc1\x06\xd0\xb1\x46\xd2\x2f"
      "\x49\xc4\x40\x44\xfc\x16\x11\x83\xd5\xec\xc6\x02\x23\xd5\x6f\xd7\xd7\x96"
      "\xa7\xff\x59\x5b\x9e\x4e\xa2\x5c\x7e\xe3\xaf\xa4\x52\xee\xda\xda\xf2\x74"
      "\x5e\x34\xff\xb9\x83\xd5\x4c\xb9\x9c\xe5\x7b\xeb\xd4\xbb\xfa\x4e\xc4\x54"
      "\xa9\x34\x7b\x39\xcb\x8f\x2f\x5e\x7c\x7f\x7c\x61\xe9\xca\xb3\x73\x17\xa7"
      "\xce\xcf\x9e\x9f\xbd\x34\x79\xee\xdc\xe9\x53\xc7\x7b\xce\x4e\x9e\x69\x49"
      "\x9c\x69\x5c\xd7\x86\x3f\x9a\x3f\x76\xf4\x95\xb7\xbf\x78\xed\xc6\xfe\x81"
      "\xec\x7b\x6d\x1c\xad\x32\x52\x3d\xbb\x75\x3d\x51\xf9\xda\xd7\xea\x2a\xdb"
      "\xe6\x50\x4d\x3a\xe9\x6a\x63\x43\xd8\x91\x62\x44\xa4\x97\xab\xbb\xd2\xff"
      "\x07\xa3\x18\xfd\xeb\xc7\x06\xe3\xe5\x4f\xdb\xda\x38\xe0\x96\x2a\x97\xcb"
      "\xe5\x7a\xef\xcf\x99\x95\x32\x70\x17\x4b\xa2\xdd\x2d\x00\xda\x23\x7f\xa3"
      "\x4f\x9f\x7f\xf3\x6d\x9f\x86\x1e\xb7\x85\xab\x2f\x54\x1f\x80\xd2\xb8\xaf"
      "\x67\x5b\xf5\x48\x57\x14\xb2\x32\xdd\x9b\x9e\x6f\x5b\x69\x24\x22\xde\x5a"
      "\xf9\xf7\xeb\x74\x8b\x5b\x34\x0f\x01\x00\x50\xeb\xfb\x74\xfc\xf3\x4c\xbd"
      "\xf1\x5f\x21\x1e\xa8\x29\x77\x4f\xb6\x86\x32\x14\x11\xf7\x46\xc4\xe1\x88"
      "\xb8\x2f\x22\x8e\x44\xc4\xfd\x11\x95\xb2\x0f\x46\xc4\x43\x3b\xaa\xbd\x6f"
      "\xcb\x0a\xc9\x7e\x8f\x7f\xd2\xf1\xdf\xf3\xd9\xda\xd6\xc6\xf1\x5f\x3e\xfa"
      "\x8b\xa1\x62\x96\x3b\x54\x89\xbf\x3b\x79\x77\xae\x34\x7b\x32\x3b\x27\xa3"
      "\xd1\xdd\x9b\xe6\x27\xb6\xa9\xe3\x87\x97\x7e\xfd\xbc\xd1\xb1\xda\xf1\x5f"
      "\xba\xa5\xf5\xe7\x63\xc1\xac\x1d\x7f\x76\x6d\x9a\xa0\x9b\x99\x5a\x9c\xda"
      "\x4b\xcc\xb5\xae\x7e\x12\x31\xdc\x55\x2f\xfe\x24\xf2\x65\x9c\x24\x22\x8e"
      "\x46\xc4\xf0\x2e\xeb\x98\x7b\xea\xdb\x63\x8d\x8e\xdd\x3c\xfe\x6d\xb4\x60"
      "\x9d\xa9\xfc\x4d\xc4\x93\xd5\xeb\xbf\x12\x9b\xe2\xcf\x25\x0d\xd7\x27\x27"
      "\x9e\x3b\x3b\x79\x66\xbc\x2f\x4a\xb3\x27\xc7\xf3\xbb\x62\xab\x9f\x7f\x59"
      "\x7d\xbd\x51\xfd\x7b\x8a\xbf\x05\xd2\xeb\x7f\x20\xbb\xff\x37\xae\x46\xae"
      "\xc7\x3f\x94\xf4\x45\x2c\x7c\x75\xe5\x42\x65\xbd\x76\x61\xdb\x5f\xf7\xf7"
      "\xc6\xa7\xca\xaa\xd5\xdf\x3f\x6b\xd8\xa7\x77\x7b\xff\xf7\x24\x6f\x56\xd2"
      "\x3d\xd9\xbe\x0f\xa7\x16\x17\x2f\x4f\x44\xf4\x24\xaf\x6e\xdd\x3f\x79\xe3"
      "\x67\xf3\x7c\x5e\x3e\x8d\x7f\xf4\x44\xfd\xfe\x7f\xb8\xe6\x4c\x3c\x1c\x11"
      "\xe9\x4d\x7c\x7c\xfd\x37\x0d\x54\xda\xfe\x68\x44\x3c\x16\x11\x27\xb6\x39"
      "\x29\x3f\xbd\xf8\xf8\x7b\x79\x7a\xf3\x8a\x6f\xe3\xf8\xb7\x99\x95\x6f\xa1"
      "\x34\xfe\x99\xba\xaf\x7f\x35\xd7\x3f\x22\x16\x96\xf2\xeb\xff\x48\x9e\x58"
      "\x6a\x36\x51\xbc\xf0\xe3\x77\x8d\xea\x6f\xee\xfa\x9f\xae\xa4\x46\xb3\x3d"
      "\xcd\xbc\xfe\x35\xdb\xc0\xbd\x9c\x3b\x00\x00\x00\xb8\x53\x14\x2a\x33\x19"
      "\x49\x61\x6c\x3d\x5d\x28\x8c\x8d\x55\xff\x86\xff\x48\x1c\x28\x94\xe6\x17"
      "\x16\x9f\xee\x9f\xff\xe0\xd2\x4c\xf5\x6f\xe5\x87\xa2\xbb\x90\xcf\x74\x0d"
      "\xd6\xcc\x87\x4e\x64\x73\xc3\x79\x7e\x72\x53\xfe\x54\x36\x6f\xfc\x65\xb1"
      "\xbf\x92\x1f\x9b\x9e\x2f\xcd\xb4\x3b\x78\xe8\x70\x07\x1b\xf4\xff\xd4\x1f"
      "\xc5\x88\xf8\x6f\xcb\x74\x2e\x70\x37\xf1\xff\x5a\xd0\xb9\xf4\x7f\xe8\x5c"
      "\xfa\x3f\x74\x2e\xfd\x1f\x3a\x97\xfe\x0f\x9d\xab\x5e\xff\xff\xb8\x0d\xed"
      "\x00\xf6\x9f\xf7\x7f\xe8\x5c\xfa\x3f\x74\x2e\xfd\x1f\x3a\x97\xfe\x0f\x1d"
      "\xa9\xe1\xff\xc6\x17\x1a\x1f\xda\x9f\xc4\xce\x3f\x67\x40\x62\x3f\x13\x51"
      "\xb8\x2d\x9a\x71\x87\x26\x0a\xd1\x74\xe1\xae\xa6\x3f\xcc\x62\x97\x89\xde"
      "\xba\x87\xda\xfd\xca\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd0"
      "\x1a\xff\x07\x00\x00\xff\xff\x18\xa9\xe3\xf9",
      1109);
  syz_mount_image(
      /*fs=*/0x20000080, /*dir=*/0x20000440,
      /*flags=MS_I_VERSION|MS_SLAVE|MS_PRIVATE|MS_POSIXACL|MS_RELATIME|MS_NOSUID|0xc0400004*/
      0xc0ed0006, /*opts=*/0x20000740, /*chdir=*/0x7e, /*size=*/0x455,
      /*img=*/0x20000940);
  memcpy((void*)0x20000000, "./file0\000", 8);
  syscall(__NR_chdir, /*dir=*/0x20000000ul);
  memcpy((void*)0x20000040, "./bus\000", 6);
  syscall(__NR_creat, /*file=*/0x20000040ul, /*mode=*/0ul);
  memcpy((void*)0x20000380, "/dev/loop", 9);
  *(uint8_t*)0x20000389 = 0x30;
  *(uint8_t*)0x2000038a = 0;
  memcpy((void*)0x20000140, "./bus\000", 6);
  syscall(__NR_mount, /*src=*/0x20000380ul, /*dst=*/0x20000140ul, /*type=*/0ul,
          /*flags=MS_BIND*/ 0x1000ul, /*data=*/0ul);
  memcpy((void*)0x20000080, "./bus\000", 6);
  res = syscall(__NR_open, /*file=*/0x20000080ul,
                /*flags=O_SYNC|O_NOCTTY|O_DIRECT|O_CLOEXEC|O_RDWR*/ 0x185102ul,
                /*mode=*/0ul);
  if (res != -1)
    r[0] = res;
  memcpy((void*)0x20000180, "memory.events\000", 14);
  syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x20000180ul,
          /*flags=*/0x26e1ul, /*mode=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0xb36000ul,
          /*prot=PROT_WRITE*/ 2ul,
          /*flags=MAP_STACK|MAP_POPULATE|MAP_FIXED|MAP_SHARED*/ 0x28011ul,
          /*fd=*/r[0], /*offset=*/0ul);
  memcpy((void*)0x20000580, "ext4\000", 5);
  memcpy((void*)0x200005c0, "./file0\000", 8);
  memcpy((void*)0x20000240, "debug", 5);
  *(uint8_t*)0x20000245 = 0x2c;
  memcpy((void*)0x20000246, "orlov", 5);
  *(uint8_t*)0x2000024b = 0x2c;
  memcpy((void*)0x2000024c, "nomblk_io_submit", 16);
  *(uint8_t*)0x2000025c = 0x2c;
  memcpy((void*)0x2000025d, "block_validity", 14);
  *(uint8_t*)0x2000026b = 0x2c;
  memcpy((void*)0x2000026c, "debug_want_extra_isize", 22);
  *(uint8_t*)0x20000282 = 0x3d;
  sprintf((char*)0x20000283, "0x%016llx", (long long)6);
  *(uint8_t*)0x20000295 = 0x2c;
  memcpy((void*)0x20000296, "init_itable", 11);
  *(uint8_t*)0x200002a1 = 0x3d;
  sprintf((char*)0x200002a2, "0x%016llx", (long long)0);
  *(uint8_t*)0x200002b4 = 0x2c;
  memcpy((void*)0x200002b5, "usrquota", 8);
  *(uint8_t*)0x200002bd = 0x2c;
  memcpy((void*)0x200002be, "usrquota", 8);
  *(uint8_t*)0x200002c6 = 0x2c;
  *(uint8_t*)0x200002c7 = 0;
  memcpy(
      (void*)0x20001bc0,
      "\x78\x9c\xec\xdd\xcd\x6f\x54\x55\x1b\x00\xf0\xe7\x4c\x3f\x28\x94\xf7\x6d"
      "\x21\x46\xc5\x85\x34\x31\x06\x12\xa5\xa5\x05\x0c\x31\x2e\x60\x4f\x1a\xfc"
      "\x88\x1b\x37\x56\x5a\x08\x52\xa0\xa1\x35\x5a\x34\xb1\x24\xb8\x31\x31\x6e"
      "\x8c\x31\x71\xe5\x42\xfc\x2f\x94\xc8\x96\x95\xae\x5c\xb8\x71\x65\x48\x88"
      "\x1a\x96\x26\x8e\xb9\x33\x73\x4b\x5b\xee\xb4\xb4\x4c\x7b\x2b\xf7\xf7\x4b"
      "\x86\xde\x7b\xce\x5c\xce\x73\x3b\x7d\x7a\xee\x9c\x9e\x73\x27\x80\xca\x1a"
      "\xca\xfe\xa9\x45\xec\x8b\x88\x99\x14\x31\x90\x16\x16\xeb\xba\xa3\x55\x39"
      "\xd4\x7c\xde\xbd\xbf\x3e\x3a\x93\x3d\x52\xd4\xeb\xaf\xff\x91\x22\xb5\xca"
      "\xf2\xe7\xa7\xd6\xd7\xfe\xd6\xc1\x7d\x11\xf1\xd3\x8f\x29\xf6\x76\x3d\xd8"
      "\xee\xec\xfc\xd5\x0b\x13\xd3\xd3\x53\x57\x5a\xfb\x23\x73\x17\x67\x46\x66"
      "\xe7\xaf\x1e\x3a\x7f\x71\xe2\xdc\xd4\xb9\xa9\x4b\x63\x2f\x8d\x1d\x3f\x76"
      "\xf4\xd8\xf1\xd1\xc3\x1d\x3b\xd7\x53\xd7\xdf\x7d\x7f\xe0\xd3\xf1\xb7\xbe"
      "\xfd\xfa\xef\x34\xfa\xdd\xaf\xe3\x29\x4e\xc4\xee\x56\xdd\xd2\xf3\xe8\x94"
      "\xa1\x18\x6a\x7e\x4f\x76\x2c\x2f\xcf\xbe\xaf\xc7\x3b\xdd\x58\x49\xba\x5a"
      "\xe7\xb3\xf4\x25\x4e\xdd\x25\x06\xc4\xba\xe4\xaf\x5f\x4f\x44\x3c\x15\x03"
      "\xd1\x15\xf7\x5f\xbc\x81\xf8\xe4\xd5\x52\x83\x03\x36\x55\x3d\x45\xd4\x81"
      "\x8a\x4a\xf2\x1f\x2a\x2a\xbf\x0e\xc8\xdf\xdb\xaf\x7c\x1f\x5c\x2b\xe5\xaa"
      "\x04\xd8\x0a\x77\x4f\x36\x07\x00\x1e\xcc\xff\xee\xe6\xd8\x60\xf4\x35\xc6"
      "\x06\x76\xdd\x4b\xb1\x74\x58\x27\x45\x44\x27\x46\xe6\xb2\x36\x6e\xdf\x1a"
      "\xbf\x7e\xf6\xd6\xf8\xf5\xd8\xa4\x71\x38\xa0\xd8\xc2\xb5\x88\x78\xba\x28"
      "\xff\x53\x23\x37\x07\x1b\xa3\xf8\x59\xfe\xd7\x96\xe5\x7f\x76\x5d\x70\xba"
      "\xf5\x35\x2b\x7f\x6d\x83\xed\x0f\xad\xd8\x97\xff\xb0\x75\x9a\xf9\xdf\xb7"
      "\xa1\xfc\x7f\x7b\x49\xfe\xbf\xb3\xc1\xf6\xe5\x3f\x00\x00\x00\x00\x00\x00"
      "\x74\xce\xcd\x93\x11\xf1\x62\xd1\xdf\xff\x6b\x8b\xf3\x7f\xa2\x60\xfe\x4f"
      "\x7f\x44\x9c\xe8\x40\xfb\x6b\xff\xfd\xaf\x76\xa7\x03\xcd\x00\x05\xee\x9e"
      "\x8c\x78\xa5\x70\xfe\x6f\x2d\x9f\xfd\x3b\xd8\xd5\xda\xfa\x5f\x63\x3e\x40"
      "\x4f\x3a\x7b\x7e\x7a\xea\x70\x44\xfc\x3f\x22\x0e\x46\xcf\x8e\x6c\x7f\x74"
      "\x95\x36\x0e\x7d\xb6\xf7\xab\x76\x75\xf9\xfc\xbf\xfc\x91\xb5\x7f\xbb\x35"
      "\x17\xb0\x15\xc7\x9d\xee\x15\xeb\x67\x27\x27\xe6\x26\x1e\xf5\xbc\x81\x88"
      "\xbb\xd7\x22\x9e\x29\x9c\xff\x9b\x16\xfb\xff\x54\xd0\xff\x67\xbf\x0f\x66"
      "\x1e\xb2\x8d\xbd\xcf\xdf\x38\xdd\xae\x6e\xed\xfc\x07\x36\x4b\xfd\x9b\x88"
      "\x03\x85\xfd\x7f\x5a\x7c\x4e\x5a\xfd\xfe\x1c\x23\x8d\xeb\x81\x91\xfc\xaa"
      "\xe0\x41\xcf\x7e\xf8\xf9\xf7\xed\xda\x97\xff\x50\x9e\xac\xff\xdf\xb5\x7a"
      "\xfe\x0f\xa6\xa5\xf7\xeb\x99\x5d\x7f\x1b\x47\xe6\xbb\xeb\xed\xea\x36\x7a"
      "\xfd\xdf\x9b\xde\x68\xdc\x72\xa6\xb7\x55\xf6\xc1\xc4\xdc\xdc\x95\xd1\x88"
      "\xde\x74\xaa\x2b\x2b\x5d\x56\x3e\xb6\xfe\x98\xe1\x71\x94\xe7\x43\x9e\x2f"
      "\x59\xfe\x1f\x7c\x6e\xf5\xf1\xbf\xa2\xeb\xff\x9d\x11\xb1\xb0\xe2\xff\x4e"
      "\x7f\x2e\x5f\x53\x9c\x7b\xf2\x9f\xfe\xdf\xda\xc5\xa3\xff\x87\xf2\x64\xf9"
      "\x3f\xb9\xae\xfe\x7f\xfd\x1b\x63\x37\x06\x7f\x68\xd7\xfe\xc3\xf5\xff\x47"
      "\x1b\x7d\xfd\xc1\x56\x89\xf1\x3f\x68\xfa\x32\x4f\xd3\xde\xe5\xe5\x05\xe9"
      "\xd8\x5d\x54\xb5\xd5\xf1\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc0\xe3\xa0\x16\x11"
      "\xbb\x23\xd5\x86\x17\xb7\x6b\xb5\xe1\xe1\x88\xfe\x88\x78\x22\x76\xd5\xa6"
      "\x2f\xcf\xce\xbd\x70\xf6\xf2\x7b\x97\x26\xb3\xba\xc6\xe7\xff\xd7\xf2\x4f"
      "\xfa\x1d\x68\xee\xa7\xfc\xf3\xff\x07\x97\xec\x8f\xad\xd8\x3f\x12\x11\x7b"
      "\x22\xe2\x8b\xae\x9d\x8d\xfd\xe1\x33\x97\xa7\x27\xcb\x3e\x79\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd8\x26\xfa\xdb\xac\xff"
      "\xcf\xfc\xde\x55\x76\x74\xc0\xa6\xeb\x2e\x3b\x00\xa0\x34\x05\xf9\xff\x73"
      "\x19\x71\x00\x5b\x4f\xff\x0f\xd5\x25\xff\xa1\xba\xe4\x3f\x54\x97\xfc\x87"
      "\xea\x92\xff\x50\x5d\xf2\x1f\xaa\x4b\xfe\x43\x75\xc9\x7f\x00\x00\x00\x00"
      "\x00\x78\xac\xec\xd9\x7f\xf3\x97\x14\x11\x0b\x2f\xef\x6c\x3c\x32\xbd\xad"
      "\xba\x9e\x52\x23\x03\x36\x5b\xad\xec\x00\x80\xd2\xb8\xc5\x0f\x54\x97\xa9"
      "\x3f\x50\x5d\xde\xe3\x03\x69\x8d\xfa\xbe\xb6\x07\xad\x75\xe4\x6a\x66\xce"
      "\x3c\xc2\xc1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x50\x39\x07\xf6\x59"
      "\xff\x0f\x55\x65\xfd\x3f\x54\x97\xf5\xff\x50\x5d\xf9\xfa\xff\xfd\x25\xc7"
      "\x01\x6c\x3d\xef\xf1\x81\x58\x63\x25\x7f\xe1\xfa\xff\x35\x8f\x02\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x3a\x69\x76\xfe\xea\x85\x89\xe9\xe9\xa9"
      "\x2b\x36\xde\xdc\x1e\x61\x6c\xe5\x46\xbd\x5e\xff\x38\xfb\x29\xd8\x2e\xf1"
      "\xfc\xc7\x37\xf2\xa9\xf0\xdb\x25\x9e\x47\xda\x28\xf7\xf7\x12\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\xdf\xbf\x01"
      "\x00\x00\xff\xff\x64\x22\x26\xa6",
      1466);
  syz_mount_image(/*fs=*/0x20000580, /*dir=*/0x200005c0,
                  /*flags=MS_STRICTATIME|MS_SILENT*/ 0x1008000,
                  /*opts=*/0x20000240, /*chdir=*/1, /*size=*/0x5ba,
                  /*img=*/0x20001bc0);
}
int main(void)
{
  syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
          /*offset=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul,
          /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
          /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
          /*offset=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
          /*offset=*/0ul);
  setup_binfmt_misc();
  setup_swap();
  use_temporary_dir();
  do_sandbox_none();
  return 0;
}