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

#define _GNU_SOURCE

#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>

#ifndef __NR_fsopen
#define __NR_fsopen 430
#endif
#ifndef __NR_landlock_create_ruleset
#define __NR_landlock_create_ruleset 444
#endif
#ifndef __NR_landlock_restrict_self
#define __NR_landlock_restrict_self 446
#endif
#ifndef __NR_open_tree
#define __NR_open_tree 428
#endif

uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff};

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);
  intptr_t res = 0;
  memset((void*)0x20000100, 0, 1);
  res = syscall(
      __NR_open_tree, /*dfd=*/0xffffff9c, /*filename=*/0x20000100ul,
      /*flags=OPEN_TREE_CLOEXEC|OPEN_TREE_CLONE|AT_SYMLINK_NOFOLLOW|AT_RECURSIVE|AT_NO_AUTOMOUNT|AT_EMPTY_PATH*/
      0x89901ul);
  if (res != -1)
    r[0] = res;
  syscall(__NR_fchdir, /*fd=*/r[0]);
  syscall(__NR_fsopen, /*type=*/0ul, /*flags=*/0ul);
  *(uint64_t*)0x20000240 = 0x1fff;
  *(uint64_t*)0x20000248 = 0;
  res = syscall(__NR_landlock_create_ruleset, /*attr=*/0x20000240ul,
                /*size=*/0x10ul, /*flags=*/0ul);
  if (res != -1)
    r[1] = res;
  syscall(__NR_landlock_restrict_self, /*ruleset_fd=*/r[1], /*flags=*/0ul);
  memcpy((void*)0x20000000, ".\000", 2);
  memcpy((void*)0x20000700, "./file7\000", 8);
  syscall(__NR_linkat, /*oldfd=*/0xffffff9c, /*old=*/0x20000000ul,
          /*newfd=*/0xffffff9c, /*new=*/0x20000700ul, /*flags=*/0ul);
  return 0;
}