Tang-ZW

Untitled

Mar 3rd, 2026
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.85 KB | None | 0 0
  1. // autogenerated by syzkaller (https://github.com/google/syzkaller)
  2.  
  3. #define _GNU_SOURCE
  4.  
  5. #include <dirent.h>
  6. #include <endian.h>
  7. #include <errno.h>
  8. #include <fcntl.h>
  9. #include <sched.h>
  10. #include <setjmp.h>
  11. #include <signal.h>
  12. #include <stdarg.h>
  13. #include <stdbool.h>
  14. #include <stdint.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <sys/mount.h>
  19. #include <sys/prctl.h>
  20. #include <sys/resource.h>
  21. #include <sys/stat.h>
  22. #include <sys/swap.h>
  23. #include <sys/syscall.h>
  24. #include <sys/time.h>
  25. #include <sys/types.h>
  26. #include <sys/wait.h>
  27. #include <time.h>
  28. #include <unistd.h>
  29.  
  30. #include <linux/capability.h>
  31. #include <linux/falloc.h>
  32.  
  33. static __thread int clone_ongoing;
  34. static __thread int skip_segv;
  35. static __thread jmp_buf segv_env;
  36.  
  37. static void segv_handler(int sig, siginfo_t* info, void* ctx)
  38. {
  39. if (__atomic_load_n(&clone_ongoing, __ATOMIC_RELAXED) != 0) {
  40. exit(sig);
  41. }
  42. uintptr_t addr = (uintptr_t)info->si_addr;
  43. const uintptr_t prog_start = 1 << 20;
  44. const uintptr_t prog_end = 100 << 20;
  45. int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0;
  46. int valid = addr < prog_start || addr > prog_end;
  47. if (skip && valid) {
  48. _longjmp(segv_env, 1);
  49. }
  50. exit(sig);
  51. }
  52.  
  53. static void install_segv_handler(void)
  54. {
  55. struct sigaction sa;
  56. memset(&sa, 0, sizeof(sa));
  57. sa.sa_handler = SIG_IGN;
  58. syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
  59. syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
  60. memset(&sa, 0, sizeof(sa));
  61. sa.sa_sigaction = segv_handler;
  62. sa.sa_flags = SA_NODEFER | SA_SIGINFO;
  63. sigaction(SIGSEGV, &sa, NULL);
  64. sigaction(SIGBUS, &sa, NULL);
  65. }
  66.  
  67. #define NONFAILING(...) \
  68. ({ \
  69. int ok = 1; \
  70. __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
  71. if (_setjmp(segv_env) == 0) { \
  72. __VA_ARGS__; \
  73. } else \
  74. ok = 0; \
  75. __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \
  76. ok; \
  77. })
  78.  
  79. static void sleep_ms(uint64_t ms)
  80. {
  81. usleep(ms * 1000);
  82. }
  83.  
  84. static uint64_t current_time_ms(void)
  85. {
  86. struct timespec ts;
  87. if (clock_gettime(CLOCK_MONOTONIC, &ts))
  88. exit(1);
  89. return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
  90. }
  91.  
  92. #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
  93. #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \
  94. *(type*)(addr) = \
  95. htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \
  96. (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))
  97.  
  98. static bool write_file(const char* file, const char* what, ...)
  99. {
  100. char buf[1024];
  101. va_list args;
  102. va_start(args, what);
  103. vsnprintf(buf, sizeof(buf), what, args);
  104. va_end(args);
  105. buf[sizeof(buf) - 1] = 0;
  106. int len = strlen(buf);
  107. int fd = open(file, O_WRONLY | O_CLOEXEC);
  108. if (fd == -1)
  109. return false;
  110. if (write(fd, buf, len) != len) {
  111. int err = errno;
  112. close(fd);
  113. errno = err;
  114. return false;
  115. }
  116. close(fd);
  117. return true;
  118. }
  119.  
  120. static int runcmdline(char* cmdline)
  121. {
  122. int ret = system(cmdline);
  123. if (ret) {
  124. }
  125. return ret;
  126. }
  127.  
  128. #define MAX_FDS 30
  129.  
  130. static void setup_gadgetfs();
  131. static void setup_binderfs();
  132. static void setup_fusectl();
  133. static void sandbox_common_mount_tmpfs(void)
  134. {
  135. write_file("/proc/sys/fs/mount-max", "100000");
  136. if (mkdir("./syz-tmp", 0777))
  137. exit(1);
  138. if (mount("", "./syz-tmp", "tmpfs", 0, NULL))
  139. exit(1);
  140. if (mkdir("./syz-tmp/newroot", 0777))
  141. exit(1);
  142. if (mkdir("./syz-tmp/newroot/dev", 0700))
  143. exit(1);
  144. unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE;
  145. if (mount("/dev", "./syz-tmp/newroot/dev", NULL, bind_mount_flags, NULL))
  146. exit(1);
  147. if (mkdir("./syz-tmp/newroot/proc", 0700))
  148. exit(1);
  149. if (mount("syz-proc", "./syz-tmp/newroot/proc", "proc", 0, NULL))
  150. exit(1);
  151. if (mkdir("./syz-tmp/newroot/selinux", 0700))
  152. exit(1);
  153. const char* selinux_path = "./syz-tmp/newroot/selinux";
  154. if (mount("/selinux", selinux_path, NULL, bind_mount_flags, NULL)) {
  155. if (errno != ENOENT)
  156. exit(1);
  157. if (mount("/sys/fs/selinux", selinux_path, NULL, bind_mount_flags, NULL) &&
  158. errno != ENOENT)
  159. exit(1);
  160. }
  161. if (mkdir("./syz-tmp/newroot/sys", 0700))
  162. exit(1);
  163. if (mount("/sys", "./syz-tmp/newroot/sys", 0, bind_mount_flags, NULL))
  164. exit(1);
  165. if (mount("/sys/kernel/debug", "./syz-tmp/newroot/sys/kernel/debug", NULL,
  166. bind_mount_flags, NULL) &&
  167. errno != ENOENT)
  168. exit(1);
  169. if (mount("/sys/fs/smackfs", "./syz-tmp/newroot/sys/fs/smackfs", NULL,
  170. bind_mount_flags, NULL) &&
  171. errno != ENOENT)
  172. exit(1);
  173. if (mount("/proc/sys/fs/binfmt_misc",
  174. "./syz-tmp/newroot/proc/sys/fs/binfmt_misc", NULL, bind_mount_flags,
  175. NULL) &&
  176. errno != ENOENT)
  177. exit(1);
  178. if (mkdir("./syz-tmp/newroot/syz-inputs", 0700))
  179. exit(1);
  180. if (mount("/syz-inputs", "./syz-tmp/newroot/syz-inputs", NULL,
  181. bind_mount_flags | MS_RDONLY, NULL) &&
  182. errno != ENOENT)
  183. exit(1);
  184. if (mkdir("./syz-tmp/pivot", 0777))
  185. exit(1);
  186. if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) {
  187. if (chdir("./syz-tmp"))
  188. exit(1);
  189. } else {
  190. if (chdir("/"))
  191. exit(1);
  192. if (umount2("./pivot", MNT_DETACH))
  193. exit(1);
  194. }
  195. if (chroot("./newroot"))
  196. exit(1);
  197. if (chdir("/"))
  198. exit(1);
  199. setup_gadgetfs();
  200. setup_binderfs();
  201. setup_fusectl();
  202. }
  203.  
  204. static void setup_gadgetfs()
  205. {
  206. if (mkdir("/dev/gadgetfs", 0777)) {
  207. }
  208. if (mount("gadgetfs", "/dev/gadgetfs", "gadgetfs", 0, NULL)) {
  209. }
  210. }
  211.  
  212. static void setup_fusectl()
  213. {
  214. if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
  215. }
  216. }
  217.  
  218. static void setup_binderfs()
  219. {
  220. if (mkdir("/dev/binderfs", 0777)) {
  221. }
  222. if (mount("binder", "/dev/binderfs", "binder", 0, NULL)) {
  223. }
  224. if (symlink("/dev/binderfs", "./binderfs")) {
  225. }
  226. }
  227.  
  228. static void loop();
  229.  
  230. static void sandbox_common()
  231. {
  232. prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  233. if (getppid() == 1)
  234. exit(1);
  235. struct rlimit rlim;
  236. rlim.rlim_cur = rlim.rlim_max = (200 << 20);
  237. setrlimit(RLIMIT_AS, &rlim);
  238. rlim.rlim_cur = rlim.rlim_max = 32 << 20;
  239. setrlimit(RLIMIT_MEMLOCK, &rlim);
  240. rlim.rlim_cur = rlim.rlim_max = 136 << 20;
  241. setrlimit(RLIMIT_FSIZE, &rlim);
  242. rlim.rlim_cur = rlim.rlim_max = 1 << 20;
  243. setrlimit(RLIMIT_STACK, &rlim);
  244. rlim.rlim_cur = rlim.rlim_max = 128 << 20;
  245. setrlimit(RLIMIT_CORE, &rlim);
  246. rlim.rlim_cur = rlim.rlim_max = 256;
  247. setrlimit(RLIMIT_NOFILE, &rlim);
  248. if (unshare(CLONE_NEWNS)) {
  249. }
  250. if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
  251. }
  252. if (unshare(CLONE_NEWIPC)) {
  253. }
  254. if (unshare(0x02000000)) {
  255. }
  256. if (unshare(CLONE_NEWUTS)) {
  257. }
  258. if (unshare(CLONE_SYSVSEM)) {
  259. }
  260. typedef struct {
  261. const char* name;
  262. const char* value;
  263. } sysctl_t;
  264. static const sysctl_t sysctls[] = {
  265. {"/proc/sys/kernel/shmmax", "16777216"},
  266. {"/proc/sys/kernel/shmall", "536870912"},
  267. {"/proc/sys/kernel/shmmni", "1024"},
  268. {"/proc/sys/kernel/msgmax", "8192"},
  269. {"/proc/sys/kernel/msgmni", "1024"},
  270. {"/proc/sys/kernel/msgmnb", "1024"},
  271. {"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
  272. };
  273. unsigned i;
  274. for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
  275. write_file(sysctls[i].name, sysctls[i].value);
  276. }
  277.  
  278. static int wait_for_loop(int pid)
  279. {
  280. if (pid < 0)
  281. exit(1);
  282. int status = 0;
  283. while (waitpid(-1, &status, __WALL) != pid) {
  284. }
  285. return WEXITSTATUS(status);
  286. }
  287.  
  288. static void drop_caps(void)
  289. {
  290. struct __user_cap_header_struct cap_hdr = {};
  291. struct __user_cap_data_struct cap_data[2] = {};
  292. cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
  293. cap_hdr.pid = getpid();
  294. if (syscall(SYS_capget, &cap_hdr, &cap_data))
  295. exit(1);
  296. const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE);
  297. cap_data[0].effective &= ~drop;
  298. cap_data[0].permitted &= ~drop;
  299. cap_data[0].inheritable &= ~drop;
  300. if (syscall(SYS_capset, &cap_hdr, &cap_data))
  301. exit(1);
  302. }
  303.  
  304. static int do_sandbox_none(void)
  305. {
  306. if (unshare(CLONE_NEWPID)) {
  307. }
  308. int pid = fork();
  309. if (pid != 0)
  310. return wait_for_loop(pid);
  311. sandbox_common();
  312. drop_caps();
  313. if (unshare(CLONE_NEWNET)) {
  314. }
  315. write_file("/proc/sys/net/ipv4/ping_group_range", "0 65535");
  316. sandbox_common_mount_tmpfs();
  317. loop();
  318. exit(1);
  319. }
  320.  
  321. static void kill_and_wait(int pid, int* status)
  322. {
  323. kill(-pid, SIGKILL);
  324. kill(pid, SIGKILL);
  325. for (int i = 0; i < 100; i++) {
  326. if (waitpid(-1, status, WNOHANG | __WALL) == pid)
  327. return;
  328. usleep(1000);
  329. }
  330. DIR* dir = opendir("/sys/fs/fuse/connections");
  331. if (dir) {
  332. for (;;) {
  333. struct dirent* ent = readdir(dir);
  334. if (!ent)
  335. break;
  336. if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
  337. continue;
  338. char abort[300];
  339. snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
  340. ent->d_name);
  341. int fd = open(abort, O_WRONLY);
  342. if (fd == -1) {
  343. continue;
  344. }
  345. if (write(fd, abort, 1) < 0) {
  346. }
  347. close(fd);
  348. }
  349. closedir(dir);
  350. } else {
  351. }
  352. while (waitpid(-1, status, __WALL) != pid) {
  353. }
  354. }
  355.  
  356. static void setup_test()
  357. {
  358. prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  359. setpgrp();
  360. write_file("/proc/self/oom_score_adj", "1000");
  361. }
  362.  
  363. static void close_fds()
  364. {
  365. for (int fd = 3; fd < MAX_FDS; fd++)
  366. close(fd);
  367. }
  368.  
  369. #define SWAP_FILE "./swap-file"
  370. #define SWAP_FILE_SIZE (128 * 1000 * 1000)
  371.  
  372. static const char* setup_swap()
  373. {
  374. swapoff(SWAP_FILE);
  375. unlink(SWAP_FILE);
  376. int fd = open(SWAP_FILE, O_CREAT | O_WRONLY | O_CLOEXEC, 0600);
  377. if (fd == -1)
  378. return "swap file open failed";
  379. fallocate(fd, FALLOC_FL_ZERO_RANGE, 0, SWAP_FILE_SIZE);
  380. close(fd);
  381. char cmdline[64];
  382. sprintf(cmdline, "mkswap %s", SWAP_FILE);
  383. if (runcmdline(cmdline))
  384. return "mkswap failed";
  385. if (swapon(SWAP_FILE, SWAP_FLAG_PREFER) == 1)
  386. return "swapon failed";
  387. return NULL;
  388. }
  389.  
  390. static void execute_one(void);
  391.  
  392. #define WAIT_FLAGS __WALL
  393.  
  394. static void loop(void)
  395. {
  396. int iter = 0;
  397. for (;; iter++) {
  398. int pid = fork();
  399. if (pid < 0)
  400. exit(1);
  401. if (pid == 0) {
  402. setup_test();
  403. execute_one();
  404. close_fds();
  405. exit(0);
  406. }
  407. int status = 0;
  408. uint64_t start = current_time_ms();
  409. for (;;) {
  410. sleep_ms(10);
  411. if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
  412. break;
  413. if (current_time_ms() - start < 5000)
  414. continue;
  415. kill_and_wait(pid, &status);
  416. break;
  417. }
  418. }
  419. }
  420.  
  421. uint64_t r[1] = {0xffffffffffffffff};
  422.  
  423. void execute_one(void)
  424. {
  425. intptr_t res = 0;
  426. if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
  427. }
  428. // perf_event_open arguments: [
  429. // attr: ptr[in, perf_event_attr] {
  430. // perf_event_attr {
  431. // type: perf_event_type = 0x2 (4 bytes)
  432. // size: len = 0x80 (4 bytes)
  433. // config0: int8 = 0x80 (1 bytes)
  434. // config1: int8 = 0x0 (1 bytes)
  435. // config2: int8 = 0x0 (1 bytes)
  436. // config3: int8 = 0x0 (1 bytes)
  437. // config4: const = 0x0 (4 bytes)
  438. // sample_freq: int64 = 0x1 (8 bytes)
  439. // sample_type: perf_sample_type = 0x0 (8 bytes)
  440. // read_format: perf_read_format = 0x0 (8 bytes)
  441. // disabled: int64 = 0x0 (0 bytes)
  442. // inherit: int64 = 0x0 (0 bytes)
  443. // pinned: int64 = 0x0 (0 bytes)
  444. // exclusive: int64 = 0x0 (0 bytes)
  445. // exclude_user: int64 = 0x0 (0 bytes)
  446. // exclude_kernel: int64 = 0x0 (0 bytes)
  447. // exclude_hv: int64 = 0x0 (0 bytes)
  448. // exclude_idle: int64 = 0x0 (0 bytes)
  449. // mmap: int64 = 0x0 (0 bytes)
  450. // comm: int64 = 0x0 (0 bytes)
  451. // freq: int64 = 0x0 (0 bytes)
  452. // inherit_stat: int64 = 0x0 (0 bytes)
  453. // enable_on_exec: int64 = 0x0 (0 bytes)
  454. // task: int64 = 0x0 (0 bytes)
  455. // watermark: int64 = 0x0 (0 bytes)
  456. // precise_ip: int64 = 0x0 (0 bytes)
  457. // mmap_data: int64 = 0x0 (0 bytes)
  458. // sample_id_all: int64 = 0x0 (0 bytes)
  459. // exclude_host: int64 = 0x0 (0 bytes)
  460. // exclude_guest: int64 = 0x0 (0 bytes)
  461. // exclude_callchain_kernel: int64 = 0x0 (0 bytes)
  462. // exclude_callchain_user: int64 = 0x0 (0 bytes)
  463. // mmap2: int64 = 0x0 (0 bytes)
  464. // comm_exec: int64 = 0x0 (0 bytes)
  465. // use_clockid: int64 = 0x0 (0 bytes)
  466. // context_switch: int64 = 0x0 (0 bytes)
  467. // write_backward: int64 = 0x0 (0 bytes)
  468. // namespaces: int64 = 0x0 (0 bytes)
  469. // ksymbol: int64 = 0x0 (0 bytes)
  470. // bpf_event: int64 = 0x0 (0 bytes)
  471. // aux_output: int64 = 0x0 (0 bytes)
  472. // cgroup: int64 = 0x0 (0 bytes)
  473. // text_poke: int64 = 0x0 (0 bytes)
  474. // build_id: int64 = 0x0 (0 bytes)
  475. // inherit_thread: int64 = 0x0 (0 bytes)
  476. // remove_on_exec: int64 = 0x0 (0 bytes)
  477. // sigtrap: int64 = 0x0 (0 bytes)
  478. // __reserved_1: const = 0x0 (8 bytes)
  479. // wakeup_events: int32 = 0x0 (4 bytes)
  480. // bp_type: perf_bp_type = 0x0 (4 bytes)
  481. // bp_config: union perf_bp_config {
  482. // perf_config_ext: perf_config_ext {
  483. // config1: int64 = 0xd1 (8 bytes)
  484. // config2: int64 = 0x0 (8 bytes)
  485. // }
  486. // }
  487. // branch_sample_type: perf_branch_sample_type = 0x0 (8 bytes)
  488. // sample_regs_user: int64 = 0x0 (8 bytes)
  489. // sample_stack_user: int32 = 0x0 (4 bytes)
  490. // clockid: clock_type = 0x0 (4 bytes)
  491. // sample_regs_intr: int64 = 0x0 (8 bytes)
  492. // aux_watermark: int32 = 0xb1a (4 bytes)
  493. // sample_max_stack: int16 = 0x0 (2 bytes)
  494. // __reserved_2: const = 0x0 (2 bytes)
  495. // aux_sample_size: int32 = 0x0 (4 bytes)
  496. // __reserved_3: const = 0x0 (4 bytes)
  497. // sig_data: int64 = 0x0 (8 bytes)
  498. // }
  499. // }
  500. // pid: pid (resource)
  501. // cpu: intptr = 0x0 (8 bytes)
  502. // group: fd_perf (resource)
  503. // flags: perf_flags = 0x0 (8 bytes)
  504. // ]
  505. // returns fd_perf
  506. NONFAILING(*(uint32_t*)0x200000000100 = 2);
  507. NONFAILING(*(uint32_t*)0x200000000104 = 0x80);
  508. NONFAILING(*(uint8_t*)0x200000000108 = 0x80);
  509. NONFAILING(*(uint8_t*)0x200000000109 = 0);
  510. NONFAILING(*(uint8_t*)0x20000000010a = 0);
  511. NONFAILING(*(uint8_t*)0x20000000010b = 0);
  512. NONFAILING(*(uint32_t*)0x20000000010c = 0);
  513. NONFAILING(*(uint64_t*)0x200000000110 = 1);
  514. NONFAILING(*(uint64_t*)0x200000000118 = 0);
  515. NONFAILING(*(uint64_t*)0x200000000120 = 0);
  516. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 0, 1));
  517. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 1, 1));
  518. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 2, 1));
  519. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 3, 1));
  520. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 4, 1));
  521. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 5, 1));
  522. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 6, 1));
  523. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 7, 1));
  524. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 8, 1));
  525. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 9, 1));
  526. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 10, 1));
  527. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 11, 1));
  528. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 12, 1));
  529. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 13, 1));
  530. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 14, 1));
  531. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 15, 2));
  532. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 17, 1));
  533. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 18, 1));
  534. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 19, 1));
  535. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 20, 1));
  536. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 21, 1));
  537. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 22, 1));
  538. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 23, 1));
  539. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 24, 1));
  540. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 25, 1));
  541. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 26, 1));
  542. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 27, 1));
  543. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 28, 1));
  544. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 29, 1));
  545. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 30, 1));
  546. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 31, 1));
  547. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 32, 1));
  548. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 33, 1));
  549. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 34, 1));
  550. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 35, 1));
  551. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 36, 1));
  552. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 37, 1));
  553. NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200000000128, 0, 38, 26));
  554. NONFAILING(*(uint32_t*)0x200000000130 = 0);
  555. NONFAILING(*(uint32_t*)0x200000000134 = 0);
  556. NONFAILING(*(uint64_t*)0x200000000138 = 0xd1);
  557. NONFAILING(*(uint64_t*)0x200000000140 = 0);
  558. NONFAILING(*(uint64_t*)0x200000000148 = 0);
  559. NONFAILING(*(uint64_t*)0x200000000150 = 0);
  560. NONFAILING(*(uint32_t*)0x200000000158 = 0);
  561. NONFAILING(*(uint32_t*)0x20000000015c = 0);
  562. NONFAILING(*(uint64_t*)0x200000000160 = 0);
  563. NONFAILING(*(uint32_t*)0x200000000168 = 0xb1a);
  564. NONFAILING(*(uint16_t*)0x20000000016c = 0);
  565. NONFAILING(*(uint16_t*)0x20000000016e = 0);
  566. NONFAILING(*(uint32_t*)0x200000000170 = 0);
  567. NONFAILING(*(uint32_t*)0x200000000174 = 0);
  568. NONFAILING(*(uint64_t*)0x200000000178 = 0);
  569. res = syscall(__NR_perf_event_open, /*attr=*/0x200000000100ul, /*pid=*/0,
  570. /*cpu=*/0ul, /*group=*/(intptr_t)-1, /*flags=*/0ul);
  571. if (res != -1)
  572. r[0] = res;
  573. // ioctl$PERF_EVENT_IOC_PERIOD arguments: [
  574. // fd: fd_perf (resource)
  575. // cmd: const = 0x40082404 (4 bytes)
  576. // period: ptr[in, int64] {
  577. // int64 = 0x9 (8 bytes)
  578. // }
  579. // ]
  580. NONFAILING(*(uint64_t*)0x200000000340 = 9);
  581. syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x40082404,
  582. /*period=*/0x200000000340ul);
  583. }
  584. int main(void)
  585. {
  586. syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  587. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  588. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  589. syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul,
  590. /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
  591. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  592. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  593. syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  594. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  595. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  596. const char* reason;
  597. (void)reason;
  598. if ((reason = setup_swap()))
  599. printf("the reproducer may not work as expected: swap setup failed: %s\n",
  600. reason);
  601. install_segv_handler();
  602. do_sandbox_none();
  603. return 0;
  604. }
  605.  
Advertisement
Add Comment
Please, Sign In to add comment