Tang-ZW

Untitled

Feb 5th, 2026
139
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 81.09 KB | None | 0 0
  1. // autogenerated by syzkaller (https://github.com/google/syzkaller)
  2.  
  3. #define _GNU_SOURCE
  4.  
  5. #include <arpa/inet.h>
  6. #include <dirent.h>
  7. #include <endian.h>
  8. #include <errno.h>
  9. #include <fcntl.h>
  10. #include <net/if.h>
  11. #include <net/if_arp.h>
  12. #include <netinet/in.h>
  13. #include <sched.h>
  14. #include <setjmp.h>
  15. #include <signal.h>
  16. #include <stdarg.h>
  17. #include <stdbool.h>
  18. #include <stddef.h>
  19. #include <stdint.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <sys/ioctl.h>
  24. #include <sys/mman.h>
  25. #include <sys/mount.h>
  26. #include <sys/prctl.h>
  27. #include <sys/resource.h>
  28. #include <sys/socket.h>
  29. #include <sys/stat.h>
  30. #include <sys/syscall.h>
  31. #include <sys/time.h>
  32. #include <sys/types.h>
  33. #include <sys/uio.h>
  34. #include <sys/wait.h>
  35. #include <time.h>
  36. #include <unistd.h>
  37.  
  38. #include <linux/capability.h>
  39. #include <linux/genetlink.h>
  40. #include <linux/if_addr.h>
  41. #include <linux/if_ether.h>
  42. #include <linux/if_link.h>
  43. #include <linux/if_tun.h>
  44. #include <linux/in6.h>
  45. #include <linux/ip.h>
  46. #include <linux/loop.h>
  47. #include <linux/neighbour.h>
  48. #include <linux/net.h>
  49. #include <linux/netlink.h>
  50. #include <linux/rtnetlink.h>
  51. #include <linux/tcp.h>
  52. #include <linux/veth.h>
  53.  
  54. #ifndef __NR_memfd_create
  55. #define __NR_memfd_create 319
  56. #endif
  57.  
  58. static unsigned long long procid;
  59.  
  60. static void sleep_ms(uint64_t ms)
  61. {
  62. usleep(ms * 1000);
  63. }
  64.  
  65. static uint64_t current_time_ms(void)
  66. {
  67. struct timespec ts;
  68. if (clock_gettime(CLOCK_MONOTONIC, &ts))
  69. exit(1);
  70. return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
  71. }
  72.  
  73. static void use_temporary_dir(void)
  74. {
  75. char tmpdir_template[] = "./syzkaller.XXXXXX";
  76. char* tmpdir = mkdtemp(tmpdir_template);
  77. if (!tmpdir)
  78. exit(1);
  79. if (chmod(tmpdir, 0777))
  80. exit(1);
  81. if (chdir(tmpdir))
  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. static bool write_file(const char* file, const char* what, ...)
  92. {
  93. char buf[1024];
  94. va_list args;
  95. va_start(args, what);
  96. vsnprintf(buf, sizeof(buf), what, args);
  97. va_end(args);
  98. buf[sizeof(buf) - 1] = 0;
  99. int len = strlen(buf);
  100. int fd = open(file, O_WRONLY | O_CLOEXEC);
  101. if (fd == -1)
  102. return false;
  103. if (write(fd, buf, len) != len) {
  104. int err = errno;
  105. close(fd);
  106. errno = err;
  107. return false;
  108. }
  109. close(fd);
  110. return true;
  111. }
  112.  
  113. struct nlmsg {
  114. char* pos;
  115. int nesting;
  116. struct nlattr* nested[8];
  117. char buf[4096];
  118. };
  119.  
  120. static void netlink_init(struct nlmsg* nlmsg, int typ, int flags,
  121. const void* data, int size)
  122. {
  123. memset(nlmsg, 0, sizeof(*nlmsg));
  124. struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
  125. hdr->nlmsg_type = typ;
  126. hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags;
  127. memcpy(hdr + 1, data, size);
  128. nlmsg->pos = (char*)(hdr + 1) + NLMSG_ALIGN(size);
  129. }
  130.  
  131. static void netlink_attr(struct nlmsg* nlmsg, int typ, const void* data,
  132. int size)
  133. {
  134. struct nlattr* attr = (struct nlattr*)nlmsg->pos;
  135. attr->nla_len = sizeof(*attr) + size;
  136. attr->nla_type = typ;
  137. if (size > 0)
  138. memcpy(attr + 1, data, size);
  139. nlmsg->pos += NLMSG_ALIGN(attr->nla_len);
  140. }
  141.  
  142. static void netlink_nest(struct nlmsg* nlmsg, int typ)
  143. {
  144. struct nlattr* attr = (struct nlattr*)nlmsg->pos;
  145. attr->nla_type = typ;
  146. nlmsg->pos += sizeof(*attr);
  147. nlmsg->nested[nlmsg->nesting++] = attr;
  148. }
  149.  
  150. static void netlink_done(struct nlmsg* nlmsg)
  151. {
  152. struct nlattr* attr = nlmsg->nested[--nlmsg->nesting];
  153. attr->nla_len = nlmsg->pos - (char*)attr;
  154. }
  155.  
  156. static int netlink_send_ext(struct nlmsg* nlmsg, int sock, uint16_t reply_type,
  157. int* reply_len, bool dofail)
  158. {
  159. if (nlmsg->pos > nlmsg->buf + sizeof(nlmsg->buf) || nlmsg->nesting)
  160. exit(1);
  161. struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
  162. hdr->nlmsg_len = nlmsg->pos - nlmsg->buf;
  163. struct sockaddr_nl addr;
  164. memset(&addr, 0, sizeof(addr));
  165. addr.nl_family = AF_NETLINK;
  166. ssize_t n = sendto(sock, nlmsg->buf, hdr->nlmsg_len, 0,
  167. (struct sockaddr*)&addr, sizeof(addr));
  168. if (n != (ssize_t)hdr->nlmsg_len) {
  169. if (dofail)
  170. exit(1);
  171. return -1;
  172. }
  173. n = recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0);
  174. if (reply_len)
  175. *reply_len = 0;
  176. if (n < 0) {
  177. if (dofail)
  178. exit(1);
  179. return -1;
  180. }
  181. if (n < (ssize_t)sizeof(struct nlmsghdr)) {
  182. errno = EINVAL;
  183. if (dofail)
  184. exit(1);
  185. return -1;
  186. }
  187. if (hdr->nlmsg_type == NLMSG_DONE)
  188. return 0;
  189. if (reply_len && hdr->nlmsg_type == reply_type) {
  190. *reply_len = n;
  191. return 0;
  192. }
  193. if (n < (ssize_t)(sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))) {
  194. errno = EINVAL;
  195. if (dofail)
  196. exit(1);
  197. return -1;
  198. }
  199. if (hdr->nlmsg_type != NLMSG_ERROR) {
  200. errno = EINVAL;
  201. if (dofail)
  202. exit(1);
  203. return -1;
  204. }
  205. errno = -((struct nlmsgerr*)(hdr + 1))->error;
  206. return -errno;
  207. }
  208.  
  209. static int netlink_send(struct nlmsg* nlmsg, int sock)
  210. {
  211. return netlink_send_ext(nlmsg, sock, 0, NULL, true);
  212. }
  213.  
  214. static int netlink_query_family_id(struct nlmsg* nlmsg, int sock,
  215. const char* family_name, bool dofail)
  216. {
  217. struct genlmsghdr genlhdr;
  218. memset(&genlhdr, 0, sizeof(genlhdr));
  219. genlhdr.cmd = CTRL_CMD_GETFAMILY;
  220. netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr));
  221. netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, family_name,
  222. strnlen(family_name, GENL_NAMSIZ - 1) + 1);
  223. int n = 0;
  224. int err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n, dofail);
  225. if (err < 0) {
  226. return -1;
  227. }
  228. uint16_t id = 0;
  229. struct nlattr* attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN +
  230. NLMSG_ALIGN(sizeof(genlhdr)));
  231. for (; (char*)attr < nlmsg->buf + n;
  232. attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
  233. if (attr->nla_type == CTRL_ATTR_FAMILY_ID) {
  234. id = *(uint16_t*)(attr + 1);
  235. break;
  236. }
  237. }
  238. if (!id) {
  239. errno = EINVAL;
  240. return -1;
  241. }
  242. recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0);
  243. return id;
  244. }
  245.  
  246. static int netlink_next_msg(struct nlmsg* nlmsg, unsigned int offset,
  247. unsigned int total_len)
  248. {
  249. struct nlmsghdr* hdr = (struct nlmsghdr*)(nlmsg->buf + offset);
  250. if (offset == total_len || offset + hdr->nlmsg_len > total_len)
  251. return -1;
  252. return hdr->nlmsg_len;
  253. }
  254.  
  255. static void netlink_add_device_impl(struct nlmsg* nlmsg, const char* type,
  256. const char* name, bool up)
  257. {
  258. struct ifinfomsg hdr;
  259. memset(&hdr, 0, sizeof(hdr));
  260. if (up)
  261. hdr.ifi_flags = hdr.ifi_change = IFF_UP;
  262. netlink_init(nlmsg, RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr,
  263. sizeof(hdr));
  264. if (name)
  265. netlink_attr(nlmsg, IFLA_IFNAME, name, strlen(name));
  266. netlink_nest(nlmsg, IFLA_LINKINFO);
  267. netlink_attr(nlmsg, IFLA_INFO_KIND, type, strlen(type));
  268. }
  269.  
  270. static void netlink_add_device(struct nlmsg* nlmsg, int sock, const char* type,
  271. const char* name)
  272. {
  273. netlink_add_device_impl(nlmsg, type, name, false);
  274. netlink_done(nlmsg);
  275. int err = netlink_send(nlmsg, sock);
  276. if (err < 0) {
  277. }
  278. }
  279.  
  280. static void netlink_add_veth(struct nlmsg* nlmsg, int sock, const char* name,
  281. const char* peer)
  282. {
  283. netlink_add_device_impl(nlmsg, "veth", name, false);
  284. netlink_nest(nlmsg, IFLA_INFO_DATA);
  285. netlink_nest(nlmsg, VETH_INFO_PEER);
  286. nlmsg->pos += sizeof(struct ifinfomsg);
  287. netlink_attr(nlmsg, IFLA_IFNAME, peer, strlen(peer));
  288. netlink_done(nlmsg);
  289. netlink_done(nlmsg);
  290. netlink_done(nlmsg);
  291. int err = netlink_send(nlmsg, sock);
  292. if (err < 0) {
  293. }
  294. }
  295.  
  296. static void netlink_add_xfrm(struct nlmsg* nlmsg, int sock, const char* name)
  297. {
  298. netlink_add_device_impl(nlmsg, "xfrm", name, true);
  299. netlink_nest(nlmsg, IFLA_INFO_DATA);
  300. int if_id = 1;
  301. netlink_attr(nlmsg, 2, &if_id, sizeof(if_id));
  302. netlink_done(nlmsg);
  303. netlink_done(nlmsg);
  304. int err = netlink_send(nlmsg, sock);
  305. if (err < 0) {
  306. }
  307. }
  308.  
  309. static void netlink_add_hsr(struct nlmsg* nlmsg, int sock, const char* name,
  310. const char* slave1, const char* slave2)
  311. {
  312. netlink_add_device_impl(nlmsg, "hsr", name, false);
  313. netlink_nest(nlmsg, IFLA_INFO_DATA);
  314. int ifindex1 = if_nametoindex(slave1);
  315. netlink_attr(nlmsg, IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1));
  316. int ifindex2 = if_nametoindex(slave2);
  317. netlink_attr(nlmsg, IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2));
  318. netlink_done(nlmsg);
  319. netlink_done(nlmsg);
  320. int err = netlink_send(nlmsg, sock);
  321. if (err < 0) {
  322. }
  323. }
  324.  
  325. static void netlink_add_linked(struct nlmsg* nlmsg, int sock, const char* type,
  326. const char* name, const char* link)
  327. {
  328. netlink_add_device_impl(nlmsg, type, name, false);
  329. netlink_done(nlmsg);
  330. int ifindex = if_nametoindex(link);
  331. netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
  332. int err = netlink_send(nlmsg, sock);
  333. if (err < 0) {
  334. }
  335. }
  336.  
  337. static void netlink_add_vlan(struct nlmsg* nlmsg, int sock, const char* name,
  338. const char* link, uint16_t id, uint16_t proto)
  339. {
  340. netlink_add_device_impl(nlmsg, "vlan", name, false);
  341. netlink_nest(nlmsg, IFLA_INFO_DATA);
  342. netlink_attr(nlmsg, IFLA_VLAN_ID, &id, sizeof(id));
  343. netlink_attr(nlmsg, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto));
  344. netlink_done(nlmsg);
  345. netlink_done(nlmsg);
  346. int ifindex = if_nametoindex(link);
  347. netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
  348. int err = netlink_send(nlmsg, sock);
  349. if (err < 0) {
  350. }
  351. }
  352.  
  353. static void netlink_add_macvlan(struct nlmsg* nlmsg, int sock, const char* name,
  354. const char* link)
  355. {
  356. netlink_add_device_impl(nlmsg, "macvlan", name, false);
  357. netlink_nest(nlmsg, IFLA_INFO_DATA);
  358. uint32_t mode = MACVLAN_MODE_BRIDGE;
  359. netlink_attr(nlmsg, IFLA_MACVLAN_MODE, &mode, sizeof(mode));
  360. netlink_done(nlmsg);
  361. netlink_done(nlmsg);
  362. int ifindex = if_nametoindex(link);
  363. netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
  364. int err = netlink_send(nlmsg, sock);
  365. if (err < 0) {
  366. }
  367. }
  368.  
  369. static void netlink_add_geneve(struct nlmsg* nlmsg, int sock, const char* name,
  370. uint32_t vni, struct in_addr* addr4,
  371. struct in6_addr* addr6)
  372. {
  373. netlink_add_device_impl(nlmsg, "geneve", name, false);
  374. netlink_nest(nlmsg, IFLA_INFO_DATA);
  375. netlink_attr(nlmsg, IFLA_GENEVE_ID, &vni, sizeof(vni));
  376. if (addr4)
  377. netlink_attr(nlmsg, IFLA_GENEVE_REMOTE, addr4, sizeof(*addr4));
  378. if (addr6)
  379. netlink_attr(nlmsg, IFLA_GENEVE_REMOTE6, addr6, sizeof(*addr6));
  380. netlink_done(nlmsg);
  381. netlink_done(nlmsg);
  382. int err = netlink_send(nlmsg, sock);
  383. if (err < 0) {
  384. }
  385. }
  386.  
  387. #define IFLA_IPVLAN_FLAGS 2
  388. #define IPVLAN_MODE_L3S 2
  389. #undef IPVLAN_F_VEPA
  390. #define IPVLAN_F_VEPA 2
  391.  
  392. static void netlink_add_ipvlan(struct nlmsg* nlmsg, int sock, const char* name,
  393. const char* link, uint16_t mode, uint16_t flags)
  394. {
  395. netlink_add_device_impl(nlmsg, "ipvlan", name, false);
  396. netlink_nest(nlmsg, IFLA_INFO_DATA);
  397. netlink_attr(nlmsg, IFLA_IPVLAN_MODE, &mode, sizeof(mode));
  398. netlink_attr(nlmsg, IFLA_IPVLAN_FLAGS, &flags, sizeof(flags));
  399. netlink_done(nlmsg);
  400. netlink_done(nlmsg);
  401. int ifindex = if_nametoindex(link);
  402. netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
  403. int err = netlink_send(nlmsg, sock);
  404. if (err < 0) {
  405. }
  406. }
  407.  
  408. static void netlink_device_change(struct nlmsg* nlmsg, int sock,
  409. const char* name, bool up, const char* master,
  410. const void* mac, int macsize,
  411. const char* new_name)
  412. {
  413. struct ifinfomsg hdr;
  414. memset(&hdr, 0, sizeof(hdr));
  415. if (up)
  416. hdr.ifi_flags = hdr.ifi_change = IFF_UP;
  417. hdr.ifi_index = if_nametoindex(name);
  418. netlink_init(nlmsg, RTM_NEWLINK, 0, &hdr, sizeof(hdr));
  419. if (new_name)
  420. netlink_attr(nlmsg, IFLA_IFNAME, new_name, strlen(new_name));
  421. if (master) {
  422. int ifindex = if_nametoindex(master);
  423. netlink_attr(nlmsg, IFLA_MASTER, &ifindex, sizeof(ifindex));
  424. }
  425. if (macsize)
  426. netlink_attr(nlmsg, IFLA_ADDRESS, mac, macsize);
  427. int err = netlink_send(nlmsg, sock);
  428. if (err < 0) {
  429. }
  430. }
  431.  
  432. static int netlink_add_addr(struct nlmsg* nlmsg, int sock, const char* dev,
  433. const void* addr, int addrsize)
  434. {
  435. struct ifaddrmsg hdr;
  436. memset(&hdr, 0, sizeof(hdr));
  437. hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6;
  438. hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120;
  439. hdr.ifa_scope = RT_SCOPE_UNIVERSE;
  440. hdr.ifa_index = if_nametoindex(dev);
  441. netlink_init(nlmsg, RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr,
  442. sizeof(hdr));
  443. netlink_attr(nlmsg, IFA_LOCAL, addr, addrsize);
  444. netlink_attr(nlmsg, IFA_ADDRESS, addr, addrsize);
  445. return netlink_send(nlmsg, sock);
  446. }
  447.  
  448. static void netlink_add_addr4(struct nlmsg* nlmsg, int sock, const char* dev,
  449. const char* addr)
  450. {
  451. struct in_addr in_addr;
  452. inet_pton(AF_INET, addr, &in_addr);
  453. int err = netlink_add_addr(nlmsg, sock, dev, &in_addr, sizeof(in_addr));
  454. if (err < 0) {
  455. }
  456. }
  457.  
  458. static void netlink_add_addr6(struct nlmsg* nlmsg, int sock, const char* dev,
  459. const char* addr)
  460. {
  461. struct in6_addr in6_addr;
  462. inet_pton(AF_INET6, addr, &in6_addr);
  463. int err = netlink_add_addr(nlmsg, sock, dev, &in6_addr, sizeof(in6_addr));
  464. if (err < 0) {
  465. }
  466. }
  467.  
  468. static struct nlmsg nlmsg;
  469.  
  470. #define DEVLINK_FAMILY_NAME "devlink"
  471.  
  472. #define DEVLINK_CMD_PORT_GET 5
  473. #define DEVLINK_ATTR_BUS_NAME 1
  474. #define DEVLINK_ATTR_DEV_NAME 2
  475. #define DEVLINK_ATTR_NETDEV_NAME 7
  476.  
  477. static struct nlmsg nlmsg2;
  478.  
  479. static void initialize_devlink_ports(const char* bus_name, const char* dev_name,
  480. const char* netdev_prefix)
  481. {
  482. struct genlmsghdr genlhdr;
  483. int len, total_len, id, err, offset;
  484. uint16_t netdev_index;
  485. int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
  486. if (sock == -1)
  487. exit(1);
  488. int rtsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  489. if (rtsock == -1)
  490. exit(1);
  491. id = netlink_query_family_id(&nlmsg, sock, DEVLINK_FAMILY_NAME, true);
  492. if (id == -1)
  493. goto error;
  494. memset(&genlhdr, 0, sizeof(genlhdr));
  495. genlhdr.cmd = DEVLINK_CMD_PORT_GET;
  496. netlink_init(&nlmsg, id, NLM_F_DUMP, &genlhdr, sizeof(genlhdr));
  497. netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1);
  498. netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1);
  499. err = netlink_send_ext(&nlmsg, sock, id, &total_len, true);
  500. if (err < 0) {
  501. goto error;
  502. }
  503. offset = 0;
  504. netdev_index = 0;
  505. while ((len = netlink_next_msg(&nlmsg, offset, total_len)) != -1) {
  506. struct nlattr* attr = (struct nlattr*)(nlmsg.buf + offset + NLMSG_HDRLEN +
  507. NLMSG_ALIGN(sizeof(genlhdr)));
  508. for (; (char*)attr < nlmsg.buf + offset + len;
  509. attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
  510. if (attr->nla_type == DEVLINK_ATTR_NETDEV_NAME) {
  511. char* port_name;
  512. char netdev_name[IFNAMSIZ];
  513. port_name = (char*)(attr + 1);
  514. snprintf(netdev_name, sizeof(netdev_name), "%s%d", netdev_prefix,
  515. netdev_index);
  516. netlink_device_change(&nlmsg2, rtsock, port_name, true, 0, 0, 0,
  517. netdev_name);
  518. break;
  519. }
  520. }
  521. offset += len;
  522. netdev_index++;
  523. }
  524. error:
  525. close(rtsock);
  526. close(sock);
  527. }
  528.  
  529. #define DEV_IPV4 "172.20.20.%d"
  530. #define DEV_IPV6 "fe80::%02x"
  531. #define DEV_MAC 0x00aaaaaaaaaa
  532.  
  533. static void netdevsim_add(unsigned int addr, unsigned int port_count)
  534. {
  535. write_file("/sys/bus/netdevsim/del_device", "%u", addr);
  536. if (write_file("/sys/bus/netdevsim/new_device", "%u %u", addr, port_count)) {
  537. char buf[32];
  538. snprintf(buf, sizeof(buf), "netdevsim%d", addr);
  539. initialize_devlink_ports("netdevsim", buf, "netdevsim");
  540. }
  541. }
  542.  
  543. #define WG_GENL_NAME "wireguard"
  544. enum wg_cmd {
  545. WG_CMD_GET_DEVICE,
  546. WG_CMD_SET_DEVICE,
  547. };
  548. enum wgdevice_attribute {
  549. WGDEVICE_A_UNSPEC,
  550. WGDEVICE_A_IFINDEX,
  551. WGDEVICE_A_IFNAME,
  552. WGDEVICE_A_PRIVATE_KEY,
  553. WGDEVICE_A_PUBLIC_KEY,
  554. WGDEVICE_A_FLAGS,
  555. WGDEVICE_A_LISTEN_PORT,
  556. WGDEVICE_A_FWMARK,
  557. WGDEVICE_A_PEERS,
  558. };
  559. enum wgpeer_attribute {
  560. WGPEER_A_UNSPEC,
  561. WGPEER_A_PUBLIC_KEY,
  562. WGPEER_A_PRESHARED_KEY,
  563. WGPEER_A_FLAGS,
  564. WGPEER_A_ENDPOINT,
  565. WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  566. WGPEER_A_LAST_HANDSHAKE_TIME,
  567. WGPEER_A_RX_BYTES,
  568. WGPEER_A_TX_BYTES,
  569. WGPEER_A_ALLOWEDIPS,
  570. WGPEER_A_PROTOCOL_VERSION,
  571. };
  572. enum wgallowedip_attribute {
  573. WGALLOWEDIP_A_UNSPEC,
  574. WGALLOWEDIP_A_FAMILY,
  575. WGALLOWEDIP_A_IPADDR,
  576. WGALLOWEDIP_A_CIDR_MASK,
  577. };
  578.  
  579. static void netlink_wireguard_setup(void)
  580. {
  581. const char ifname_a[] = "wg0";
  582. const char ifname_b[] = "wg1";
  583. const char ifname_c[] = "wg2";
  584. const char private_a[] =
  585. "\xa0\x5c\xa8\x4f\x6c\x9c\x8e\x38\x53\xe2\xfd\x7a\x70\xae\x0f\xb2\x0f\xa1"
  586. "\x52\x60\x0c\xb0\x08\x45\x17\x4f\x08\x07\x6f\x8d\x78\x43";
  587. const char private_b[] =
  588. "\xb0\x80\x73\xe8\xd4\x4e\x91\xe3\xda\x92\x2c\x22\x43\x82\x44\xbb\x88\x5c"
  589. "\x69\xe2\x69\xc8\xe9\xd8\x35\xb1\x14\x29\x3a\x4d\xdc\x6e";
  590. const char private_c[] =
  591. "\xa0\xcb\x87\x9a\x47\xf5\xbc\x64\x4c\x0e\x69\x3f\xa6\xd0\x31\xc7\x4a\x15"
  592. "\x53\xb6\xe9\x01\xb9\xff\x2f\x51\x8c\x78\x04\x2f\xb5\x42";
  593. const char public_a[] =
  594. "\x97\x5c\x9d\x81\xc9\x83\xc8\x20\x9e\xe7\x81\x25\x4b\x89\x9f\x8e\xd9\x25"
  595. "\xae\x9f\x09\x23\xc2\x3c\x62\xf5\x3c\x57\xcd\xbf\x69\x1c";
  596. const char public_b[] =
  597. "\xd1\x73\x28\x99\xf6\x11\xcd\x89\x94\x03\x4d\x7f\x41\x3d\xc9\x57\x63\x0e"
  598. "\x54\x93\xc2\x85\xac\xa4\x00\x65\xcb\x63\x11\xbe\x69\x6b";
  599. const char public_c[] =
  600. "\xf4\x4d\xa3\x67\xa8\x8e\xe6\x56\x4f\x02\x02\x11\x45\x67\x27\x08\x2f\x5c"
  601. "\xeb\xee\x8b\x1b\xf5\xeb\x73\x37\x34\x1b\x45\x9b\x39\x22";
  602. const uint16_t listen_a = 20001;
  603. const uint16_t listen_b = 20002;
  604. const uint16_t listen_c = 20003;
  605. const uint16_t af_inet = AF_INET;
  606. const uint16_t af_inet6 = AF_INET6;
  607. const struct sockaddr_in endpoint_b_v4 = {
  608. .sin_family = AF_INET,
  609. .sin_port = htons(listen_b),
  610. .sin_addr = {htonl(INADDR_LOOPBACK)}};
  611. const struct sockaddr_in endpoint_c_v4 = {
  612. .sin_family = AF_INET,
  613. .sin_port = htons(listen_c),
  614. .sin_addr = {htonl(INADDR_LOOPBACK)}};
  615. struct sockaddr_in6 endpoint_a_v6 = {.sin6_family = AF_INET6,
  616. .sin6_port = htons(listen_a)};
  617. endpoint_a_v6.sin6_addr = in6addr_loopback;
  618. struct sockaddr_in6 endpoint_c_v6 = {.sin6_family = AF_INET6,
  619. .sin6_port = htons(listen_c)};
  620. endpoint_c_v6.sin6_addr = in6addr_loopback;
  621. const struct in_addr first_half_v4 = {0};
  622. const struct in_addr second_half_v4 = {(uint32_t)htonl(128 << 24)};
  623. const struct in6_addr first_half_v6 = {{{0}}};
  624. const struct in6_addr second_half_v6 = {{{0x80}}};
  625. const uint8_t half_cidr = 1;
  626. const uint16_t persistent_keepalives[] = {1, 3, 7, 9, 14, 19};
  627. struct genlmsghdr genlhdr = {.cmd = WG_CMD_SET_DEVICE, .version = 1};
  628. int sock;
  629. int id, err;
  630. sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
  631. if (sock == -1) {
  632. return;
  633. }
  634. id = netlink_query_family_id(&nlmsg, sock, WG_GENL_NAME, true);
  635. if (id == -1)
  636. goto error;
  637. netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
  638. netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_a, strlen(ifname_a) + 1);
  639. netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_a, 32);
  640. netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_a, 2);
  641. netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
  642. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  643. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
  644. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
  645. sizeof(endpoint_b_v4));
  646. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  647. &persistent_keepalives[0], 2);
  648. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  649. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  650. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  651. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
  652. sizeof(first_half_v4));
  653. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  654. netlink_done(&nlmsg);
  655. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  656. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  657. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
  658. sizeof(first_half_v6));
  659. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  660. netlink_done(&nlmsg);
  661. netlink_done(&nlmsg);
  662. netlink_done(&nlmsg);
  663. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  664. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
  665. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v6,
  666. sizeof(endpoint_c_v6));
  667. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  668. &persistent_keepalives[1], 2);
  669. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  670. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  671. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  672. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
  673. sizeof(second_half_v4));
  674. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  675. netlink_done(&nlmsg);
  676. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  677. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  678. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
  679. sizeof(second_half_v6));
  680. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  681. netlink_done(&nlmsg);
  682. netlink_done(&nlmsg);
  683. netlink_done(&nlmsg);
  684. netlink_done(&nlmsg);
  685. err = netlink_send(&nlmsg, sock);
  686. if (err < 0) {
  687. }
  688. netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
  689. netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_b, strlen(ifname_b) + 1);
  690. netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_b, 32);
  691. netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_b, 2);
  692. netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
  693. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  694. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
  695. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
  696. sizeof(endpoint_a_v6));
  697. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  698. &persistent_keepalives[2], 2);
  699. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  700. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  701. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  702. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
  703. sizeof(first_half_v4));
  704. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  705. netlink_done(&nlmsg);
  706. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  707. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  708. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
  709. sizeof(first_half_v6));
  710. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  711. netlink_done(&nlmsg);
  712. netlink_done(&nlmsg);
  713. netlink_done(&nlmsg);
  714. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  715. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
  716. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v4,
  717. sizeof(endpoint_c_v4));
  718. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  719. &persistent_keepalives[3], 2);
  720. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  721. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  722. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  723. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
  724. sizeof(second_half_v4));
  725. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  726. netlink_done(&nlmsg);
  727. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  728. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  729. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
  730. sizeof(second_half_v6));
  731. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  732. netlink_done(&nlmsg);
  733. netlink_done(&nlmsg);
  734. netlink_done(&nlmsg);
  735. netlink_done(&nlmsg);
  736. err = netlink_send(&nlmsg, sock);
  737. if (err < 0) {
  738. }
  739. netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
  740. netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_c, strlen(ifname_c) + 1);
  741. netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_c, 32);
  742. netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_c, 2);
  743. netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
  744. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  745. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
  746. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
  747. sizeof(endpoint_a_v6));
  748. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  749. &persistent_keepalives[4], 2);
  750. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  751. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  752. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  753. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
  754. sizeof(first_half_v4));
  755. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  756. netlink_done(&nlmsg);
  757. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  758. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  759. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
  760. sizeof(first_half_v6));
  761. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  762. netlink_done(&nlmsg);
  763. netlink_done(&nlmsg);
  764. netlink_done(&nlmsg);
  765. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  766. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
  767. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
  768. sizeof(endpoint_b_v4));
  769. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  770. &persistent_keepalives[5], 2);
  771. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  772. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  773. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  774. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
  775. sizeof(second_half_v4));
  776. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  777. netlink_done(&nlmsg);
  778. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  779. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  780. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
  781. sizeof(second_half_v6));
  782. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  783. netlink_done(&nlmsg);
  784. netlink_done(&nlmsg);
  785. netlink_done(&nlmsg);
  786. netlink_done(&nlmsg);
  787. err = netlink_send(&nlmsg, sock);
  788. if (err < 0) {
  789. }
  790.  
  791. error:
  792. close(sock);
  793. }
  794.  
  795. static void initialize_netdevices(void)
  796. {
  797. char netdevsim[16];
  798. sprintf(netdevsim, "netdevsim%d", (int)procid);
  799. struct {
  800. const char* type;
  801. const char* dev;
  802. } devtypes[] = {
  803. {"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"}, {"vcan", "vcan0"},
  804. {"bond", "bond0"}, {"team", "team0"}, {"dummy", "dummy0"},
  805. {"nlmon", "nlmon0"}, {"caif", "caif0"}, {"batadv", "batadv0"},
  806. {"vxcan", "vxcan1"}, {"veth", 0}, {"wireguard", "wg0"},
  807. {"wireguard", "wg1"}, {"wireguard", "wg2"},
  808. };
  809. const char* devmasters[] = {"bridge", "bond", "team", "batadv"};
  810. struct {
  811. const char* name;
  812. int macsize;
  813. bool noipv6;
  814. } devices[] = {
  815. {"lo", ETH_ALEN},
  816. {"sit0", 0},
  817. {"bridge0", ETH_ALEN},
  818. {"vcan0", 0, true},
  819. {"tunl0", 0},
  820. {"gre0", 0},
  821. {"gretap0", ETH_ALEN},
  822. {"ip_vti0", 0},
  823. {"ip6_vti0", 0},
  824. {"ip6tnl0", 0},
  825. {"ip6gre0", 0},
  826. {"ip6gretap0", ETH_ALEN},
  827. {"erspan0", ETH_ALEN},
  828. {"bond0", ETH_ALEN},
  829. {"veth0", ETH_ALEN},
  830. {"veth1", ETH_ALEN},
  831. {"team0", ETH_ALEN},
  832. {"veth0_to_bridge", ETH_ALEN},
  833. {"veth1_to_bridge", ETH_ALEN},
  834. {"veth0_to_bond", ETH_ALEN},
  835. {"veth1_to_bond", ETH_ALEN},
  836. {"veth0_to_team", ETH_ALEN},
  837. {"veth1_to_team", ETH_ALEN},
  838. {"veth0_to_hsr", ETH_ALEN},
  839. {"veth1_to_hsr", ETH_ALEN},
  840. {"hsr0", 0},
  841. {"dummy0", ETH_ALEN},
  842. {"nlmon0", 0},
  843. {"vxcan0", 0, true},
  844. {"vxcan1", 0, true},
  845. {"caif0", ETH_ALEN},
  846. {"batadv0", ETH_ALEN},
  847. {netdevsim, ETH_ALEN},
  848. {"xfrm0", ETH_ALEN},
  849. {"veth0_virt_wifi", ETH_ALEN},
  850. {"veth1_virt_wifi", ETH_ALEN},
  851. {"virt_wifi0", ETH_ALEN},
  852. {"veth0_vlan", ETH_ALEN},
  853. {"veth1_vlan", ETH_ALEN},
  854. {"vlan0", ETH_ALEN},
  855. {"vlan1", ETH_ALEN},
  856. {"macvlan0", ETH_ALEN},
  857. {"macvlan1", ETH_ALEN},
  858. {"ipvlan0", ETH_ALEN},
  859. {"ipvlan1", ETH_ALEN},
  860. {"veth0_macvtap", ETH_ALEN},
  861. {"veth1_macvtap", ETH_ALEN},
  862. {"macvtap0", ETH_ALEN},
  863. {"macsec0", ETH_ALEN},
  864. {"veth0_to_batadv", ETH_ALEN},
  865. {"veth1_to_batadv", ETH_ALEN},
  866. {"batadv_slave_0", ETH_ALEN},
  867. {"batadv_slave_1", ETH_ALEN},
  868. {"geneve0", ETH_ALEN},
  869. {"geneve1", ETH_ALEN},
  870. {"wg0", 0},
  871. {"wg1", 0},
  872. {"wg2", 0},
  873. };
  874. int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  875. if (sock == -1)
  876. exit(1);
  877. unsigned i;
  878. for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++)
  879. netlink_add_device(&nlmsg, sock, devtypes[i].type, devtypes[i].dev);
  880. for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) {
  881. char master[32], slave0[32], veth0[32], slave1[32], veth1[32];
  882. sprintf(slave0, "%s_slave_0", devmasters[i]);
  883. sprintf(veth0, "veth0_to_%s", devmasters[i]);
  884. netlink_add_veth(&nlmsg, sock, slave0, veth0);
  885. sprintf(slave1, "%s_slave_1", devmasters[i]);
  886. sprintf(veth1, "veth1_to_%s", devmasters[i]);
  887. netlink_add_veth(&nlmsg, sock, slave1, veth1);
  888. sprintf(master, "%s0", devmasters[i]);
  889. netlink_device_change(&nlmsg, sock, slave0, false, master, 0, 0, NULL);
  890. netlink_device_change(&nlmsg, sock, slave1, false, master, 0, 0, NULL);
  891. }
  892. netlink_add_xfrm(&nlmsg, sock, "xfrm0");
  893. netlink_device_change(&nlmsg, sock, "bridge_slave_0", true, 0, 0, 0, NULL);
  894. netlink_device_change(&nlmsg, sock, "bridge_slave_1", true, 0, 0, 0, NULL);
  895. netlink_add_veth(&nlmsg, sock, "hsr_slave_0", "veth0_to_hsr");
  896. netlink_add_veth(&nlmsg, sock, "hsr_slave_1", "veth1_to_hsr");
  897. netlink_add_hsr(&nlmsg, sock, "hsr0", "hsr_slave_0", "hsr_slave_1");
  898. netlink_device_change(&nlmsg, sock, "hsr_slave_0", true, 0, 0, 0, NULL);
  899. netlink_device_change(&nlmsg, sock, "hsr_slave_1", true, 0, 0, 0, NULL);
  900. netlink_add_veth(&nlmsg, sock, "veth0_virt_wifi", "veth1_virt_wifi");
  901. netlink_add_linked(&nlmsg, sock, "virt_wifi", "virt_wifi0",
  902. "veth1_virt_wifi");
  903. netlink_add_veth(&nlmsg, sock, "veth0_vlan", "veth1_vlan");
  904. netlink_add_vlan(&nlmsg, sock, "vlan0", "veth0_vlan", 0, htons(ETH_P_8021Q));
  905. netlink_add_vlan(&nlmsg, sock, "vlan1", "veth0_vlan", 1, htons(ETH_P_8021AD));
  906. netlink_add_macvlan(&nlmsg, sock, "macvlan0", "veth1_vlan");
  907. netlink_add_macvlan(&nlmsg, sock, "macvlan1", "veth1_vlan");
  908. netlink_add_ipvlan(&nlmsg, sock, "ipvlan0", "veth0_vlan", IPVLAN_MODE_L2, 0);
  909. netlink_add_ipvlan(&nlmsg, sock, "ipvlan1", "veth0_vlan", IPVLAN_MODE_L3S,
  910. IPVLAN_F_VEPA);
  911. netlink_add_veth(&nlmsg, sock, "veth0_macvtap", "veth1_macvtap");
  912. netlink_add_linked(&nlmsg, sock, "macvtap", "macvtap0", "veth0_macvtap");
  913. netlink_add_linked(&nlmsg, sock, "macsec", "macsec0", "veth1_macvtap");
  914. char addr[32];
  915. sprintf(addr, DEV_IPV4, 14 + 10);
  916. struct in_addr geneve_addr4;
  917. if (inet_pton(AF_INET, addr, &geneve_addr4) <= 0)
  918. exit(1);
  919. struct in6_addr geneve_addr6;
  920. if (inet_pton(AF_INET6, "fc00::01", &geneve_addr6) <= 0)
  921. exit(1);
  922. netlink_add_geneve(&nlmsg, sock, "geneve0", 0, &geneve_addr4, 0);
  923. netlink_add_geneve(&nlmsg, sock, "geneve1", 1, 0, &geneve_addr6);
  924. netdevsim_add((int)procid, 4);
  925. netlink_wireguard_setup();
  926. for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
  927. char addr[32];
  928. sprintf(addr, DEV_IPV4, i + 10);
  929. netlink_add_addr4(&nlmsg, sock, devices[i].name, addr);
  930. if (!devices[i].noipv6) {
  931. sprintf(addr, DEV_IPV6, i + 10);
  932. netlink_add_addr6(&nlmsg, sock, devices[i].name, addr);
  933. }
  934. uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40);
  935. netlink_device_change(&nlmsg, sock, devices[i].name, true, 0, &macaddr,
  936. devices[i].macsize, NULL);
  937. }
  938. close(sock);
  939. }
  940. static void initialize_netdevices_init(void)
  941. {
  942. int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  943. if (sock == -1)
  944. exit(1);
  945. struct {
  946. const char* type;
  947. int macsize;
  948. bool noipv6;
  949. bool noup;
  950. } devtypes[] = {
  951. {"nr", 7, true},
  952. {"rose", 5, true, true},
  953. };
  954. unsigned i;
  955. for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) {
  956. char dev[32], addr[32];
  957. sprintf(dev, "%s%d", devtypes[i].type, (int)procid);
  958. sprintf(addr, "172.30.%d.%d", i, (int)procid + 1);
  959. netlink_add_addr4(&nlmsg, sock, dev, addr);
  960. if (!devtypes[i].noipv6) {
  961. sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1);
  962. netlink_add_addr6(&nlmsg, sock, dev, addr);
  963. }
  964. int macsize = devtypes[i].macsize;
  965. uint64_t macaddr = 0xbbbbbb +
  966. ((unsigned long long)i << (8 * (macsize - 2))) +
  967. (procid << (8 * (macsize - 1)));
  968. netlink_device_change(&nlmsg, sock, dev, !devtypes[i].noup, 0, &macaddr,
  969. macsize, NULL);
  970. }
  971. close(sock);
  972. }
  973.  
  974. #define MAX_FDS 30
  975.  
  976. //% This code is derived from puff.{c,h}, found in the zlib development. The
  977. //% original files come with the following copyright notice:
  978.  
  979. //% Copyright (C) 2002-2013 Mark Adler, all rights reserved
  980. //% version 2.3, 21 Jan 2013
  981. //% This software is provided 'as-is', without any express or implied
  982. //% warranty. In no event will the author be held liable for any damages
  983. //% arising from the use of this software.
  984. //% Permission is granted to anyone to use this software for any purpose,
  985. //% including commercial applications, and to alter it and redistribute it
  986. //% freely, subject to the following restrictions:
  987. //% 1. The origin of this software must not be misrepresented; you must not
  988. //% claim that you wrote the original software. If you use this software
  989. //% in a product, an acknowledgment in the product documentation would be
  990. //% appreciated but is not required.
  991. //% 2. Altered source versions must be plainly marked as such, and must not be
  992. //% misrepresented as being the original software.
  993. //% 3. This notice may not be removed or altered from any source distribution.
  994. //% Mark Adler [email protected]
  995.  
  996. //% BEGIN CODE DERIVED FROM puff.{c,h}
  997.  
  998. #define MAXBITS 15
  999. #define MAXLCODES 286
  1000. #define MAXDCODES 30
  1001. #define MAXCODES (MAXLCODES + MAXDCODES)
  1002. #define FIXLCODES 288
  1003.  
  1004. struct puff_state {
  1005. unsigned char* out;
  1006. unsigned long outlen;
  1007. unsigned long outcnt;
  1008. const unsigned char* in;
  1009. unsigned long inlen;
  1010. unsigned long incnt;
  1011. int bitbuf;
  1012. int bitcnt;
  1013. jmp_buf env;
  1014. };
  1015. static int puff_bits(struct puff_state* s, int need)
  1016. {
  1017. long val = s->bitbuf;
  1018. while (s->bitcnt < need) {
  1019. if (s->incnt == s->inlen)
  1020. longjmp(s->env, 1);
  1021. val |= (long)(s->in[s->incnt++]) << s->bitcnt;
  1022. s->bitcnt += 8;
  1023. }
  1024. s->bitbuf = (int)(val >> need);
  1025. s->bitcnt -= need;
  1026. return (int)(val & ((1L << need) - 1));
  1027. }
  1028. static int puff_stored(struct puff_state* s)
  1029. {
  1030. s->bitbuf = 0;
  1031. s->bitcnt = 0;
  1032. if (s->incnt + 4 > s->inlen)
  1033. return 2;
  1034. unsigned len = s->in[s->incnt++];
  1035. len |= s->in[s->incnt++] << 8;
  1036. if (s->in[s->incnt++] != (~len & 0xff) ||
  1037. s->in[s->incnt++] != ((~len >> 8) & 0xff))
  1038. return -2;
  1039. if (s->incnt + len > s->inlen)
  1040. return 2;
  1041. if (s->outcnt + len > s->outlen)
  1042. return 1;
  1043. for (; len--; s->outcnt++, s->incnt++) {
  1044. if (s->in[s->incnt])
  1045. s->out[s->outcnt] = s->in[s->incnt];
  1046. }
  1047. return 0;
  1048. }
  1049. struct puff_huffman {
  1050. short* count;
  1051. short* symbol;
  1052. };
  1053. static int puff_decode(struct puff_state* s, const struct puff_huffman* h)
  1054. {
  1055. int first = 0;
  1056. int index = 0;
  1057. int bitbuf = s->bitbuf;
  1058. int left = s->bitcnt;
  1059. int code = first = index = 0;
  1060. int len = 1;
  1061. short* next = h->count + 1;
  1062. while (1) {
  1063. while (left--) {
  1064. code |= bitbuf & 1;
  1065. bitbuf >>= 1;
  1066. int count = *next++;
  1067. if (code - count < first) {
  1068. s->bitbuf = bitbuf;
  1069. s->bitcnt = (s->bitcnt - len) & 7;
  1070. return h->symbol[index + (code - first)];
  1071. }
  1072. index += count;
  1073. first += count;
  1074. first <<= 1;
  1075. code <<= 1;
  1076. len++;
  1077. }
  1078. left = (MAXBITS + 1) - len;
  1079. if (left == 0)
  1080. break;
  1081. if (s->incnt == s->inlen)
  1082. longjmp(s->env, 1);
  1083. bitbuf = s->in[s->incnt++];
  1084. if (left > 8)
  1085. left = 8;
  1086. }
  1087. return -10;
  1088. }
  1089. static int puff_construct(struct puff_huffman* h, const short* length, int n)
  1090. {
  1091. int len;
  1092. for (len = 0; len <= MAXBITS; len++)
  1093. h->count[len] = 0;
  1094. int symbol;
  1095. for (symbol = 0; symbol < n; symbol++)
  1096. (h->count[length[symbol]])++;
  1097. if (h->count[0] == n)
  1098. return 0;
  1099. int left = 1;
  1100. for (len = 1; len <= MAXBITS; len++) {
  1101. left <<= 1;
  1102. left -= h->count[len];
  1103. if (left < 0)
  1104. return left;
  1105. }
  1106. short offs[MAXBITS + 1];
  1107. offs[1] = 0;
  1108. for (len = 1; len < MAXBITS; len++)
  1109. offs[len + 1] = offs[len] + h->count[len];
  1110. for (symbol = 0; symbol < n; symbol++)
  1111. if (length[symbol] != 0)
  1112. h->symbol[offs[length[symbol]]++] = symbol;
  1113. return left;
  1114. }
  1115. static int puff_codes(struct puff_state* s, const struct puff_huffman* lencode,
  1116. const struct puff_huffman* distcode)
  1117. {
  1118. static const short lens[29] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13,
  1119. 15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
  1120. 67, 83, 99, 115, 131, 163, 195, 227, 258};
  1121. static const short lext[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2,
  1122. 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
  1123. static const short dists[30] = {
  1124. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25,
  1125. 33, 49, 65, 97, 129, 193, 257, 385, 513, 769,
  1126. 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577};
  1127. static const short dext[30] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
  1128. 4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
  1129. 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
  1130. int symbol;
  1131. do {
  1132. symbol = puff_decode(s, lencode);
  1133. if (symbol < 0)
  1134. return symbol;
  1135. if (symbol < 256) {
  1136. if (s->outcnt == s->outlen)
  1137. return 1;
  1138. if (symbol)
  1139. s->out[s->outcnt] = symbol;
  1140. s->outcnt++;
  1141. } else if (symbol > 256) {
  1142. symbol -= 257;
  1143. if (symbol >= 29)
  1144. return -10;
  1145. int len = lens[symbol] + puff_bits(s, lext[symbol]);
  1146. symbol = puff_decode(s, distcode);
  1147. if (symbol < 0)
  1148. return symbol;
  1149. unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]);
  1150. if (dist > s->outcnt)
  1151. return -11;
  1152. if (s->outcnt + len > s->outlen)
  1153. return 1;
  1154. while (len--) {
  1155. if (dist <= s->outcnt && s->out[s->outcnt - dist])
  1156. s->out[s->outcnt] = s->out[s->outcnt - dist];
  1157. s->outcnt++;
  1158. }
  1159. }
  1160. } while (symbol != 256);
  1161. return 0;
  1162. }
  1163. static int puff_fixed(struct puff_state* s)
  1164. {
  1165. static int virgin = 1;
  1166. static short lencnt[MAXBITS + 1], lensym[FIXLCODES];
  1167. static short distcnt[MAXBITS + 1], distsym[MAXDCODES];
  1168. static struct puff_huffman lencode, distcode;
  1169. if (virgin) {
  1170. lencode.count = lencnt;
  1171. lencode.symbol = lensym;
  1172. distcode.count = distcnt;
  1173. distcode.symbol = distsym;
  1174. short lengths[FIXLCODES];
  1175. int symbol;
  1176. for (symbol = 0; symbol < 144; symbol++)
  1177. lengths[symbol] = 8;
  1178. for (; symbol < 256; symbol++)
  1179. lengths[symbol] = 9;
  1180. for (; symbol < 280; symbol++)
  1181. lengths[symbol] = 7;
  1182. for (; symbol < FIXLCODES; symbol++)
  1183. lengths[symbol] = 8;
  1184. puff_construct(&lencode, lengths, FIXLCODES);
  1185. for (symbol = 0; symbol < MAXDCODES; symbol++)
  1186. lengths[symbol] = 5;
  1187. puff_construct(&distcode, lengths, MAXDCODES);
  1188. virgin = 0;
  1189. }
  1190. return puff_codes(s, &lencode, &distcode);
  1191. }
  1192. static int puff_dynamic(struct puff_state* s)
  1193. {
  1194. static const short order[19] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5,
  1195. 11, 4, 12, 3, 13, 2, 14, 1, 15};
  1196. int nlen = puff_bits(s, 5) + 257;
  1197. int ndist = puff_bits(s, 5) + 1;
  1198. int ncode = puff_bits(s, 4) + 4;
  1199. if (nlen > MAXLCODES || ndist > MAXDCODES)
  1200. return -3;
  1201. short lengths[MAXCODES];
  1202. int index;
  1203. for (index = 0; index < ncode; index++)
  1204. lengths[order[index]] = puff_bits(s, 3);
  1205. for (; index < 19; index++)
  1206. lengths[order[index]] = 0;
  1207. short lencnt[MAXBITS + 1], lensym[MAXLCODES];
  1208. struct puff_huffman lencode = {lencnt, lensym};
  1209. int err = puff_construct(&lencode, lengths, 19);
  1210. if (err != 0)
  1211. return -4;
  1212. index = 0;
  1213. while (index < nlen + ndist) {
  1214. int symbol;
  1215. int len;
  1216. symbol = puff_decode(s, &lencode);
  1217. if (symbol < 0)
  1218. return symbol;
  1219. if (symbol < 16)
  1220. lengths[index++] = symbol;
  1221. else {
  1222. len = 0;
  1223. if (symbol == 16) {
  1224. if (index == 0)
  1225. return -5;
  1226. len = lengths[index - 1];
  1227. symbol = 3 + puff_bits(s, 2);
  1228. } else if (symbol == 17)
  1229. symbol = 3 + puff_bits(s, 3);
  1230. else
  1231. symbol = 11 + puff_bits(s, 7);
  1232. if (index + symbol > nlen + ndist)
  1233. return -6;
  1234. while (symbol--)
  1235. lengths[index++] = len;
  1236. }
  1237. }
  1238. if (lengths[256] == 0)
  1239. return -9;
  1240. err = puff_construct(&lencode, lengths, nlen);
  1241. if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1]))
  1242. return -7;
  1243. short distcnt[MAXBITS + 1], distsym[MAXDCODES];
  1244. struct puff_huffman distcode = {distcnt, distsym};
  1245. err = puff_construct(&distcode, lengths + nlen, ndist);
  1246. if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1]))
  1247. return -8;
  1248. return puff_codes(s, &lencode, &distcode);
  1249. }
  1250. static int puff(unsigned char* dest, unsigned long* destlen,
  1251. const unsigned char* source, unsigned long sourcelen)
  1252. {
  1253. struct puff_state s = {
  1254. .out = dest,
  1255. .outlen = *destlen,
  1256. .outcnt = 0,
  1257. .in = source,
  1258. .inlen = sourcelen,
  1259. .incnt = 0,
  1260. .bitbuf = 0,
  1261. .bitcnt = 0,
  1262. };
  1263. int err;
  1264. if (setjmp(s.env) != 0)
  1265. err = 2;
  1266. else {
  1267. int last;
  1268. do {
  1269. last = puff_bits(&s, 1);
  1270. int type = puff_bits(&s, 2);
  1271. err = type == 0 ? puff_stored(&s)
  1272. : (type == 1 ? puff_fixed(&s)
  1273. : (type == 2 ? puff_dynamic(&s) : -1));
  1274. if (err != 0)
  1275. break;
  1276. } while (!last);
  1277. }
  1278. *destlen = s.outcnt;
  1279. return err;
  1280. }
  1281.  
  1282. //% END CODE DERIVED FROM puff.{c,h}
  1283.  
  1284. #define ZLIB_HEADER_WIDTH 2
  1285.  
  1286. static int puff_zlib_to_file(const unsigned char* source,
  1287. unsigned long sourcelen, int dest_fd)
  1288. {
  1289. if (sourcelen < ZLIB_HEADER_WIDTH)
  1290. return 0;
  1291. source += ZLIB_HEADER_WIDTH;
  1292. sourcelen -= ZLIB_HEADER_WIDTH;
  1293. const unsigned long max_destlen = 132 << 20;
  1294. void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ,
  1295. MAP_PRIVATE | MAP_ANON, -1, 0);
  1296. if (ret == MAP_FAILED)
  1297. return -1;
  1298. unsigned char* dest = (unsigned char*)ret;
  1299. unsigned long destlen = max_destlen;
  1300. int err = puff(dest, &destlen, source, sourcelen);
  1301. if (err) {
  1302. munmap(dest, max_destlen);
  1303. errno = -err;
  1304. return -1;
  1305. }
  1306. if (write(dest_fd, dest, destlen) != (ssize_t)destlen) {
  1307. munmap(dest, max_destlen);
  1308. return -1;
  1309. }
  1310. return munmap(dest, max_destlen);
  1311. }
  1312.  
  1313. static int setup_loop_device(unsigned char* data, unsigned long size,
  1314. const char* loopname, int* loopfd_p)
  1315. {
  1316. int err = 0, loopfd = -1;
  1317. int memfd = syscall(__NR_memfd_create, "syzkaller", 0);
  1318. if (memfd == -1) {
  1319. err = errno;
  1320. goto error;
  1321. }
  1322. if (puff_zlib_to_file(data, size, memfd)) {
  1323. err = errno;
  1324. goto error_close_memfd;
  1325. }
  1326. loopfd = open(loopname, O_RDWR);
  1327. if (loopfd == -1) {
  1328. err = errno;
  1329. goto error_close_memfd;
  1330. }
  1331. if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
  1332. if (errno != EBUSY) {
  1333. err = errno;
  1334. goto error_close_loop;
  1335. }
  1336. ioctl(loopfd, LOOP_CLR_FD, 0);
  1337. usleep(1000);
  1338. if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
  1339. err = errno;
  1340. goto error_close_loop;
  1341. }
  1342. }
  1343. close(memfd);
  1344. *loopfd_p = loopfd;
  1345. return 0;
  1346.  
  1347. error_close_loop:
  1348. close(loopfd);
  1349. error_close_memfd:
  1350. close(memfd);
  1351. error:
  1352. errno = err;
  1353. return -1;
  1354. }
  1355.  
  1356. static void reset_loop_device(const char* loopname)
  1357. {
  1358. int loopfd = open(loopname, O_RDWR);
  1359. if (loopfd == -1) {
  1360. return;
  1361. }
  1362. if (ioctl(loopfd, LOOP_CLR_FD, 0)) {
  1363. }
  1364. close(loopfd);
  1365. }
  1366.  
  1367. static long syz_mount_image(volatile long fsarg, volatile long dir,
  1368. volatile long flags, volatile long optsarg,
  1369. volatile long change_dir,
  1370. volatile unsigned long size, volatile long image)
  1371. {
  1372. unsigned char* data = (unsigned char*)image;
  1373. int res = -1, err = 0, need_loop_device = !!size;
  1374. char* mount_opts = (char*)optsarg;
  1375. char* target = (char*)dir;
  1376. char* fs = (char*)fsarg;
  1377. char* source = NULL;
  1378. char loopname[64];
  1379. if (need_loop_device) {
  1380. int loopfd;
  1381. memset(loopname, 0, sizeof(loopname));
  1382. snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
  1383. if (setup_loop_device(data, size, loopname, &loopfd) == -1)
  1384. return -1;
  1385. close(loopfd);
  1386. source = loopname;
  1387. }
  1388. mkdir(target, 0777);
  1389. char opts[256];
  1390. memset(opts, 0, sizeof(opts));
  1391. if (strlen(mount_opts) > (sizeof(opts) - 32)) {
  1392. }
  1393. strncpy(opts, mount_opts, sizeof(opts) - 32);
  1394. if (strcmp(fs, "iso9660") == 0) {
  1395. flags |= MS_RDONLY;
  1396. } else if (strncmp(fs, "ext", 3) == 0) {
  1397. bool has_remount_ro = false;
  1398. char* remount_ro_start = strstr(opts, "errors=remount-ro");
  1399. if (remount_ro_start != NULL) {
  1400. char after = *(remount_ro_start + strlen("errors=remount-ro"));
  1401. char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1);
  1402. has_remount_ro = ((before == '\0' || before == ',') &&
  1403. (after == '\0' || after == ','));
  1404. }
  1405. if (strstr(opts, "errors=panic") || !has_remount_ro)
  1406. strcat(opts, ",errors=continue");
  1407. } else if (strcmp(fs, "xfs") == 0) {
  1408. strcat(opts, ",nouuid");
  1409. } else if (strncmp(fs, "gfs2", 4) == 0 &&
  1410. (strstr(opts, "errors=panic") || strstr(opts, "debug"))) {
  1411. strcat(opts, ",errors=withdraw");
  1412. }
  1413. res = mount(source, target, fs, flags, opts);
  1414. if (res == -1) {
  1415. err = errno;
  1416. goto error_clear_loop;
  1417. }
  1418. res = open(target, O_RDONLY | O_DIRECTORY);
  1419. if (res == -1) {
  1420. err = errno;
  1421. goto error_clear_loop;
  1422. }
  1423. if (change_dir) {
  1424. res = chdir(target);
  1425. if (res == -1) {
  1426. err = errno;
  1427. }
  1428. }
  1429.  
  1430. error_clear_loop:
  1431. if (need_loop_device)
  1432. reset_loop_device(loopname);
  1433. errno = err;
  1434. return res;
  1435. }
  1436.  
  1437. static void setup_gadgetfs();
  1438. static void setup_binderfs();
  1439. static void setup_fusectl();
  1440. static void sandbox_common_mount_tmpfs(void)
  1441. {
  1442. write_file("/proc/sys/fs/mount-max", "100000");
  1443. if (mkdir("./syz-tmp", 0777))
  1444. exit(1);
  1445. if (mount("", "./syz-tmp", "tmpfs", 0, NULL))
  1446. exit(1);
  1447. if (mkdir("./syz-tmp/newroot", 0777))
  1448. exit(1);
  1449. if (mkdir("./syz-tmp/newroot/dev", 0700))
  1450. exit(1);
  1451. unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE;
  1452. if (mount("/dev", "./syz-tmp/newroot/dev", NULL, bind_mount_flags, NULL))
  1453. exit(1);
  1454. if (mkdir("./syz-tmp/newroot/proc", 0700))
  1455. exit(1);
  1456. if (mount("syz-proc", "./syz-tmp/newroot/proc", "proc", 0, NULL))
  1457. exit(1);
  1458. if (mkdir("./syz-tmp/newroot/selinux", 0700))
  1459. exit(1);
  1460. const char* selinux_path = "./syz-tmp/newroot/selinux";
  1461. if (mount("/selinux", selinux_path, NULL, bind_mount_flags, NULL)) {
  1462. if (errno != ENOENT)
  1463. exit(1);
  1464. if (mount("/sys/fs/selinux", selinux_path, NULL, bind_mount_flags, NULL) &&
  1465. errno != ENOENT)
  1466. exit(1);
  1467. }
  1468. if (mkdir("./syz-tmp/newroot/sys", 0700))
  1469. exit(1);
  1470. if (mount("/sys", "./syz-tmp/newroot/sys", 0, bind_mount_flags, NULL))
  1471. exit(1);
  1472. if (mount("/sys/kernel/debug", "./syz-tmp/newroot/sys/kernel/debug", NULL,
  1473. bind_mount_flags, NULL) &&
  1474. errno != ENOENT)
  1475. exit(1);
  1476. if (mount("/sys/fs/smackfs", "./syz-tmp/newroot/sys/fs/smackfs", NULL,
  1477. bind_mount_flags, NULL) &&
  1478. errno != ENOENT)
  1479. exit(1);
  1480. if (mount("/proc/sys/fs/binfmt_misc",
  1481. "./syz-tmp/newroot/proc/sys/fs/binfmt_misc", NULL, bind_mount_flags,
  1482. NULL) &&
  1483. errno != ENOENT)
  1484. exit(1);
  1485. if (mkdir("./syz-tmp/newroot/syz-inputs", 0700))
  1486. exit(1);
  1487. if (mount("/syz-inputs", "./syz-tmp/newroot/syz-inputs", NULL,
  1488. bind_mount_flags | MS_RDONLY, NULL) &&
  1489. errno != ENOENT)
  1490. exit(1);
  1491. if (mkdir("./syz-tmp/pivot", 0777))
  1492. exit(1);
  1493. if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) {
  1494. if (chdir("./syz-tmp"))
  1495. exit(1);
  1496. } else {
  1497. if (chdir("/"))
  1498. exit(1);
  1499. if (umount2("./pivot", MNT_DETACH))
  1500. exit(1);
  1501. }
  1502. if (chroot("./newroot"))
  1503. exit(1);
  1504. if (chdir("/"))
  1505. exit(1);
  1506. setup_gadgetfs();
  1507. setup_binderfs();
  1508. setup_fusectl();
  1509. }
  1510.  
  1511. static void setup_gadgetfs()
  1512. {
  1513. if (mkdir("/dev/gadgetfs", 0777)) {
  1514. }
  1515. if (mount("gadgetfs", "/dev/gadgetfs", "gadgetfs", 0, NULL)) {
  1516. }
  1517. }
  1518.  
  1519. static void setup_fusectl()
  1520. {
  1521. if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
  1522. }
  1523. }
  1524.  
  1525. static void setup_binderfs()
  1526. {
  1527. if (mkdir("/dev/binderfs", 0777)) {
  1528. }
  1529. if (mount("binder", "/dev/binderfs", "binder", 0, NULL)) {
  1530. }
  1531. }
  1532.  
  1533. static void loop();
  1534.  
  1535. static void sandbox_common()
  1536. {
  1537. prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  1538. if (getppid() == 1)
  1539. exit(1);
  1540. struct rlimit rlim;
  1541. rlim.rlim_cur = rlim.rlim_max = (200 << 20);
  1542. setrlimit(RLIMIT_AS, &rlim);
  1543. rlim.rlim_cur = rlim.rlim_max = 32 << 20;
  1544. setrlimit(RLIMIT_MEMLOCK, &rlim);
  1545. rlim.rlim_cur = rlim.rlim_max = 136 << 20;
  1546. setrlimit(RLIMIT_FSIZE, &rlim);
  1547. rlim.rlim_cur = rlim.rlim_max = 1 << 20;
  1548. setrlimit(RLIMIT_STACK, &rlim);
  1549. rlim.rlim_cur = rlim.rlim_max = 128 << 20;
  1550. setrlimit(RLIMIT_CORE, &rlim);
  1551. rlim.rlim_cur = rlim.rlim_max = 256;
  1552. setrlimit(RLIMIT_NOFILE, &rlim);
  1553. if (unshare(CLONE_NEWNS)) {
  1554. }
  1555. if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
  1556. }
  1557. if (unshare(CLONE_NEWIPC)) {
  1558. }
  1559. if (unshare(0x02000000)) {
  1560. }
  1561. if (unshare(CLONE_NEWUTS)) {
  1562. }
  1563. if (unshare(CLONE_SYSVSEM)) {
  1564. }
  1565. typedef struct {
  1566. const char* name;
  1567. const char* value;
  1568. } sysctl_t;
  1569. static const sysctl_t sysctls[] = {
  1570. {"/proc/sys/kernel/shmmax", "16777216"},
  1571. {"/proc/sys/kernel/shmall", "536870912"},
  1572. {"/proc/sys/kernel/shmmni", "1024"},
  1573. {"/proc/sys/kernel/msgmax", "8192"},
  1574. {"/proc/sys/kernel/msgmni", "1024"},
  1575. {"/proc/sys/kernel/msgmnb", "1024"},
  1576. {"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
  1577. };
  1578. unsigned i;
  1579. for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
  1580. write_file(sysctls[i].name, sysctls[i].value);
  1581. }
  1582.  
  1583. static int wait_for_loop(int pid)
  1584. {
  1585. if (pid < 0)
  1586. exit(1);
  1587. int status = 0;
  1588. while (waitpid(-1, &status, __WALL) != pid) {
  1589. }
  1590. return WEXITSTATUS(status);
  1591. }
  1592.  
  1593. static void drop_caps(void)
  1594. {
  1595. struct __user_cap_header_struct cap_hdr = {};
  1596. struct __user_cap_data_struct cap_data[2] = {};
  1597. cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
  1598. cap_hdr.pid = getpid();
  1599. if (syscall(SYS_capget, &cap_hdr, &cap_data))
  1600. exit(1);
  1601. const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE);
  1602. cap_data[0].effective &= ~drop;
  1603. cap_data[0].permitted &= ~drop;
  1604. cap_data[0].inheritable &= ~drop;
  1605. if (syscall(SYS_capset, &cap_hdr, &cap_data))
  1606. exit(1);
  1607. }
  1608.  
  1609. static int do_sandbox_none(void)
  1610. {
  1611. if (unshare(CLONE_NEWPID)) {
  1612. }
  1613. int pid = fork();
  1614. if (pid != 0)
  1615. return wait_for_loop(pid);
  1616. sandbox_common();
  1617. drop_caps();
  1618. initialize_netdevices_init();
  1619. if (unshare(CLONE_NEWNET)) {
  1620. }
  1621. write_file("/proc/sys/net/ipv4/ping_group_range", "0 65535");
  1622. initialize_netdevices();
  1623. sandbox_common_mount_tmpfs();
  1624. loop();
  1625. exit(1);
  1626. }
  1627.  
  1628. #define FS_IOC_SETFLAGS _IOW('f', 2, long)
  1629. static void remove_dir(const char* dir)
  1630. {
  1631. int iter = 0;
  1632. DIR* dp = 0;
  1633. const int umount_flags = MNT_FORCE | UMOUNT_NOFOLLOW;
  1634.  
  1635. retry:
  1636. while (umount2(dir, umount_flags) == 0) {
  1637. }
  1638. dp = opendir(dir);
  1639. if (dp == NULL) {
  1640. if (errno == EMFILE) {
  1641. exit(1);
  1642. }
  1643. exit(1);
  1644. }
  1645. struct dirent* ep = 0;
  1646. while ((ep = readdir(dp))) {
  1647. if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
  1648. continue;
  1649. char filename[FILENAME_MAX];
  1650. snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
  1651. while (umount2(filename, umount_flags) == 0) {
  1652. }
  1653. struct stat st;
  1654. if (lstat(filename, &st))
  1655. exit(1);
  1656. if (S_ISDIR(st.st_mode)) {
  1657. remove_dir(filename);
  1658. continue;
  1659. }
  1660. int i;
  1661. for (i = 0;; i++) {
  1662. if (unlink(filename) == 0)
  1663. break;
  1664. if (errno == EPERM) {
  1665. int fd = open(filename, O_RDONLY);
  1666. if (fd != -1) {
  1667. long flags = 0;
  1668. if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
  1669. }
  1670. close(fd);
  1671. continue;
  1672. }
  1673. }
  1674. if (errno == EROFS) {
  1675. break;
  1676. }
  1677. if (errno != EBUSY || i > 100)
  1678. exit(1);
  1679. if (umount2(filename, umount_flags))
  1680. exit(1);
  1681. }
  1682. }
  1683. closedir(dp);
  1684. for (int i = 0;; i++) {
  1685. if (rmdir(dir) == 0)
  1686. break;
  1687. if (i < 100) {
  1688. if (errno == EPERM) {
  1689. int fd = open(dir, O_RDONLY);
  1690. if (fd != -1) {
  1691. long flags = 0;
  1692. if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
  1693. }
  1694. close(fd);
  1695. continue;
  1696. }
  1697. }
  1698. if (errno == EROFS) {
  1699. break;
  1700. }
  1701. if (errno == EBUSY) {
  1702. if (umount2(dir, umount_flags))
  1703. exit(1);
  1704. continue;
  1705. }
  1706. if (errno == ENOTEMPTY) {
  1707. if (iter < 100) {
  1708. iter++;
  1709. goto retry;
  1710. }
  1711. }
  1712. }
  1713. exit(1);
  1714. }
  1715. }
  1716.  
  1717. static void kill_and_wait(int pid, int* status)
  1718. {
  1719. kill(-pid, SIGKILL);
  1720. kill(pid, SIGKILL);
  1721. for (int i = 0; i < 100; i++) {
  1722. if (waitpid(-1, status, WNOHANG | __WALL) == pid)
  1723. return;
  1724. usleep(1000);
  1725. }
  1726. DIR* dir = opendir("/sys/fs/fuse/connections");
  1727. if (dir) {
  1728. for (;;) {
  1729. struct dirent* ent = readdir(dir);
  1730. if (!ent)
  1731. break;
  1732. if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
  1733. continue;
  1734. char abort[300];
  1735. snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
  1736. ent->d_name);
  1737. int fd = open(abort, O_WRONLY);
  1738. if (fd == -1) {
  1739. continue;
  1740. }
  1741. if (write(fd, abort, 1) < 0) {
  1742. }
  1743. close(fd);
  1744. }
  1745. closedir(dir);
  1746. } else {
  1747. }
  1748. while (waitpid(-1, status, __WALL) != pid) {
  1749. }
  1750. }
  1751.  
  1752. static void reset_loop()
  1753. {
  1754. char buf[64];
  1755. snprintf(buf, sizeof(buf), "/dev/loop%llu", procid);
  1756. int loopfd = open(buf, O_RDWR);
  1757. if (loopfd != -1) {
  1758. ioctl(loopfd, LOOP_CLR_FD, 0);
  1759. close(loopfd);
  1760. }
  1761. }
  1762.  
  1763. static void setup_test()
  1764. {
  1765. prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  1766. setpgrp();
  1767. write_file("/proc/self/oom_score_adj", "1000");
  1768. if (symlink("/dev/binderfs", "./binderfs")) {
  1769. }
  1770. }
  1771.  
  1772. static void close_fds()
  1773. {
  1774. for (int fd = 3; fd < MAX_FDS; fd++)
  1775. close(fd);
  1776. }
  1777.  
  1778. static void setup_sysctl()
  1779. {
  1780. int cad_pid = fork();
  1781. if (cad_pid < 0)
  1782. exit(1);
  1783. if (cad_pid == 0) {
  1784. for (;;)
  1785. sleep(100);
  1786. }
  1787. char tmppid[32];
  1788. snprintf(tmppid, sizeof(tmppid), "%d", cad_pid);
  1789. struct {
  1790. const char* name;
  1791. const char* data;
  1792. } files[] = {
  1793. {"/sys/kernel/debug/x86/nmi_longest_ns", "10000000000"},
  1794. {"/proc/sys/kernel/hung_task_check_interval_secs", "20"},
  1795. {"/proc/sys/net/core/bpf_jit_kallsyms", "1"},
  1796. {"/proc/sys/net/core/bpf_jit_harden", "0"},
  1797. {"/proc/sys/kernel/kptr_restrict", "0"},
  1798. {"/proc/sys/kernel/softlockup_all_cpu_backtrace", "1"},
  1799. {"/proc/sys/fs/mount-max", "100"},
  1800. {"/proc/sys/vm/oom_dump_tasks", "0"},
  1801. {"/proc/sys/debug/exception-trace", "0"},
  1802. {"/proc/sys/kernel/printk", "7 4 1 3"},
  1803. {"/proc/sys/kernel/keys/gc_delay", "1"},
  1804. {"/proc/sys/vm/oom_kill_allocating_task", "1"},
  1805. {"/proc/sys/kernel/ctrl-alt-del", "0"},
  1806. {"/proc/sys/kernel/cad_pid", tmppid},
  1807. };
  1808. for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++) {
  1809. if (!write_file(files[i].name, files[i].data)) {
  1810. }
  1811. }
  1812. kill(cad_pid, SIGKILL);
  1813. while (waitpid(cad_pid, NULL, 0) != cad_pid)
  1814. ;
  1815. }
  1816.  
  1817. static void execute_one(void);
  1818.  
  1819. #define WAIT_FLAGS __WALL
  1820.  
  1821. static void loop(void)
  1822. {
  1823. int iter = 0;
  1824. for (;; iter++) {
  1825. char cwdbuf[32];
  1826. sprintf(cwdbuf, "./%d", iter);
  1827. if (mkdir(cwdbuf, 0777))
  1828. exit(1);
  1829. reset_loop();
  1830. int pid = fork();
  1831. if (pid < 0)
  1832. exit(1);
  1833. if (pid == 0) {
  1834. if (chdir(cwdbuf))
  1835. exit(1);
  1836. setup_test();
  1837. execute_one();
  1838. close_fds();
  1839. exit(0);
  1840. }
  1841. int status = 0;
  1842. uint64_t start = current_time_ms();
  1843. for (;;) {
  1844. sleep_ms(10);
  1845. if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
  1846. break;
  1847. if (current_time_ms() - start < 5000)
  1848. continue;
  1849. kill_and_wait(pid, &status);
  1850. break;
  1851. }
  1852. remove_dir(cwdbuf);
  1853. }
  1854. }
  1855.  
  1856. uint64_t r[1] = {0xffffffffffffffff};
  1857.  
  1858. void execute_one(void)
  1859. {
  1860. intptr_t res = 0;
  1861. if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
  1862. }
  1863. // perf_event_open arguments: [
  1864. // attr: ptr[in, perf_event_attr] {
  1865. // perf_event_attr {
  1866. // type: perf_event_type = 0x3 (4 bytes)
  1867. // size: len = 0x80 (4 bytes)
  1868. // config0: int8 = 0x0 (1 bytes)
  1869. // config1: int8 = 0x0 (1 bytes)
  1870. // config2: int8 = 0x0 (1 bytes)
  1871. // config3: int8 = 0x0 (1 bytes)
  1872. // config4: const = 0x0 (4 bytes)
  1873. // sample_freq: int64 = 0x5 (8 bytes)
  1874. // sample_type: perf_sample_type = 0x0 (8 bytes)
  1875. // read_format: perf_read_format = 0x0 (8 bytes)
  1876. // disabled: int64 = 0x0 (0 bytes)
  1877. // inherit: int64 = 0x0 (0 bytes)
  1878. // pinned: int64 = 0x0 (0 bytes)
  1879. // exclusive: int64 = 0x0 (0 bytes)
  1880. // exclude_user: int64 = 0x0 (0 bytes)
  1881. // exclude_kernel: int64 = 0x0 (0 bytes)
  1882. // exclude_hv: int64 = 0x0 (0 bytes)
  1883. // exclude_idle: int64 = 0x0 (0 bytes)
  1884. // mmap: int64 = 0x0 (0 bytes)
  1885. // comm: int64 = 0x0 (0 bytes)
  1886. // freq: int64 = 0x0 (0 bytes)
  1887. // inherit_stat: int64 = 0x0 (0 bytes)
  1888. // enable_on_exec: int64 = 0x0 (0 bytes)
  1889. // task: int64 = 0x0 (0 bytes)
  1890. // watermark: int64 = 0x0 (0 bytes)
  1891. // precise_ip: int64 = 0x0 (0 bytes)
  1892. // mmap_data: int64 = 0x0 (0 bytes)
  1893. // sample_id_all: int64 = 0x0 (0 bytes)
  1894. // exclude_host: int64 = 0x0 (0 bytes)
  1895. // exclude_guest: int64 = 0x0 (0 bytes)
  1896. // exclude_callchain_kernel: int64 = 0x0 (0 bytes)
  1897. // exclude_callchain_user: int64 = 0x0 (0 bytes)
  1898. // mmap2: int64 = 0x0 (0 bytes)
  1899. // comm_exec: int64 = 0x0 (0 bytes)
  1900. // use_clockid: int64 = 0x0 (0 bytes)
  1901. // context_switch: int64 = 0x0 (0 bytes)
  1902. // write_backward: int64 = 0x0 (0 bytes)
  1903. // namespaces: int64 = 0x0 (0 bytes)
  1904. // ksymbol: int64 = 0x0 (0 bytes)
  1905. // bpf_event: int64 = 0x0 (0 bytes)
  1906. // aux_output: int64 = 0x0 (0 bytes)
  1907. // cgroup: int64 = 0x0 (0 bytes)
  1908. // text_poke: int64 = 0x0 (0 bytes)
  1909. // build_id: int64 = 0x0 (0 bytes)
  1910. // inherit_thread: int64 = 0x0 (0 bytes)
  1911. // remove_on_exec: int64 = 0x0 (0 bytes)
  1912. // sigtrap: int64 = 0x0 (0 bytes)
  1913. // __reserved_1: const = 0x0 (8 bytes)
  1914. // wakeup_events: int32 = 0x0 (4 bytes)
  1915. // bp_type: perf_bp_type = 0x0 (4 bytes)
  1916. // bp_config: union perf_bp_config {
  1917. // perf_bp: perf_bp {
  1918. // bp_addr: nil
  1919. // bp_len: perf_bp_lens = 0x0 (8 bytes)
  1920. // }
  1921. // }
  1922. // branch_sample_type: perf_branch_sample_type = 0x0 (8 bytes)
  1923. // sample_regs_user: int64 = 0x0 (8 bytes)
  1924. // sample_stack_user: int32 = 0x0 (4 bytes)
  1925. // clockid: clock_type = 0x0 (4 bytes)
  1926. // sample_regs_intr: int64 = 0x0 (8 bytes)
  1927. // aux_watermark: int32 = 0x5 (4 bytes)
  1928. // sample_max_stack: int16 = 0x8 (2 bytes)
  1929. // __reserved_2: const = 0x0 (2 bytes)
  1930. // aux_sample_size: int32 = 0x0 (4 bytes)
  1931. // __reserved_3: const = 0x0 (4 bytes)
  1932. // sig_data: int64 = 0x0 (8 bytes)
  1933. // }
  1934. // }
  1935. // pid: pid (resource)
  1936. // cpu: intptr = 0xffffffffffffffff (8 bytes)
  1937. // group: fd_perf (resource)
  1938. // flags: perf_flags = 0x0 (8 bytes)
  1939. // ]
  1940. // returns fd_perf
  1941. *(uint32_t*)0x20000001d000 = 3;
  1942. *(uint32_t*)0x20000001d004 = 0x80;
  1943. *(uint8_t*)0x20000001d008 = 0;
  1944. *(uint8_t*)0x20000001d009 = 0;
  1945. *(uint8_t*)0x20000001d00a = 0;
  1946. *(uint8_t*)0x20000001d00b = 0;
  1947. *(uint32_t*)0x20000001d00c = 0;
  1948. *(uint64_t*)0x20000001d010 = 5;
  1949. *(uint64_t*)0x20000001d018 = 0;
  1950. *(uint64_t*)0x20000001d020 = 0;
  1951. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 0, 1);
  1952. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 1, 1);
  1953. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 2, 1);
  1954. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 3, 1);
  1955. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 4, 1);
  1956. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 5, 1);
  1957. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 6, 1);
  1958. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 7, 1);
  1959. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 8, 1);
  1960. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 9, 1);
  1961. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 10, 1);
  1962. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 11, 1);
  1963. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 12, 1);
  1964. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 13, 1);
  1965. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 14, 1);
  1966. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 15, 2);
  1967. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 17, 1);
  1968. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 18, 1);
  1969. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 19, 1);
  1970. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 20, 1);
  1971. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 21, 1);
  1972. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 22, 1);
  1973. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 23, 1);
  1974. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 24, 1);
  1975. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 25, 1);
  1976. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 26, 1);
  1977. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 27, 1);
  1978. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 28, 1);
  1979. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 29, 1);
  1980. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 30, 1);
  1981. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 31, 1);
  1982. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 32, 1);
  1983. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 33, 1);
  1984. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 34, 1);
  1985. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 35, 1);
  1986. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 36, 1);
  1987. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 37, 1);
  1988. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 38, 26);
  1989. *(uint32_t*)0x20000001d030 = 0;
  1990. *(uint32_t*)0x20000001d034 = 0;
  1991. *(uint64_t*)0x20000001d038 = 0;
  1992. *(uint64_t*)0x20000001d040 = 0;
  1993. *(uint64_t*)0x20000001d048 = 0;
  1994. *(uint64_t*)0x20000001d050 = 0;
  1995. *(uint32_t*)0x20000001d058 = 0;
  1996. *(uint32_t*)0x20000001d05c = 0;
  1997. *(uint64_t*)0x20000001d060 = 0;
  1998. *(uint32_t*)0x20000001d068 = 5;
  1999. *(uint16_t*)0x20000001d06c = 8;
  2000. *(uint16_t*)0x20000001d06e = 0;
  2001. *(uint32_t*)0x20000001d070 = 0;
  2002. *(uint32_t*)0x20000001d074 = 0;
  2003. *(uint64_t*)0x20000001d078 = 0;
  2004. res = syscall(__NR_perf_event_open, /*attr=*/0x20000001d000ul, /*pid=*/0,
  2005. /*cpu=*/(intptr_t)-1, /*group=*/(intptr_t)-1, /*flags=*/0ul);
  2006. if (res != -1)
  2007. r[0] = res;
  2008. // connect$inet6 arguments: [
  2009. // fd: sock_in6 (resource)
  2010. // addr: nil
  2011. // addrlen: len = 0x0 (8 bytes)
  2012. // ]
  2013. syscall(__NR_connect, /*fd=*/(intptr_t)-1, /*addr=*/0ul, /*addrlen=*/0ul);
  2014. // perf_event_open arguments: [
  2015. // attr: ptr[in, perf_event_attr] {
  2016. // perf_event_attr {
  2017. // type: perf_event_type = 0x3 (4 bytes)
  2018. // size: len = 0x80 (4 bytes)
  2019. // config0: int8 = 0x0 (1 bytes)
  2020. // config1: int8 = 0x0 (1 bytes)
  2021. // config2: int8 = 0x0 (1 bytes)
  2022. // config3: int8 = 0x0 (1 bytes)
  2023. // config4: const = 0x0 (4 bytes)
  2024. // sample_freq: int64 = 0x588 (8 bytes)
  2025. // sample_type: perf_sample_type = 0x0 (8 bytes)
  2026. // read_format: perf_read_format = 0x0 (8 bytes)
  2027. // disabled: int64 = 0x0 (0 bytes)
  2028. // inherit: int64 = 0x0 (0 bytes)
  2029. // pinned: int64 = 0x0 (0 bytes)
  2030. // exclusive: int64 = 0x0 (0 bytes)
  2031. // exclude_user: int64 = 0x0 (0 bytes)
  2032. // exclude_kernel: int64 = 0x0 (0 bytes)
  2033. // exclude_hv: int64 = 0x0 (0 bytes)
  2034. // exclude_idle: int64 = 0x0 (0 bytes)
  2035. // mmap: int64 = 0x0 (0 bytes)
  2036. // comm: int64 = 0x0 (0 bytes)
  2037. // freq: int64 = 0x0 (0 bytes)
  2038. // inherit_stat: int64 = 0x0 (0 bytes)
  2039. // enable_on_exec: int64 = 0x0 (0 bytes)
  2040. // task: int64 = 0x0 (0 bytes)
  2041. // watermark: int64 = 0x0 (0 bytes)
  2042. // precise_ip: int64 = 0x0 (0 bytes)
  2043. // mmap_data: int64 = 0x0 (0 bytes)
  2044. // sample_id_all: int64 = 0x0 (0 bytes)
  2045. // exclude_host: int64 = 0x0 (0 bytes)
  2046. // exclude_guest: int64 = 0x0 (0 bytes)
  2047. // exclude_callchain_kernel: int64 = 0x0 (0 bytes)
  2048. // exclude_callchain_user: int64 = 0x0 (0 bytes)
  2049. // mmap2: int64 = 0x0 (0 bytes)
  2050. // comm_exec: int64 = 0x0 (0 bytes)
  2051. // use_clockid: int64 = 0x0 (0 bytes)
  2052. // context_switch: int64 = 0x0 (0 bytes)
  2053. // write_backward: int64 = 0x0 (0 bytes)
  2054. // namespaces: int64 = 0x0 (0 bytes)
  2055. // ksymbol: int64 = 0x0 (0 bytes)
  2056. // bpf_event: int64 = 0x0 (0 bytes)
  2057. // aux_output: int64 = 0x0 (0 bytes)
  2058. // cgroup: int64 = 0x0 (0 bytes)
  2059. // text_poke: int64 = 0x0 (0 bytes)
  2060. // build_id: int64 = 0x0 (0 bytes)
  2061. // inherit_thread: int64 = 0x0 (0 bytes)
  2062. // remove_on_exec: int64 = 0x0 (0 bytes)
  2063. // sigtrap: int64 = 0x0 (0 bytes)
  2064. // __reserved_1: const = 0x0 (8 bytes)
  2065. // wakeup_events: int32 = 0x0 (4 bytes)
  2066. // bp_type: perf_bp_type = 0x0 (4 bytes)
  2067. // bp_config: union perf_bp_config {
  2068. // perf_bp: perf_bp {
  2069. // bp_addr: nil
  2070. // bp_len: perf_bp_lens = 0x0 (8 bytes)
  2071. // }
  2072. // }
  2073. // branch_sample_type: perf_branch_sample_type = 0x0 (8 bytes)
  2074. // sample_regs_user: int64 = 0x36 (8 bytes)
  2075. // sample_stack_user: int32 = 0x0 (4 bytes)
  2076. // clockid: clock_type = 0x0 (4 bytes)
  2077. // sample_regs_intr: int64 = 0x0 (8 bytes)
  2078. // aux_watermark: int32 = 0x5 (4 bytes)
  2079. // sample_max_stack: int16 = 0x8 (2 bytes)
  2080. // __reserved_2: const = 0x0 (2 bytes)
  2081. // aux_sample_size: int32 = 0x0 (4 bytes)
  2082. // __reserved_3: const = 0x0 (4 bytes)
  2083. // sig_data: int64 = 0x0 (8 bytes)
  2084. // }
  2085. // }
  2086. // pid: pid (resource)
  2087. // cpu: intptr = 0xffffffffffffffff (8 bytes)
  2088. // group: fd_perf (resource)
  2089. // flags: perf_flags = 0x0 (8 bytes)
  2090. // ]
  2091. // returns fd_perf
  2092. *(uint32_t*)0x20000001d000 = 3;
  2093. *(uint32_t*)0x20000001d004 = 0x80;
  2094. *(uint8_t*)0x20000001d008 = 0;
  2095. *(uint8_t*)0x20000001d009 = 0;
  2096. *(uint8_t*)0x20000001d00a = 0;
  2097. *(uint8_t*)0x20000001d00b = 0;
  2098. *(uint32_t*)0x20000001d00c = 0;
  2099. *(uint64_t*)0x20000001d010 = 0x588;
  2100. *(uint64_t*)0x20000001d018 = 0;
  2101. *(uint64_t*)0x20000001d020 = 0;
  2102. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 0, 1);
  2103. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 1, 1);
  2104. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 2, 1);
  2105. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 3, 1);
  2106. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 4, 1);
  2107. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 5, 1);
  2108. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 6, 1);
  2109. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 7, 1);
  2110. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 8, 1);
  2111. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 9, 1);
  2112. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 10, 1);
  2113. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 11, 1);
  2114. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 12, 1);
  2115. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 13, 1);
  2116. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 14, 1);
  2117. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 15, 2);
  2118. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 17, 1);
  2119. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 18, 1);
  2120. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 19, 1);
  2121. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 20, 1);
  2122. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 21, 1);
  2123. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 22, 1);
  2124. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 23, 1);
  2125. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 24, 1);
  2126. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 25, 1);
  2127. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 26, 1);
  2128. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 27, 1);
  2129. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 28, 1);
  2130. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 29, 1);
  2131. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 30, 1);
  2132. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 31, 1);
  2133. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 32, 1);
  2134. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 33, 1);
  2135. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 34, 1);
  2136. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 35, 1);
  2137. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 36, 1);
  2138. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 37, 1);
  2139. STORE_BY_BITMASK(uint64_t, , 0x20000001d028, 0, 38, 26);
  2140. *(uint32_t*)0x20000001d030 = 0;
  2141. *(uint32_t*)0x20000001d034 = 0;
  2142. *(uint64_t*)0x20000001d038 = 0;
  2143. *(uint64_t*)0x20000001d040 = 0;
  2144. *(uint64_t*)0x20000001d048 = 0;
  2145. *(uint64_t*)0x20000001d050 = 0x36;
  2146. *(uint32_t*)0x20000001d058 = 0;
  2147. *(uint32_t*)0x20000001d05c = 0;
  2148. *(uint64_t*)0x20000001d060 = 0;
  2149. *(uint32_t*)0x20000001d068 = 5;
  2150. *(uint16_t*)0x20000001d06c = 8;
  2151. *(uint16_t*)0x20000001d06e = 0;
  2152. *(uint32_t*)0x20000001d070 = 0;
  2153. *(uint32_t*)0x20000001d074 = 0;
  2154. *(uint64_t*)0x20000001d078 = 0;
  2155. syscall(__NR_perf_event_open, /*attr=*/0x20000001d000ul, /*pid=*/0,
  2156. /*cpu=*/(intptr_t)-1, /*group=*/(intptr_t)-1, /*flags=*/0ul);
  2157. // ioctl$sock_SIOCETHTOOL arguments: [
  2158. // fd: sock (resource)
  2159. // cmd: const = 0x8946 (4 bytes)
  2160. // arg: nil
  2161. // ]
  2162. syscall(__NR_ioctl, /*fd=*/(intptr_t)-1, /*cmd=*/0x8946, /*arg=*/0ul);
  2163. // ioctl$int_in arguments: [
  2164. // fd: fd (resource)
  2165. // cmd: ioctl_int_in = 0x5452 (4 bytes)
  2166. // v: ptr[in, int64] {
  2167. // int64 = 0x1ff (8 bytes)
  2168. // }
  2169. // ]
  2170. *(uint64_t*)0x200000000200 = 0x1ff;
  2171. syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=FIOASYNC*/ 0x5452,
  2172. /*v=*/0x200000000200ul);
  2173. // sendmsg$nl_route_sched_retired arguments: [
  2174. // fd: sock_nl_route (resource)
  2175. // msg: nil
  2176. // f: send_flags = 0x0 (8 bytes)
  2177. // ]
  2178. syscall(__NR_sendmsg, /*fd=*/(intptr_t)-1, /*msg=*/0ul, /*f=*/0ul);
  2179. // syz_mount_image$ext4 arguments: [
  2180. // fs: ptr[in, buffer] {
  2181. // buffer: {65 78 74 34 00} (length 0x5)
  2182. // }
  2183. // dir: ptr[in, buffer] {
  2184. // buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
  2185. // }
  2186. // flags: mount_flags = 0x200008 (8 bytes)
  2187. // opts: ptr[in, fs_options[ext4_options]] {
  2188. // fs_options[ext4_options] {
  2189. // elems: array[fs_opt_elem[ext4_options]] {
  2190. // fs_opt_elem[ext4_options] {
  2191. // elem: union ext4_options {
  2192. // auto_da_alloc: buffer: {61 75 74 6f 5f 64 61 5f 61 6c 6c 6f
  2193. // 63} (length 0xd)
  2194. // }
  2195. // comma: const = 0x2c (1 bytes)
  2196. // }
  2197. // fs_opt_elem[ext4_options] {
  2198. // elem: union ext4_options {
  2199. // max_dir_size_kb: fs_opt["max_dir_size_kb", fmt[hex, int32]] {
  2200. // name: buffer: {6d 61 78 5f 64 69 72 5f 73 69 7a 65 5f 6b 62}
  2201. // (length 0xf) eq: const = 0x3d (1 bytes) val: int32 = 0x8000
  2202. // (18 bytes)
  2203. // }
  2204. // }
  2205. // comma: const = 0x2c (1 bytes)
  2206. // }
  2207. // fs_opt_elem[ext4_options] {
  2208. // elem: union ext4_options {
  2209. // noacl: buffer: {6e 6f 61 63 6c} (length 0x5)
  2210. // }
  2211. // comma: const = 0x2c (1 bytes)
  2212. // }
  2213. // }
  2214. // common: array[fs_opt_elem[fs_options_common]] {
  2215. // }
  2216. // null: const = 0x0 (1 bytes)
  2217. // }
  2218. // }
  2219. // chdir: int8 = 0x4 (1 bytes)
  2220. // size: len = 0x4ee (8 bytes)
  2221. // img: ptr[in, buffer] {
  2222. // buffer: (compressed buffer with length 0x4ee)
  2223. // }
  2224. // ]
  2225. // returns fd_dir
  2226. memcpy((void*)0x2000000005c0, "ext4\000", 5);
  2227. memcpy((void*)0x200000000000, "./file0\000", 8);
  2228. memcpy((void*)0x200000000140, "auto_da_alloc", 13);
  2229. *(uint8_t*)0x20000000014d = 0x2c;
  2230. memcpy((void*)0x20000000014e, "max_dir_size_kb", 15);
  2231. *(uint8_t*)0x20000000015d = 0x3d;
  2232. sprintf((char*)0x20000000015e, "0x%016llx", (long long)0x8000);
  2233. *(uint8_t*)0x200000000170 = 0x2c;
  2234. memcpy((void*)0x200000000171, "noacl", 5);
  2235. *(uint8_t*)0x200000000176 = 0x2c;
  2236. *(uint8_t*)0x200000000177 = 0;
  2237. memcpy(
  2238. (void*)0x200000000600,
  2239. "\x78\x9c\xec\xdd\xcf\x6f\x1c\x57\x1d\x00\xf0\xef\x8c\x7f\xad\x5d\xb7\x76"
  2240. "\x4b\x0f\x80\x80\x86\x52\x1a\x50\x94\xb5\xbd\x69\xad\xaa\x07\x68\x4e\x08"
  2241. "\xa1\x4a\x88\x1e\x41\x4a\x8c\xbd\xb1\x2c\xef\x7a\x2d\xef\x3a\xc4\x26\x07"
  2242. "\xe7\x7f\x40\x22\x12\x27\x38\xf2\x07\x70\xce\x89\x3b\x17\x04\x37\x2e\xe1"
  2243. "\x80\x14\xc0\x02\xc5\x91\x38\x2c\xda\xd9\xb1\x63\x6c\xaf\x6d\xfc\x63\x37"
  2244. "\xf5\x7e\x3e\xd2\x68\xde\x9b\x37\x99\xef\x7b\x59\xcd\x3c\xef\x57\xf6\xbc"
  2245. "\x00\xfa\xd6\xb5\x88\xd8\x8a\x88\xe1\x88\xb8\x1b\x11\x13\xf9\xf1\x24\xdf"
  2246. "\xe2\x93\xf6\xd6\x3a\xef\xf9\xf6\xc3\xf9\x9d\xed\x87\xf3\x49\x34\x9b\x9f"
  2247. "\xfd\x23\xc9\xda\x9f\x0f\xbc\xbc\x56\x92\xef\x5f\xcb\xaf\x59\x88\x88\x1f"
  2248. "\x7d\x2f\xe2\xa7\xc9\xe1\xb8\xf5\x8d\xcd\xe5\xb9\x4a\xa5\xbc\x96\xd7\xa7"
  2249. "\x1a\xd5\xd5\xa9\xfa\xc6\xe6\xcd\xa5\xea\xdc\x62\x79\xb1\xbc\x52\x2a\xcd"
  2250. "\xce\xcc\x4e\x7f\x74\xeb\xc3\xd2\x85\x8d\xf5\x9d\xea\x70\x5e\xfa\xea\xd3"
  2251. "\x3f\x6c\x7d\xfb\xe7\xad\x6e\x8d\xe7\x47\x5a\x63\xbb\xb0\x40\xfb\xb4\x87"
  2252. "\x3e\xb4\x17\xa7\x65\x30\x22\x7e\x70\x19\xc1\x7a\x60\x20\x1f\xcf\x70\xaf"
  2253. "\x3b\xc2\x99\xa4\x11\xf1\x56\x44\xbc\x9b\xdd\xff\x13\x31\x90\x7d\x9a\x00"
  2254. "\xc0\x55\xd6\x6c\x4e\x44\x73\x62\x7f\x1d\x00\xb8\xea\xd2\x2c\x07\x96\xa4"
  2255. "\xc5\x3c\x17\x30\x1e\x69\x5a\x2c\xb6\x73\x78\x6f\xc7\x58\x5a\xa9\xd5\x1b"
  2256. "\x37\xee\xd5\xd6\x57\x16\xda\xb9\xb2\xc9\x18\x4a\xef\x2d\x55\xca\xd3\x79"
  2257. "\xae\x70\x32\x86\x92\x56\x7d\x26\x2b\xbf\xac\x97\x0e\xd4\x6f\x45\xc4\x9b"
  2258. "\x11\xf1\x8b\x91\xd1\xac\x5e\x9c\xaf\x55\x16\x7a\xf9\x83\x0f\x00\xf4\xb1"
  2259. "\xd7\x0e\xcc\xff\xff\x1e\x69\xcf\xff\x00\xc0\x15\x57\xe8\x75\x07\x00\x80"
  2260. "\xae\x33\xff\x03\x40\xff\x31\xff\x03\x40\xff\x31\xff\x03\x40\xff\x31\xff"
  2261. "\x03\x40\xff\x31\xff\x03\x40\xff\x39\x76\xfe\x7f\x7f\xa0\x7b\x1d\x01\x00"
  2262. "\xba\xe1\x87\x9f\x7e\xda\xda\x9a\x3b\xf9\xfb\xaf\x17\xee\x6f\xac\x2f\xd7"
  2263. "\xee\xdf\x5c\x28\xd7\x97\x8b\xd5\xf5\xf9\xe2\x7c\x6d\x6d\xb5\xb8\x58\xab"
  2264. "\x2d\x66\xef\xec\xa9\x9e\x74\xbd\x4a\xad\xb6\x3a\xf3\x41\xac\x3f\x98\xfc"
  2265. "\xce\x6a\xbd\x31\x55\xdf\xd8\xbc\x53\xad\xad\xaf\x34\xee\x64\xef\xf5\xbe"
  2266. "\x53\x1e\xea\xca\xa8\x00\x80\xe3\xbc\xf9\xce\x93\x3f\x27\x11\xb1\xf5\xf1"
  2267. "\x68\xb6\xc5\xbe\xb5\x1c\xcc\xd5\x70\xb5\xa5\xbd\xee\x00\xd0\x33\x92\xfb"
  2268. "\xd0\xbf\xce\xb2\xda\xd7\x11\xcb\xf9\x01\x9f\x43\xe7\xf8\x8e\x2f\x3d\x00"
  2269. "\x57\x44\x32\x7a\x7c\x7b\x21\x22\x0e\x9d\xd2\x6c\x36\x9b\x97\xd8\x27\xe0"
  2270. "\x72\x5d\xff\x92\xfc\x3f\xf4\x2b\xf9\x7f\xe8\x5f\xf2\xff\xd0\xbf\xce\x92"
  2271. "\xff\x07\xae\x86\x66\x33\x39\xed\x9a\xff\x71\xda\x13\x01\x80\x57\x9b\x1c"
  2272. "\x3f\xd0\xe1\x77\xfa\xde\xca\xf7\xbf\xcd\x5f\x11\xf2\x93\x85\x83\x67\x3c"
  2273. "\xbe\xcc\x5e\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2274. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc0\xab\x6d\x77\xfd\xdf\x62\xbe\x16"
  2275. "\xf8\x78\xa4\x69\xb1\x18\xf1\x7a\x44\x4c\xc6\x50\x72\x6f\xa9\x52\x9e\x8e"
  2276. "\x88\x37\x22\xe2\x4f\x23\x43\x23\xad\xfa\x4c\x8f\xfb\x0c\x00\x9c\x57\xfa"
  2277. "\xb7\x24\x5f\xff\xeb\xfa\xc4\x7b\xe3\x07\x5b\x87\x93\x17\x23\xd9\x3e\x22"
  2278. "\x7e\xf6\xab\xcf\x7e\xf9\x60\xae\xd1\x58\xfb\x63\xeb\xf8\x3f\xf7\x8e\x37"
  2279. "\x1e\xe7\xc7\x4b\xbd\xe8\x3f\x00\x70\x92\xdd\x79\x3a\xdb\xef\xfb\x22\xff"
  2280. "\x7c\xfb\xe1\xfc\xee\xd6\xcd\xfe\x3c\xbb\x9d\x46\x14\xda\xf1\x77\xb6\x87"
  2281. "\x63\x67\x2f\xfe\x60\x0c\x66\xfb\x42\x0c\x45\xc4\xd8\xbf\x92\xbc\xde\x96"
  2282. "\xec\xcb\x5d\x9c\xc7\xd6\xa3\x88\xf8\xe2\x51\xe3\x4f\x62\x3c\xcb\x81\xb4"
  2283. "\x57\x3e\x3d\x18\xbf\x15\xfb\xf5\xae\xc6\x4f\xff\x27\x7e\x9a\xb5\xb5\xf7"
  2284. "\xad\xff\x8b\x2f\x5c\x40\x5f\xa0\xdf\x3c\xb9\x1d\x11\x9f\x1c\x75\xff\xa5"
  2285. "\x71\x2d\xdb\x1f\x7d\xff\x17\xb2\x27\xd4\xf9\x3d\xbb\x9d\x5d\xac\x75\xa9"
  2286. "\xf9\x9d\xec\x19\xf8\x32\xfe\xee\xf3\x6f\xa0\xc3\xf3\xef\xda\x69\x63\x7c"
  2287. "\xf0\xfb\xef\xb7\x4b\xa3\x87\xdb\x1e\x45\x7c\x79\x30\x62\x37\xf6\xce\xbe"
  2288. "\xe7\xcf\x6e\xfc\xa4\x43\xfc\xf7\x4e\x19\xff\x2f\x5f\xf9\xda\xbb\x9d\xda"
  2289. "\x9a\xbf\x8e\xb8\x1e\x47\xc7\xdf\x1f\x6b\xaa\x51\x5d\x9d\xaa\x6f\x6c\xde"
  2290. "\x5c\xaa\xce\x2d\x96\x17\xcb\x2b\xa5\xd2\xec\xcc\xec\xf4\x47\xb7\x3e\x2c"
  2291. "\x4d\x65\x39\xea\xa9\xce\xb3\xc1\xdf\x3f\xbe\xf1\x46\xa7\xb6\xd6\xf8\xc7"
  2292. "\x3a\xc4\x2f\x9c\x30\xfe\x6f\x9e\x72\xfc\xbf\xf9\xcf\xdd\x1f\x7f\xfd\x98"
  2293. "\xf8\xdf\xfa\xc6\x51\xf1\xd3\x78\xfb\x98\xf8\xad\x39\xf1\xfd\x53\xc6\x9f"
  2294. "\x1b\xfb\x5d\xa1\x53\x5b\x2b\xfe\x42\x87\xf1\x9f\xf4\xf9\xdf\x38\x65\xfc"
  2295. "\xa7\x7f\xdd\x3c\xb4\x6c\x38\x00\xd0\x3b\xf5\x8d\xcd\xe5\xb9\x4a\xa5\xbc"
  2296. "\xa6\xa0\xa0\x70\x9e\xc2\x77\xbb\x15\x6b\x38\xfe\xaf\x7f\xd5\x6c\x9e\x29"
  2297. "\x56\xa7\x27\xc6\x45\x64\xdd\x80\x57\xc1\xde\x4d\x1f\x11\x2f\x7a\xdd\x19"
  2298. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\x48\xdd\xf8\x8b\xa5\x5e"
  2299. "\x8f\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2300. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2301. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2302. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2303. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2304. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2305. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2306. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2307. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2308. "\x00\x00\x00\x00\x00\x00\x00\x80\xab\xeb\xbf\x01\x00\x00\xff\xff\xb2\x73"
  2309. "\xd2\x3c",
  2310. 1262);
  2311. syz_mount_image(/*fs=*/0x2000000005c0, /*dir=*/0x200000000000,
  2312. /*flags=MS_RELATIME|MS_NOEXEC*/ 0x200008,
  2313. /*opts=*/0x200000000140, /*chdir=*/4, /*size=*/0x4ee,
  2314. /*img=*/0x200000000600);
  2315. }
  2316. int main(void)
  2317. {
  2318. syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  2319. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  2320. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  2321. syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul,
  2322. /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
  2323. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  2324. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  2325. syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  2326. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  2327. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  2328. setup_sysctl();
  2329. const char* reason;
  2330. (void)reason;
  2331. for (procid = 0; procid < 4; procid++) {
  2332. if (fork() == 0) {
  2333. use_temporary_dir();
  2334. do_sandbox_none();
  2335. }
  2336. }
  2337. sleep(1000000);
  2338. return 0;
  2339. }
  2340.  
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment