Tang-ZW

Untitled

Apr 21st, 2026
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.80 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.  
  37. static unsigned long long procid;
  38.  
  39. static void sleep_ms(uint64_t ms)
  40. {
  41. usleep(ms * 1000);
  42. }
  43.  
  44. static uint64_t current_time_ms(void)
  45. {
  46. struct timespec ts;
  47. if (clock_gettime(CLOCK_MONOTONIC, &ts))
  48. exit(1);
  49. return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
  50. }
  51.  
  52. static void use_temporary_dir(void)
  53. {
  54. char tmpdir_template[] = "./syzkaller.XXXXXX";
  55. char* tmpdir = mkdtemp(tmpdir_template);
  56. if (!tmpdir)
  57. exit(1);
  58. if (chmod(tmpdir, 0777))
  59. exit(1);
  60. if (chdir(tmpdir))
  61. exit(1);
  62. }
  63.  
  64. static void thread_start(void* (*fn)(void*), void* arg)
  65. {
  66. pthread_t th;
  67. pthread_attr_t attr;
  68. pthread_attr_init(&attr);
  69. pthread_attr_setstacksize(&attr, 128 << 10);
  70. int i = 0;
  71. for (; i < 100; i++) {
  72. if (pthread_create(&th, &attr, fn, arg) == 0) {
  73. pthread_attr_destroy(&attr);
  74. return;
  75. }
  76. if (errno == EAGAIN) {
  77. usleep(50);
  78. continue;
  79. }
  80. break;
  81. }
  82. exit(1);
  83. }
  84.  
  85. #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
  86. #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \
  87. *(type*)(addr) = \
  88. htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \
  89. (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))
  90.  
  91. typedef struct {
  92. int state;
  93. } event_t;
  94.  
  95. static void event_init(event_t* ev)
  96. {
  97. ev->state = 0;
  98. }
  99.  
  100. static void event_reset(event_t* ev)
  101. {
  102. ev->state = 0;
  103. }
  104.  
  105. static void event_set(event_t* ev)
  106. {
  107. if (ev->state)
  108. exit(1);
  109. __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE);
  110. syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000);
  111. }
  112.  
  113. static void event_wait(event_t* ev)
  114. {
  115. while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
  116. syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0);
  117. }
  118.  
  119. static int event_isset(event_t* ev)
  120. {
  121. return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE);
  122. }
  123.  
  124. static int event_timedwait(event_t* ev, uint64_t timeout)
  125. {
  126. uint64_t start = current_time_ms();
  127. uint64_t now = start;
  128. for (;;) {
  129. uint64_t remain = timeout - (now - start);
  130. struct timespec ts;
  131. ts.tv_sec = remain / 1000;
  132. ts.tv_nsec = (remain % 1000) * 1000 * 1000;
  133. syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts);
  134. if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
  135. return 1;
  136. now = current_time_ms();
  137. if (now - start > timeout)
  138. return 0;
  139. }
  140. }
  141.  
  142. static bool write_file(const char* file, const char* what, ...)
  143. {
  144. char buf[1024];
  145. va_list args;
  146. va_start(args, what);
  147. vsnprintf(buf, sizeof(buf), what, args);
  148. va_end(args);
  149. buf[sizeof(buf) - 1] = 0;
  150. int len = strlen(buf);
  151. int fd = open(file, O_WRONLY | O_CLOEXEC);
  152. if (fd == -1)
  153. return false;
  154. if (write(fd, buf, len) != len) {
  155. int err = errno;
  156. close(fd);
  157. errno = err;
  158. return false;
  159. }
  160. close(fd);
  161. return true;
  162. }
  163.  
  164. //% This code is derived from puff.{c,h}, found in the zlib development. The
  165. //% original files come with the following copyright notice:
  166.  
  167. //% Copyright (C) 2002-2013 Mark Adler, all rights reserved
  168. //% version 2.3, 21 Jan 2013
  169. //% This software is provided 'as-is', without any express or implied
  170. //% warranty. In no event will the author be held liable for any damages
  171. //% arising from the use of this software.
  172. //% Permission is granted to anyone to use this software for any purpose,
  173. //% including commercial applications, and to alter it and redistribute it
  174. //% freely, subject to the following restrictions:
  175. //% 1. The origin of this software must not be misrepresented; you must not
  176. //% claim that you wrote the original software. If you use this software
  177. //% in a product, an acknowledgment in the product documentation would be
  178. //% appreciated but is not required.
  179. //% 2. Altered source versions must be plainly marked as such, and must not be
  180. //% misrepresented as being the original software.
  181. //% 3. This notice may not be removed or altered from any source distribution.
  182. //% Mark Adler [email protected]
  183.  
  184. //% BEGIN CODE DERIVED FROM puff.{c,h}
  185.  
  186. #define MAXBITS 15
  187. #define MAXLCODES 286
  188. #define MAXDCODES 30
  189. #define MAXCODES (MAXLCODES + MAXDCODES)
  190. #define FIXLCODES 288
  191.  
  192. struct puff_state {
  193. unsigned char* out;
  194. unsigned long outlen;
  195. unsigned long outcnt;
  196. const unsigned char* in;
  197. unsigned long inlen;
  198. unsigned long incnt;
  199. int bitbuf;
  200. int bitcnt;
  201. jmp_buf env;
  202. };
  203. static int puff_bits(struct puff_state* s, int need)
  204. {
  205. long val = s->bitbuf;
  206. while (s->bitcnt < need) {
  207. if (s->incnt == s->inlen)
  208. longjmp(s->env, 1);
  209. val |= (long)(s->in[s->incnt++]) << s->bitcnt;
  210. s->bitcnt += 8;
  211. }
  212. s->bitbuf = (int)(val >> need);
  213. s->bitcnt -= need;
  214. return (int)(val & ((1L << need) - 1));
  215. }
  216. static int puff_stored(struct puff_state* s)
  217. {
  218. s->bitbuf = 0;
  219. s->bitcnt = 0;
  220. if (s->incnt + 4 > s->inlen)
  221. return 2;
  222. unsigned len = s->in[s->incnt++];
  223. len |= s->in[s->incnt++] << 8;
  224. if (s->in[s->incnt++] != (~len & 0xff) ||
  225. s->in[s->incnt++] != ((~len >> 8) & 0xff))
  226. return -2;
  227. if (s->incnt + len > s->inlen)
  228. return 2;
  229. if (s->outcnt + len > s->outlen)
  230. return 1;
  231. for (; len--; s->outcnt++, s->incnt++) {
  232. if (s->in[s->incnt])
  233. s->out[s->outcnt] = s->in[s->incnt];
  234. }
  235. return 0;
  236. }
  237. struct puff_huffman {
  238. short* count;
  239. short* symbol;
  240. };
  241. static int puff_decode(struct puff_state* s, const struct puff_huffman* h)
  242. {
  243. int first = 0;
  244. int index = 0;
  245. int bitbuf = s->bitbuf;
  246. int left = s->bitcnt;
  247. int code = first = index = 0;
  248. int len = 1;
  249. short* next = h->count + 1;
  250. while (1) {
  251. while (left--) {
  252. code |= bitbuf & 1;
  253. bitbuf >>= 1;
  254. int count = *next++;
  255. if (code - count < first) {
  256. s->bitbuf = bitbuf;
  257. s->bitcnt = (s->bitcnt - len) & 7;
  258. return h->symbol[index + (code - first)];
  259. }
  260. index += count;
  261. first += count;
  262. first <<= 1;
  263. code <<= 1;
  264. len++;
  265. }
  266. left = (MAXBITS + 1) - len;
  267. if (left == 0)
  268. break;
  269. if (s->incnt == s->inlen)
  270. longjmp(s->env, 1);
  271. bitbuf = s->in[s->incnt++];
  272. if (left > 8)
  273. left = 8;
  274. }
  275. return -10;
  276. }
  277. static int puff_construct(struct puff_huffman* h, const short* length, int n)
  278. {
  279. int len;
  280. for (len = 0; len <= MAXBITS; len++)
  281. h->count[len] = 0;
  282. int symbol;
  283. for (symbol = 0; symbol < n; symbol++)
  284. (h->count[length[symbol]])++;
  285. if (h->count[0] == n)
  286. return 0;
  287. int left = 1;
  288. for (len = 1; len <= MAXBITS; len++) {
  289. left <<= 1;
  290. left -= h->count[len];
  291. if (left < 0)
  292. return left;
  293. }
  294. short offs[MAXBITS + 1];
  295. offs[1] = 0;
  296. for (len = 1; len < MAXBITS; len++)
  297. offs[len + 1] = offs[len] + h->count[len];
  298. for (symbol = 0; symbol < n; symbol++)
  299. if (length[symbol] != 0)
  300. h->symbol[offs[length[symbol]]++] = symbol;
  301. return left;
  302. }
  303. static int puff_codes(struct puff_state* s, const struct puff_huffman* lencode,
  304. const struct puff_huffman* distcode)
  305. {
  306. static const short lens[29] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13,
  307. 15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
  308. 67, 83, 99, 115, 131, 163, 195, 227, 258};
  309. static const short lext[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2,
  310. 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
  311. static const short dists[30] = {
  312. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25,
  313. 33, 49, 65, 97, 129, 193, 257, 385, 513, 769,
  314. 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577};
  315. static const short dext[30] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
  316. 4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
  317. 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
  318. int symbol;
  319. do {
  320. symbol = puff_decode(s, lencode);
  321. if (symbol < 0)
  322. return symbol;
  323. if (symbol < 256) {
  324. if (s->outcnt == s->outlen)
  325. return 1;
  326. if (symbol)
  327. s->out[s->outcnt] = symbol;
  328. s->outcnt++;
  329. } else if (symbol > 256) {
  330. symbol -= 257;
  331. if (symbol >= 29)
  332. return -10;
  333. int len = lens[symbol] + puff_bits(s, lext[symbol]);
  334. symbol = puff_decode(s, distcode);
  335. if (symbol < 0)
  336. return symbol;
  337. unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]);
  338. if (dist > s->outcnt)
  339. return -11;
  340. if (s->outcnt + len > s->outlen)
  341. return 1;
  342. while (len--) {
  343. if (dist <= s->outcnt && s->out[s->outcnt - dist])
  344. s->out[s->outcnt] = s->out[s->outcnt - dist];
  345. s->outcnt++;
  346. }
  347. }
  348. } while (symbol != 256);
  349. return 0;
  350. }
  351. static int puff_fixed(struct puff_state* s)
  352. {
  353. static int virgin = 1;
  354. static short lencnt[MAXBITS + 1], lensym[FIXLCODES];
  355. static short distcnt[MAXBITS + 1], distsym[MAXDCODES];
  356. static struct puff_huffman lencode, distcode;
  357. if (virgin) {
  358. lencode.count = lencnt;
  359. lencode.symbol = lensym;
  360. distcode.count = distcnt;
  361. distcode.symbol = distsym;
  362. short lengths[FIXLCODES];
  363. int symbol;
  364. for (symbol = 0; symbol < 144; symbol++)
  365. lengths[symbol] = 8;
  366. for (; symbol < 256; symbol++)
  367. lengths[symbol] = 9;
  368. for (; symbol < 280; symbol++)
  369. lengths[symbol] = 7;
  370. for (; symbol < FIXLCODES; symbol++)
  371. lengths[symbol] = 8;
  372. puff_construct(&lencode, lengths, FIXLCODES);
  373. for (symbol = 0; symbol < MAXDCODES; symbol++)
  374. lengths[symbol] = 5;
  375. puff_construct(&distcode, lengths, MAXDCODES);
  376. virgin = 0;
  377. }
  378. return puff_codes(s, &lencode, &distcode);
  379. }
  380. static int puff_dynamic(struct puff_state* s)
  381. {
  382. static const short order[19] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5,
  383. 11, 4, 12, 3, 13, 2, 14, 1, 15};
  384. int nlen = puff_bits(s, 5) + 257;
  385. int ndist = puff_bits(s, 5) + 1;
  386. int ncode = puff_bits(s, 4) + 4;
  387. if (nlen > MAXLCODES || ndist > MAXDCODES)
  388. return -3;
  389. short lengths[MAXCODES];
  390. int index;
  391. for (index = 0; index < ncode; index++)
  392. lengths[order[index]] = puff_bits(s, 3);
  393. for (; index < 19; index++)
  394. lengths[order[index]] = 0;
  395. short lencnt[MAXBITS + 1], lensym[MAXLCODES];
  396. struct puff_huffman lencode = {lencnt, lensym};
  397. int err = puff_construct(&lencode, lengths, 19);
  398. if (err != 0)
  399. return -4;
  400. index = 0;
  401. while (index < nlen + ndist) {
  402. int symbol;
  403. int len;
  404. symbol = puff_decode(s, &lencode);
  405. if (symbol < 0)
  406. return symbol;
  407. if (symbol < 16)
  408. lengths[index++] = symbol;
  409. else {
  410. len = 0;
  411. if (symbol == 16) {
  412. if (index == 0)
  413. return -5;
  414. len = lengths[index - 1];
  415. symbol = 3 + puff_bits(s, 2);
  416. } else if (symbol == 17)
  417. symbol = 3 + puff_bits(s, 3);
  418. else
  419. symbol = 11 + puff_bits(s, 7);
  420. if (index + symbol > nlen + ndist)
  421. return -6;
  422. while (symbol--)
  423. lengths[index++] = len;
  424. }
  425. }
  426. if (lengths[256] == 0)
  427. return -9;
  428. err = puff_construct(&lencode, lengths, nlen);
  429. if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1]))
  430. return -7;
  431. short distcnt[MAXBITS + 1], distsym[MAXDCODES];
  432. struct puff_huffman distcode = {distcnt, distsym};
  433. err = puff_construct(&distcode, lengths + nlen, ndist);
  434. if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1]))
  435. return -8;
  436. return puff_codes(s, &lencode, &distcode);
  437. }
  438. static int puff(unsigned char* dest, unsigned long* destlen,
  439. const unsigned char* source, unsigned long sourcelen)
  440. {
  441. struct puff_state s = {
  442. .out = dest,
  443. .outlen = *destlen,
  444. .outcnt = 0,
  445. .in = source,
  446. .inlen = sourcelen,
  447. .incnt = 0,
  448. .bitbuf = 0,
  449. .bitcnt = 0,
  450. };
  451. int err;
  452. if (setjmp(s.env) != 0)
  453. err = 2;
  454. else {
  455. int last;
  456. do {
  457. last = puff_bits(&s, 1);
  458. int type = puff_bits(&s, 2);
  459. err = type == 0 ? puff_stored(&s)
  460. : (type == 1 ? puff_fixed(&s)
  461. : (type == 2 ? puff_dynamic(&s) : -1));
  462. if (err != 0)
  463. break;
  464. } while (!last);
  465. }
  466. *destlen = s.outcnt;
  467. return err;
  468. }
  469.  
  470. //% END CODE DERIVED FROM puff.{c,h}
  471.  
  472. #define ZLIB_HEADER_WIDTH 2
  473.  
  474. static int puff_zlib_to_file(const unsigned char* source,
  475. unsigned long sourcelen, int dest_fd)
  476. {
  477. if (sourcelen < ZLIB_HEADER_WIDTH)
  478. return 0;
  479. source += ZLIB_HEADER_WIDTH;
  480. sourcelen -= ZLIB_HEADER_WIDTH;
  481. const unsigned long max_destlen = 132 << 20;
  482. void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ,
  483. MAP_PRIVATE | MAP_ANON, -1, 0);
  484. if (ret == MAP_FAILED)
  485. return -1;
  486. unsigned char* dest = (unsigned char*)ret;
  487. unsigned long destlen = max_destlen;
  488. int err = puff(dest, &destlen, source, sourcelen);
  489. if (err) {
  490. munmap(dest, max_destlen);
  491. errno = -err;
  492. return -1;
  493. }
  494. if (write(dest_fd, dest, destlen) != (ssize_t)destlen) {
  495. munmap(dest, max_destlen);
  496. return -1;
  497. }
  498. return munmap(dest, max_destlen);
  499. }
  500.  
  501. static int setup_loop_device(unsigned char* data, unsigned long size,
  502. const char* loopname, int* loopfd_p)
  503. {
  504. int err = 0, loopfd = -1;
  505. int memfd = syscall(__NR_memfd_create, "syzkaller", 0);
  506. if (memfd == -1) {
  507. err = errno;
  508. goto error;
  509. }
  510. if (puff_zlib_to_file(data, size, memfd)) {
  511. err = errno;
  512. goto error_close_memfd;
  513. }
  514. loopfd = open(loopname, O_RDWR);
  515. if (loopfd == -1) {
  516. err = errno;
  517. goto error_close_memfd;
  518. }
  519. if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
  520. if (errno != EBUSY) {
  521. err = errno;
  522. goto error_close_loop;
  523. }
  524. ioctl(loopfd, LOOP_CLR_FD, 0);
  525. usleep(1000);
  526. if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
  527. err = errno;
  528. goto error_close_loop;
  529. }
  530. }
  531. close(memfd);
  532. *loopfd_p = loopfd;
  533. return 0;
  534.  
  535. error_close_loop:
  536. close(loopfd);
  537. error_close_memfd:
  538. close(memfd);
  539. error:
  540. errno = err;
  541. return -1;
  542. }
  543.  
  544. static void reset_loop_device(const char* loopname)
  545. {
  546. int loopfd = open(loopname, O_RDWR);
  547. if (loopfd == -1) {
  548. return;
  549. }
  550. if (ioctl(loopfd, LOOP_CLR_FD, 0)) {
  551. }
  552. close(loopfd);
  553. }
  554.  
  555. static long syz_mount_image(volatile long fsarg, volatile long dir,
  556. volatile long flags, volatile long optsarg,
  557. volatile long change_dir,
  558. volatile unsigned long size, volatile long image)
  559. {
  560. unsigned char* data = (unsigned char*)image;
  561. int res = -1, err = 0, need_loop_device = !!size;
  562. char* mount_opts = (char*)optsarg;
  563. char* target = (char*)dir;
  564. char* fs = (char*)fsarg;
  565. char* source = NULL;
  566. char loopname[64];
  567. if (need_loop_device) {
  568. int loopfd;
  569. memset(loopname, 0, sizeof(loopname));
  570. snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
  571. if (setup_loop_device(data, size, loopname, &loopfd) == -1)
  572. return -1;
  573. close(loopfd);
  574. source = loopname;
  575. }
  576. mkdir(target, 0777);
  577. char opts[256];
  578. memset(opts, 0, sizeof(opts));
  579. if (strlen(mount_opts) > (sizeof(opts) - 32)) {
  580. }
  581. strncpy(opts, mount_opts, sizeof(opts) - 32);
  582. if (strcmp(fs, "iso9660") == 0) {
  583. flags |= MS_RDONLY;
  584. } else if (strncmp(fs, "ext", 3) == 0) {
  585. bool has_remount_ro = false;
  586. char* remount_ro_start = strstr(opts, "errors=remount-ro");
  587. if (remount_ro_start != NULL) {
  588. char after = *(remount_ro_start + strlen("errors=remount-ro"));
  589. char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1);
  590. has_remount_ro = ((before == '\0' || before == ',') &&
  591. (after == '\0' || after == ','));
  592. }
  593. if (strstr(opts, "errors=panic") || !has_remount_ro)
  594. strcat(opts, ",errors=continue");
  595. } else if (strcmp(fs, "xfs") == 0) {
  596. strcat(opts, ",nouuid");
  597. } else if (strncmp(fs, "gfs2", 4) == 0 &&
  598. (strstr(opts, "errors=panic") || strstr(opts, "debug"))) {
  599. strcat(opts, ",errors=withdraw");
  600. }
  601. res = mount(source, target, fs, flags, opts);
  602. if (res == -1) {
  603. err = errno;
  604. goto error_clear_loop;
  605. }
  606. res = open(target, O_RDONLY | O_DIRECTORY);
  607. if (res == -1) {
  608. err = errno;
  609. goto error_clear_loop;
  610. }
  611. if (change_dir) {
  612. res = chdir(target);
  613. if (res == -1) {
  614. err = errno;
  615. }
  616. }
  617.  
  618. error_clear_loop:
  619. if (need_loop_device)
  620. reset_loop_device(loopname);
  621. errno = err;
  622. return res;
  623. }
  624.  
  625. #define FS_IOC_SETFLAGS _IOW('f', 2, long)
  626. static void remove_dir(const char* dir)
  627. {
  628. int iter = 0;
  629. DIR* dp = 0;
  630. const int umount_flags = MNT_FORCE | UMOUNT_NOFOLLOW;
  631.  
  632. retry:
  633. while (umount2(dir, umount_flags) == 0) {
  634. }
  635. dp = opendir(dir);
  636. if (dp == NULL) {
  637. if (errno == EMFILE) {
  638. exit(1);
  639. }
  640. exit(1);
  641. }
  642. struct dirent* ep = 0;
  643. while ((ep = readdir(dp))) {
  644. if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
  645. continue;
  646. char filename[FILENAME_MAX];
  647. snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
  648. while (umount2(filename, umount_flags) == 0) {
  649. }
  650. struct stat st;
  651. if (lstat(filename, &st))
  652. exit(1);
  653. if (S_ISDIR(st.st_mode)) {
  654. remove_dir(filename);
  655. continue;
  656. }
  657. int i;
  658. for (i = 0;; i++) {
  659. if (unlink(filename) == 0)
  660. break;
  661. if (errno == EPERM) {
  662. int fd = open(filename, O_RDONLY);
  663. if (fd != -1) {
  664. long flags = 0;
  665. if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
  666. }
  667. close(fd);
  668. continue;
  669. }
  670. }
  671. if (errno == EROFS) {
  672. break;
  673. }
  674. if (errno != EBUSY || i > 100)
  675. exit(1);
  676. if (umount2(filename, umount_flags))
  677. exit(1);
  678. }
  679. }
  680. closedir(dp);
  681. for (int i = 0;; i++) {
  682. if (rmdir(dir) == 0)
  683. break;
  684. if (i < 100) {
  685. if (errno == EPERM) {
  686. int fd = open(dir, O_RDONLY);
  687. if (fd != -1) {
  688. long flags = 0;
  689. if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
  690. }
  691. close(fd);
  692. continue;
  693. }
  694. }
  695. if (errno == EROFS) {
  696. break;
  697. }
  698. if (errno == EBUSY) {
  699. if (umount2(dir, umount_flags))
  700. exit(1);
  701. continue;
  702. }
  703. if (errno == ENOTEMPTY) {
  704. if (iter < 100) {
  705. iter++;
  706. goto retry;
  707. }
  708. }
  709. }
  710. exit(1);
  711. }
  712. }
  713.  
  714. static void kill_and_wait(int pid, int* status)
  715. {
  716. kill(-pid, SIGKILL);
  717. kill(pid, SIGKILL);
  718. for (int i = 0; i < 100; i++) {
  719. if (waitpid(-1, status, WNOHANG | __WALL) == pid)
  720. return;
  721. usleep(1000);
  722. }
  723. DIR* dir = opendir("/sys/fs/fuse/connections");
  724. if (dir) {
  725. for (;;) {
  726. struct dirent* ent = readdir(dir);
  727. if (!ent)
  728. break;
  729. if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
  730. continue;
  731. char abort[300];
  732. snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
  733. ent->d_name);
  734. int fd = open(abort, O_WRONLY);
  735. if (fd == -1) {
  736. continue;
  737. }
  738. if (write(fd, abort, 1) < 0) {
  739. }
  740. close(fd);
  741. }
  742. closedir(dir);
  743. } else {
  744. }
  745. while (waitpid(-1, status, __WALL) != pid) {
  746. }
  747. }
  748.  
  749. static void reset_loop()
  750. {
  751. char buf[64];
  752. snprintf(buf, sizeof(buf), "/dev/loop%llu", procid);
  753. int loopfd = open(buf, O_RDWR);
  754. if (loopfd != -1) {
  755. ioctl(loopfd, LOOP_CLR_FD, 0);
  756. close(loopfd);
  757. }
  758. }
  759.  
  760. static void setup_test()
  761. {
  762. prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  763. setpgrp();
  764. write_file("/proc/self/oom_score_adj", "1000");
  765. if (symlink("/dev/binderfs", "./binderfs")) {
  766. }
  767. }
  768.  
  769. struct thread_t {
  770. int created, call;
  771. event_t ready, done;
  772. };
  773.  
  774. static struct thread_t threads[16];
  775. static void execute_call(int call);
  776. static int running;
  777.  
  778. static void* thr(void* arg)
  779. {
  780. struct thread_t* th = (struct thread_t*)arg;
  781. for (;;) {
  782. event_wait(&th->ready);
  783. event_reset(&th->ready);
  784. execute_call(th->call);
  785. __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
  786. event_set(&th->done);
  787. }
  788. return 0;
  789. }
  790.  
  791. static void execute_one(void)
  792. {
  793. if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
  794. }
  795. int i, call, thread;
  796. for (call = 0; call < 9; call++) {
  797. for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0]));
  798. thread++) {
  799. struct thread_t* th = &threads[thread];
  800. if (!th->created) {
  801. th->created = 1;
  802. event_init(&th->ready);
  803. event_init(&th->done);
  804. event_set(&th->done);
  805. thread_start(thr, th);
  806. }
  807. if (!event_isset(&th->done))
  808. continue;
  809. event_reset(&th->done);
  810. th->call = call;
  811. __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
  812. event_set(&th->ready);
  813. event_timedwait(&th->done, 50 + (call == 1 ? 4000 : 0));
  814. break;
  815. }
  816. }
  817. for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++)
  818. sleep_ms(1);
  819. }
  820.  
  821. static void execute_one(void);
  822.  
  823. #define WAIT_FLAGS __WALL
  824.  
  825. static void loop(void)
  826. {
  827. int iter = 0;
  828. for (;; iter++) {
  829. char cwdbuf[32];
  830. sprintf(cwdbuf, "./%d", iter);
  831. if (mkdir(cwdbuf, 0777))
  832. exit(1);
  833. reset_loop();
  834. int pid = fork();
  835. if (pid < 0)
  836. exit(1);
  837. if (pid == 0) {
  838. if (chdir(cwdbuf))
  839. exit(1);
  840. setup_test();
  841. execute_one();
  842. exit(0);
  843. }
  844. int status = 0;
  845. uint64_t start = current_time_ms();
  846. for (;;) {
  847. sleep_ms(10);
  848. if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
  849. break;
  850. if (current_time_ms() - start < 5000)
  851. continue;
  852. kill_and_wait(pid, &status);
  853. break;
  854. }
  855. remove_dir(cwdbuf);
  856. }
  857. }
  858.  
  859. uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff};
  860.  
  861. void execute_call(int call)
  862. {
  863. intptr_t res = 0;
  864. switch (call) {
  865. case 0:
  866. // perf_event_open arguments: [
  867. // attr: ptr[in, perf_event_attr] {
  868. // perf_event_attr {
  869. // type: perf_event_type = 0x1 (4 bytes)
  870. // size: len = 0x80 (4 bytes)
  871. // config0: int8 = 0x0 (1 bytes)
  872. // config1: int8 = 0x0 (1 bytes)
  873. // config2: int8 = 0x0 (1 bytes)
  874. // config3: int8 = 0x0 (1 bytes)
  875. // config4: const = 0x0 (4 bytes)
  876. // sample_freq: int64 = 0x50d (8 bytes)
  877. // sample_type: perf_sample_type = 0x0 (8 bytes)
  878. // read_format: perf_read_format = 0x0 (8 bytes)
  879. // disabled: int64 = 0x0 (0 bytes)
  880. // inherit: int64 = 0x0 (0 bytes)
  881. // pinned: int64 = 0x0 (0 bytes)
  882. // exclusive: int64 = 0x0 (0 bytes)
  883. // exclude_user: int64 = 0x0 (0 bytes)
  884. // exclude_kernel: int64 = 0x1 (0 bytes)
  885. // exclude_hv: int64 = 0x0 (0 bytes)
  886. // exclude_idle: int64 = 0x0 (0 bytes)
  887. // mmap: int64 = 0x0 (0 bytes)
  888. // comm: int64 = 0x0 (0 bytes)
  889. // freq: int64 = 0x0 (0 bytes)
  890. // inherit_stat: int64 = 0x0 (0 bytes)
  891. // enable_on_exec: int64 = 0x0 (0 bytes)
  892. // task: int64 = 0x0 (0 bytes)
  893. // watermark: int64 = 0x0 (0 bytes)
  894. // precise_ip: int64 = 0x0 (0 bytes)
  895. // mmap_data: int64 = 0x0 (0 bytes)
  896. // sample_id_all: int64 = 0x0 (0 bytes)
  897. // exclude_host: int64 = 0x0 (0 bytes)
  898. // exclude_guest: int64 = 0x0 (0 bytes)
  899. // exclude_callchain_kernel: int64 = 0x0 (0 bytes)
  900. // exclude_callchain_user: int64 = 0x0 (0 bytes)
  901. // mmap2: int64 = 0x0 (0 bytes)
  902. // comm_exec: int64 = 0x0 (0 bytes)
  903. // use_clockid: int64 = 0x0 (0 bytes)
  904. // context_switch: int64 = 0x0 (0 bytes)
  905. // write_backward: int64 = 0x0 (0 bytes)
  906. // namespaces: int64 = 0x0 (0 bytes)
  907. // ksymbol: int64 = 0x0 (0 bytes)
  908. // bpf_event: int64 = 0x0 (0 bytes)
  909. // aux_output: int64 = 0x0 (0 bytes)
  910. // cgroup: int64 = 0x0 (0 bytes)
  911. // text_poke: int64 = 0x1496d (0 bytes)
  912. // build_id: int64 = 0x0 (0 bytes)
  913. // inherit_thread: int64 = 0x0 (0 bytes)
  914. // remove_on_exec: int64 = 0x4 (0 bytes)
  915. // sigtrap: int64 = 0x0 (0 bytes)
  916. // __reserved_1: const = 0x0 (8 bytes)
  917. // wakeup_events: int32 = 0x0 (4 bytes)
  918. // bp_type: perf_bp_type = 0x0 (4 bytes)
  919. // bp_config: union perf_bp_config {
  920. // perf_config_ext: perf_config_ext {
  921. // config1: int64 = 0x3 (8 bytes)
  922. // config2: int64 = 0xfffffffffffffff3 (8 bytes)
  923. // }
  924. // }
  925. // branch_sample_type: perf_branch_sample_type = 0x104421 (8 bytes)
  926. // sample_regs_user: int64 = 0x0 (8 bytes)
  927. // sample_stack_user: int32 = 0x0 (4 bytes)
  928. // clockid: clock_type = 0x0 (4 bytes)
  929. // sample_regs_intr: int64 = 0x0 (8 bytes)
  930. // aux_watermark: int32 = 0x0 (4 bytes)
  931. // sample_max_stack: int16 = 0x0 (2 bytes)
  932. // __reserved_2: const = 0x0 (2 bytes)
  933. // aux_sample_size: int32 = 0x0 (4 bytes)
  934. // __reserved_3: const = 0x0 (4 bytes)
  935. // sig_data: int64 = 0x20000 (8 bytes)
  936. // }
  937. // }
  938. // pid: pid (resource)
  939. // cpu: intptr = 0xff7fffffffffffff (8 bytes)
  940. // group: fd_perf (resource)
  941. // flags: perf_flags = 0x0 (8 bytes)
  942. // ]
  943. // returns fd_perf
  944. *(uint32_t*)0x200000000700 = 1;
  945. *(uint32_t*)0x200000000704 = 0x80;
  946. *(uint8_t*)0x200000000708 = 0;
  947. *(uint8_t*)0x200000000709 = 0;
  948. *(uint8_t*)0x20000000070a = 0;
  949. *(uint8_t*)0x20000000070b = 0;
  950. *(uint32_t*)0x20000000070c = 0;
  951. *(uint64_t*)0x200000000710 = 0x50d;
  952. *(uint64_t*)0x200000000718 = 0;
  953. *(uint64_t*)0x200000000720 = 0;
  954. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 0, 1);
  955. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 1, 1);
  956. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 2, 1);
  957. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 3, 1);
  958. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 4, 1);
  959. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 1, 5, 1);
  960. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 6, 1);
  961. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 7, 1);
  962. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 8, 1);
  963. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 9, 1);
  964. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 10, 1);
  965. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 11, 1);
  966. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 12, 1);
  967. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 13, 1);
  968. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 14, 1);
  969. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 15, 2);
  970. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 17, 1);
  971. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 18, 1);
  972. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 19, 1);
  973. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 20, 1);
  974. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 21, 1);
  975. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 22, 1);
  976. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 23, 1);
  977. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 24, 1);
  978. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 25, 1);
  979. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 26, 1);
  980. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 27, 1);
  981. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 28, 1);
  982. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 29, 1);
  983. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 30, 1);
  984. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 31, 1);
  985. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 32, 1);
  986. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0x1496d, 33, 1);
  987. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 34, 1);
  988. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 35, 1);
  989. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 4, 36, 1);
  990. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 37, 1);
  991. STORE_BY_BITMASK(uint64_t, , 0x200000000728, 0, 38, 26);
  992. *(uint32_t*)0x200000000730 = 0;
  993. *(uint32_t*)0x200000000734 = 0;
  994. *(uint64_t*)0x200000000738 = 3;
  995. *(uint64_t*)0x200000000740 = 0xfffffffffffffff3;
  996. *(uint64_t*)0x200000000748 = 0x104421;
  997. *(uint64_t*)0x200000000750 = 0;
  998. *(uint32_t*)0x200000000758 = 0;
  999. *(uint32_t*)0x20000000075c = 0;
  1000. *(uint64_t*)0x200000000760 = 0;
  1001. *(uint32_t*)0x200000000768 = 0;
  1002. *(uint16_t*)0x20000000076c = 0;
  1003. *(uint16_t*)0x20000000076e = 0;
  1004. *(uint32_t*)0x200000000770 = 0;
  1005. *(uint32_t*)0x200000000774 = 0;
  1006. *(uint64_t*)0x200000000778 = 0x20000;
  1007. syscall(__NR_perf_event_open, /*attr=*/0x200000000700ul, /*pid=*/0,
  1008. /*cpu=*/0xff7ffffffffffffful, /*group=*/(intptr_t)-1,
  1009. /*flags=*/0ul);
  1010. break;
  1011. case 1:
  1012. // syz_mount_image$ext4 arguments: [
  1013. // fs: ptr[in, buffer] {
  1014. // buffer: {65 78 74 34 00} (length 0x5)
  1015. // }
  1016. // dir: ptr[in, buffer] {
  1017. // buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
  1018. // }
  1019. // flags: mount_flags = 0x2000480 (8 bytes)
  1020. // opts: ptr[in, fs_options[ext4_options]] {
  1021. // fs_options[ext4_options] {
  1022. // elems: array[fs_opt_elem[ext4_options]] {
  1023. // }
  1024. // common: array[fs_opt_elem[fs_options_common]] {
  1025. // }
  1026. // null: const = 0x0 (1 bytes)
  1027. // }
  1028. // }
  1029. // chdir: int8 = 0x1 (1 bytes)
  1030. // size: len = 0x76a (8 bytes)
  1031. // img: ptr[in, buffer] {
  1032. // buffer: (compressed buffer with length 0x76a)
  1033. // }
  1034. // ]
  1035. // returns fd_dir
  1036. memcpy((void*)0x200000000780, "ext4\000", 5);
  1037. memcpy((void*)0x200000000240, "./file0\000", 8);
  1038. *(uint8_t*)0x200000000000 = 0;
  1039. memcpy(
  1040. (void*)0x200000000fc0,
  1041. "\x78\x9c\xec\xdd\xdf\x6b\x5b\x55\x1c\x00\xf0\xef\x4d\xdb\x75\xed\xa6"
  1042. "\xad\x20\xe8\x7c\x2a\x08\x5a\x18\x4b\xed\xac\x9b\x82\x0f\x13\x1f\x44"
  1043. "\x70\x30\xd0\x67\xb7\x90\x66\x65\x36\x6d\x46\x93\x8e\xb5\x14\xdc\x10"
  1044. "\xc1\x17\x41\xc5\x07\x41\x5f\xf6\xec\x8f\xf9\xe6\xab\x3f\x5e\xf5\xbf"
  1045. "\xf0\x41\x36\xa6\x76\xc3\x89\x0f\x52\xb9\x69\xd2\x65\x6b\xd2\xa5\x5b"
  1046. "\x93\x08\xf9\x7c\xe0\x34\xe7\xdc\x7b\xd3\x73\xbe\x39\xf7\x9e\x7b\x92"
  1047. "\x7b\x49\x02\xe8\x5b\x13\xe9\x9f\x4c\xc4\xa1\x88\xf8\x28\x89\x18\xab"
  1048. "\x2d\x4f\x22\x62\xa8\x9a\x1b\x8c\x38\xb1\xb9\xdd\xed\xf5\xb5\x7c\x9a"
  1049. "\x92\xd8\xd8\x78\xf3\x8f\xa4\xba\xcd\xad\xf5\xb5\x7c\x34\x3c\x27\x75"
  1050. "\xa0\x56\x78\x32\x22\x7e\x7c\x3f\xe2\x70\x66\x7b\xbd\xe5\x95\xd5\xf9"
  1051. "\x5c\xb1\x58\x58\xaa\x95\xa7\x2a\x0b\xe7\xa7\xca\x2b\xab\x47\xce\x2d"
  1052. "\xe4\xe6\x0a\x73\x85\xc5\x63\xd3\x33\x33\x47\x8f\xbf\x70\xfc\xd8\xde"
  1053. "\xc5\xfa\xd7\x2f\xab\x07\xaf\x7f\xfc\xda\xb3\xdf\x9c\xf8\xe7\xbd\x27"
  1054. "\xae\x7e\xf8\x53\x12\x27\xe2\x60\x6d\x5d\x63\x1c\x7b\x65\x22\x26\x6a"
  1055. "\xaf\xc9\x50\xfa\x12\xde\xe5\xd5\xbd\xae\xac\xc7\x92\x5e\x37\x80\x07"
  1056. "\x92\x1e\x9a\x03\x9b\x47\x79\x1c\x8a\xb1\x18\xa8\xe6\x5a\x18\xe9\x66"
  1057. "\xcb\x00\x80\x4e\x79\x37\x22\x36\x00\x80\x3e\x93\x38\xff\x03\x40\x9f"
  1058. "\xa9\x7f\x0e\x70\x6b\x7d\x2d\x5f\x4f\xbd\xfd\x44\xa2\xbb\x6e\xbc\x12"
  1059. "\x11\xfb\x37\xe3\xaf\x5f\xdf\xdc\x5c\x33\x58\xbb\x66\xb7\xbf\x7a\x1d"
  1060. "\x74\xf4\x56\x72\xd7\x95\x91\x24\x22\xc6\xf7\xa0\xfe\x89\x88\xf8\xe2"
  1061. "\xbb\xb7\xbf\x4a\x53\x74\xe8\x3a\x24\x40\x33\x97\x2e\x47\xc4\x99\xf1"
  1062. "\x89\xed\xe3\x7f\xb2\xed\x9e\x85\xdd\x7a\xae\x8d\x6d\x26\xee\x29\x1b"
  1063. "\xff\xa0\x7b\xbe\x4f\xe7\x3f\x2f\x36\x9b\xff\x65\xb6\xe6\x3f\xd1\x64"
  1064. "\xfe\x33\xdc\xe4\xd8\x7d\x10\xf7\x3f\xfe\x33\xd7\xf6\xa0\x9a\x96\xd2"
  1065. "\xf9\xdf\xcb\x0d\xf7\xb6\xdd\x6e\x88\xbf\x66\x7c\xa0\x56\x7a\xa4\x3a"
  1066. "\xe7\x1b\x4a\xce\x9e\x2b\x16\xd2\xb1\xed\xd1\x88\x98\x8c\xa1\xe1\xb4"
  1067. "\x3c\xbd\x43\x1d\x93\x37\xff\xbd\xd9\x6a\x5d\xe3\xfc\xef\xcf\x4f\xde"
  1068. "\xf9\x32\xad\x3f\x7d\xbc\xb3\x45\xe6\xda\xe0\xf0\xdd\xcf\x99\xcd\x55"
  1069. "\x72\x0f\x13\x73\xa3\x1b\x97\x23\x9e\x1a\x6c\x16\x7f\xb2\xd5\xff\x49"
  1070. "\x8b\xf9\xef\xa9\x36\xeb\x78\xfd\xa5\x0f\x3e\x6f\xb5\x2e\x8d\x3f\x8d"
  1071. "\xb7\x9e\xb6\xc7\xdf\x59\x1b\x57\x22\x9e\x69\xda\xff\x77\xee\x68\x4b"
  1072. "\x76\xbc\x3f\x71\xaa\xba\x3b\x4c\xd5\x77\x8a\x26\xbe\xfd\xf5\xb3\xd1"
  1073. "\x56\xf5\x37\xf6\x7f\x9a\xd2\xfa\xeb\xef\x05\xba\x21\xed\xff\xd1\x9d"
  1074. "\xe3\x1f\x4f\x1a\xef\xd7\x2c\xef\xbe\x8e\x9f\xaf\x8c\xfd\xd0\x6a\xdd"
  1075. "\xfd\xe3\x6f\xbe\xff\xef\x4b\xde\xaa\xe6\xf7\xd5\x96\x5d\xcc\x55\x2a"
  1076. "\x4b\xd3\x11\xfb\x92\x37\xb6\x2f\x3f\x7a\xe7\xb9\xf5\x72\x7d\xfb\x34"
  1077. "\xfe\xc9\xa7\x9b\x1f\xff\x3b\xed\xff\xe9\x7b\xc2\x33\x6d\xc6\x3f\x78"
  1078. "\xfd\xf7\xaf\x1f\x3c\xfe\xce\x4a\xe3\x9f\xdd\x55\xff\xef\x3e\x73\xf5"
  1079. "\xf6\xfc\x40\xab\xfa\xdb\xeb\xff\x99\x6a\x6e\xb2\xb6\xa4\x9d\xf1\xaf"
  1080. "\xdd\x06\x3e\xcc\x6b\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1081. "\x00\x00\x00\x00\x00\x00\x00\x00\xed\xca\x44\xc4\xc1\x48\x32\xd9\xad"
  1082. "\x7c\x26\x93\xcd\x6e\xfe\x86\xf7\xe3\x31\x9a\x29\x96\xca\x95\xc3\x67"
  1083. "\x4b\xcb\x8b\xb3\x51\xfd\xad\xec\xf1\x18\xca\xd4\xbf\xea\x72\xac\xe1"
  1084. "\xfb\x50\xa7\x6b\xdf\x87\x5f\x2f\x1f\xbd\xa7\xfc\x7c\x44\x3c\x16\x11"
  1085. "\x9f\x0e\x8f\x54\xcb\xd9\x7c\xa9\x38\xdb\xeb\xe0\x01\x00\x00\x00\x00"
  1086. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1087. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa0\xe6\x40\x8b\xdf\xff\x4f\xfd"
  1088. "\x36\xdc\xeb\xd6\x01\x00\x1d\xb3\xbf\xd7\x0d\x00\x00\xba\xce\xf9\x1f"
  1089. "\x00\xfa\xcf\xee\xce\xff\x23\x1d\x6b\x07\x00\xd0\x3d\xde\xff\x03\x40"
  1090. "\xff\x71\xfe\x07\x80\xfe\xe3\xfc\x0f\x00\x00\x00\x00\x00\x00\x00\x00"
  1091. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1092. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1093. "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x87\x9d\x3a\x79\x32\x4d\x1b\x7f"
  1094. "\xaf\xaf\xe5\xd3\xf2\xec\x85\x95\xe5\xf9\xd2\x85\x23\xb3\x85\xf2\x7c"
  1095. "\x76\x61\x39\x9f\xcd\x97\x96\xce\x67\xe7\x4a\xa5\xb9\x62\x21\x9b\x2f"
  1096. "\x2d\xb4\xfc\x47\x97\x36\x1f\x8a\xa5\xd2\xf9\x99\x58\x5c\xbe\x38\x55"
  1097. "\x29\x94\x2b\x53\xe5\x95\xd5\xd3\x0b\xa5\xe5\xc5\xca\xe9\x73\x0b\xb9"
  1098. "\xb9\xc2\xe9\xc2\x50\xd7\x22\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1099. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1100. "\x00\x00\x00\x00\x80\xf6\x95\x57\x56\xe7\x73\xc5\x62\x61\x49\x46\x46"
  1101. "\x46\x66\x2b\xd3\x38\x4a\x8c\xf4\x6e\x80\x02\x00\x00\x00\x00\x00\x00"
  1102. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1103. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1104. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1105. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1106. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1107. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1108. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1109. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1110. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1111. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1112. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1113. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1114. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1115. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1116. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1117. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1118. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1119. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1120. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1121. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1122. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1123. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1124. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1125. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1126. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1127. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1128. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1129. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1130. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1131. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1132. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1133. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1134. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1135. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1136. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1137. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1138. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1139. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1140. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1141. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1142. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1143. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1144. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1145. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1146. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1147. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1148. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1149. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1150. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  1151. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8"
  1152. "\x9f\xfb\x2f\x00\x00\xff\xff\xd1\x32\x2a\xca",
  1153. 1898);
  1154. syz_mount_image(/*fs=*/0x200000000780, /*dir=*/0x200000000240,
  1155. /*flags=MS_LAZYTIME|MS_NOATIME|MS_DIRSYNC*/ 0x2000480,
  1156. /*opts=*/0x200000000000, /*chdir=*/1, /*size=*/0x76a,
  1157. /*img=*/0x200000000fc0);
  1158. break;
  1159. case 2:
  1160. // open arguments: [
  1161. // file: ptr[in, buffer] {
  1162. // buffer: {2e 2f 62 75 73 00} (length 0x6)
  1163. // }
  1164. // flags: open_flags = 0x6fe44da629969272 (8 bytes)
  1165. // mode: open_mode = 0x0 (8 bytes)
  1166. // ]
  1167. // returns fd
  1168. memcpy((void*)0x200000000500, "./bus\000", 6);
  1169. res = syscall(
  1170. __NR_open, /*file=*/0x200000000500ul,
  1171. /*flags=O_TRUNC|O_SYNC|O_NOFOLLOW|O_NOATIME|O_LARGEFILE|O_CREAT|0x6fe44da629800032*/
  1172. 0x6fe44da629969272ul, /*mode=*/0ul);
  1173. if (res != -1)
  1174. r[0] = res;
  1175. break;
  1176. case 3:
  1177. // write$binfmt_script arguments: [
  1178. // fd: fd_binfmt (resource)
  1179. // data: ptr[in, binfmt_script] {
  1180. // binfmt_script {
  1181. // hdr: buffer: {23 21 20} (length 0x3)
  1182. // bin: buffer: {} (length 0x0)
  1183. // args: array[binfmt_script_arg] {
  1184. // }
  1185. // nl: const = 0xa (1 bytes)
  1186. // data: buffer: {} (length 0x0)
  1187. // }
  1188. // }
  1189. // len: bytesize = 0x9 (8 bytes)
  1190. // ]
  1191. memcpy((void*)0x200000000f80, "#! ", 3);
  1192. *(uint8_t*)0x200000000f83 = 0xa;
  1193. syscall(__NR_write, /*fd=*/r[0], /*data=*/0x200000000f80ul, /*len=*/9ul);
  1194. break;
  1195. case 4:
  1196. // openat arguments: [
  1197. // fd: fd_dir (resource)
  1198. // file: ptr[in, buffer] {
  1199. // buffer: {2e 2f 62 75 73 00} (length 0x6)
  1200. // }
  1201. // flags: open_flags = 0x0 (4 bytes)
  1202. // mode: open_mode = 0x0 (2 bytes)
  1203. // ]
  1204. // returns fd
  1205. memcpy((void*)0x200000000000, "./bus\000", 6);
  1206. res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000000ul,
  1207. /*flags=*/0, /*mode=*/0);
  1208. if (res != -1)
  1209. r[1] = res;
  1210. break;
  1211. case 5:
  1212. // open arguments: [
  1213. // file: ptr[in, buffer] {
  1214. // buffer: {2e 2f 62 75 73 00} (length 0x6)
  1215. // }
  1216. // flags: open_flags = 0x8082 (8 bytes)
  1217. // mode: open_mode = 0x0 (8 bytes)
  1218. // ]
  1219. // returns fd
  1220. memcpy((void*)0x2000000002c0, "./bus\000", 6);
  1221. res = syscall(__NR_open, /*file=*/0x2000000002c0ul,
  1222. /*flags=O_LARGEFILE|O_EXCL|O_RDWR*/ 0x8082ul, /*mode=*/0ul);
  1223. if (res != -1)
  1224. r[2] = res;
  1225. break;
  1226. case 6:
  1227. // mmap arguments: [
  1228. // addr: VMA[0x600000]
  1229. // len: len = 0x600000 (8 bytes)
  1230. // prot: mmap_prot = 0x7ffffe (8 bytes)
  1231. // flags: mmap_flags = 0x4002011 (8 bytes)
  1232. // fd: fd (resource)
  1233. // offset: intptr = 0x0 (8 bytes)
  1234. // ]
  1235. syscall(
  1236. __NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x600000ul,
  1237. /*prot=PROT_SEM|PROT_WRITE|PROT_EXEC|0x7ffff0*/ 0x7ffffeul,
  1238. /*flags=MAP_UNINITIALIZED|MAP_LOCKED|MAP_FIXED|MAP_SHARED*/ 0x4002011ul,
  1239. /*fd=*/r[2], /*offset=*/0ul);
  1240. break;
  1241. case 7:
  1242. // sendfile arguments: [
  1243. // fdout: fd (resource)
  1244. // fdin: fd (resource)
  1245. // off: nil
  1246. // count: intptr = 0x80000041 (8 bytes)
  1247. // ]
  1248. syscall(__NR_sendfile, /*fdout=*/r[0], /*fdin=*/r[1], /*off=*/0ul,
  1249. /*count=*/0x80000041ul);
  1250. break;
  1251. case 8:
  1252. // ioctl$RTC_ALM_SET arguments: [
  1253. // fd: fd_rtc (resource)
  1254. // cmd: const = 0x40247007 (4 bytes)
  1255. // arg: ptr[in, rtc_time] {
  1256. // rtc_time {
  1257. // tm_sec: int32 = 0x1 (4 bytes)
  1258. // tm_min: int32 = 0x25 (4 bytes)
  1259. // tm_hour: int32 = 0x17 (4 bytes)
  1260. // tm_mday: int32 = 0x17 (4 bytes)
  1261. // tm_mon: int32 = 0x0 (4 bytes)
  1262. // tm_year: int32 = 0x3 (4 bytes)
  1263. // tm_wday: int32 = 0x2 (4 bytes)
  1264. // tm_yday: int32 = 0x78 (4 bytes)
  1265. // tm_isdst: rtc_isdst = 0xffffffffffffffff (4 bytes)
  1266. // }
  1267. // }
  1268. // ]
  1269. *(uint32_t*)0x200000000040 = 1;
  1270. *(uint32_t*)0x200000000044 = 0x25;
  1271. *(uint32_t*)0x200000000048 = 0x17;
  1272. *(uint32_t*)0x20000000004c = 0x17;
  1273. *(uint32_t*)0x200000000050 = 0;
  1274. *(uint32_t*)0x200000000054 = 3;
  1275. *(uint32_t*)0x200000000058 = 2;
  1276. *(uint32_t*)0x20000000005c = 0x78;
  1277. *(uint32_t*)0x200000000060 = -1;
  1278. syscall(__NR_ioctl, /*fd=*/(intptr_t)-1, /*cmd=*/0x40247007,
  1279. /*arg=*/0x200000000040ul);
  1280. break;
  1281. }
  1282. }
  1283. int main(void)
  1284. {
  1285. syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  1286. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  1287. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  1288. syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul,
  1289. /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
  1290. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  1291. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  1292. syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  1293. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  1294. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  1295. const char* reason;
  1296. (void)reason;
  1297. for (procid = 0; procid < 4; procid++) {
  1298. if (fork() == 0) {
  1299. use_temporary_dir();
  1300. loop();
  1301. }
  1302. }
  1303. sleep(1000000);
  1304. return 0;
  1305. }
  1306.  
Advertisement
Add Comment
Please, Sign In to add comment