Tang-ZW

Untitled

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