Staring at the reproducer, we do
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);
-> Writable anonymous memmory
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;
res = syscall(__NR_userfaultfd,
/*flags=UFFD_USER_MODE_ONLY|O_NONBLOCK*/ 0x801ul);
if (res != -1)
r[0] = res;
*(uint64_t*)0x200004c0 = 0xaa;
*(uint64_t*)0x200004c8 = 0;
*(uint64_t*)0x200004d0 = 0;
syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc018aa3f, /*arg=*/0x200004c0ul);
-> _UFFDIO_API handshake?
syscall(__NR_mprotect, /*addr=*/0x20ffc000ul, /*len=*/0x3000ul,
/*prot=PROT_SEM|PROT_EXEC*/ 0xcul);
-> Protect target range R/O. I assume: no page populated yet?
-> 3 pages starting at 0x20ffc000ul;
*(uint64_t*)0x20000180 = 0x20ffc000;
*(uint64_t*)0x20000188 = 0x3000;
*(uint64_t*)0x20000190 = 3;
*(uint64_t*)0x20000198 = 0;
syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc020aa00, /*arg=*/0x20000180ul);
-> _UFFDIO_REGISTER (aa00)
-> _range = 3 pages starting at 0x20ffc000ul
-> _mode = UFFDIO_REGISTER_MODE_WP | UFFDIO_REGISTER_MODE_MINOR
*(uint64_t*)0x20000000 = 0x20ffd000;
*(uint64_t*)0x20000008 = 0x20ffb000;
*(uint64_t*)0x20000010 = 0x1000;
*(uint64_t*)0x20000018 = 3;
*(uint64_t*)0x20000020 = 0;
syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc028aa03, /*arg=*/0x20000000ul);
-> _UFFDIO_COPY (aa03)
-> dst = 0x20ffd000
-> src = 0x20ffb000
-> len = 0x1000 (single page)
-> mode = UFFDIO_COPY_MODE_DONTWAKE|UFFDIO_COPY_MODE_WP
-> We are copying into the R/O range. src should be R/W and trigger a page fault
on access where we get a fresh page.
*(uint16_t*)0x200000c0 = 1;
*(uint64_t*)0x200000c8 = 0x20000040;
*(uint16_t*)0x20000040 = 6;
*(uint8_t*)0x20000042 = 0;
*(uint8_t*)0x20000043 = 0;
*(uint32_t*)0x20000044 = 0x7fffffff;
res = syscall(__NR_seccomp, /*op=*/1ul, /*flags=*/0ul, /*arg=*/0x200000c0ul);
if (res != -1)
r[1] = res;
syscall(__NR_open_tree, /*dfd=*/-1, /*filename=*/0ul, /*flags=*/0ul);
-> No idea what happens here and if it is relevant. If __NR_seccomp failed, we would
no set r[1].
syscall(__NR_close_range, /*fd=*/r[1], /*max_fd=*/-1, /*flags=*/0ul);
-> Is that closing uffd as well, especially if __NR_seccomp failed?
syscall(__NR_mprotect, /*addr=*/0x20ffc000ul, /*len=*/0x4000ul,
/*prot=PROT_SEM|PROT_WRITE|PROT_READ|PROT_EXEC*/ 0xful);
-> Restore write permissions. This seems to fire the uffd-wp page table check I assume.