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

#define _GNU_SOURCE

#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.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/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

#include <linux/loop.h>

#ifndef __NR_memfd_create
#define __NR_memfd_create 319
#endif
#ifndef __NR_pwritev2
#define __NR_pwritev2 328
#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 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;
}

//% 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;
}

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 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);
  }
}

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

static void execute_one(void);

#define WAIT_FLAGS __WALL

static void loop(void)
{
  int iter = 0;
  for (;; iter++) {
    reset_loop();
    int pid = fork();
    if (pid < 0)
      exit(1);
    if (pid == 0) {
      setup_test();
      execute_one();
      exit(0);
    }
    int status = 0;
    uint64_t start = current_time_ms();
    for (;;) {
      sleep_ms(10);
      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
        break;
      if (current_time_ms() - start < 5000)
        continue;
      kill_and_wait(pid, &status);
      break;
    }
  }
}

uint64_t r[1] = {0xffffffffffffffff};

void execute_one(void)
{
  intptr_t res = 0;
  if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
  }
  memcpy((void*)0x20000040, "ext4\000", 5);
  memcpy((void*)0x20000200, "./file1\000", 8);
  memcpy((void*)0x200003c0, "user_xattr", 10);
  *(uint8_t*)0x200003ca = 0x2c;
  memcpy((void*)0x200003cb, "noquota", 7);
  *(uint8_t*)0x200003d2 = 0x2c;
  memcpy((void*)0x200003d3, "barrier", 7);
  *(uint8_t*)0x200003da = 0x3d;
  sprintf((char*)0x200003db, "0x%016llx", (long long)6);
  *(uint8_t*)0x200003ed = 0x2c;
  memcpy((void*)0x200003ee, "jqfmt=vfsv1", 11);
  *(uint8_t*)0x200003f9 = 0x2c;
  memcpy((void*)0x200003fa, "block_validity", 14);
  *(uint8_t*)0x20000408 = 0x2c;
  memcpy((void*)0x20000409, "max_dir_size_kb", 15);
  *(uint8_t*)0x20000418 = 0x3d;
  sprintf((char*)0x20000419, "0x%016llx", (long long)0x7b1);
  *(uint8_t*)0x2000042b = 0x2c;
  memcpy((void*)0x2000042c, "stripe", 6);
  *(uint8_t*)0x20000432 = 0x3d;
  sprintf((char*)0x20000433, "0x%016llx", (long long)0x20);
  *(uint8_t*)0x20000445 = 0x2c;
  memcpy((void*)0x20000446, "bsdgroups", 9);
  *(uint8_t*)0x2000044f = 0x2c;
  memcpy((void*)0x20000450, "max_batch_time", 14);
  *(uint8_t*)0x2000045e = 0x3d;
  sprintf((char*)0x2000045f, "0x%016llx", (long long)0x3fe);
  *(uint8_t*)0x20000471 = 0x2c;
  memcpy((void*)0x20000472, "user_xattr", 10);
  *(uint8_t*)0x2000047c = 0x2c;
  memcpy((void*)0x2000047d, "nodiscard", 9);
  *(uint8_t*)0x20000486 = 0x2c;
  *(uint8_t*)0x20000487 = 0;
  memcpy(
      (void*)0x20001080,
      "\x78\x9c\xec\xdd\xcd\x6b\x1c\xe5\x1f\x00\xf0\xef\x6c\x76\xfb\xfe\xfb\x35"
      "\x85\x52\x54\x44\x02\x3d\x58\xa9\xdd\x34\x89\x2f\x15\x3c\xd4\xa3\x68\xb1"
      "\xa0\xf7\xba\x24\xd3\x50\xb2\xe9\x96\xec\xa6\x34\xb1\x60\x7b\xb0\x17\x2f"
      "\x52\x04\x11\x0b\xe2\x5d\xef\x1e\x8b\xff\x80\x7f\x45\x41\x0b\x45\x4a\xd0"
      "\x83\x97\xc8\x6c\x66\xd3\x6d\xb3\x9b\xb7\x6e\x9a\x6d\xf7\xf3\x81\x69\x9f"
      "\x67\x66\x92\x67\xbe\xf3\xcc\xf7\xc9\x33\x3b\xbb\x6c\x00\x03\x6b\x24\xfb"
      "\xa7\x10\xf1\x72\x44\x7c\x93\x44\x1c\x6e\xdb\x56\x8c\x7c\xe3\xc8\xca\x7e"
      "\x4b\x0f\xaf\x4f\x66\x4b\x12\xcb\xcb\x9f\xfe\x95\x44\x92\xaf\x6b\xed\x9f"
      "\xe4\xff\x1f\xcc\x2b\x2f\x45\xc4\x6f\x5f\x45\x9c\x2c\xac\x6d\xb7\xbe\xb0"
      "\x38\x53\xa9\x56\xd3\xb9\xbc\x3e\xda\x98\xbd\x32\x5a\x5f\x58\x3c\x75\x69"
      "\xb6\x32\x9d\x4e\xa7\x97\xc7\x27\x26\xce\xbc\x3d\x31\xfe\xde\xbb\xef\xf4"
      "\x2c\xd6\x37\xce\xff\xf3\xfd\x27\x77\x3f\x3c\xf3\xf5\xf1\xa5\xef\x7e\xb9"
      "\x7f\xe4\x76\x12\x67\xe3\x50\xbe\xad\x3d\x8e\xa7\x70\xa3\xbd\x32\x12\x23"
      "\xf9\x39\x29\xc5\xd9\x27\x76\x1c\xeb\x41\x63\xfd\x24\xd9\xed\x03\x60\x5b"
      "\x86\xf2\x3c\x2f\x45\x36\x06\x1c\x2e\xb5\xb2\x1e\x78\xf1\x7d\x19\x11\xcb"
      "\xc0\x80\x4a\xb6\x98\xff\x7b\x8d\x17\xf0\x82\x68\xcd\x03\x5a\xf7\xf6\x3d"
      "\xba\x0f\x7e\x6e\x3c\xf8\x60\xe5\x06\x68\x6d\xfc\xc5\x95\xd7\x46\x62\x5f"
      "\xf3\xde\xe8\xc0\x52\xf2\xd8\x9d\x51\x76\xbf\x3b\xdc\x83\xf6\xb3\x36\x7e"
      "\xfd\xf3\xce\xed\x6c\x89\xde\xbd\x0e\x01\xb0\xa1\x1b\x37\x23\xe2\x74\xb1"
      "\xb8\x76\xfc\x4b\xf2\xf1\x6f\xfb\x4e\x6f\x62\x9f\x27\xdb\x30\xfe\xc1\xb3"
      "\x73\x37\x9b\xff\xbc\xd9\x69\xfe\x53\x58\x9d\xff\x44\x87\xf9\xcf\xc1\x0e"
      "\xb9\xbb\x1d\x1b\xe7\x7f\xe1\x7e\x0f\x9a\xe9\x2a\x9b\xff\xbd\xdf\x71\xfe"
      "\xbb\xfa\xd0\x6a\x78\x28\xaf\xfd\xaf\x39\xe7\x2b\x25\x17\x2f\x55\xd3\x6c"
      "\x6c\xfb\x7f\x44\x9c\x88\xd2\xde\xac\xbe\xde\xf3\x9c\x33\x4b\xf7\x96\xbb"
      "\x6d\x6b\x9f\xff\x65\x4b\xd6\x7e\x6b\x2e\x98\x1f\xc7\xfd\xe2\xde\xc7\x7f"
      "\x66\xaa\xd2\xa8\x3c\x4d\xcc\xed\x1e\xdc\x8c\x78\xa5\xe3\xfc\x37\x59\xed"
      "\xff\xa4\x43\xff\x67\xe7\xe3\xfc\x26\xdb\x38\x96\xde\x79\xad\xdb\xb6\x8d"
      "\xe3\xdf\x59\xcb\x3f\x45\xbc\xde\xb1\xff\x1f\x3d\xd1\x4a\xd6\x7f\x3e\x39"
      "\xda\xbc\x1e\x46\x5b\x57\xc5\x5a\x7f\xdf\x3a\xf6\x7b\xb7\xf6\x77\x3b\xfe"
      "\xac\xff\x0f\xac\x1f\xff\x70\xd2\xfe\xbc\xb6\xbe\xf5\x36\x7e\xdc\xf7\x6f"
      "\xda\x6d\xdb\x76\xaf\xff\x3d\xc9\x67\xcd\xf2\x9e\x7c\xdd\xb5\x4a\xa3\x31"
      "\x37\x16\xb1\x27\xf9\x78\xed\xfa\xf1\x47\x3f\xdb\xaa\xb7\xf6\xcf\xe2\x3f"
      "\x71\x7c\xfd\xf1\xaf\xd3\xf5\xbf\x3f\x22\x3e\xdf\x64\xfc\xb7\x8e\xfe\xfc"
      "\xea\xf6\xe3\xdf\x59\x59\xfc\x53\x5b\xea\xff\xad\x17\xee\x7d\xf4\xc5\x0f"
      "\xdd\xda\xdf\x5c\xff\xbf\xd5\x2c\x9d\xc8\xd7\x6c\x66\xfc\xdb\xec\x01\x3e"
      "\xcd\xb9\x03\x00\x00\x00\x00\x00\x80\x7e\x53\x88\x88\x43\x91\x14\xca\xab"
      "\xe5\x42\xa1\x5c\x5e\x79\x7f\xc7\xd1\x38\x50\xa8\xd6\xea\x8d\x93\x17\x6b"
      "\xf3\x97\xa7\xa2\xf9\x59\xd9\xe1\x28\x15\x5a\x4f\xba\x0f\xb7\xbd\x1f\x62"
      "\x2c\x7f\x3f\x6c\xab\x3e\xfe\x44\x7d\x22\x22\x8e\x44\xc4\xb7\x43\xfb\x9b"
      "\xf5\xf2\x64\xad\x3a\xb5\xdb\xc1\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x40\x9f\x38\xd8\xe5\xf3\xff\x99\x3f\x86\x76\xfb\xe8"
      "\x80\x1d\xe7\x2b\xbf\x61\x70\x6d\x98\xff\xbd\xf8\xa6\x27\xa0\x2f\xf9\xfb"
      "\x0f\x83\x4b\xfe\xc3\xe0\x92\xff\x30\xb8\xe4\x3f\x0c\x2e\xf9\x0f\x83\x4b"
      "\xfe\xc3\xe0\x92\xff\x30\xb8\xe4\x3f\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf4\xd4\xf9\x73\xe7\xb2"
      "\x65\x79\xe9\xe1\xf5\xc9\xac\x3e\x75\x75\x61\x7e\xa6\x76\xf5\xd4\x54\x5a"
      "\x9f\x29\xcf\xce\x4f\x96\x27\x6b\x73\x57\xca\xd3\xb5\xda\x74\x35\x2d\x4f"
      "\xd6\x66\x37\xfa\x7d\xd5\x5a\xed\xca\xd8\x78\xcc\x5f\x1b\x6d\xa4\xf5\xc6"
      "\x68\x7d\x61\xf1\xc2\x6c\x6d\xfe\x72\xe3\xc2\xa5\xd9\xca\x74\x7a\x21\x2d"
      "\x3d\x93\xa8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\xe0\xf9\x52\x5f\x58\x9c\xa9\x54\xab\xe9\x5c\x8f\x0a\x85\x88\xe8\xe9\x2f"
      "\x54\x58\x53\xc8\xfa\xed\x46\xb1\x5f\xce\x73\xb1\x3f\x0e\x43\xa1\xc7\x85"
      "\xdd\x1e\x99\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\x91"
      "\xff\x02\x00\x00\xff\xff\x7f\x5e\x31\xdc",
      1378);
  syz_mount_image(/*fs=*/0x20000040, /*dir=*/0x20000200, /*flags=*/0,
                  /*opts=*/0x200003c0, /*chdir=*/1, /*size=*/0x562,
                  /*img=*/0x20001080);
  memcpy((void*)0x200002c0, "ext4\000", 5);
  memcpy((void*)0x200001c0, "./file0\000", 8);
  memcpy((void*)0x20000880, "errors=remount-ro", 17);
  *(uint8_t*)0x20000891 = 0x2c;
  memcpy((void*)0x20000892, "bsdgroups", 9);
  *(uint8_t*)0x2000089b = 0x2c;
  memcpy((void*)0x2000089c, "user_xattr", 10);
  *(uint8_t*)0x200008a6 = 0x2c;
  memcpy((void*)0x200008a7, "noauto_da_alloc", 15);
  *(uint8_t*)0x200008b6 = 0x2c;
  memcpy((void*)0x200008b7, "bsdgroups", 9);
  *(uint8_t*)0x200008c0 = 0x2c;
  memcpy((void*)0x200008c1, "oldalloc", 8);
  *(uint8_t*)0x200008c9 = 0x2c;
  memcpy((void*)0x200008ca, "stripe", 6);
  *(uint8_t*)0x200008d0 = 0x3d;
  sprintf((char*)0x200008d1, "0x%016llx", (long long)5);
  *(uint8_t*)0x200008e3 = 0x2c;
  *(uint8_t*)0x200008e4 = 0;
  memcpy(
      (void*)0x20000400,
      "\x78\x9c\xec\xdb\xcd\x6f\x14\xe5\x1f\x00\xf0\xef\xcc\xb6\xe5\xf7\xe3\xad"
      "\x15\xf1\x05\x44\xad\x12\x63\xe3\x4b\x4b\x0b\x2a\x07\x2f\x1a\x4d\x3c\x60"
      "\x34\xd1\x03\x1e\xeb\xb6\x10\xc2\x42\x0d\xad\x89\x10\x22\xd5\x18\xbc\x98"
      "\x18\x12\x3d\x1b\x8f\x26\xfe\x05\xde\xbc\x18\xf5\x64\xe2\x55\xef\x86\x84"
      "\x28\x17\xd0\x53\xcd\xcc\xce\xc0\xee\xb2\x5b\x28\x6c\x77\x2b\xfb\xf9\x24"
      "\x03\xcf\xb3\xf3\x6c\x9f\xe7\xbb\xcf\x3c\x33\xcf\xcc\xb3\x1b\xc0\xc0\x1a"
      "\xcf\xfe\x49\x22\xb6\x46\xc4\x6f\x11\x31\x5a\xcf\x36\x17\x18\xaf\xff\x77"
      "\xf5\xf2\xd9\xea\xdf\x97\xcf\x56\x93\x58\x59\x79\xeb\xcf\x24\x2f\x77\xe5"
      "\xf2\xd9\x6a\x59\xb4\x7c\xdf\x96\x22\x33\x91\x46\xa4\x9f\x24\x45\x25\xcd"
      "\x16\x4f\x9f\x39\x3e\x5b\xab\xcd\x9f\x2a\xf2\x53\x4b\x27\xde\x9b\x5a\x3c"
      "\x7d\xe6\xd9\x63\x27\x66\x8f\xce\x1f\x9d\x3f\x39\x73\xf0\xe0\x81\xfd\xd3"
      "\x2f\x3c\x3f\xf3\x5c\x57\xe2\xcc\xe2\xba\xb2\xfb\xc3\x85\x3d\xbb\x5e\x7b"
      "\xe7\xc2\xeb\xd5\xc3\x17\xde\xfd\xe9\xdb\xac\xbd\x5b\x8b\xfd\x8d\x71\x74"
      "\xcb\x78\x16\xf8\x5f\x2b\xb9\xd6\x7d\x4f\x74\xbb\xb2\x3e\xdb\xd6\x90\x4e"
      "\x86\xfa\xd8\x10\xd6\xa4\x12\x11\x59\x77\x0d\xe7\xe3\x7f\x34\x2a\x71\xbd"
      "\xf3\x46\xe3\xd5\x8f\xfb\xda\x38\x60\x5d\x65\xd7\xa6\x4d\x9d\x77\x2f\xaf"
      "\x00\x77\xb1\x24\xfa\xdd\x02\xa0\x3f\xca\x0b\x7d\x76\xff\x5b\x6e\x3d\x9a"
      "\x7a\x6c\x08\x97\x5e\xaa\xdf\x00\x65\x71\x5f\x2d\xb6\xfa\x9e\xa1\x48\x8b"
      "\x32\xc3\x2d\xf7\xb7\xdd\x34\x1e\x11\x87\x97\xff\xf9\x2a\xdb\x62\x9d\x9e"
      "\x43\x00\x00\x34\xfa\xac\xfa\xe5\xa1\x78\xa6\xdd\xfc\x2f\x8d\xfb\x1b\xca"
      "\x6d\x2f\xd6\x50\xc6\x22\xe2\x9e\x88\xd8\x11\x11\xf7\x46\xc4\xce\x88\xb8"
      "\x2f\x22\x2f\xfb\x40\x44\x3c\xb8\xc6\xfa\x5b\x97\x86\x6e\x9c\xff\xa4\x17"
      "\x6f\x2b\xb0\x5b\x94\xcd\xff\x5e\x2c\xd6\xb6\x9a\xe7\x7f\xe5\xec\x2f\xc6"
      "\x2a\x45\x6e\x5b\x1e\xff\x70\x72\xe4\x58\x6d\x7e\x5f\xf1\x99\x4c\xc4\xf0"
      "\xa6\x2c\x3f\xbd\x4a\x1d\xdf\xbf\xf2\xeb\xe7\x9d\xf6\x35\xce\xff\xb2\x2d"
      "\xab\xbf\x9c\x0b\x16\xed\xb8\x38\xd4\xf2\x80\x6e\x6e\x76\x69\x36\x9f\x94"
      "\x76\xc1\xa5\x8f\x22\x76\x0f\xb5\x8b\x3f\xb9\xb6\x12\x90\x44\xc4\xae\x88"
      "\xd8\xbd\xb6\x3f\xbd\xbd\x4c\x1c\x7b\xea\x9b\x3d\x9d\x0a\xdd\x3c\xfe\x55"
      "\x74\x61\x9d\x69\xe5\xeb\x88\x27\xeb\xfd\xbf\x1c\x2d\xf1\x97\x92\xd5\xd7"
      "\x27\xa7\xfe\x17\xb5\xf9\x7d\x53\xe5\x51\x71\xa3\x9f\x7f\x39\xff\x66\xa7"
      "\xfa\xef\x28\xfe\x2e\xc8\xfa\x7f\x73\xf3\xf1\xdf\x5a\x64\x2c\x69\x5c\xaf"
      "\x5d\x5c\x7b\x1d\xe7\x7f\xff\xb4\xe3\x3d\xcd\xed\x1e\xff\x23\xc9\xdb\xf9"
      "\xf9\x68\xa4\x78\xed\x83\xd9\xa5\xa5\x53\xd3\x11\x23\xc9\xa1\x3c\xdf\xf4"
      "\xfa\xcc\xf5\xf7\x96\xf9\xb2\x7c\x16\xff\xc4\xde\xf6\xe3\x7f\x47\xf1\x9e"
      "\x2c\xfe\x87\x22\x22\x3b\x88\x1f\x8e\x88\x47\x22\xe2\xd1\xa2\xed\x8f\x45"
      "\xc4\xe3\x11\xb1\x77\x95\xf8\x7f\x7c\xb9\xf3\xbe\x8d\xd0\xff\x73\x6d\xcf"
      "\x7f\xd7\x8e\xff\x96\xfe\x5f\x7b\xa2\x72\xfc\x87\xef\x3a\xd5\x7f\x6b\xfd"
      "\x7f\x20\x4f\x4d\x14\xaf\xe4\xe7\xbf\x9b\xb8\xd5\x06\xde\xc9\x67\x07\x00"
      "\x00\x00\xff\x15\x69\xfe\x1d\xf8\x24\x9d\xbc\x96\x4e\xd3\xc9\xc9\xfa\x77"
      "\xf8\x77\xc6\xe6\xb4\xb6\xb0\xb8\xf4\xf4\x91\x85\xf7\x4f\xce\xd5\xbf\x2b"
      "\x3f\x16\xc3\x69\xf9\xa4\x6b\xb4\xe1\x79\xe8\x74\xb2\x5c\xfc\xc5\x7a\x7e"
      "\xa6\x78\x56\x5c\xee\xdf\x5f\x3c\x37\xfe\xa2\xf2\xff\x3c\x3f\x59\x5d\xa8"
      "\xcd\xf5\x39\x76\x18\x74\x5b\x3a\x8c\xff\xcc\x1f\x95\x7e\xb7\x0e\x58\x77"
      "\xed\xd6\xd1\x66\x46\xfa\xd0\x10\xa0\xe7\x5a\xc7\x7f\xda\x9c\x3d\xf7\x46"
      "\x2f\x1b\x03\xf4\x94\xdf\x6b\xc3\xe0\xba\xc9\xf8\x4f\x7b\xd5\x0e\xa0\xf7"
      "\x5c\xff\x61\x70\xb5\x1b\xff\xe7\x5a\xf2\xd6\x02\xe0\xee\xe4\xfa\x0f\x83"
      "\xcb\xf8\x87\xc1\x65\xfc\xc3\xe0\x32\xfe\x61\x20\xdd\xc9\xef\xfa\x25\x06"
      "\x39\x11\xe9\x86\x68\x86\xc4\x3a\x25\xfa\x7d\x66\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\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\xe8\x8e\x7f\x03\x00\x00\xff\xff\xca\xf2\xee"
      "\xdc",
      1098);
  syz_mount_image(/*fs=*/0x200002c0, /*dir=*/0x200001c0,
                  /*flags=MS_I_VERSION|MS_NOATIME|0x300*/ 0x800700,
                  /*opts=*/0x20000880, /*chdir=*/2, /*size=*/0x44a,
                  /*img=*/0x20000400);
  memcpy((void*)0x200000c0, "./file1\000", 8);
  res =
      syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000c0ul,
              /*flags=O_SYNC|O_CREAT|FASYNC|O_RDWR*/ 0x103042ul, /*mode=*/0ul);
  if (res != -1)
    r[0] = res;
  memcpy((void*)0x20000f40, "msdos\000", 6);
  memcpy((void*)0x20000140, ".\000", 2);
  syz_mount_image(
      /*fs=*/0x20000f40, /*dir=*/0x20000140,
      /*flags=MS_I_VERSION|MS_PRIVATE|MS_SYNCHRONOUS|MS_STRICTATIME|MS_SILENT|MS_REMOUNT|0x202408*/
      0x1a4a438, /*opts=*/0x200008c0, /*chdir=*/0xb, /*size=*/0,
      /*img=*/0x20000000);
  *(uint64_t*)0x200002c0 = 0x20000140;
  memset((void*)0x20000140, 231, 1);
  *(uint64_t*)0x200002c8 = 1;
  syscall(__NR_pwritev2, /*fd=*/r[0], /*vec=*/0x200002c0ul, /*vlen=*/0xful,
          /*off_low=*/0xa12, /*off_high=*/0, /*flags=*/0ul);
}
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);
  const char* reason;
  (void)reason;
  loop();
  return 0;
}