Tang-ZW

Untitled

Feb 5th, 2026
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 63.79 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 <signal.h>
  15. #include <stdarg.h>
  16. #include <stdbool.h>
  17. #include <stdint.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <sys/ioctl.h>
  22. #include <sys/mount.h>
  23. #include <sys/prctl.h>
  24. #include <sys/resource.h>
  25. #include <sys/socket.h>
  26. #include <sys/stat.h>
  27. #include <sys/swap.h>
  28. #include <sys/syscall.h>
  29. #include <sys/time.h>
  30. #include <sys/types.h>
  31. #include <sys/uio.h>
  32. #include <sys/wait.h>
  33. #include <time.h>
  34. #include <unistd.h>
  35.  
  36. #include <linux/capability.h>
  37. #include <linux/falloc.h>
  38. #include <linux/genetlink.h>
  39. #include <linux/if_addr.h>
  40. #include <linux/if_ether.h>
  41. #include <linux/if_link.h>
  42. #include <linux/if_tun.h>
  43. #include <linux/in6.h>
  44. #include <linux/ip.h>
  45. #include <linux/neighbour.h>
  46. #include <linux/net.h>
  47. #include <linux/netlink.h>
  48. #include <linux/rtnetlink.h>
  49. #include <linux/tcp.h>
  50. #include <linux/veth.h>
  51.  
  52. static unsigned long long procid;
  53.  
  54. static void sleep_ms(uint64_t ms)
  55. {
  56. usleep(ms * 1000);
  57. }
  58.  
  59. static uint64_t current_time_ms(void)
  60. {
  61. struct timespec ts;
  62. if (clock_gettime(CLOCK_MONOTONIC, &ts))
  63. exit(1);
  64. return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
  65. }
  66.  
  67. static void use_temporary_dir(void)
  68. {
  69. char tmpdir_template[] = "./syzkaller.XXXXXX";
  70. char* tmpdir = mkdtemp(tmpdir_template);
  71. if (!tmpdir)
  72. exit(1);
  73. if (chmod(tmpdir, 0777))
  74. exit(1);
  75. if (chdir(tmpdir))
  76. exit(1);
  77. }
  78.  
  79. #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
  80. #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \
  81. *(type*)(addr) = \
  82. htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \
  83. (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))
  84.  
  85. static bool write_file(const char* file, const char* what, ...)
  86. {
  87. char buf[1024];
  88. va_list args;
  89. va_start(args, what);
  90. vsnprintf(buf, sizeof(buf), what, args);
  91. va_end(args);
  92. buf[sizeof(buf) - 1] = 0;
  93. int len = strlen(buf);
  94. int fd = open(file, O_WRONLY | O_CLOEXEC);
  95. if (fd == -1)
  96. return false;
  97. if (write(fd, buf, len) != len) {
  98. int err = errno;
  99. close(fd);
  100. errno = err;
  101. return false;
  102. }
  103. close(fd);
  104. return true;
  105. }
  106.  
  107. struct nlmsg {
  108. char* pos;
  109. int nesting;
  110. struct nlattr* nested[8];
  111. char buf[4096];
  112. };
  113.  
  114. static void netlink_init(struct nlmsg* nlmsg, int typ, int flags,
  115. const void* data, int size)
  116. {
  117. memset(nlmsg, 0, sizeof(*nlmsg));
  118. struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
  119. hdr->nlmsg_type = typ;
  120. hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags;
  121. memcpy(hdr + 1, data, size);
  122. nlmsg->pos = (char*)(hdr + 1) + NLMSG_ALIGN(size);
  123. }
  124.  
  125. static void netlink_attr(struct nlmsg* nlmsg, int typ, const void* data,
  126. int size)
  127. {
  128. struct nlattr* attr = (struct nlattr*)nlmsg->pos;
  129. attr->nla_len = sizeof(*attr) + size;
  130. attr->nla_type = typ;
  131. if (size > 0)
  132. memcpy(attr + 1, data, size);
  133. nlmsg->pos += NLMSG_ALIGN(attr->nla_len);
  134. }
  135.  
  136. static void netlink_nest(struct nlmsg* nlmsg, int typ)
  137. {
  138. struct nlattr* attr = (struct nlattr*)nlmsg->pos;
  139. attr->nla_type = typ;
  140. nlmsg->pos += sizeof(*attr);
  141. nlmsg->nested[nlmsg->nesting++] = attr;
  142. }
  143.  
  144. static void netlink_done(struct nlmsg* nlmsg)
  145. {
  146. struct nlattr* attr = nlmsg->nested[--nlmsg->nesting];
  147. attr->nla_len = nlmsg->pos - (char*)attr;
  148. }
  149.  
  150. static int netlink_send_ext(struct nlmsg* nlmsg, int sock, uint16_t reply_type,
  151. int* reply_len, bool dofail)
  152. {
  153. if (nlmsg->pos > nlmsg->buf + sizeof(nlmsg->buf) || nlmsg->nesting)
  154. exit(1);
  155. struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
  156. hdr->nlmsg_len = nlmsg->pos - nlmsg->buf;
  157. struct sockaddr_nl addr;
  158. memset(&addr, 0, sizeof(addr));
  159. addr.nl_family = AF_NETLINK;
  160. ssize_t n = sendto(sock, nlmsg->buf, hdr->nlmsg_len, 0,
  161. (struct sockaddr*)&addr, sizeof(addr));
  162. if (n != (ssize_t)hdr->nlmsg_len) {
  163. if (dofail)
  164. exit(1);
  165. return -1;
  166. }
  167. n = recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0);
  168. if (reply_len)
  169. *reply_len = 0;
  170. if (n < 0) {
  171. if (dofail)
  172. exit(1);
  173. return -1;
  174. }
  175. if (n < (ssize_t)sizeof(struct nlmsghdr)) {
  176. errno = EINVAL;
  177. if (dofail)
  178. exit(1);
  179. return -1;
  180. }
  181. if (hdr->nlmsg_type == NLMSG_DONE)
  182. return 0;
  183. if (reply_len && hdr->nlmsg_type == reply_type) {
  184. *reply_len = n;
  185. return 0;
  186. }
  187. if (n < (ssize_t)(sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))) {
  188. errno = EINVAL;
  189. if (dofail)
  190. exit(1);
  191. return -1;
  192. }
  193. if (hdr->nlmsg_type != NLMSG_ERROR) {
  194. errno = EINVAL;
  195. if (dofail)
  196. exit(1);
  197. return -1;
  198. }
  199. errno = -((struct nlmsgerr*)(hdr + 1))->error;
  200. return -errno;
  201. }
  202.  
  203. static int netlink_send(struct nlmsg* nlmsg, int sock)
  204. {
  205. return netlink_send_ext(nlmsg, sock, 0, NULL, true);
  206. }
  207.  
  208. static int netlink_query_family_id(struct nlmsg* nlmsg, int sock,
  209. const char* family_name, bool dofail)
  210. {
  211. struct genlmsghdr genlhdr;
  212. memset(&genlhdr, 0, sizeof(genlhdr));
  213. genlhdr.cmd = CTRL_CMD_GETFAMILY;
  214. netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr));
  215. netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, family_name,
  216. strnlen(family_name, GENL_NAMSIZ - 1) + 1);
  217. int n = 0;
  218. int err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n, dofail);
  219. if (err < 0) {
  220. return -1;
  221. }
  222. uint16_t id = 0;
  223. struct nlattr* attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN +
  224. NLMSG_ALIGN(sizeof(genlhdr)));
  225. for (; (char*)attr < nlmsg->buf + n;
  226. attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
  227. if (attr->nla_type == CTRL_ATTR_FAMILY_ID) {
  228. id = *(uint16_t*)(attr + 1);
  229. break;
  230. }
  231. }
  232. if (!id) {
  233. errno = EINVAL;
  234. return -1;
  235. }
  236. recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0);
  237. return id;
  238. }
  239.  
  240. static int netlink_next_msg(struct nlmsg* nlmsg, unsigned int offset,
  241. unsigned int total_len)
  242. {
  243. struct nlmsghdr* hdr = (struct nlmsghdr*)(nlmsg->buf + offset);
  244. if (offset == total_len || offset + hdr->nlmsg_len > total_len)
  245. return -1;
  246. return hdr->nlmsg_len;
  247. }
  248.  
  249. static void netlink_add_device_impl(struct nlmsg* nlmsg, const char* type,
  250. const char* name, bool up)
  251. {
  252. struct ifinfomsg hdr;
  253. memset(&hdr, 0, sizeof(hdr));
  254. if (up)
  255. hdr.ifi_flags = hdr.ifi_change = IFF_UP;
  256. netlink_init(nlmsg, RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr,
  257. sizeof(hdr));
  258. if (name)
  259. netlink_attr(nlmsg, IFLA_IFNAME, name, strlen(name));
  260. netlink_nest(nlmsg, IFLA_LINKINFO);
  261. netlink_attr(nlmsg, IFLA_INFO_KIND, type, strlen(type));
  262. }
  263.  
  264. static void netlink_add_device(struct nlmsg* nlmsg, int sock, const char* type,
  265. const char* name)
  266. {
  267. netlink_add_device_impl(nlmsg, type, name, false);
  268. netlink_done(nlmsg);
  269. int err = netlink_send(nlmsg, sock);
  270. if (err < 0) {
  271. }
  272. }
  273.  
  274. static void netlink_add_veth(struct nlmsg* nlmsg, int sock, const char* name,
  275. const char* peer)
  276. {
  277. netlink_add_device_impl(nlmsg, "veth", name, false);
  278. netlink_nest(nlmsg, IFLA_INFO_DATA);
  279. netlink_nest(nlmsg, VETH_INFO_PEER);
  280. nlmsg->pos += sizeof(struct ifinfomsg);
  281. netlink_attr(nlmsg, IFLA_IFNAME, peer, strlen(peer));
  282. netlink_done(nlmsg);
  283. netlink_done(nlmsg);
  284. netlink_done(nlmsg);
  285. int err = netlink_send(nlmsg, sock);
  286. if (err < 0) {
  287. }
  288. }
  289.  
  290. static void netlink_add_xfrm(struct nlmsg* nlmsg, int sock, const char* name)
  291. {
  292. netlink_add_device_impl(nlmsg, "xfrm", name, true);
  293. netlink_nest(nlmsg, IFLA_INFO_DATA);
  294. int if_id = 1;
  295. netlink_attr(nlmsg, 2, &if_id, sizeof(if_id));
  296. netlink_done(nlmsg);
  297. netlink_done(nlmsg);
  298. int err = netlink_send(nlmsg, sock);
  299. if (err < 0) {
  300. }
  301. }
  302.  
  303. static void netlink_add_hsr(struct nlmsg* nlmsg, int sock, const char* name,
  304. const char* slave1, const char* slave2)
  305. {
  306. netlink_add_device_impl(nlmsg, "hsr", name, false);
  307. netlink_nest(nlmsg, IFLA_INFO_DATA);
  308. int ifindex1 = if_nametoindex(slave1);
  309. netlink_attr(nlmsg, IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1));
  310. int ifindex2 = if_nametoindex(slave2);
  311. netlink_attr(nlmsg, IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2));
  312. netlink_done(nlmsg);
  313. netlink_done(nlmsg);
  314. int err = netlink_send(nlmsg, sock);
  315. if (err < 0) {
  316. }
  317. }
  318.  
  319. static void netlink_add_linked(struct nlmsg* nlmsg, int sock, const char* type,
  320. const char* name, const char* link)
  321. {
  322. netlink_add_device_impl(nlmsg, type, name, false);
  323. netlink_done(nlmsg);
  324. int ifindex = if_nametoindex(link);
  325. netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
  326. int err = netlink_send(nlmsg, sock);
  327. if (err < 0) {
  328. }
  329. }
  330.  
  331. static void netlink_add_vlan(struct nlmsg* nlmsg, int sock, const char* name,
  332. const char* link, uint16_t id, uint16_t proto)
  333. {
  334. netlink_add_device_impl(nlmsg, "vlan", name, false);
  335. netlink_nest(nlmsg, IFLA_INFO_DATA);
  336. netlink_attr(nlmsg, IFLA_VLAN_ID, &id, sizeof(id));
  337. netlink_attr(nlmsg, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto));
  338. netlink_done(nlmsg);
  339. netlink_done(nlmsg);
  340. int ifindex = if_nametoindex(link);
  341. netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
  342. int err = netlink_send(nlmsg, sock);
  343. if (err < 0) {
  344. }
  345. }
  346.  
  347. static void netlink_add_macvlan(struct nlmsg* nlmsg, int sock, const char* name,
  348. const char* link)
  349. {
  350. netlink_add_device_impl(nlmsg, "macvlan", name, false);
  351. netlink_nest(nlmsg, IFLA_INFO_DATA);
  352. uint32_t mode = MACVLAN_MODE_BRIDGE;
  353. netlink_attr(nlmsg, IFLA_MACVLAN_MODE, &mode, sizeof(mode));
  354. netlink_done(nlmsg);
  355. netlink_done(nlmsg);
  356. int ifindex = if_nametoindex(link);
  357. netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
  358. int err = netlink_send(nlmsg, sock);
  359. if (err < 0) {
  360. }
  361. }
  362.  
  363. static void netlink_add_geneve(struct nlmsg* nlmsg, int sock, const char* name,
  364. uint32_t vni, struct in_addr* addr4,
  365. struct in6_addr* addr6)
  366. {
  367. netlink_add_device_impl(nlmsg, "geneve", name, false);
  368. netlink_nest(nlmsg, IFLA_INFO_DATA);
  369. netlink_attr(nlmsg, IFLA_GENEVE_ID, &vni, sizeof(vni));
  370. if (addr4)
  371. netlink_attr(nlmsg, IFLA_GENEVE_REMOTE, addr4, sizeof(*addr4));
  372. if (addr6)
  373. netlink_attr(nlmsg, IFLA_GENEVE_REMOTE6, addr6, sizeof(*addr6));
  374. netlink_done(nlmsg);
  375. netlink_done(nlmsg);
  376. int err = netlink_send(nlmsg, sock);
  377. if (err < 0) {
  378. }
  379. }
  380.  
  381. #define IFLA_IPVLAN_FLAGS 2
  382. #define IPVLAN_MODE_L3S 2
  383. #undef IPVLAN_F_VEPA
  384. #define IPVLAN_F_VEPA 2
  385.  
  386. static void netlink_add_ipvlan(struct nlmsg* nlmsg, int sock, const char* name,
  387. const char* link, uint16_t mode, uint16_t flags)
  388. {
  389. netlink_add_device_impl(nlmsg, "ipvlan", name, false);
  390. netlink_nest(nlmsg, IFLA_INFO_DATA);
  391. netlink_attr(nlmsg, IFLA_IPVLAN_MODE, &mode, sizeof(mode));
  392. netlink_attr(nlmsg, IFLA_IPVLAN_FLAGS, &flags, sizeof(flags));
  393. netlink_done(nlmsg);
  394. netlink_done(nlmsg);
  395. int ifindex = if_nametoindex(link);
  396. netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
  397. int err = netlink_send(nlmsg, sock);
  398. if (err < 0) {
  399. }
  400. }
  401.  
  402. static void netlink_device_change(struct nlmsg* nlmsg, int sock,
  403. const char* name, bool up, const char* master,
  404. const void* mac, int macsize,
  405. const char* new_name)
  406. {
  407. struct ifinfomsg hdr;
  408. memset(&hdr, 0, sizeof(hdr));
  409. if (up)
  410. hdr.ifi_flags = hdr.ifi_change = IFF_UP;
  411. hdr.ifi_index = if_nametoindex(name);
  412. netlink_init(nlmsg, RTM_NEWLINK, 0, &hdr, sizeof(hdr));
  413. if (new_name)
  414. netlink_attr(nlmsg, IFLA_IFNAME, new_name, strlen(new_name));
  415. if (master) {
  416. int ifindex = if_nametoindex(master);
  417. netlink_attr(nlmsg, IFLA_MASTER, &ifindex, sizeof(ifindex));
  418. }
  419. if (macsize)
  420. netlink_attr(nlmsg, IFLA_ADDRESS, mac, macsize);
  421. int err = netlink_send(nlmsg, sock);
  422. if (err < 0) {
  423. }
  424. }
  425.  
  426. static int netlink_add_addr(struct nlmsg* nlmsg, int sock, const char* dev,
  427. const void* addr, int addrsize)
  428. {
  429. struct ifaddrmsg hdr;
  430. memset(&hdr, 0, sizeof(hdr));
  431. hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6;
  432. hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120;
  433. hdr.ifa_scope = RT_SCOPE_UNIVERSE;
  434. hdr.ifa_index = if_nametoindex(dev);
  435. netlink_init(nlmsg, RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr,
  436. sizeof(hdr));
  437. netlink_attr(nlmsg, IFA_LOCAL, addr, addrsize);
  438. netlink_attr(nlmsg, IFA_ADDRESS, addr, addrsize);
  439. return netlink_send(nlmsg, sock);
  440. }
  441.  
  442. static void netlink_add_addr4(struct nlmsg* nlmsg, int sock, const char* dev,
  443. const char* addr)
  444. {
  445. struct in_addr in_addr;
  446. inet_pton(AF_INET, addr, &in_addr);
  447. int err = netlink_add_addr(nlmsg, sock, dev, &in_addr, sizeof(in_addr));
  448. if (err < 0) {
  449. }
  450. }
  451.  
  452. static void netlink_add_addr6(struct nlmsg* nlmsg, int sock, const char* dev,
  453. const char* addr)
  454. {
  455. struct in6_addr in6_addr;
  456. inet_pton(AF_INET6, addr, &in6_addr);
  457. int err = netlink_add_addr(nlmsg, sock, dev, &in6_addr, sizeof(in6_addr));
  458. if (err < 0) {
  459. }
  460. }
  461.  
  462. static struct nlmsg nlmsg;
  463.  
  464. #define DEVLINK_FAMILY_NAME "devlink"
  465.  
  466. #define DEVLINK_CMD_PORT_GET 5
  467. #define DEVLINK_ATTR_BUS_NAME 1
  468. #define DEVLINK_ATTR_DEV_NAME 2
  469. #define DEVLINK_ATTR_NETDEV_NAME 7
  470.  
  471. static struct nlmsg nlmsg2;
  472.  
  473. static void initialize_devlink_ports(const char* bus_name, const char* dev_name,
  474. const char* netdev_prefix)
  475. {
  476. struct genlmsghdr genlhdr;
  477. int len, total_len, id, err, offset;
  478. uint16_t netdev_index;
  479. int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
  480. if (sock == -1)
  481. exit(1);
  482. int rtsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  483. if (rtsock == -1)
  484. exit(1);
  485. id = netlink_query_family_id(&nlmsg, sock, DEVLINK_FAMILY_NAME, true);
  486. if (id == -1)
  487. goto error;
  488. memset(&genlhdr, 0, sizeof(genlhdr));
  489. genlhdr.cmd = DEVLINK_CMD_PORT_GET;
  490. netlink_init(&nlmsg, id, NLM_F_DUMP, &genlhdr, sizeof(genlhdr));
  491. netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1);
  492. netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1);
  493. err = netlink_send_ext(&nlmsg, sock, id, &total_len, true);
  494. if (err < 0) {
  495. goto error;
  496. }
  497. offset = 0;
  498. netdev_index = 0;
  499. while ((len = netlink_next_msg(&nlmsg, offset, total_len)) != -1) {
  500. struct nlattr* attr = (struct nlattr*)(nlmsg.buf + offset + NLMSG_HDRLEN +
  501. NLMSG_ALIGN(sizeof(genlhdr)));
  502. for (; (char*)attr < nlmsg.buf + offset + len;
  503. attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
  504. if (attr->nla_type == DEVLINK_ATTR_NETDEV_NAME) {
  505. char* port_name;
  506. char netdev_name[IFNAMSIZ];
  507. port_name = (char*)(attr + 1);
  508. snprintf(netdev_name, sizeof(netdev_name), "%s%d", netdev_prefix,
  509. netdev_index);
  510. netlink_device_change(&nlmsg2, rtsock, port_name, true, 0, 0, 0,
  511. netdev_name);
  512. break;
  513. }
  514. }
  515. offset += len;
  516. netdev_index++;
  517. }
  518. error:
  519. close(rtsock);
  520. close(sock);
  521. }
  522.  
  523. static int runcmdline(char* cmdline)
  524. {
  525. int ret = system(cmdline);
  526. if (ret) {
  527. }
  528. return ret;
  529. }
  530.  
  531. #define DEV_IPV4 "172.20.20.%d"
  532. #define DEV_IPV6 "fe80::%02x"
  533. #define DEV_MAC 0x00aaaaaaaaaa
  534.  
  535. static void netdevsim_add(unsigned int addr, unsigned int port_count)
  536. {
  537. write_file("/sys/bus/netdevsim/del_device", "%u", addr);
  538. if (write_file("/sys/bus/netdevsim/new_device", "%u %u", addr, port_count)) {
  539. char buf[32];
  540. snprintf(buf, sizeof(buf), "netdevsim%d", addr);
  541. initialize_devlink_ports("netdevsim", buf, "netdevsim");
  542. }
  543. }
  544.  
  545. #define WG_GENL_NAME "wireguard"
  546. enum wg_cmd {
  547. WG_CMD_GET_DEVICE,
  548. WG_CMD_SET_DEVICE,
  549. };
  550. enum wgdevice_attribute {
  551. WGDEVICE_A_UNSPEC,
  552. WGDEVICE_A_IFINDEX,
  553. WGDEVICE_A_IFNAME,
  554. WGDEVICE_A_PRIVATE_KEY,
  555. WGDEVICE_A_PUBLIC_KEY,
  556. WGDEVICE_A_FLAGS,
  557. WGDEVICE_A_LISTEN_PORT,
  558. WGDEVICE_A_FWMARK,
  559. WGDEVICE_A_PEERS,
  560. };
  561. enum wgpeer_attribute {
  562. WGPEER_A_UNSPEC,
  563. WGPEER_A_PUBLIC_KEY,
  564. WGPEER_A_PRESHARED_KEY,
  565. WGPEER_A_FLAGS,
  566. WGPEER_A_ENDPOINT,
  567. WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  568. WGPEER_A_LAST_HANDSHAKE_TIME,
  569. WGPEER_A_RX_BYTES,
  570. WGPEER_A_TX_BYTES,
  571. WGPEER_A_ALLOWEDIPS,
  572. WGPEER_A_PROTOCOL_VERSION,
  573. };
  574. enum wgallowedip_attribute {
  575. WGALLOWEDIP_A_UNSPEC,
  576. WGALLOWEDIP_A_FAMILY,
  577. WGALLOWEDIP_A_IPADDR,
  578. WGALLOWEDIP_A_CIDR_MASK,
  579. };
  580.  
  581. static void netlink_wireguard_setup(void)
  582. {
  583. const char ifname_a[] = "wg0";
  584. const char ifname_b[] = "wg1";
  585. const char ifname_c[] = "wg2";
  586. const char private_a[] =
  587. "\xa0\x5c\xa8\x4f\x6c\x9c\x8e\x38\x53\xe2\xfd\x7a\x70\xae\x0f\xb2\x0f\xa1"
  588. "\x52\x60\x0c\xb0\x08\x45\x17\x4f\x08\x07\x6f\x8d\x78\x43";
  589. const char private_b[] =
  590. "\xb0\x80\x73\xe8\xd4\x4e\x91\xe3\xda\x92\x2c\x22\x43\x82\x44\xbb\x88\x5c"
  591. "\x69\xe2\x69\xc8\xe9\xd8\x35\xb1\x14\x29\x3a\x4d\xdc\x6e";
  592. const char private_c[] =
  593. "\xa0\xcb\x87\x9a\x47\xf5\xbc\x64\x4c\x0e\x69\x3f\xa6\xd0\x31\xc7\x4a\x15"
  594. "\x53\xb6\xe9\x01\xb9\xff\x2f\x51\x8c\x78\x04\x2f\xb5\x42";
  595. const char public_a[] =
  596. "\x97\x5c\x9d\x81\xc9\x83\xc8\x20\x9e\xe7\x81\x25\x4b\x89\x9f\x8e\xd9\x25"
  597. "\xae\x9f\x09\x23\xc2\x3c\x62\xf5\x3c\x57\xcd\xbf\x69\x1c";
  598. const char public_b[] =
  599. "\xd1\x73\x28\x99\xf6\x11\xcd\x89\x94\x03\x4d\x7f\x41\x3d\xc9\x57\x63\x0e"
  600. "\x54\x93\xc2\x85\xac\xa4\x00\x65\xcb\x63\x11\xbe\x69\x6b";
  601. const char public_c[] =
  602. "\xf4\x4d\xa3\x67\xa8\x8e\xe6\x56\x4f\x02\x02\x11\x45\x67\x27\x08\x2f\x5c"
  603. "\xeb\xee\x8b\x1b\xf5\xeb\x73\x37\x34\x1b\x45\x9b\x39\x22";
  604. const uint16_t listen_a = 20001;
  605. const uint16_t listen_b = 20002;
  606. const uint16_t listen_c = 20003;
  607. const uint16_t af_inet = AF_INET;
  608. const uint16_t af_inet6 = AF_INET6;
  609. const struct sockaddr_in endpoint_b_v4 = {
  610. .sin_family = AF_INET,
  611. .sin_port = htons(listen_b),
  612. .sin_addr = {htonl(INADDR_LOOPBACK)}};
  613. const struct sockaddr_in endpoint_c_v4 = {
  614. .sin_family = AF_INET,
  615. .sin_port = htons(listen_c),
  616. .sin_addr = {htonl(INADDR_LOOPBACK)}};
  617. struct sockaddr_in6 endpoint_a_v6 = {.sin6_family = AF_INET6,
  618. .sin6_port = htons(listen_a)};
  619. endpoint_a_v6.sin6_addr = in6addr_loopback;
  620. struct sockaddr_in6 endpoint_c_v6 = {.sin6_family = AF_INET6,
  621. .sin6_port = htons(listen_c)};
  622. endpoint_c_v6.sin6_addr = in6addr_loopback;
  623. const struct in_addr first_half_v4 = {0};
  624. const struct in_addr second_half_v4 = {(uint32_t)htonl(128 << 24)};
  625. const struct in6_addr first_half_v6 = {{{0}}};
  626. const struct in6_addr second_half_v6 = {{{0x80}}};
  627. const uint8_t half_cidr = 1;
  628. const uint16_t persistent_keepalives[] = {1, 3, 7, 9, 14, 19};
  629. struct genlmsghdr genlhdr = {.cmd = WG_CMD_SET_DEVICE, .version = 1};
  630. int sock;
  631. int id, err;
  632. sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
  633. if (sock == -1) {
  634. return;
  635. }
  636. id = netlink_query_family_id(&nlmsg, sock, WG_GENL_NAME, true);
  637. if (id == -1)
  638. goto error;
  639. netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
  640. netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_a, strlen(ifname_a) + 1);
  641. netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_a, 32);
  642. netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_a, 2);
  643. netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
  644. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  645. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
  646. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
  647. sizeof(endpoint_b_v4));
  648. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  649. &persistent_keepalives[0], 2);
  650. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  651. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  652. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  653. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
  654. sizeof(first_half_v4));
  655. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  656. netlink_done(&nlmsg);
  657. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  658. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  659. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
  660. sizeof(first_half_v6));
  661. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  662. netlink_done(&nlmsg);
  663. netlink_done(&nlmsg);
  664. netlink_done(&nlmsg);
  665. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  666. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
  667. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v6,
  668. sizeof(endpoint_c_v6));
  669. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  670. &persistent_keepalives[1], 2);
  671. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  672. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  673. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  674. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
  675. sizeof(second_half_v4));
  676. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  677. netlink_done(&nlmsg);
  678. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  679. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  680. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
  681. sizeof(second_half_v6));
  682. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  683. netlink_done(&nlmsg);
  684. netlink_done(&nlmsg);
  685. netlink_done(&nlmsg);
  686. netlink_done(&nlmsg);
  687. err = netlink_send(&nlmsg, sock);
  688. if (err < 0) {
  689. }
  690. netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
  691. netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_b, strlen(ifname_b) + 1);
  692. netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_b, 32);
  693. netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_b, 2);
  694. netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
  695. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  696. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
  697. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
  698. sizeof(endpoint_a_v6));
  699. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  700. &persistent_keepalives[2], 2);
  701. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  702. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  703. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  704. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
  705. sizeof(first_half_v4));
  706. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  707. netlink_done(&nlmsg);
  708. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  709. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  710. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
  711. sizeof(first_half_v6));
  712. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  713. netlink_done(&nlmsg);
  714. netlink_done(&nlmsg);
  715. netlink_done(&nlmsg);
  716. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  717. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
  718. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v4,
  719. sizeof(endpoint_c_v4));
  720. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  721. &persistent_keepalives[3], 2);
  722. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  723. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  724. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  725. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
  726. sizeof(second_half_v4));
  727. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  728. netlink_done(&nlmsg);
  729. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  730. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  731. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
  732. sizeof(second_half_v6));
  733. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  734. netlink_done(&nlmsg);
  735. netlink_done(&nlmsg);
  736. netlink_done(&nlmsg);
  737. netlink_done(&nlmsg);
  738. err = netlink_send(&nlmsg, sock);
  739. if (err < 0) {
  740. }
  741. netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
  742. netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_c, strlen(ifname_c) + 1);
  743. netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_c, 32);
  744. netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_c, 2);
  745. netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
  746. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  747. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
  748. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
  749. sizeof(endpoint_a_v6));
  750. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  751. &persistent_keepalives[4], 2);
  752. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  753. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  754. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  755. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
  756. sizeof(first_half_v4));
  757. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  758. netlink_done(&nlmsg);
  759. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  760. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  761. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
  762. sizeof(first_half_v6));
  763. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  764. netlink_done(&nlmsg);
  765. netlink_done(&nlmsg);
  766. netlink_done(&nlmsg);
  767. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  768. netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
  769. netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
  770. sizeof(endpoint_b_v4));
  771. netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
  772. &persistent_keepalives[5], 2);
  773. netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
  774. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  775. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
  776. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
  777. sizeof(second_half_v4));
  778. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  779. netlink_done(&nlmsg);
  780. netlink_nest(&nlmsg, NLA_F_NESTED | 0);
  781. netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
  782. netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
  783. sizeof(second_half_v6));
  784. netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
  785. netlink_done(&nlmsg);
  786. netlink_done(&nlmsg);
  787. netlink_done(&nlmsg);
  788. netlink_done(&nlmsg);
  789. err = netlink_send(&nlmsg, sock);
  790. if (err < 0) {
  791. }
  792.  
  793. error:
  794. close(sock);
  795. }
  796.  
  797. static void initialize_netdevices(void)
  798. {
  799. char netdevsim[16];
  800. sprintf(netdevsim, "netdevsim%d", (int)procid);
  801. struct {
  802. const char* type;
  803. const char* dev;
  804. } devtypes[] = {
  805. {"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"}, {"vcan", "vcan0"},
  806. {"bond", "bond0"}, {"team", "team0"}, {"dummy", "dummy0"},
  807. {"nlmon", "nlmon0"}, {"caif", "caif0"}, {"batadv", "batadv0"},
  808. {"vxcan", "vxcan1"}, {"veth", 0}, {"wireguard", "wg0"},
  809. {"wireguard", "wg1"}, {"wireguard", "wg2"},
  810. };
  811. const char* devmasters[] = {"bridge", "bond", "team", "batadv"};
  812. struct {
  813. const char* name;
  814. int macsize;
  815. bool noipv6;
  816. } devices[] = {
  817. {"lo", ETH_ALEN},
  818. {"sit0", 0},
  819. {"bridge0", ETH_ALEN},
  820. {"vcan0", 0, true},
  821. {"tunl0", 0},
  822. {"gre0", 0},
  823. {"gretap0", ETH_ALEN},
  824. {"ip_vti0", 0},
  825. {"ip6_vti0", 0},
  826. {"ip6tnl0", 0},
  827. {"ip6gre0", 0},
  828. {"ip6gretap0", ETH_ALEN},
  829. {"erspan0", ETH_ALEN},
  830. {"bond0", ETH_ALEN},
  831. {"veth0", ETH_ALEN},
  832. {"veth1", ETH_ALEN},
  833. {"team0", ETH_ALEN},
  834. {"veth0_to_bridge", ETH_ALEN},
  835. {"veth1_to_bridge", ETH_ALEN},
  836. {"veth0_to_bond", ETH_ALEN},
  837. {"veth1_to_bond", ETH_ALEN},
  838. {"veth0_to_team", ETH_ALEN},
  839. {"veth1_to_team", ETH_ALEN},
  840. {"veth0_to_hsr", ETH_ALEN},
  841. {"veth1_to_hsr", ETH_ALEN},
  842. {"hsr0", 0},
  843. {"dummy0", ETH_ALEN},
  844. {"nlmon0", 0},
  845. {"vxcan0", 0, true},
  846. {"vxcan1", 0, true},
  847. {"caif0", ETH_ALEN},
  848. {"batadv0", ETH_ALEN},
  849. {netdevsim, ETH_ALEN},
  850. {"xfrm0", ETH_ALEN},
  851. {"veth0_virt_wifi", ETH_ALEN},
  852. {"veth1_virt_wifi", ETH_ALEN},
  853. {"virt_wifi0", ETH_ALEN},
  854. {"veth0_vlan", ETH_ALEN},
  855. {"veth1_vlan", ETH_ALEN},
  856. {"vlan0", ETH_ALEN},
  857. {"vlan1", ETH_ALEN},
  858. {"macvlan0", ETH_ALEN},
  859. {"macvlan1", ETH_ALEN},
  860. {"ipvlan0", ETH_ALEN},
  861. {"ipvlan1", ETH_ALEN},
  862. {"veth0_macvtap", ETH_ALEN},
  863. {"veth1_macvtap", ETH_ALEN},
  864. {"macvtap0", ETH_ALEN},
  865. {"macsec0", ETH_ALEN},
  866. {"veth0_to_batadv", ETH_ALEN},
  867. {"veth1_to_batadv", ETH_ALEN},
  868. {"batadv_slave_0", ETH_ALEN},
  869. {"batadv_slave_1", ETH_ALEN},
  870. {"geneve0", ETH_ALEN},
  871. {"geneve1", ETH_ALEN},
  872. {"wg0", 0},
  873. {"wg1", 0},
  874. {"wg2", 0},
  875. };
  876. int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  877. if (sock == -1)
  878. exit(1);
  879. unsigned i;
  880. for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++)
  881. netlink_add_device(&nlmsg, sock, devtypes[i].type, devtypes[i].dev);
  882. for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) {
  883. char master[32], slave0[32], veth0[32], slave1[32], veth1[32];
  884. sprintf(slave0, "%s_slave_0", devmasters[i]);
  885. sprintf(veth0, "veth0_to_%s", devmasters[i]);
  886. netlink_add_veth(&nlmsg, sock, slave0, veth0);
  887. sprintf(slave1, "%s_slave_1", devmasters[i]);
  888. sprintf(veth1, "veth1_to_%s", devmasters[i]);
  889. netlink_add_veth(&nlmsg, sock, slave1, veth1);
  890. sprintf(master, "%s0", devmasters[i]);
  891. netlink_device_change(&nlmsg, sock, slave0, false, master, 0, 0, NULL);
  892. netlink_device_change(&nlmsg, sock, slave1, false, master, 0, 0, NULL);
  893. }
  894. netlink_add_xfrm(&nlmsg, sock, "xfrm0");
  895. netlink_device_change(&nlmsg, sock, "bridge_slave_0", true, 0, 0, 0, NULL);
  896. netlink_device_change(&nlmsg, sock, "bridge_slave_1", true, 0, 0, 0, NULL);
  897. netlink_add_veth(&nlmsg, sock, "hsr_slave_0", "veth0_to_hsr");
  898. netlink_add_veth(&nlmsg, sock, "hsr_slave_1", "veth1_to_hsr");
  899. netlink_add_hsr(&nlmsg, sock, "hsr0", "hsr_slave_0", "hsr_slave_1");
  900. netlink_device_change(&nlmsg, sock, "hsr_slave_0", true, 0, 0, 0, NULL);
  901. netlink_device_change(&nlmsg, sock, "hsr_slave_1", true, 0, 0, 0, NULL);
  902. netlink_add_veth(&nlmsg, sock, "veth0_virt_wifi", "veth1_virt_wifi");
  903. netlink_add_linked(&nlmsg, sock, "virt_wifi", "virt_wifi0",
  904. "veth1_virt_wifi");
  905. netlink_add_veth(&nlmsg, sock, "veth0_vlan", "veth1_vlan");
  906. netlink_add_vlan(&nlmsg, sock, "vlan0", "veth0_vlan", 0, htons(ETH_P_8021Q));
  907. netlink_add_vlan(&nlmsg, sock, "vlan1", "veth0_vlan", 1, htons(ETH_P_8021AD));
  908. netlink_add_macvlan(&nlmsg, sock, "macvlan0", "veth1_vlan");
  909. netlink_add_macvlan(&nlmsg, sock, "macvlan1", "veth1_vlan");
  910. netlink_add_ipvlan(&nlmsg, sock, "ipvlan0", "veth0_vlan", IPVLAN_MODE_L2, 0);
  911. netlink_add_ipvlan(&nlmsg, sock, "ipvlan1", "veth0_vlan", IPVLAN_MODE_L3S,
  912. IPVLAN_F_VEPA);
  913. netlink_add_veth(&nlmsg, sock, "veth0_macvtap", "veth1_macvtap");
  914. netlink_add_linked(&nlmsg, sock, "macvtap", "macvtap0", "veth0_macvtap");
  915. netlink_add_linked(&nlmsg, sock, "macsec", "macsec0", "veth1_macvtap");
  916. char addr[32];
  917. sprintf(addr, DEV_IPV4, 14 + 10);
  918. struct in_addr geneve_addr4;
  919. if (inet_pton(AF_INET, addr, &geneve_addr4) <= 0)
  920. exit(1);
  921. struct in6_addr geneve_addr6;
  922. if (inet_pton(AF_INET6, "fc00::01", &geneve_addr6) <= 0)
  923. exit(1);
  924. netlink_add_geneve(&nlmsg, sock, "geneve0", 0, &geneve_addr4, 0);
  925. netlink_add_geneve(&nlmsg, sock, "geneve1", 1, 0, &geneve_addr6);
  926. netdevsim_add((int)procid, 4);
  927. netlink_wireguard_setup();
  928. for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
  929. char addr[32];
  930. sprintf(addr, DEV_IPV4, i + 10);
  931. netlink_add_addr4(&nlmsg, sock, devices[i].name, addr);
  932. if (!devices[i].noipv6) {
  933. sprintf(addr, DEV_IPV6, i + 10);
  934. netlink_add_addr6(&nlmsg, sock, devices[i].name, addr);
  935. }
  936. uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40);
  937. netlink_device_change(&nlmsg, sock, devices[i].name, true, 0, &macaddr,
  938. devices[i].macsize, NULL);
  939. }
  940. close(sock);
  941. }
  942. static void initialize_netdevices_init(void)
  943. {
  944. int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  945. if (sock == -1)
  946. exit(1);
  947. struct {
  948. const char* type;
  949. int macsize;
  950. bool noipv6;
  951. bool noup;
  952. } devtypes[] = {
  953. {"nr", 7, true},
  954. {"rose", 5, true, true},
  955. };
  956. unsigned i;
  957. for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) {
  958. char dev[32], addr[32];
  959. sprintf(dev, "%s%d", devtypes[i].type, (int)procid);
  960. sprintf(addr, "172.30.%d.%d", i, (int)procid + 1);
  961. netlink_add_addr4(&nlmsg, sock, dev, addr);
  962. if (!devtypes[i].noipv6) {
  963. sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1);
  964. netlink_add_addr6(&nlmsg, sock, dev, addr);
  965. }
  966. int macsize = devtypes[i].macsize;
  967. uint64_t macaddr = 0xbbbbbb +
  968. ((unsigned long long)i << (8 * (macsize - 2))) +
  969. (procid << (8 * (macsize - 1)));
  970. netlink_device_change(&nlmsg, sock, dev, !devtypes[i].noup, 0, &macaddr,
  971. macsize, NULL);
  972. }
  973. close(sock);
  974. }
  975.  
  976. #define MAX_FDS 30
  977.  
  978. static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2)
  979. {
  980. if (a0 == 0xc || a0 == 0xb) {
  981. char buf[128];
  982. sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1,
  983. (uint8_t)a2);
  984. return open(buf, O_RDWR, 0);
  985. } else {
  986. unsigned long nb = a1;
  987. char buf[1024];
  988. char* hash;
  989. strncpy(buf, (char*)a0, sizeof(buf) - 1);
  990. buf[sizeof(buf) - 1] = 0;
  991. while ((hash = strchr(buf, '#'))) {
  992. *hash = '0' + (char)(nb % 10);
  993. nb /= 10;
  994. }
  995. return open(buf, a2, 0);
  996. }
  997. }
  998.  
  999. static void setup_gadgetfs();
  1000. static void setup_binderfs();
  1001. static void setup_fusectl();
  1002. static void sandbox_common_mount_tmpfs(void)
  1003. {
  1004. write_file("/proc/sys/fs/mount-max", "100000");
  1005. if (mkdir("./syz-tmp", 0777))
  1006. exit(1);
  1007. if (mount("", "./syz-tmp", "tmpfs", 0, NULL))
  1008. exit(1);
  1009. if (mkdir("./syz-tmp/newroot", 0777))
  1010. exit(1);
  1011. if (mkdir("./syz-tmp/newroot/dev", 0700))
  1012. exit(1);
  1013. unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE;
  1014. if (mount("/dev", "./syz-tmp/newroot/dev", NULL, bind_mount_flags, NULL))
  1015. exit(1);
  1016. if (mkdir("./syz-tmp/newroot/proc", 0700))
  1017. exit(1);
  1018. if (mount("syz-proc", "./syz-tmp/newroot/proc", "proc", 0, NULL))
  1019. exit(1);
  1020. if (mkdir("./syz-tmp/newroot/selinux", 0700))
  1021. exit(1);
  1022. const char* selinux_path = "./syz-tmp/newroot/selinux";
  1023. if (mount("/selinux", selinux_path, NULL, bind_mount_flags, NULL)) {
  1024. if (errno != ENOENT)
  1025. exit(1);
  1026. if (mount("/sys/fs/selinux", selinux_path, NULL, bind_mount_flags, NULL) &&
  1027. errno != ENOENT)
  1028. exit(1);
  1029. }
  1030. if (mkdir("./syz-tmp/newroot/sys", 0700))
  1031. exit(1);
  1032. if (mount("/sys", "./syz-tmp/newroot/sys", 0, bind_mount_flags, NULL))
  1033. exit(1);
  1034. if (mount("/sys/kernel/debug", "./syz-tmp/newroot/sys/kernel/debug", NULL,
  1035. bind_mount_flags, NULL) &&
  1036. errno != ENOENT)
  1037. exit(1);
  1038. if (mount("/sys/fs/smackfs", "./syz-tmp/newroot/sys/fs/smackfs", NULL,
  1039. bind_mount_flags, NULL) &&
  1040. errno != ENOENT)
  1041. exit(1);
  1042. if (mount("/proc/sys/fs/binfmt_misc",
  1043. "./syz-tmp/newroot/proc/sys/fs/binfmt_misc", NULL, bind_mount_flags,
  1044. NULL) &&
  1045. errno != ENOENT)
  1046. exit(1);
  1047. if (mkdir("./syz-tmp/newroot/syz-inputs", 0700))
  1048. exit(1);
  1049. if (mount("/syz-inputs", "./syz-tmp/newroot/syz-inputs", NULL,
  1050. bind_mount_flags | MS_RDONLY, NULL) &&
  1051. errno != ENOENT)
  1052. exit(1);
  1053. if (mkdir("./syz-tmp/pivot", 0777))
  1054. exit(1);
  1055. if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) {
  1056. if (chdir("./syz-tmp"))
  1057. exit(1);
  1058. } else {
  1059. if (chdir("/"))
  1060. exit(1);
  1061. if (umount2("./pivot", MNT_DETACH))
  1062. exit(1);
  1063. }
  1064. if (chroot("./newroot"))
  1065. exit(1);
  1066. if (chdir("/"))
  1067. exit(1);
  1068. setup_gadgetfs();
  1069. setup_binderfs();
  1070. setup_fusectl();
  1071. }
  1072.  
  1073. static void setup_gadgetfs()
  1074. {
  1075. if (mkdir("/dev/gadgetfs", 0777)) {
  1076. }
  1077. if (mount("gadgetfs", "/dev/gadgetfs", "gadgetfs", 0, NULL)) {
  1078. }
  1079. }
  1080.  
  1081. static void setup_fusectl()
  1082. {
  1083. if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
  1084. }
  1085. }
  1086.  
  1087. static void setup_binderfs()
  1088. {
  1089. if (mkdir("/dev/binderfs", 0777)) {
  1090. }
  1091. if (mount("binder", "/dev/binderfs", "binder", 0, NULL)) {
  1092. }
  1093. }
  1094.  
  1095. static void loop();
  1096.  
  1097. static void sandbox_common()
  1098. {
  1099. prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  1100. if (getppid() == 1)
  1101. exit(1);
  1102. struct rlimit rlim;
  1103. rlim.rlim_cur = rlim.rlim_max = (200 << 20);
  1104. setrlimit(RLIMIT_AS, &rlim);
  1105. rlim.rlim_cur = rlim.rlim_max = 32 << 20;
  1106. setrlimit(RLIMIT_MEMLOCK, &rlim);
  1107. rlim.rlim_cur = rlim.rlim_max = 136 << 20;
  1108. setrlimit(RLIMIT_FSIZE, &rlim);
  1109. rlim.rlim_cur = rlim.rlim_max = 1 << 20;
  1110. setrlimit(RLIMIT_STACK, &rlim);
  1111. rlim.rlim_cur = rlim.rlim_max = 128 << 20;
  1112. setrlimit(RLIMIT_CORE, &rlim);
  1113. rlim.rlim_cur = rlim.rlim_max = 256;
  1114. setrlimit(RLIMIT_NOFILE, &rlim);
  1115. if (unshare(CLONE_NEWNS)) {
  1116. }
  1117. if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
  1118. }
  1119. if (unshare(CLONE_NEWIPC)) {
  1120. }
  1121. if (unshare(0x02000000)) {
  1122. }
  1123. if (unshare(CLONE_NEWUTS)) {
  1124. }
  1125. if (unshare(CLONE_SYSVSEM)) {
  1126. }
  1127. typedef struct {
  1128. const char* name;
  1129. const char* value;
  1130. } sysctl_t;
  1131. static const sysctl_t sysctls[] = {
  1132. {"/proc/sys/kernel/shmmax", "16777216"},
  1133. {"/proc/sys/kernel/shmall", "536870912"},
  1134. {"/proc/sys/kernel/shmmni", "1024"},
  1135. {"/proc/sys/kernel/msgmax", "8192"},
  1136. {"/proc/sys/kernel/msgmni", "1024"},
  1137. {"/proc/sys/kernel/msgmnb", "1024"},
  1138. {"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
  1139. };
  1140. unsigned i;
  1141. for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
  1142. write_file(sysctls[i].name, sysctls[i].value);
  1143. }
  1144.  
  1145. static int wait_for_loop(int pid)
  1146. {
  1147. if (pid < 0)
  1148. exit(1);
  1149. int status = 0;
  1150. while (waitpid(-1, &status, __WALL) != pid) {
  1151. }
  1152. return WEXITSTATUS(status);
  1153. }
  1154.  
  1155. static void drop_caps(void)
  1156. {
  1157. struct __user_cap_header_struct cap_hdr = {};
  1158. struct __user_cap_data_struct cap_data[2] = {};
  1159. cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
  1160. cap_hdr.pid = getpid();
  1161. if (syscall(SYS_capget, &cap_hdr, &cap_data))
  1162. exit(1);
  1163. const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE);
  1164. cap_data[0].effective &= ~drop;
  1165. cap_data[0].permitted &= ~drop;
  1166. cap_data[0].inheritable &= ~drop;
  1167. if (syscall(SYS_capset, &cap_hdr, &cap_data))
  1168. exit(1);
  1169. }
  1170.  
  1171. static int do_sandbox_none(void)
  1172. {
  1173. if (unshare(CLONE_NEWPID)) {
  1174. }
  1175. int pid = fork();
  1176. if (pid != 0)
  1177. return wait_for_loop(pid);
  1178. sandbox_common();
  1179. drop_caps();
  1180. initialize_netdevices_init();
  1181. if (unshare(CLONE_NEWNET)) {
  1182. }
  1183. write_file("/proc/sys/net/ipv4/ping_group_range", "0 65535");
  1184. initialize_netdevices();
  1185. sandbox_common_mount_tmpfs();
  1186. loop();
  1187. exit(1);
  1188. }
  1189.  
  1190. #define FS_IOC_SETFLAGS _IOW('f', 2, long)
  1191. static void remove_dir(const char* dir)
  1192. {
  1193. int iter = 0;
  1194. DIR* dp = 0;
  1195. const int umount_flags = MNT_FORCE | UMOUNT_NOFOLLOW;
  1196.  
  1197. retry:
  1198. while (umount2(dir, umount_flags) == 0) {
  1199. }
  1200. dp = opendir(dir);
  1201. if (dp == NULL) {
  1202. if (errno == EMFILE) {
  1203. exit(1);
  1204. }
  1205. exit(1);
  1206. }
  1207. struct dirent* ep = 0;
  1208. while ((ep = readdir(dp))) {
  1209. if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
  1210. continue;
  1211. char filename[FILENAME_MAX];
  1212. snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
  1213. while (umount2(filename, umount_flags) == 0) {
  1214. }
  1215. struct stat st;
  1216. if (lstat(filename, &st))
  1217. exit(1);
  1218. if (S_ISDIR(st.st_mode)) {
  1219. remove_dir(filename);
  1220. continue;
  1221. }
  1222. int i;
  1223. for (i = 0;; i++) {
  1224. if (unlink(filename) == 0)
  1225. break;
  1226. if (errno == EPERM) {
  1227. int fd = open(filename, O_RDONLY);
  1228. if (fd != -1) {
  1229. long flags = 0;
  1230. if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
  1231. }
  1232. close(fd);
  1233. continue;
  1234. }
  1235. }
  1236. if (errno == EROFS) {
  1237. break;
  1238. }
  1239. if (errno != EBUSY || i > 100)
  1240. exit(1);
  1241. if (umount2(filename, umount_flags))
  1242. exit(1);
  1243. }
  1244. }
  1245. closedir(dp);
  1246. for (int i = 0;; i++) {
  1247. if (rmdir(dir) == 0)
  1248. break;
  1249. if (i < 100) {
  1250. if (errno == EPERM) {
  1251. int fd = open(dir, O_RDONLY);
  1252. if (fd != -1) {
  1253. long flags = 0;
  1254. if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
  1255. }
  1256. close(fd);
  1257. continue;
  1258. }
  1259. }
  1260. if (errno == EROFS) {
  1261. break;
  1262. }
  1263. if (errno == EBUSY) {
  1264. if (umount2(dir, umount_flags))
  1265. exit(1);
  1266. continue;
  1267. }
  1268. if (errno == ENOTEMPTY) {
  1269. if (iter < 100) {
  1270. iter++;
  1271. goto retry;
  1272. }
  1273. }
  1274. }
  1275. exit(1);
  1276. }
  1277. }
  1278.  
  1279. static void kill_and_wait(int pid, int* status)
  1280. {
  1281. kill(-pid, SIGKILL);
  1282. kill(pid, SIGKILL);
  1283. for (int i = 0; i < 100; i++) {
  1284. if (waitpid(-1, status, WNOHANG | __WALL) == pid)
  1285. return;
  1286. usleep(1000);
  1287. }
  1288. DIR* dir = opendir("/sys/fs/fuse/connections");
  1289. if (dir) {
  1290. for (;;) {
  1291. struct dirent* ent = readdir(dir);
  1292. if (!ent)
  1293. break;
  1294. if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
  1295. continue;
  1296. char abort[300];
  1297. snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
  1298. ent->d_name);
  1299. int fd = open(abort, O_WRONLY);
  1300. if (fd == -1) {
  1301. continue;
  1302. }
  1303. if (write(fd, abort, 1) < 0) {
  1304. }
  1305. close(fd);
  1306. }
  1307. closedir(dir);
  1308. } else {
  1309. }
  1310. while (waitpid(-1, status, __WALL) != pid) {
  1311. }
  1312. }
  1313.  
  1314. static void setup_test()
  1315. {
  1316. prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  1317. setpgrp();
  1318. write_file("/proc/self/oom_score_adj", "1000");
  1319. if (symlink("/dev/binderfs", "./binderfs")) {
  1320. }
  1321. }
  1322.  
  1323. static void close_fds()
  1324. {
  1325. for (int fd = 3; fd < MAX_FDS; fd++)
  1326. close(fd);
  1327. }
  1328.  
  1329. static const char* setup_binfmt_misc()
  1330. {
  1331. if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0) &&
  1332. errno != EBUSY) {
  1333. return NULL;
  1334. }
  1335. if (!write_file("/proc/sys/fs/binfmt_misc/register",
  1336. ":syz0:M:0:\x01::./file0:") ||
  1337. !write_file("/proc/sys/fs/binfmt_misc/register",
  1338. ":syz1:M:1:\x02::./file0:POC"))
  1339. return "write(/proc/sys/fs/binfmt_misc/register) failed";
  1340. return NULL;
  1341. }
  1342.  
  1343. #define SWAP_FILE "./swap-file"
  1344. #define SWAP_FILE_SIZE (128 * 1000 * 1000)
  1345.  
  1346. static const char* setup_swap()
  1347. {
  1348. swapoff(SWAP_FILE);
  1349. unlink(SWAP_FILE);
  1350. int fd = open(SWAP_FILE, O_CREAT | O_WRONLY | O_CLOEXEC, 0600);
  1351. if (fd == -1)
  1352. return "swap file open failed";
  1353. fallocate(fd, FALLOC_FL_ZERO_RANGE, 0, SWAP_FILE_SIZE);
  1354. close(fd);
  1355. char cmdline[64];
  1356. sprintf(cmdline, "mkswap %s", SWAP_FILE);
  1357. if (runcmdline(cmdline))
  1358. return "mkswap failed";
  1359. if (swapon(SWAP_FILE, SWAP_FLAG_PREFER) == 1)
  1360. return "swapon failed";
  1361. return NULL;
  1362. }
  1363.  
  1364. static void execute_one(void);
  1365.  
  1366. #define WAIT_FLAGS __WALL
  1367.  
  1368. static void loop(void)
  1369. {
  1370. int iter = 0;
  1371. for (;; iter++) {
  1372. char cwdbuf[32];
  1373. sprintf(cwdbuf, "./%d", iter);
  1374. if (mkdir(cwdbuf, 0777))
  1375. exit(1);
  1376. int pid = fork();
  1377. if (pid < 0)
  1378. exit(1);
  1379. if (pid == 0) {
  1380. if (chdir(cwdbuf))
  1381. exit(1);
  1382. setup_test();
  1383. execute_one();
  1384. close_fds();
  1385. exit(0);
  1386. }
  1387. int status = 0;
  1388. uint64_t start = current_time_ms();
  1389. for (;;) {
  1390. sleep_ms(10);
  1391. if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
  1392. break;
  1393. if (current_time_ms() - start < 5000)
  1394. continue;
  1395. kill_and_wait(pid, &status);
  1396. break;
  1397. }
  1398. remove_dir(cwdbuf);
  1399. }
  1400. }
  1401.  
  1402. uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff};
  1403.  
  1404. void execute_one(void)
  1405. {
  1406. intptr_t res = 0;
  1407. if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
  1408. }
  1409. // setxattr$trusted_overlay_upper arguments: [
  1410. // path: nil
  1411. // name: nil
  1412. // val: nil
  1413. // size: len = 0xfe57 (8 bytes)
  1414. // flags: setxattr_flags = 0x2 (8 bytes)
  1415. // ]
  1416. syscall(__NR_setxattr, /*path=*/0ul, /*name=*/0ul, /*val=*/0ul,
  1417. /*size=*/0xfe57ul, /*flags=XATTR_REPLACE*/ 2ul);
  1418. // socket$inet_udp arguments: [
  1419. // domain: const = 0x2 (8 bytes)
  1420. // type: const = 0x2 (8 bytes)
  1421. // proto: const = 0x0 (4 bytes)
  1422. // ]
  1423. // returns sock_udp
  1424. syscall(__NR_socket, /*domain=*/2ul, /*type=*/2ul, /*proto=*/0);
  1425. // pipe2$9p arguments: [
  1426. // pipefd: nil
  1427. // flags: pipe_flags = 0x0 (8 bytes)
  1428. // ]
  1429. syscall(__NR_pipe2, /*pipefd=*/0ul, /*flags=*/0ul);
  1430. // syz_open_dev$tty1 arguments: [
  1431. // dev: const = 0xc (8 bytes)
  1432. // major: const = 0x4 (8 bytes)
  1433. // minor: intptr = 0x1 (8 bytes)
  1434. // ]
  1435. // returns fd_tty
  1436. syz_open_dev(/*dev=*/0xc, /*major=*/4, /*minor=*/1);
  1437. // perf_event_open arguments: [
  1438. // attr: ptr[in, perf_event_attr] {
  1439. // perf_event_attr {
  1440. // type: perf_event_type = 0x4 (4 bytes)
  1441. // size: len = 0x80 (4 bytes)
  1442. // config0: int8 = 0x7 (1 bytes)
  1443. // config1: int8 = 0x9 (1 bytes)
  1444. // config2: int8 = 0xfb (1 bytes)
  1445. // config3: int8 = 0x60 (1 bytes)
  1446. // config4: const = 0x0 (4 bytes)
  1447. // sample_freq: int64 = 0x7 (8 bytes)
  1448. // sample_type: perf_sample_type = 0x95100 (8 bytes)
  1449. // read_format: perf_read_format = 0x1 (8 bytes)
  1450. // disabled: int64 = 0x0 (0 bytes)
  1451. // inherit: int64 = 0x1 (0 bytes)
  1452. // pinned: int64 = 0x1 (0 bytes)
  1453. // exclusive: int64 = 0x1 (0 bytes)
  1454. // exclude_user: int64 = 0x0 (0 bytes)
  1455. // exclude_kernel: int64 = 0x1 (0 bytes)
  1456. // exclude_hv: int64 = 0x0 (0 bytes)
  1457. // exclude_idle: int64 = 0x0 (0 bytes)
  1458. // mmap: int64 = 0x0 (0 bytes)
  1459. // comm: int64 = 0x0 (0 bytes)
  1460. // freq: int64 = 0x0 (0 bytes)
  1461. // inherit_stat: int64 = 0x0 (0 bytes)
  1462. // enable_on_exec: int64 = 0x1 (0 bytes)
  1463. // task: int64 = 0x1 (0 bytes)
  1464. // watermark: int64 = 0x1 (0 bytes)
  1465. // precise_ip: int64 = 0x0 (0 bytes)
  1466. // mmap_data: int64 = 0x1 (0 bytes)
  1467. // sample_id_all: int64 = 0x1 (0 bytes)
  1468. // exclude_host: int64 = 0x0 (0 bytes)
  1469. // exclude_guest: int64 = 0x0 (0 bytes)
  1470. // exclude_callchain_kernel: int64 = 0x1 (0 bytes)
  1471. // exclude_callchain_user: int64 = 0x1 (0 bytes)
  1472. // mmap2: int64 = 0x1 (0 bytes)
  1473. // comm_exec: int64 = 0x0 (0 bytes)
  1474. // use_clockid: int64 = 0x0 (0 bytes)
  1475. // context_switch: int64 = 0x1 (0 bytes)
  1476. // write_backward: int64 = 0x0 (0 bytes)
  1477. // namespaces: int64 = 0x1 (0 bytes)
  1478. // ksymbol: int64 = 0x1 (0 bytes)
  1479. // bpf_event: int64 = 0x0 (0 bytes)
  1480. // aux_output: int64 = 0x0 (0 bytes)
  1481. // cgroup: int64 = 0x1 (0 bytes)
  1482. // text_poke: int64 = 0x0 (0 bytes)
  1483. // build_id: int64 = 0x1 (0 bytes)
  1484. // inherit_thread: int64 = 0x0 (0 bytes)
  1485. // remove_on_exec: int64 = 0x0 (0 bytes)
  1486. // sigtrap: int64 = 0x0 (0 bytes)
  1487. // __reserved_1: const = 0x0 (8 bytes)
  1488. // wakeup_events: int32 = 0xffffffff (4 bytes)
  1489. // bp_type: perf_bp_type = 0x1 (4 bytes)
  1490. // bp_config: union perf_bp_config {
  1491. // perf_config_ext: perf_config_ext {
  1492. // config1: int64 = 0x0 (8 bytes)
  1493. // config2: int64 = 0x20 (8 bytes)
  1494. // }
  1495. // }
  1496. // branch_sample_type: perf_branch_sample_type = 0x188 (8 bytes)
  1497. // sample_regs_user: int64 = 0x61 (8 bytes)
  1498. // sample_stack_user: int32 = 0x9 (4 bytes)
  1499. // clockid: clock_type = 0x9 (4 bytes)
  1500. // sample_regs_intr: int64 = 0x5197 (8 bytes)
  1501. // aux_watermark: int32 = 0x0 (4 bytes)
  1502. // sample_max_stack: int16 = 0xd (2 bytes)
  1503. // __reserved_2: const = 0x0 (2 bytes)
  1504. // aux_sample_size: int32 = 0x0 (4 bytes)
  1505. // __reserved_3: const = 0x0 (4 bytes)
  1506. // sig_data: int64 = 0x7ff (8 bytes)
  1507. // }
  1508. // }
  1509. // pid: pid (resource)
  1510. // cpu: intptr = 0x0 (8 bytes)
  1511. // group: fd_perf (resource)
  1512. // flags: perf_flags = 0x8 (8 bytes)
  1513. // ]
  1514. // returns fd_perf
  1515. *(uint32_t*)0x2000000007c0 = 4;
  1516. *(uint32_t*)0x2000000007c4 = 0x80;
  1517. *(uint8_t*)0x2000000007c8 = 7;
  1518. *(uint8_t*)0x2000000007c9 = 9;
  1519. *(uint8_t*)0x2000000007ca = 0xfb;
  1520. *(uint8_t*)0x2000000007cb = 0x60;
  1521. *(uint32_t*)0x2000000007cc = 0;
  1522. *(uint64_t*)0x2000000007d0 = 7;
  1523. *(uint64_t*)0x2000000007d8 = 0x95100;
  1524. *(uint64_t*)0x2000000007e0 = 1;
  1525. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 0, 1);
  1526. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 1, 1);
  1527. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 2, 1);
  1528. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 3, 1);
  1529. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 4, 1);
  1530. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 5, 1);
  1531. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 6, 1);
  1532. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 7, 1);
  1533. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 8, 1);
  1534. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 9, 1);
  1535. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 10, 1);
  1536. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 11, 1);
  1537. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 12, 1);
  1538. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 13, 1);
  1539. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 14, 1);
  1540. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 15, 2);
  1541. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 17, 1);
  1542. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 18, 1);
  1543. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 19, 1);
  1544. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 20, 1);
  1545. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 21, 1);
  1546. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 22, 1);
  1547. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 23, 1);
  1548. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 24, 1);
  1549. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 25, 1);
  1550. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 26, 1);
  1551. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 27, 1);
  1552. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 28, 1);
  1553. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 29, 1);
  1554. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 30, 1);
  1555. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 31, 1);
  1556. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 32, 1);
  1557. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 33, 1);
  1558. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 34, 1);
  1559. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 35, 1);
  1560. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 36, 1);
  1561. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 37, 1);
  1562. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 38, 26);
  1563. *(uint32_t*)0x2000000007f0 = -1;
  1564. *(uint32_t*)0x2000000007f4 = 1;
  1565. *(uint64_t*)0x2000000007f8 = 0;
  1566. *(uint64_t*)0x200000000800 = 0x20;
  1567. *(uint64_t*)0x200000000808 = 0x188;
  1568. *(uint64_t*)0x200000000810 = 0x61;
  1569. *(uint32_t*)0x200000000818 = 9;
  1570. *(uint32_t*)0x20000000081c = 9;
  1571. *(uint64_t*)0x200000000820 = 0x5197;
  1572. *(uint32_t*)0x200000000828 = 0;
  1573. *(uint16_t*)0x20000000082c = 0xd;
  1574. *(uint16_t*)0x20000000082e = 0;
  1575. *(uint32_t*)0x200000000830 = 0;
  1576. *(uint32_t*)0x200000000834 = 0;
  1577. *(uint64_t*)0x200000000838 = 0x7ff;
  1578. syscall(__NR_perf_event_open, /*attr=*/0x2000000007c0ul, /*pid=*/0,
  1579. /*cpu=*/0ul, /*group=*/(intptr_t)-1,
  1580. /*flags=PERF_FLAG_FD_CLOEXEC*/ 8ul);
  1581. // perf_event_open arguments: [
  1582. // attr: ptr[in, perf_event_attr] {
  1583. // perf_event_attr {
  1584. // type: perf_event_type = 0x4 (4 bytes)
  1585. // size: len = 0x80 (4 bytes)
  1586. // config0: int8 = 0x7 (1 bytes)
  1587. // config1: int8 = 0x9 (1 bytes)
  1588. // config2: int8 = 0xfb (1 bytes)
  1589. // config3: int8 = 0x60 (1 bytes)
  1590. // config4: const = 0x0 (4 bytes)
  1591. // sample_freq: int64 = 0x7 (8 bytes)
  1592. // sample_type: perf_sample_type = 0x95100 (8 bytes)
  1593. // read_format: perf_read_format = 0x1 (8 bytes)
  1594. // disabled: int64 = 0x0 (0 bytes)
  1595. // inherit: int64 = 0x1 (0 bytes)
  1596. // pinned: int64 = 0x1 (0 bytes)
  1597. // exclusive: int64 = 0x1 (0 bytes)
  1598. // exclude_user: int64 = 0x0 (0 bytes)
  1599. // exclude_kernel: int64 = 0x1 (0 bytes)
  1600. // exclude_hv: int64 = 0x0 (0 bytes)
  1601. // exclude_idle: int64 = 0x0 (0 bytes)
  1602. // mmap: int64 = 0x0 (0 bytes)
  1603. // comm: int64 = 0x0 (0 bytes)
  1604. // freq: int64 = 0x0 (0 bytes)
  1605. // inherit_stat: int64 = 0x0 (0 bytes)
  1606. // enable_on_exec: int64 = 0x1 (0 bytes)
  1607. // task: int64 = 0x1 (0 bytes)
  1608. // watermark: int64 = 0x1 (0 bytes)
  1609. // precise_ip: int64 = 0x0 (0 bytes)
  1610. // mmap_data: int64 = 0x1 (0 bytes)
  1611. // sample_id_all: int64 = 0x1 (0 bytes)
  1612. // exclude_host: int64 = 0x0 (0 bytes)
  1613. // exclude_guest: int64 = 0x0 (0 bytes)
  1614. // exclude_callchain_kernel: int64 = 0x1 (0 bytes)
  1615. // exclude_callchain_user: int64 = 0x1 (0 bytes)
  1616. // mmap2: int64 = 0x1 (0 bytes)
  1617. // comm_exec: int64 = 0x0 (0 bytes)
  1618. // use_clockid: int64 = 0x0 (0 bytes)
  1619. // context_switch: int64 = 0x1 (0 bytes)
  1620. // write_backward: int64 = 0x0 (0 bytes)
  1621. // namespaces: int64 = 0x1 (0 bytes)
  1622. // ksymbol: int64 = 0x1 (0 bytes)
  1623. // bpf_event: int64 = 0x0 (0 bytes)
  1624. // aux_output: int64 = 0x0 (0 bytes)
  1625. // cgroup: int64 = 0x1 (0 bytes)
  1626. // text_poke: int64 = 0x0 (0 bytes)
  1627. // build_id: int64 = 0x1 (0 bytes)
  1628. // inherit_thread: int64 = 0x0 (0 bytes)
  1629. // remove_on_exec: int64 = 0x0 (0 bytes)
  1630. // sigtrap: int64 = 0x0 (0 bytes)
  1631. // __reserved_1: const = 0x0 (8 bytes)
  1632. // wakeup_events: int32 = 0xffffffff (4 bytes)
  1633. // bp_type: perf_bp_type = 0x1 (4 bytes)
  1634. // bp_config: union perf_bp_config {
  1635. // perf_config_ext: perf_config_ext {
  1636. // config1: int64 = 0x0 (8 bytes)
  1637. // config2: int64 = 0x20 (8 bytes)
  1638. // }
  1639. // }
  1640. // branch_sample_type: perf_branch_sample_type = 0x188 (8 bytes)
  1641. // sample_regs_user: int64 = 0x61 (8 bytes)
  1642. // sample_stack_user: int32 = 0x9 (4 bytes)
  1643. // clockid: clock_type = 0x9 (4 bytes)
  1644. // sample_regs_intr: int64 = 0x5197 (8 bytes)
  1645. // aux_watermark: int32 = 0x0 (4 bytes)
  1646. // sample_max_stack: int16 = 0xd (2 bytes)
  1647. // __reserved_2: const = 0x0 (2 bytes)
  1648. // aux_sample_size: int32 = 0x0 (4 bytes)
  1649. // __reserved_3: const = 0x0 (4 bytes)
  1650. // sig_data: int64 = 0x7ff (8 bytes)
  1651. // }
  1652. // }
  1653. // pid: pid (resource)
  1654. // cpu: intptr = 0x0 (8 bytes)
  1655. // group: fd_perf (resource)
  1656. // flags: perf_flags = 0x8 (8 bytes)
  1657. // ]
  1658. // returns fd_perf
  1659. *(uint32_t*)0x2000000007c0 = 4;
  1660. *(uint32_t*)0x2000000007c4 = 0x80;
  1661. *(uint8_t*)0x2000000007c8 = 7;
  1662. *(uint8_t*)0x2000000007c9 = 9;
  1663. *(uint8_t*)0x2000000007ca = 0xfb;
  1664. *(uint8_t*)0x2000000007cb = 0x60;
  1665. *(uint32_t*)0x2000000007cc = 0;
  1666. *(uint64_t*)0x2000000007d0 = 7;
  1667. *(uint64_t*)0x2000000007d8 = 0x95100;
  1668. *(uint64_t*)0x2000000007e0 = 1;
  1669. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 0, 1);
  1670. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 1, 1);
  1671. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 2, 1);
  1672. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 3, 1);
  1673. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 4, 1);
  1674. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 5, 1);
  1675. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 6, 1);
  1676. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 7, 1);
  1677. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 8, 1);
  1678. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 9, 1);
  1679. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 10, 1);
  1680. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 11, 1);
  1681. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 12, 1);
  1682. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 13, 1);
  1683. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 14, 1);
  1684. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 15, 2);
  1685. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 17, 1);
  1686. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 18, 1);
  1687. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 19, 1);
  1688. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 20, 1);
  1689. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 21, 1);
  1690. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 22, 1);
  1691. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 23, 1);
  1692. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 24, 1);
  1693. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 25, 1);
  1694. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 26, 1);
  1695. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 27, 1);
  1696. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 28, 1);
  1697. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 29, 1);
  1698. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 30, 1);
  1699. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 31, 1);
  1700. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 32, 1);
  1701. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 33, 1);
  1702. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 1, 34, 1);
  1703. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 35, 1);
  1704. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 36, 1);
  1705. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 37, 1);
  1706. STORE_BY_BITMASK(uint64_t, , 0x2000000007e8, 0, 38, 26);
  1707. *(uint32_t*)0x2000000007f0 = -1;
  1708. *(uint32_t*)0x2000000007f4 = 1;
  1709. *(uint64_t*)0x2000000007f8 = 0;
  1710. *(uint64_t*)0x200000000800 = 0x20;
  1711. *(uint64_t*)0x200000000808 = 0x188;
  1712. *(uint64_t*)0x200000000810 = 0x61;
  1713. *(uint32_t*)0x200000000818 = 9;
  1714. *(uint32_t*)0x20000000081c = 9;
  1715. *(uint64_t*)0x200000000820 = 0x5197;
  1716. *(uint32_t*)0x200000000828 = 0;
  1717. *(uint16_t*)0x20000000082c = 0xd;
  1718. *(uint16_t*)0x20000000082e = 0;
  1719. *(uint32_t*)0x200000000830 = 0;
  1720. *(uint32_t*)0x200000000834 = 0;
  1721. *(uint64_t*)0x200000000838 = 0x7ff;
  1722. res = syscall(__NR_perf_event_open, /*attr=*/0x2000000007c0ul, /*pid=*/0,
  1723. /*cpu=*/0ul, /*group=*/(intptr_t)-1,
  1724. /*flags=PERF_FLAG_FD_CLOEXEC*/ 8ul);
  1725. if (res != -1)
  1726. r[0] = res;
  1727. // mmap$perf arguments: [
  1728. // addr: VMA[0x2000]
  1729. // len: len = 0x2000 (8 bytes)
  1730. // prot: mmap_prot = 0x2000000 (8 bytes)
  1731. // flags: mmap_flags = 0x11 (8 bytes)
  1732. // fd: fd_perf (resource)
  1733. // offset: intptr = 0x0 (8 bytes)
  1734. // ]
  1735. syscall(__NR_mmap, /*addr=*/0x200000ffd000ul, /*len=*/0x2000ul,
  1736. /*prot=PROT_GROWSUP*/ 0x2000000ul,
  1737. /*flags=MAP_FIXED|MAP_SHARED*/ 0x11ul, /*fd=*/r[0], /*offset=*/0ul);
  1738. // socket$inet arguments: [
  1739. // domain: const = 0x2 (8 bytes)
  1740. // type: socket_type = 0x1 (8 bytes)
  1741. // proto: int32 = 0x0 (4 bytes)
  1742. // ]
  1743. // returns sock_in
  1744. res = syscall(__NR_socket, /*domain=*/2ul, /*type=SOCK_STREAM*/ 1ul,
  1745. /*proto=*/0);
  1746. if (res != -1)
  1747. r[1] = res;
  1748. // ioctl$SIOCGSTAMP arguments: [
  1749. // fd: sock (resource)
  1750. // cmd: const = 0x80108907 (4 bytes)
  1751. // arg: nil
  1752. // ]
  1753. syscall(__NR_ioctl, /*fd=*/(intptr_t)-1, /*cmd=*/0x80108907, /*arg=*/0ul);
  1754. // perf_event_open arguments: [
  1755. // attr: nil
  1756. // pid: pid (resource)
  1757. // cpu: intptr = 0xffffffffffffffff (8 bytes)
  1758. // group: fd_perf (resource)
  1759. // flags: perf_flags = 0x0 (8 bytes)
  1760. // ]
  1761. // returns fd_perf
  1762. syscall(__NR_perf_event_open, /*attr=*/0ul, /*pid=*/0, /*cpu=*/(intptr_t)-1,
  1763. /*group=*/(intptr_t)-1, /*flags=*/0ul);
  1764. // sendmsg$nl_xfrm arguments: [
  1765. // fd: sock_nl_xfrm (resource)
  1766. // msg: nil
  1767. // f: send_flags = 0x0 (8 bytes)
  1768. // ]
  1769. syscall(__NR_sendmsg, /*fd=*/(intptr_t)-1, /*msg=*/0ul, /*f=*/0ul);
  1770. // bind$inet arguments: [
  1771. // fd: sock_in (resource)
  1772. // addr: nil
  1773. // addrlen: len = 0x0 (8 bytes)
  1774. // ]
  1775. syscall(__NR_bind, /*fd=*/r[1], /*addr=*/0ul, /*addrlen=*/0ul);
  1776. // socket$nl_netfilter arguments: [
  1777. // domain: const = 0x10 (8 bytes)
  1778. // type: const = 0x3 (8 bytes)
  1779. // proto: const = 0xc (4 bytes)
  1780. // ]
  1781. // returns sock_nl_netfilter
  1782. res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0xc);
  1783. if (res != -1)
  1784. r[2] = res;
  1785. // sendmsg$IPCTNL_MSG_CT_NEW arguments: [
  1786. // fd: sock_nl_netfilter (resource)
  1787. // msg: nil
  1788. // f: send_flags = 0x0 (8 bytes)
  1789. // ]
  1790. syscall(__NR_sendmsg, /*fd=*/r[2], /*msg=*/0ul, /*f=*/0ul);
  1791. // sendto$inet arguments: [
  1792. // fd: sock_in (resource)
  1793. // buf: nil
  1794. // len: len = 0x0 (8 bytes)
  1795. // f: send_flags = 0x200007fd (8 bytes)
  1796. // addr: nil
  1797. // addrlen: len = 0x0 (8 bytes)
  1798. // ]
  1799. syscall(
  1800. __NR_sendto, /*fd=*/r[1], /*buf=*/0ul, /*len=*/0ul,
  1801. /*f=MSG_FASTOPEN|MSG_PROBE|MSG_OOB|MSG_EOR|MSG_DONTWAIT|MSG_DONTROUTE|0x728*/
  1802. 0x200007fdul, /*addr=*/0ul, /*addrlen=*/0ul);
  1803. // sendto$inet arguments: [
  1804. // fd: sock_in (resource)
  1805. // buf: nil
  1806. // len: len = 0x0 (8 bytes)
  1807. // f: send_flags = 0x200007fd (8 bytes)
  1808. // addr: nil
  1809. // addrlen: len = 0x0 (8 bytes)
  1810. // ]
  1811. syscall(
  1812. __NR_sendto, /*fd=*/r[1], /*buf=*/0ul, /*len=*/0ul,
  1813. /*f=MSG_FASTOPEN|MSG_PROBE|MSG_OOB|MSG_EOR|MSG_DONTWAIT|MSG_DONTROUTE|0x728*/
  1814. 0x200007fdul, /*addr=*/0ul, /*addrlen=*/0ul);
  1815. // sendto$inet arguments: [
  1816. // fd: sock_in (resource)
  1817. // buf: nil
  1818. // len: len = 0x0 (8 bytes)
  1819. // f: send_flags = 0xc840 (8 bytes)
  1820. // addr: nil
  1821. // addrlen: len = 0x0 (8 bytes)
  1822. // ]
  1823. syscall(__NR_sendto, /*fd=*/(intptr_t)-1, /*buf=*/0ul, /*len=*/0ul,
  1824. /*f=MSG_NOSIGNAL|MSG_MORE|MSG_DONTWAIT|MSG_CONFIRM*/ 0xc840ul,
  1825. /*addr=*/0ul, /*addrlen=*/0ul);
  1826. // creat arguments: [
  1827. // file: nil
  1828. // mode: open_mode = 0x0 (8 bytes)
  1829. // ]
  1830. // returns fd
  1831. syscall(__NR_creat, /*file=*/0ul, /*mode=*/0ul);
  1832. // ioctl$TIOCGSID arguments: [
  1833. // fd: fd_tty (resource)
  1834. // cmd: const = 0x5429 (4 bytes)
  1835. // arg: nil
  1836. // ]
  1837. syscall(__NR_ioctl, /*fd=*/(intptr_t)-1, /*cmd=*/0x5429, /*arg=*/0ul);
  1838. }
  1839. int main(void)
  1840. {
  1841. syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  1842. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  1843. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  1844. syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul,
  1845. /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
  1846. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  1847. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  1848. syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
  1849. /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
  1850. /*fd=*/(intptr_t)-1, /*offset=*/0ul);
  1851. const char* reason;
  1852. (void)reason;
  1853. if ((reason = setup_binfmt_misc()))
  1854. printf("the reproducer may not work as expected: binfmt_misc setup failed: "
  1855. "%s\n",
  1856. reason);
  1857. if ((reason = setup_swap()))
  1858. printf("the reproducer may not work as expected: swap setup failed: %s\n",
  1859. reason);
  1860. for (procid = 0; procid < 4; procid++) {
  1861. if (fork() == 0) {
  1862. use_temporary_dir();
  1863. do_sandbox_none();
  1864. }
  1865. }
  1866. sleep(1000000);
  1867. return 0;
  1868. }
  1869.  
Advertisement
Add Comment
Please, Sign In to add comment