Tang-ZW

Untitled

Nov 21st, 2026
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.51 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 <pthread.h>
  10. #include <setjmp.h>
  11. #include <signal.h>
  12. #include <stdarg.h>
  13. #include <stdbool.h>
  14. #include <stddef.h>
  15. #include <stdint.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <sys/ioctl.h>
  20. #include <sys/mman.h>
  21. #include <sys/mount.h>
  22. #include <sys/prctl.h>
  23. #include <sys/stat.h>
  24. #include <sys/syscall.h>
  25. #include <sys/types.h>
  26. #include <sys/wait.h>
  27. #include <time.h>
  28. #include <unistd.h>
  29.  
  30. #include <linux/futex.h>
  31. #include <linux/loop.h>
  32.  
  33. #ifndef __NR_memfd_create
  34. #define __NR_memfd_create 319
  35. #endif
  36. #ifndef __NR_quotactl_fd
  37. #define __NR_quotactl_fd 443
  38. #endif
  39.  
  40. static unsigned long long procid;
  41.  
  42. static void sleep_ms(uint64_t ms)
  43. {
  44. usleep(ms * 1000);
  45. }
  46.  
  47. static uint64_t current_time_ms(void)
  48. {
  49. struct timespec ts;
  50. if (clock_gettime(CLOCK_MONOTONIC, &ts))
  51. exit(1);
  52. return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
  53. }
  54.  
  55. static void thread_start(void* (*fn)(void*), void* arg)
  56. {
  57. pthread_t th;
  58. pthread_attr_t attr;
  59. pthread_attr_init(&attr);
  60. pthread_attr_setstacksize(&attr, 128 << 10);
  61. int i = 0;
  62. for (; i < 100; i++) {
  63. if (pthread_create(&th, &attr, fn, arg) == 0) {
  64. pthread_attr_destroy(&attr);
  65. return;
  66. }
  67. if (errno == EAGAIN) {
  68. usleep(50);
  69. continue;
  70. }
  71. break;
  72. }
  73. exit(1);
  74. }
  75.  
  76. typedef struct {
  77. int state;
  78. } event_t;
  79.  
  80. static void event_init(event_t* ev)
  81. {
  82. ev->state = 0;
  83. }
  84.  
  85. static void event_reset(event_t* ev)
  86. {
  87. ev->state = 0;
  88. }
  89.  
  90. static void event_set(event_t* ev)
  91. {
  92. if (ev->state)
  93. exit(1);
  94. __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE);
  95. syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000);
  96. }
  97.  
  98. static void event_wait(event_t* ev)
  99. {
  100. while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
  101. syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0);
  102. }
  103.  
  104. static int event_isset(event_t* ev)
  105. {
  106. return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE);
  107. }
  108.  
  109. static int event_timedwait(event_t* ev, uint64_t timeout)
  110. {
  111. uint64_t start = current_time_ms();
  112. uint64_t now = start;
  113. for (;;) {
  114. uint64_t remain = timeout - (now - start);
  115. struct timespec ts;
  116. ts.tv_sec = remain / 1000;
  117. ts.tv_nsec = (remain % 1000) * 1000 * 1000;
  118. syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts);
  119. if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
  120. return 1;
  121. now = current_time_ms();
  122. if (now - start > timeout)
  123. return 0;
  124. }
  125. }
  126.  
  127. static bool write_file(const char* file, const char* what, ...)
  128. {
  129. char buf[1024];
  130. va_list args;
  131. va_start(args, what);
  132. vsnprintf(buf, sizeof(buf), what, args);
  133. va_end(args);
  134. buf[sizeof(buf) - 1] = 0;
  135. int len = strlen(buf);
  136. int fd = open(file, O_WRONLY | O_CLOEXEC);
  137. if (fd == -1)
  138. return false;
  139. if (write(fd, buf, len) != len) {
  140. int err = errno;
  141. close(fd);
  142. errno = err;
  143. return false;
  144. }
  145. close(fd);
  146. return true;
  147. }
  148.  
  149. //% This code is derived from puff.{c,h}, found in the zlib development. The
  150. //% original files come with the following copyright notice:
  151.  
  152. //% Copyright (C) 2002-2013 Mark Adler, all rights reserved
  153. //% version 2.3, 21 Jan 2013
  154. //% This software is provided 'as-is', without any express or implied
  155. //% warranty. In no event will the author be held liable for any damages
  156. //% arising from the use of this software.
  157. //% Permission is granted to anyone to use this software for any purpose,
  158. //% including commercial applications, and to alter it and redistribute it
  159. //% freely, subject to the following restrictions:
  160. //% 1. The origin of this software must not be misrepresented; you must not
  161. //% claim that you wrote the original software. If you use this software
  162. //% in a product, an acknowledgment in the product documentation would be
  163. //% appreciated but is not required.
  164. //% 2. Altered source versions must be plainly marked as such, and must not be
  165. //% misrepresented as being the original software.
  166. //% 3. This notice may not be removed or altered from any source distribution.
  167. //% Mark Adler [email protected]
  168.  
  169. //% BEGIN CODE DERIVED FROM puff.{c,h}
  170.  
  171. #define MAXBITS 15
  172. #define MAXLCODES 286
  173. #define MAXDCODES 30
  174. #define MAXCODES (MAXLCODES + MAXDCODES)
  175. #define FIXLCODES 288
  176.  
  177. struct puff_state {
  178. unsigned char* out;
  179. unsigned long outlen;
  180. unsigned long outcnt;
  181. const unsigned char* in;
  182. unsigned long inlen;
  183. unsigned long incnt;
  184. int bitbuf;
  185. int bitcnt;
  186. jmp_buf env;
  187. };
  188. static int puff_bits(struct puff_state* s, int need)
  189. {
  190. long val = s->bitbuf;
  191. while (s->bitcnt < need) {
  192. if (s->incnt == s->inlen)
  193. longjmp(s->env, 1);
  194. val |= (long)(s->in[s->incnt++]) << s->bitcnt;
  195. s->bitcnt += 8;
  196. }
  197. s->bitbuf = (int)(val >> need);
  198. s->bitcnt -= need;
  199. return (int)(val & ((1L << need) - 1));
  200. }
  201. static int puff_stored(struct puff_state* s)
  202. {
  203. s->bitbuf = 0;
  204. s->bitcnt = 0;
  205. if (s->incnt + 4 > s->inlen)
  206. return 2;
  207. unsigned len = s->in[s->incnt++];
  208. len |= s->in[s->incnt++] << 8;
  209. if (s->in[s->incnt++] != (~len & 0xff) ||
  210. s->in[s->incnt++] != ((~len >> 8) & 0xff))
  211. return -2;
  212. if (s->incnt + len > s->inlen)
  213. return 2;
  214. if (s->outcnt + len > s->outlen)
  215. return 1;
  216. for (; len--; s->outcnt++, s->incnt++) {
  217. if (s->in[s->incnt])
  218. s->out[s->outcnt] = s->in[s->incnt];
  219. }
  220. return 0;
  221. }
  222. struct puff_huffman {
  223. short* count;
  224. short* symbol;
  225. };
  226. static int puff_decode(struct puff_state* s, const struct puff_huffman* h)
  227. {
  228. int first = 0;
  229. int index = 0;
  230. int bitbuf = s->bitbuf;
  231. int left = s->bitcnt;
  232. int code = first = index = 0;
  233. int len = 1;
  234. short* next = h->count + 1;
  235. while (1) {
  236. while (left--) {
  237. code |= bitbuf & 1;
  238. bitbuf >>= 1;
  239. int count = *next++;
  240. if (code - count < first) {
  241. s->bitbuf = bitbuf;
  242. s->bitcnt = (s->bitcnt - len) & 7;
  243. return h->symbol[index + (code - first)];
  244. }
  245. index += count;
  246. first += count;
  247. first <<= 1;
  248. code <<= 1;
  249. len++;
  250. }
  251. left = (MAXBITS + 1) - len;
  252. if (left == 0)
  253. break;
  254. if (s->incnt == s->inlen)
  255. longjmp(s->env, 1);
  256. bitbuf = s->in[s->incnt++];
  257. if (left > 8)
  258. left = 8;
  259. }
  260. return -10;
  261. }
  262. static int puff_construct(struct puff_huffman* h, const short* length, int n)
  263. {
  264. int len;
  265. for (len = 0; len <= MAXBITS; len++)
  266. h->count[len] = 0;
  267. int symbol;
  268. for (symbol = 0; symbol < n; symbol++)
  269. (h->count[length[symbol]])++;
  270. if (h->count[0] == n)
  271. return 0;
  272. int left = 1;
  273. for (len = 1; len <= MAXBITS; len++) {
  274. left <<= 1;
  275. left -= h->count[len];
  276. if (left < 0)
  277. return left;
  278. }
  279. short offs[MAXBITS + 1];
  280. offs[1] = 0;
  281. for (len = 1; len < MAXBITS; len++)
  282. offs[len + 1] = offs[len] + h->count[len];
  283. for (symbol = 0; symbol < n; symbol++)
  284. if (length[symbol] != 0)
  285. h->symbol[offs[length[symbol]]++] = symbol;
  286. return left;
  287. }
  288. static int puff_codes(struct puff_state* s, const struct puff_huffman* lencode,
  289. const struct puff_huffman* distcode)
  290. {
  291. static const short lens[29] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13,
  292. 15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
  293. 67, 83, 99, 115, 131, 163, 195, 227, 258};
  294. static const short lext[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2,
  295. 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
  296. static const short dists[30] = {
  297. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25,
  298. 33, 49, 65, 97, 129, 193, 257, 385, 513, 769,
  299. 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577};
  300. static const short dext[30] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
  301. 4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
  302. 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
  303. int symbol;
  304. do {
  305. symbol = puff_decode(s, lencode);
  306. if (symbol < 0)
  307. return symbol;
  308. if (symbol < 256) {
  309. if (s->outcnt == s->outlen)
  310. return 1;
  311. if (symbol)
  312. s->out[s->outcnt] = symbol;
  313. s->outcnt++;
  314. } else if (symbol > 256) {
  315. symbol -= 257;
  316. if (symbol >= 29)
  317. return -10;
  318. int len = lens[symbol] + puff_bits(s, lext[symbol]);
  319. symbol = puff_decode(s, distcode);
  320. if (symbol < 0)
  321. return symbol;
  322. unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]);
  323. if (dist > s->outcnt)
  324. return -11;
  325. if (s->outcnt + len > s->outlen)
  326. return 1;
  327. while (len--) {
  328. if (dist <= s->outcnt && s->out[s->outcnt - dist])
  329. s->out[s->outcnt] = s->out[s->outcnt - dist];
  330. s->outcnt++;
  331. }
  332. }
  333. } while (symbol != 256);
  334. return 0;
  335. }
  336. static int puff_fixed(struct puff_state* s)
  337. {
  338. static int virgin = 1;
  339. static short lencnt[MAXBITS + 1], lensym[FIXLCODES];
  340. static short distcnt[MAXBITS + 1], distsym[MAXDCODES];
  341. static struct puff_huffman lencode, distcode;
  342. if (virgin) {
  343. lencode.count = lencnt;
  344. lencode.symbol = lensym;
  345. distcode.count = distcnt;
  346. distcode.symbol = distsym;
  347. short lengths[FIXLCODES];
  348. int symbol;
  349. for (symbol = 0; symbol < 144; symbol++)
  350. lengths[symbol] = 8;
  351. for (; symbol < 256; symbol++)
  352. lengths[symbol] = 9;
  353. for (; symbol < 280; symbol++)
  354. lengths[symbol] = 7;
  355. for (; symbol < FIXLCODES; symbol++)
  356. lengths[symbol] = 8;
  357. puff_construct(&lencode, lengths, FIXLCODES);
  358. for (symbol = 0; symbol < MAXDCODES; symbol++)
  359. lengths[symbol] = 5;
  360. puff_construct(&distcode, lengths, MAXDCODES);
  361. virgin = 0;
  362. }
  363. return puff_codes(s, &lencode, &distcode);
  364. }
  365. static int puff_dynamic(struct puff_state* s)
  366. {
  367. static const short order[19] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5,
  368. 11, 4, 12, 3, 13, 2, 14, 1, 15};
  369. int nlen = puff_bits(s, 5) + 257;
  370. int ndist = puff_bits(s, 5) + 1;
  371. int ncode = puff_bits(s, 4) + 4;
  372. if (nlen > MAXLCODES || ndist > MAXDCODES)
  373. return -3;
  374. short lengths[MAXCODES];
  375. int index;
  376. for (index = 0; index < ncode; index++)
  377. lengths[order[index]] = puff_bits(s, 3);
  378. for (; index < 19; index++)
  379. lengths[order[index]] = 0;
  380. short lencnt[MAXBITS + 1], lensym[MAXLCODES];
  381. struct puff_huffman lencode = {lencnt, lensym};
  382. int err = puff_construct(&lencode, lengths, 19);
  383. if (err != 0)
  384. return -4;
  385. index = 0;
  386. while (index < nlen + ndist) {
  387. int symbol;
  388. int len;
  389. symbol = puff_decode(s, &lencode);
  390. if (symbol < 0)
  391. return symbol;
  392. if (symbol < 16)
  393. lengths[index++] = symbol;
  394. else {
  395. len = 0;
  396. if (symbol == 16) {
  397. if (index == 0)
  398. return -5;
  399. len = lengths[index - 1];
  400. symbol = 3 + puff_bits(s, 2);
  401. } else if (symbol == 17)
  402. symbol = 3 + puff_bits(s, 3);
  403. else
  404. symbol = 11 + puff_bits(s, 7);
  405. if (index + symbol > nlen + ndist)
  406. return -6;
  407. while (symbol--)
  408. lengths[index++] = len;
  409. }
  410. }
  411. if (lengths[256] == 0)
  412. return -9;
  413. err = puff_construct(&lencode, lengths, nlen);
  414. if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1]))
  415. return -7;
  416. short distcnt[MAXBITS + 1], distsym[MAXDCODES];
  417. struct puff_huffman distcode = {distcnt, distsym};
  418. err = puff_construct(&distcode, lengths + nlen, ndist);
  419. if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1]))
  420. return -8;
  421. return puff_codes(s, &lencode, &distcode);
  422. }
  423. static int puff(unsigned char* dest, unsigned long* destlen,
  424. const unsigned char* source, unsigned long sourcelen)
  425. {
  426. struct puff_state s = {
  427. .out = dest,
  428. .outlen = *destlen,
  429. .outcnt = 0,
  430. .in = source,
  431. .inlen = sourcelen,
  432. .incnt = 0,
  433. .bitbuf = 0,
  434. .bitcnt = 0,
  435. };
  436. int err;
  437. if (setjmp(s.env) != 0)
  438. err = 2;
  439. else {
  440. int last;
  441. do {
  442. last = puff_bits(&s, 1);
  443. int type = puff_bits(&s, 2);
  444. err = type == 0 ? puff_stored(&s)
  445. : (type == 1 ? puff_fixed(&s)
  446. : (type == 2 ? puff_dynamic(&s) : -1));
  447. if (err != 0)
  448. break;
  449. } while (!last);
  450. }
  451. *destlen = s.outcnt;
  452. return err;
  453. }
  454.  
  455. //% END CODE DERIVED FROM puff.{c,h}
  456.  
  457. #define ZLIB_HEADER_WIDTH 2
  458.  
  459. static int puff_zlib_to_file(const unsigned char* source,
  460. unsigned long sourcelen, int dest_fd)
  461. {
  462. if (sourcelen < ZLIB_HEADER_WIDTH)
  463. return 0;
  464. source += ZLIB_HEADER_WIDTH;
  465. sourcelen -= ZLIB_HEADER_WIDTH;
  466. const unsigned long max_destlen = 132 << 20;
  467. void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ,
  468. MAP_PRIVATE | MAP_ANON, -1, 0);
  469. if (ret == MAP_FAILED)
  470. return -1;
  471. unsigned char* dest = (unsigned char*)ret;
  472. unsigned long destlen = max_destlen;
  473. int err = puff(dest, &destlen, source, sourcelen);
  474. if (err) {
  475. munmap(dest, max_destlen);
  476. errno = -err;
  477. return -1;
  478. }
  479. if (write(dest_fd, dest, destlen) != (ssize_t)destlen) {
  480. munmap(dest, max_destlen);
  481. return -1;
  482. }
  483. return munmap(dest, max_destlen);
  484. }
  485.  
  486. static int setup_loop_device(unsigned char* data, unsigned long size,
  487. const char* loopname, int* loopfd_p)
  488. {
  489. int err = 0, loopfd = -1;
  490. int memfd = syscall(__NR_memfd_create, "syzkaller", 0);
  491. if (memfd == -1) {
  492. err = errno;
  493. goto error;
  494. }
  495. if (puff_zlib_to_file(data, size, memfd)) {
  496. err = errno;
  497. goto error_close_memfd;
  498. }
  499. loopfd = open(loopname, O_RDWR);
  500. if (loopfd == -1) {
  501. err = errno;
  502. goto error_close_memfd;
  503. }
  504. if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
  505. if (errno != EBUSY) {
  506. err = errno;
  507. goto error_close_loop;
  508. }
  509. ioctl(loopfd, LOOP_CLR_FD, 0);
  510. usleep(1000);
  511. if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
  512. err = errno;
  513. goto error_close_loop;
  514. }
  515. }
  516. close(memfd);
  517. *loopfd_p = loopfd;
  518. return 0;
  519.  
  520. error_close_loop:
  521. close(loopfd);
  522. error_close_memfd:
  523. close(memfd);
  524. error:
  525. errno = err;
  526. return -1;
  527. }
  528.  
  529. static void reset_loop_device(const char* loopname)
  530. {
  531. int loopfd = open(loopname, O_RDWR);
  532. if (loopfd == -1) {
  533. return;
  534. }
  535. if (ioctl(loopfd, LOOP_CLR_FD, 0)) {
  536. }
  537. close(loopfd);
  538. }
  539.  
  540. static long syz_mount_image(volatile long fsarg, volatile long dir,
  541. volatile long flags, volatile long optsarg,
  542. volatile long change_dir,
  543. volatile unsigned long size, volatile long image)
  544. {
  545. unsigned char* data = (unsigned char*)image;
  546. int res = -1, err = 0, need_loop_device = !!size;
  547. char* mount_opts = (char*)optsarg;
  548. char* target = (char*)dir;
  549. char* fs = (char*)fsarg;
  550. char* source = NULL;
  551. char loopname[64];
  552. if (need_loop_device) {
  553. int loopfd;
  554. memset(loopname, 0, sizeof(loopname));
  555. snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
  556. if (setup_loop_device(data, size, loopname, &loopfd) == -1)
  557. return -1;
  558. close(loopfd);
  559. source = loopname;
  560. }
  561. mkdir(target, 0777);
  562. char opts[256];
  563. memset(opts, 0, sizeof(opts));
  564. if (strlen(mount_opts) > (sizeof(opts) - 32)) {
  565. }
  566. strncpy(opts, mount_opts, sizeof(opts) - 32);
  567. if (strcmp(fs, "iso9660") == 0) {
  568. flags |= MS_RDONLY;
  569. } else if (strncmp(fs, "ext", 3) == 0) {
  570. bool has_remount_ro = false;
  571. char* remount_ro_start = strstr(opts, "errors=remount-ro");
  572. if (remount_ro_start != NULL) {
  573. char after = *(remount_ro_start + strlen("errors=remount-ro"));
  574. char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1);
  575. has_remount_ro = ((before == '\0' || before == ',') &&
  576. (after == '\0' || after == ','));
  577. }
  578. if (strstr(opts, "errors=panic") || !has_remount_ro)
  579. strcat(opts, ",errors=continue");
  580. } else if (strcmp(fs, "xfs") == 0) {
  581. strcat(opts, ",nouuid");
  582. } else if (strncmp(fs, "gfs2", 4) == 0 &&
  583. (strstr(opts, "errors=panic") || strstr(opts, "debug"))) {
  584. strcat(opts, ",errors=withdraw");
  585. }
  586. res = mount(source, target, fs, flags, opts);
  587. if (res == -1) {
  588. err = errno;
  589. goto error_clear_loop;
  590. }
  591. res = open(target, O_RDONLY | O_DIRECTORY);
  592. if (res == -1) {
  593. err = errno;
  594. goto error_clear_loop;
  595. }
  596. if (change_dir) {
  597. res = chdir(target);
  598. if (res == -1) {
  599. err = errno;
  600. }
  601. }
  602.  
  603. error_clear_loop:
  604. if (need_loop_device)
  605. reset_loop_device(loopname);
  606. errno = err;
  607. return res;
  608. }
  609.  
  610. static void kill_and_wait(int pid, int* status)
  611. {
  612. kill(-pid, SIGKILL);
  613. kill(pid, SIGKILL);
  614. for (int i = 0; i < 100; i++) {
  615. if (waitpid(-1, status, WNOHANG | __WALL) == pid)
  616. return;
  617. usleep(1000);
  618. }
  619. DIR* dir = opendir("/sys/fs/fuse/connections");
  620. if (dir) {
  621. for (;;) {
  622. struct dirent* ent = readdir(dir);
  623. if (!ent)
  624. break;
  625. if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
  626. continue;
  627. char abort[300];
  628. snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
  629. ent->d_name);
  630. int fd = open(abort, O_WRONLY);
  631. if (fd == -1) {
  632. continue;
  633. }
  634. if (write(fd, abort, 1) < 0) {
  635. }
  636. close(fd);
  637. }
  638. closedir(dir);
  639. } else {
  640. }
  641. while (waitpid(-1, status, __WALL) != pid) {
  642. }
  643. }
  644.  
  645. static void reset_loop()
  646. {
  647. char buf[64];
  648. snprintf(buf, sizeof(buf), "/dev/loop%llu", procid);
  649. int loopfd = open(buf, O_RDWR);
  650. if (loopfd != -1) {
  651. ioctl(loopfd, LOOP_CLR_FD, 0);
  652. close(loopfd);
  653. }
  654. }
  655.  
  656. static void setup_test()
  657. {
  658. prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  659. setpgrp();
  660. write_file("/proc/self/oom_score_adj", "1000");
  661. }
  662.  
  663. struct thread_t {
  664. int created, call;
  665. event_t ready, done;
  666. };
  667.  
  668. static struct thread_t threads[16];
  669. static void execute_call(int call);
  670. static int running;
  671.  
  672. static void* thr(void* arg)
  673. {
  674. struct thread_t* th = (struct thread_t*)arg;
  675. for (;;) {
  676. event_wait(&th->ready);
  677. event_reset(&th->ready);
  678. execute_call(th->call);
  679. __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
  680. event_set(&th->done);
  681. }
  682. return 0;
  683. }
  684.  
  685. static void execute_one(void)
  686. {
  687. if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
  688. }
  689. int i, call, thread;
  690. for (call = 0; call < 10; call++) {
  691. for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0]));
  692. thread++) {
  693. struct thread_t* th = &threads[thread];
  694. if (!th->created) {
  695. th->created = 1;
  696. event_init(&th->ready);
  697. event_init(&th->done);
  698. event_set(&th->done);
  699. thread_start(thr, th);
  700. }
  701. if (!event_isset(&th->done))
  702. continue;
  703. event_reset(&th->done);
  704. th->call = call;
  705. __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
  706. event_set(&th->ready);
  707. event_timedwait(&th->done, 50 + (call == 0 ? 4000 : 0));
  708. break;
  709. }
  710. }
  711. for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++)
  712. sleep_ms(1);
  713. }
  714.  
  715. static void execute_one(void);
  716.  
  717. #define WAIT_FLAGS __WALL
  718.  
  719. static void loop(void)
  720. {
  721. int iter = 0;
  722. for (;; iter++) {
  723. reset_loop();
  724. int pid = fork();
  725. if (pid < 0)
  726. exit(1);
  727. if (pid == 0) {
  728. setup_test();
  729. execute_one();
  730. exit(0);
  731. }
  732. int status = 0;
  733. uint64_t start = current_time_ms();
  734. for (;;) {
  735. sleep_ms(10);
  736. if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
  737. break;
  738. if (current_time_ms() - start < 5000)
  739. continue;
  740. kill_and_wait(pid, &status);
  741. break;
  742. }
  743. }
  744. }
  745.  
  746. uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff,
  747. 0x0};
  748.  
  749. void execute_call(int call)
  750. {
  751. intptr_t res = 0;
  752. switch (call) {
  753. case 0:
  754. // syz_mount_image$ext4 arguments: [
  755. // fs: ptr[in, buffer] {
  756. // buffer: {65 78 74 34 00} (length 0x5)
  757. // }
  758. // dir: ptr[in, buffer] {
  759. // buffer: {2e 2f 62 75 73 00} (length 0x6)
  760. // }
  761. // flags: mount_flags = 0x0 (8 bytes)
  762. // opts: ptr[in, fs_options[ext4_options]] {
  763. // fs_options[ext4_options] {
  764. // elems: array[fs_opt_elem[ext4_options]] {
  765. // }
  766. // common: array[fs_opt_elem[fs_options_common]] {
  767. // }
  768. // null: const = 0x0 (1 bytes)
  769. // }
  770. // }
  771. // chdir: int8 = 0x1 (1 bytes)
  772. // size: len = 0x79e (8 bytes)
  773. // img: ptr[in, buffer] {
  774. // buffer: (compressed buffer with length 0x79e)
  775. // }
  776. // ]
  777. // returns fd_dir
  778. memcpy((void*)0x200000000040, "ext4\000", 5);
  779. memcpy((void*)0x200000000000, "./bus\000", 6);
  780. *(uint8_t*)0x2000000001c0 = 0;
  781. memcpy(
  782. (void*)0x2000000018c0,
  783. "\x78\x9c\xec\xdd\xcb\x6b\x5c\x65\x1b\x00\xf0\xe7\x4c\x6e\x4d\xda\xef"
  784. "\x4b\x3e\xf8\x40\xeb\x2a\x20\x68\xa0\x74\x62\x6a\x6c\x15\x5c\x54\x5c"
  785. "\x88\x60\xa1\xa0\x6b\xdb\x30\x99\x86\x36\x93\x4c\xc9\x4c\x4a\x13\x02"
  786. "\x6d\x11\xc1\x8d\xa0\xc5\x85\xa0\x9b\xee\x04\x2f\x75\xe7\xd6\xcb\x56"
  787. "\xff\x0b\x17\xd2\x52\x6c\x1a\x8c\xb8\x90\x91\x33\x99\x69\x27\xcd\x4c"
  788. "\x3a\x69\x6e\x8d\xf9\xfd\xe0\xb4\xef\x3b\xe7\x4c\x9e\xf7\x39\x97\xf7"
  789. "\xbc\x33\xe7\x30\x27\x80\x7d\x6b\x30\xfd\x27\x13\x71\x38\x22\x3e\x4a"
  790. "\x22\xfa\x6b\xaf\x27\x11\xd1\x55\x2d\x75\x46\x9c\x5c\x59\x6e\x79\x71"
  791. "\x21\x97\x4e\x49\x54\x2a\x6f\xff\x9e\x54\x97\x59\x5a\x5c\xc8\x45\xc3"
  792. "\x7b\x52\x07\x6b\x95\xa7\x23\xe2\xc7\xf7\x23\x8e\x64\xd6\xc6\x2d\xcd"
  793. "\xcd\x4f\x8e\x15\x0a\xf9\x99\x5a\x7d\xb8\x3c\x75\x71\xb8\x34\x37\x7f"
  794. "\xf4\xfc\xd4\xd8\x44\x7e\x22\x3f\x7d\x7c\x64\x74\xf4\xd8\x89\x97\x4e"
  795. "\x1c\xdf\xba\x5c\xff\xf8\x65\xfe\xd0\xed\x8f\xdf\x78\xfe\x9b\x93\x7f"
  796. "\xbd\xf7\xd4\xcd\x0f\x7f\x4a\xe2\x64\x1c\xaa\xcd\x6b\xcc\x63\xab\x0c"
  797. "\xc6\x60\x6d\x9d\x74\xa5\xab\x70\x95\xd7\xb7\x3a\xd8\x2e\x4b\xd6\x99"
  798. "\x77\x60\x07\xdb\xc1\xc6\xa4\x87\x66\xc7\xca\x51\x1e\x87\xa3\x3f\x3a"
  799. "\xaa\xa5\x16\x7a\x77\xb2\x65\x00\xc0\x76\xb9\x12\x11\x15\x00\x60\x9f"
  800. "\x49\x9c\xff\x01\x60\x9f\xa9\x7f\x0f\xb0\xb4\xb8\x90\xab\x4f\xeb\x7c"
  801. "\x5d\xb0\xce\xc5\x81\xbd\xe9\xce\x6b\x2b\x17\xa8\x96\x6a\xd7\x36\x97"
  802. "\xef\xe7\xdf\x59\xbb\x66\x77\xa0\x7a\x1d\xb4\x6f\x29\x59\x95\x7c\x12"
  803. "\x11\x03\x5b\x10\x7f\x30\x22\x3e\xff\xee\xdd\xaf\xd2\x29\xb6\xe9\x3a"
  804. "\x24\x40\x33\x57\xaf\x45\xc4\xd9\x81\xc1\xb5\xfd\x7f\xb2\xe6\x9e\x85"
  805. "\x8d\x7a\xa1\x8d\x65\x06\x1f\xaa\x37\xf4\x7f\xdd\x9b\x0c\x0f\x3c\xc2"
  806. "\xf7\xe9\xf8\xe7\xe5\x66\xe3\xbf\xcc\xfd\xf1\x4f\x34\x19\xff\xf4\x34"
  807. "\x39\x76\x1f\xc7\x3a\xc7\x7f\x4d\xe6\xd6\x16\x84\x69\x29\x1d\xff\xbd"
  808. "\xda\x70\x6f\xdb\x72\x43\xfe\x35\x03\x1d\xb5\xda\x7f\xaa\x63\xbe\xae"
  809. "\xe4\xdc\xf9\x42\x3e\xed\xdb\xfe\x1b\x11\x43\xd1\xd5\x93\xd6\x47\xd6"
  810. "\x89\x31\x74\xef\xef\x7b\xad\xe6\x35\x8e\xff\xee\x5e\xbf\x90\xf6\x79"
  811. "\xb9\xbb\xd7\x2f\x7c\xf9\x60\x89\xcc\xad\xce\x9e\xd5\xef\x19\x1f\x2b"
  812. "\x8f\x6d\x26\xe7\x46\x77\xae\x45\x3c\xd3\xd9\x2c\xff\x7a\xff\xbf\x72"
  813. "\x0f\x5b\xb3\xf1\xef\xe9\x36\x63\xbc\xf9\xca\x07\x9f\xb5\x9a\x97\xe6"
  814. "\x9f\xe6\x5b\x9f\xd2\xf8\xab\xf3\xdf\x5e\x95\x1b\x11\xcf\x35\xdd\xfe"
  815. "\x0f\xee\x68\x4b\xd6\xbd\x3f\x71\xb8\xba\x3b\x0c\xd7\x77\x8a\x26\xbe"
  816. "\xfd\xf5\xd3\xbe\x56\xf1\x1b\xb7\x7f\x3a\xa5\xf1\xeb\x9f\x05\x76\x42"
  817. "\xba\xfd\xfb\xd6\xcf\x7f\x20\x69\xbc\x5f\xb3\xb4\xf1\x18\x3f\xdf\xe8"
  818. "\xff\xa1\xd5\xbc\x47\xe7\xdf\x7c\xff\xef\x4e\xde\xa9\x96\xeb\x83\x84"
  819. "\xcb\x63\xe5\xf2\xcc\x48\x44\x77\xf2\xd6\xda\xd7\x8f\x3d\x78\x6f\xbd"
  820. "\x5e\x5f\x3e\xcd\x7f\xe8\xd9\xee\xa6\xc7\x7f\xbd\xff\x6b\xb6\xff\xa7"
  821. "\x9f\x09\xcf\xb6\x99\x7f\xe7\xed\x6b\x5f\x3f\x7e\xfe\xdb\x2b\xcd\x7f"
  822. "\x7c\x43\xdb\x7f\xe3\x85\x9b\xcb\x93\x1d\xad\xe2\xb7\xb7\xfd\x47\xab"
  823. "\xa5\xa1\xda\x2b\xed\xf4\x7f\xed\x36\x70\x33\xeb\x0e\x00\x00\x00\x00"
  824. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xda\x95"
  825. "\x89\x88\x43\x91\x64\xb2\xf7\xcb\x99\x4c\x36\xbb\xf2\x0c\xef\xff\x47"
  826. "\x5f\xa6\x50\x2c\x95\x8f\x9c\x2b\xce\x4e\x8f\x47\xf5\x59\xd9\x03\xd1"
  827. "\x95\xa9\xff\xd4\x65\x7f\xc3\xef\xa1\x8e\xd4\x7e\x0f\xbf\x5e\x3f\xf6"
  828. "\x50\xfd\xc5\x88\xf8\x5f\x44\x7c\xd2\xd3\x5b\xad\x67\x73\xc5\xc2\xf8"
  829. "\x6e\x27\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  830. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  831. "\x35\x07\x5b\x3c\xff\x3f\xf5\x5b\xcf\x6e\xb7\x0e\x00\xd8\x36\x07\x76"
  832. "\xbb\x01\x00\xc0\x8e\x73\xfe\x07\x80\xfd\x67\x63\xe7\xff\xde\x6d\x6b"
  833. "\x07\x00\xb0\x73\x7c\xfe\x07\x80\xfd\xc7\xf9\x1f\x00\xf6\x1f\xe7\x7f"
  834. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  835. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  836. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  837. "\xb6\xd9\xe9\x53\xa7\xd2\xa9\xf2\xe7\xe2\x42\x2e\xad\x8f\x5f\x9a\x9b"
  838. "\x9d\x2c\x5e\x3a\x3a\x9e\x2f\x4d\x66\xa7\x66\x73\xd9\x5c\x71\xe6\x62"
  839. "\x76\xa2\x58\x9c\x28\xe4\xb3\xb9\xe2\x54\xcb\x3f\x74\x75\xe5\xbf\x42"
  840. "\xb1\x78\x71\x34\xa6\x67\x2f\x0f\x97\xf3\xa5\xf2\x70\x69\x6e\xfe\xcc"
  841. "\x54\x71\x76\xba\x7c\xe6\xfc\xd4\xd8\x44\xfe\x4c\xbe\x6b\xc7\x32\x03"
  842. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  843. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf6\x95\xe6"
  844. "\xe6\x27\xc7\x0a\x85\xfc\xcc\x9e\x29\x54\x2a\x95\x2b\x4f\x40\x33\xfe"
  845. "\x0d\x85\x8e\xda\x4e\xf0\xa4\xb4\x67\xcf\x15\x32\x9b\x58\x75\x5f\xec"
  846. "\x76\xe3\x1f\x51\x68\xec\x25\x7a\x77\xa7\x73\x02\x00\x00\x00\x00\x00"
  847. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  848. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  849. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  850. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  851. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  852. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  853. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  854. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  855. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  856. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  857. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  858. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  859. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  860. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  861. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  862. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  863. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  864. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  865. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  866. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  867. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  868. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  869. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  870. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  871. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  872. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  873. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  874. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  875. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  876. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  877. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  878. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  879. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  880. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  881. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  882. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  883. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  884. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  885. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  886. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  887. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  888. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  889. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  890. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  891. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  892. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  893. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  894. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  895. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  896. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  897. "\xd8\x03\xfe\x09\x00\x00\xff\xff\xaa\x8a\x25\x14",
  898. 1950);
  899. syz_mount_image(/*fs=*/0x200000000040, /*dir=*/0x200000000000, /*flags=*/0,
  900. /*opts=*/0x2000000001c0, /*chdir=*/1, /*size=*/0x79e,
  901. /*img=*/0x2000000018c0);
  902. break;
  903. case 1:
  904. // openat$cgroup_ro arguments: [
  905. // fd: fd_cgroup (resource)
  906. // file: ptr[in, buffer] {
  907. // buffer: {62 6c 6b 69 6f 2e 62 66 71 2e 69 6f 5f 6d 65 72 67 65 64
  908. // 00} (length 0x14)
  909. // }
  910. // flags: const = 0x275a (4 bytes)
  911. // mode: const = 0x0 (2 bytes)
  912. // ]
  913. // returns fd
  914. memcpy((void*)0x2000000000c0, "blkio.bfq.io_merged\000", 20);
  915. res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x2000000000c0ul,
  916. /*flags=*/0x275a, /*mode=*/0);
  917. if (res != -1)
  918. r[0] = res;
  919. break;
  920. case 2:
  921. // creat arguments: [
  922. // file: ptr[in, buffer] {
  923. // buffer: {2e 2f 62 75 73 00} (length 0x6)
  924. // }
  925. // mode: open_mode = 0x0 (8 bytes)
  926. // ]
  927. // returns fd
  928. memcpy((void*)0x2000000003c0, "./bus\000", 6);
  929. syscall(__NR_creat, /*file=*/0x2000000003c0ul, /*mode=*/0ul);
  930. break;
  931. case 3:
  932. // open arguments: [
  933. // file: ptr[in, buffer] {
  934. // buffer: {2e 2f 62 75 73 00} (length 0x6)
  935. // }
  936. // flags: open_flags = 0x14103e (8 bytes)
  937. // mode: open_mode = 0x0 (8 bytes)
  938. // ]
  939. // returns fd
  940. memcpy((void*)0x2000000000c0, "./bus\000", 6);
  941. res = syscall(__NR_open, /*file=*/0x2000000000c0ul,
  942. /*flags=O_SYNC|O_NOATIME|O_RDWR|0x3c*/ 0x14103eul,
  943. /*mode=*/0ul);
  944. if (res != -1)
  945. r[1] = res;
  946. break;
  947. case 4:
  948. // open arguments: [
  949. // file: ptr[in, buffer] {
  950. // buffer: {2e 2f 62 75 73 00} (length 0x6)
  951. // }
  952. // flags: open_flags = 0x143042 (8 bytes)
  953. // mode: open_mode = 0x0 (8 bytes)
  954. // ]
  955. // returns fd
  956. memcpy((void*)0x2000000004c0, "./bus\000", 6);
  957. res = syscall(__NR_open, /*file=*/0x2000000004c0ul,
  958. /*flags=O_SYNC|O_NOATIME|O_CREAT|FASYNC|O_RDWR*/ 0x143042ul,
  959. /*mode=*/0ul);
  960. if (res != -1)
  961. r[2] = res;
  962. break;
  963. case 5:
  964. // ftruncate arguments: [
  965. // fd: fd (resource)
  966. // len: intptr = 0x2008002 (8 bytes)
  967. // ]
  968. syscall(__NR_ftruncate, /*fd=*/r[2], /*len=*/0x2008002ul);
  969. break;
  970. case 6:
  971. // mmap arguments: [
  972. // addr: VMA[0x600000]
  973. // len: len = 0x600000 (8 bytes)
  974. // prot: mmap_prot = 0x7ffffe (8 bytes)
  975. // flags: mmap_flags = 0x11 (8 bytes)
  976. // fd: fd (resource)
  977. // offset: intptr = 0x0 (8 bytes)
  978. // ]
  979. syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x600000ul,
  980. /*prot=PROT_SEM|PROT_WRITE|PROT_EXEC|0x7ffff0*/ 0x7ffffeul,
  981. /*flags=MAP_FIXED|MAP_SHARED*/ 0x11ul, /*fd=*/r[1], /*offset=*/0ul);
  982. break;
  983. case 7:
  984. // gettid arguments: [
  985. // ]
  986. // returns pid
  987. res = syscall(__NR_gettid);
  988. if (res != -1)
  989. r[3] = res;
  990. break;
  991. case 8:
  992. // process_vm_writev arguments: [
  993. // pid: pid (resource)
  994. // loc_vec: ptr[in, array[iovec[out, array[int8]]]] {
  995. // array[iovec[out, array[int8]]] {
  996. // iovec[out, array[int8]] {
  997. // addr: ptr[out, buffer] {
  998. // buffer: (DirOut)
  999. // }
  1000. // len: len = 0x1f80 (8 bytes)
  1001. // }
  1002. // }
  1003. // }
  1004. // loc_vlen: len = 0x2b (8 bytes)
  1005. // rem_vec: ptr[in, array[iovec[out, array[int8]]]] {
  1006. // array[iovec[out, array[int8]]] {
  1007. // iovec[out, array[int8]] {
  1008. // addr: ptr[out, buffer] {
  1009. // buffer: (DirOut)
  1010. // }
  1011. // len: len = 0x2034afa5 (8 bytes)
  1012. // }
  1013. // }
  1014. // }
  1015. // rem_vlen: len = 0x1 (8 bytes)
  1016. // flags: const = 0x0 (8 bytes)
  1017. // ]
  1018. *(uint64_t*)0x200000c22000 = 0x20000034afa4;
  1019. *(uint64_t*)0x200000c22008 = 0x1f80;
  1020. *(uint64_t*)0x200000c22fa0 = 0x200000000080;
  1021. *(uint64_t*)0x200000c22fa8 = 0x2034afa5;
  1022. syscall(__NR_process_vm_writev, /*pid=*/r[3], /*loc_vec=*/0x200000c22000ul,
  1023. /*loc_vlen=*/0x2bul, /*rem_vec=*/0x200000c22fa0ul, /*rem_vlen=*/1ul,
  1024. /*flags=*/0ul);
  1025. break;
  1026. case 9:
  1027. // quotactl_fd$Q_QUOTAOFF arguments: [
  1028. // fd: fd (resource)
  1029. // cmd: quota_cmd_quota_off = 0xffffffff80000302 (8 bytes)
  1030. // id: uid (resource)
  1031. // addr: const = 0x0 (8 bytes)
  1032. // ]
  1033. syscall(__NR_quotactl_fd, /*fd=*/r[0],
  1034. /*cmd=Q_QUOTAOFF_PRJ*/ 0xffffffff80000302ul, /*id=*/0xee01,
  1035. /*addr=*/0ul);
  1036. break;
  1037. }
  1038. }
  1039. int main(void)
  1040. {
  1041. syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  1042. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  1043. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  1044. syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul,
  1045. /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
  1046. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  1047. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  1048. syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  1049. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  1050. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  1051. const char* reason;
  1052. (void)reason;
  1053. for (procid = 0; procid < 4; procid++) {
  1054. if (fork() == 0) {
  1055. loop();
  1056. }
  1057. }
  1058. sleep(1000000);
  1059. return 0;
  1060. }
  1061.  
Advertisement
Add Comment
Please, Sign In to add comment