verifier.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. =============
  2. eBPF verifier
  3. =============
  4. The safety of the eBPF program is determined in two steps.
  5. First step does DAG check to disallow loops and other CFG validation.
  6. In particular it will detect programs that have unreachable instructions.
  7. (though classic BPF checker allows them)
  8. Second step starts from the first insn and descends all possible paths.
  9. It simulates execution of every insn and observes the state change of
  10. registers and stack.
  11. At the start of the program the register R1 contains a pointer to context
  12. and has type PTR_TO_CTX.
  13. If verifier sees an insn that does R2=R1, then R2 has now type
  14. PTR_TO_CTX as well and can be used on the right hand side of expression.
  15. If R1=PTR_TO_CTX and insn is R2=R1+R1, then R2=SCALAR_VALUE,
  16. since addition of two valid pointers makes invalid pointer.
  17. (In 'secure' mode verifier will reject any type of pointer arithmetic to make
  18. sure that kernel addresses don't leak to unprivileged users)
  19. If register was never written to, it's not readable::
  20. bpf_mov R0 = R2
  21. bpf_exit
  22. will be rejected, since R2 is unreadable at the start of the program.
  23. After kernel function call, R1-R5 are reset to unreadable and
  24. R0 has a return type of the function.
  25. Since R6-R9 are callee saved, their state is preserved across the call.
  26. ::
  27. bpf_mov R6 = 1
  28. bpf_call foo
  29. bpf_mov R0 = R6
  30. bpf_exit
  31. is a correct program. If there was R1 instead of R6, it would have
  32. been rejected.
  33. load/store instructions are allowed only with registers of valid types, which
  34. are PTR_TO_CTX, PTR_TO_MAP, PTR_TO_STACK. They are bounds and alignment checked.
  35. For example::
  36. bpf_mov R1 = 1
  37. bpf_mov R2 = 2
  38. bpf_xadd *(u32 *)(R1 + 3) += R2
  39. bpf_exit
  40. will be rejected, since R1 doesn't have a valid pointer type at the time of
  41. execution of instruction bpf_xadd.
  42. At the start R1 type is PTR_TO_CTX (a pointer to generic ``struct bpf_context``)
  43. A callback is used to customize verifier to restrict eBPF program access to only
  44. certain fields within ctx structure with specified size and alignment.
  45. For example, the following insn::
  46. bpf_ld R0 = *(u32 *)(R6 + 8)
  47. intends to load a word from address R6 + 8 and store it into R0
  48. If R6=PTR_TO_CTX, via is_valid_access() callback the verifier will know
  49. that offset 8 of size 4 bytes can be accessed for reading, otherwise
  50. the verifier will reject the program.
  51. If R6=PTR_TO_STACK, then access should be aligned and be within
  52. stack bounds, which are [-MAX_BPF_STACK, 0). In this example offset is 8,
  53. so it will fail verification, since it's out of bounds.
  54. The verifier will allow eBPF program to read data from stack only after
  55. it wrote into it.
  56. Classic BPF verifier does similar check with M[0-15] memory slots.
  57. For example::
  58. bpf_ld R0 = *(u32 *)(R10 - 4)
  59. bpf_exit
  60. is invalid program.
  61. Though R10 is correct read-only register and has type PTR_TO_STACK
  62. and R10 - 4 is within stack bounds, there were no stores into that location.
  63. Pointer register spill/fill is tracked as well, since four (R6-R9)
  64. callee saved registers may not be enough for some programs.
  65. Allowed function calls are customized with bpf_verifier_ops->get_func_proto()
  66. The eBPF verifier will check that registers match argument constraints.
  67. After the call register R0 will be set to return type of the function.
  68. Function calls is a main mechanism to extend functionality of eBPF programs.
  69. Socket filters may let programs to call one set of functions, whereas tracing
  70. filters may allow completely different set.
  71. If a function made accessible to eBPF program, it needs to be thought through
  72. from safety point of view. The verifier will guarantee that the function is
  73. called with valid arguments.
  74. seccomp vs socket filters have different security restrictions for classic BPF.
  75. Seccomp solves this by two stage verifier: classic BPF verifier is followed
  76. by seccomp verifier. In case of eBPF one configurable verifier is shared for
  77. all use cases.
  78. See details of eBPF verifier in kernel/bpf/verifier.c
  79. Register value tracking
  80. =======================
  81. In order to determine the safety of an eBPF program, the verifier must track
  82. the range of possible values in each register and also in each stack slot.
  83. This is done with ``struct bpf_reg_state``, defined in include/linux/
  84. bpf_verifier.h, which unifies tracking of scalar and pointer values. Each
  85. register state has a type, which is either NOT_INIT (the register has not been
  86. written to), SCALAR_VALUE (some value which is not usable as a pointer), or a
  87. pointer type. The types of pointers describe their base, as follows:
  88. PTR_TO_CTX
  89. Pointer to bpf_context.
  90. CONST_PTR_TO_MAP
  91. Pointer to struct bpf_map. "Const" because arithmetic
  92. on these pointers is forbidden.
  93. PTR_TO_MAP_VALUE
  94. Pointer to the value stored in a map element.
  95. PTR_TO_MAP_VALUE_OR_NULL
  96. Either a pointer to a map value, or NULL; map accesses
  97. (see maps.rst) return this type, which becomes a
  98. PTR_TO_MAP_VALUE when checked != NULL. Arithmetic on
  99. these pointers is forbidden.
  100. PTR_TO_STACK
  101. Frame pointer.
  102. PTR_TO_PACKET
  103. skb->data.
  104. PTR_TO_PACKET_END
  105. skb->data + headlen; arithmetic forbidden.
  106. PTR_TO_SOCKET
  107. Pointer to struct bpf_sock_ops, implicitly refcounted.
  108. PTR_TO_SOCKET_OR_NULL
  109. Either a pointer to a socket, or NULL; socket lookup
  110. returns this type, which becomes a PTR_TO_SOCKET when
  111. checked != NULL. PTR_TO_SOCKET is reference-counted,
  112. so programs must release the reference through the
  113. socket release function before the end of the program.
  114. Arithmetic on these pointers is forbidden.
  115. However, a pointer may be offset from this base (as a result of pointer
  116. arithmetic), and this is tracked in two parts: the 'fixed offset' and 'variable
  117. offset'. The former is used when an exactly-known value (e.g. an immediate
  118. operand) is added to a pointer, while the latter is used for values which are
  119. not exactly known. The variable offset is also used in SCALAR_VALUEs, to track
  120. the range of possible values in the register.
  121. The verifier's knowledge about the variable offset consists of:
  122. * minimum and maximum values as unsigned
  123. * minimum and maximum values as signed
  124. * knowledge of the values of individual bits, in the form of a 'tnum': a u64
  125. 'mask' and a u64 'value'. 1s in the mask represent bits whose value is unknown;
  126. 1s in the value represent bits known to be 1. Bits known to be 0 have 0 in both
  127. mask and value; no bit should ever be 1 in both. For example, if a byte is read
  128. into a register from memory, the register's top 56 bits are known zero, while
  129. the low 8 are unknown - which is represented as the tnum (0x0; 0xff). If we
  130. then OR this with 0x40, we get (0x40; 0xbf), then if we add 1 we get (0x0;
  131. 0x1ff), because of potential carries.
  132. Besides arithmetic, the register state can also be updated by conditional
  133. branches. For instance, if a SCALAR_VALUE is compared > 8, in the 'true' branch
  134. it will have a umin_value (unsigned minimum value) of 9, whereas in the 'false'
  135. branch it will have a umax_value of 8. A signed compare (with BPF_JSGT or
  136. BPF_JSGE) would instead update the signed minimum/maximum values. Information
  137. from the signed and unsigned bounds can be combined; for instance if a value is
  138. first tested < 8 and then tested s> 4, the verifier will conclude that the value
  139. is also > 4 and s< 8, since the bounds prevent crossing the sign boundary.
  140. PTR_TO_PACKETs with a variable offset part have an 'id', which is common to all
  141. pointers sharing that same variable offset. This is important for packet range
  142. checks: after adding a variable to a packet pointer register A, if you then copy
  143. it to another register B and then add a constant 4 to A, both registers will
  144. share the same 'id' but the A will have a fixed offset of +4. Then if A is
  145. bounds-checked and found to be less than a PTR_TO_PACKET_END, the register B is
  146. now known to have a safe range of at least 4 bytes. See 'Direct packet access',
  147. below, for more on PTR_TO_PACKET ranges.
  148. The 'id' field is also used on PTR_TO_MAP_VALUE_OR_NULL, common to all copies of
  149. the pointer returned from a map lookup. This means that when one copy is
  150. checked and found to be non-NULL, all copies can become PTR_TO_MAP_VALUEs.
  151. As well as range-checking, the tracked information is also used for enforcing
  152. alignment of pointer accesses. For instance, on most systems the packet pointer
  153. is 2 bytes after a 4-byte alignment. If a program adds 14 bytes to that to jump
  154. over the Ethernet header, then reads IHL and addes (IHL * 4), the resulting
  155. pointer will have a variable offset known to be 4n+2 for some n, so adding the 2
  156. bytes (NET_IP_ALIGN) gives a 4-byte alignment and so word-sized accesses through
  157. that pointer are safe.
  158. The 'id' field is also used on PTR_TO_SOCKET and PTR_TO_SOCKET_OR_NULL, common
  159. to all copies of the pointer returned from a socket lookup. This has similar
  160. behaviour to the handling for PTR_TO_MAP_VALUE_OR_NULL->PTR_TO_MAP_VALUE, but
  161. it also handles reference tracking for the pointer. PTR_TO_SOCKET implicitly
  162. represents a reference to the corresponding ``struct sock``. To ensure that the
  163. reference is not leaked, it is imperative to NULL-check the reference and in
  164. the non-NULL case, and pass the valid reference to the socket release function.
  165. Direct packet access
  166. ====================
  167. In cls_bpf and act_bpf programs the verifier allows direct access to the packet
  168. data via skb->data and skb->data_end pointers.
  169. Ex::
  170. 1: r4 = *(u32 *)(r1 +80) /* load skb->data_end */
  171. 2: r3 = *(u32 *)(r1 +76) /* load skb->data */
  172. 3: r5 = r3
  173. 4: r5 += 14
  174. 5: if r5 > r4 goto pc+16
  175. R1=ctx R3=pkt(id=0,off=0,r=14) R4=pkt_end R5=pkt(id=0,off=14,r=14) R10=fp
  176. 6: r0 = *(u16 *)(r3 +12) /* access 12 and 13 bytes of the packet */
  177. this 2byte load from the packet is safe to do, since the program author
  178. did check ``if (skb->data + 14 > skb->data_end) goto err`` at insn #5 which
  179. means that in the fall-through case the register R3 (which points to skb->data)
  180. has at least 14 directly accessible bytes. The verifier marks it
  181. as R3=pkt(id=0,off=0,r=14).
  182. id=0 means that no additional variables were added to the register.
  183. off=0 means that no additional constants were added.
  184. r=14 is the range of safe access which means that bytes [R3, R3 + 14) are ok.
  185. Note that R5 is marked as R5=pkt(id=0,off=14,r=14). It also points
  186. to the packet data, but constant 14 was added to the register, so
  187. it now points to ``skb->data + 14`` and accessible range is [R5, R5 + 14 - 14)
  188. which is zero bytes.
  189. More complex packet access may look like::
  190. R0=inv1 R1=ctx R3=pkt(id=0,off=0,r=14) R4=pkt_end R5=pkt(id=0,off=14,r=14) R10=fp
  191. 6: r0 = *(u8 *)(r3 +7) /* load 7th byte from the packet */
  192. 7: r4 = *(u8 *)(r3 +12)
  193. 8: r4 *= 14
  194. 9: r3 = *(u32 *)(r1 +76) /* load skb->data */
  195. 10: r3 += r4
  196. 11: r2 = r1
  197. 12: r2 <<= 48
  198. 13: r2 >>= 48
  199. 14: r3 += r2
  200. 15: r2 = r3
  201. 16: r2 += 8
  202. 17: r1 = *(u32 *)(r1 +80) /* load skb->data_end */
  203. 18: if r2 > r1 goto pc+2
  204. R0=inv(id=0,umax_value=255,var_off=(0x0; 0xff)) R1=pkt_end R2=pkt(id=2,off=8,r=8) R3=pkt(id=2,off=0,r=8) R4=inv(id=0,umax_value=3570,var_off=(0x0; 0xfffe)) R5=pkt(id=0,off=14,r=14) R10=fp
  205. 19: r1 = *(u8 *)(r3 +4)
  206. The state of the register R3 is R3=pkt(id=2,off=0,r=8)
  207. id=2 means that two ``r3 += rX`` instructions were seen, so r3 points to some
  208. offset within a packet and since the program author did
  209. ``if (r3 + 8 > r1) goto err`` at insn #18, the safe range is [R3, R3 + 8).
  210. The verifier only allows 'add'/'sub' operations on packet registers. Any other
  211. operation will set the register state to 'SCALAR_VALUE' and it won't be
  212. available for direct packet access.
  213. Operation ``r3 += rX`` may overflow and become less than original skb->data,
  214. therefore the verifier has to prevent that. So when it sees ``r3 += rX``
  215. instruction and rX is more than 16-bit value, any subsequent bounds-check of r3
  216. against skb->data_end will not give us 'range' information, so attempts to read
  217. through the pointer will give "invalid access to packet" error.
  218. Ex. after insn ``r4 = *(u8 *)(r3 +12)`` (insn #7 above) the state of r4 is
  219. R4=inv(id=0,umax_value=255,var_off=(0x0; 0xff)) which means that upper 56 bits
  220. of the register are guaranteed to be zero, and nothing is known about the lower
  221. 8 bits. After insn ``r4 *= 14`` the state becomes
  222. R4=inv(id=0,umax_value=3570,var_off=(0x0; 0xfffe)), since multiplying an 8-bit
  223. value by constant 14 will keep upper 52 bits as zero, also the least significant
  224. bit will be zero as 14 is even. Similarly ``r2 >>= 48`` will make
  225. R2=inv(id=0,umax_value=65535,var_off=(0x0; 0xffff)), since the shift is not sign
  226. extending. This logic is implemented in adjust_reg_min_max_vals() function,
  227. which calls adjust_ptr_min_max_vals() for adding pointer to scalar (or vice
  228. versa) and adjust_scalar_min_max_vals() for operations on two scalars.
  229. The end result is that bpf program author can access packet directly
  230. using normal C code as::
  231. void *data = (void *)(long)skb->data;
  232. void *data_end = (void *)(long)skb->data_end;
  233. struct eth_hdr *eth = data;
  234. struct iphdr *iph = data + sizeof(*eth);
  235. struct udphdr *udp = data + sizeof(*eth) + sizeof(*iph);
  236. if (data + sizeof(*eth) + sizeof(*iph) + sizeof(*udp) > data_end)
  237. return 0;
  238. if (eth->h_proto != htons(ETH_P_IP))
  239. return 0;
  240. if (iph->protocol != IPPROTO_UDP || iph->ihl != 5)
  241. return 0;
  242. if (udp->dest == 53 || udp->source == 9)
  243. ...;
  244. which makes such programs easier to write comparing to LD_ABS insn
  245. and significantly faster.
  246. Pruning
  247. =======
  248. The verifier does not actually walk all possible paths through the program. For
  249. each new branch to analyse, the verifier looks at all the states it's previously
  250. been in when at this instruction. If any of them contain the current state as a
  251. subset, the branch is 'pruned' - that is, the fact that the previous state was
  252. accepted implies the current state would be as well. For instance, if in the
  253. previous state, r1 held a packet-pointer, and in the current state, r1 holds a
  254. packet-pointer with a range as long or longer and at least as strict an
  255. alignment, then r1 is safe. Similarly, if r2 was NOT_INIT before then it can't
  256. have been used by any path from that point, so any value in r2 (including
  257. another NOT_INIT) is safe. The implementation is in the function regsafe().
  258. Pruning considers not only the registers but also the stack (and any spilled
  259. registers it may hold). They must all be safe for the branch to be pruned.
  260. This is implemented in states_equal().
  261. Understanding eBPF verifier messages
  262. ====================================
  263. The following are few examples of invalid eBPF programs and verifier error
  264. messages as seen in the log:
  265. Program with unreachable instructions::
  266. static struct bpf_insn prog[] = {
  267. BPF_EXIT_INSN(),
  268. BPF_EXIT_INSN(),
  269. };
  270. Error::
  271. unreachable insn 1
  272. Program that reads uninitialized register::
  273. BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
  274. BPF_EXIT_INSN(),
  275. Error::
  276. 0: (bf) r0 = r2
  277. R2 !read_ok
  278. Program that doesn't initialize R0 before exiting::
  279. BPF_MOV64_REG(BPF_REG_2, BPF_REG_1),
  280. BPF_EXIT_INSN(),
  281. Error::
  282. 0: (bf) r2 = r1
  283. 1: (95) exit
  284. R0 !read_ok
  285. Program that accesses stack out of bounds::
  286. BPF_ST_MEM(BPF_DW, BPF_REG_10, 8, 0),
  287. BPF_EXIT_INSN(),
  288. Error::
  289. 0: (7a) *(u64 *)(r10 +8) = 0
  290. invalid stack off=8 size=8
  291. Program that doesn't initialize stack before passing its address into function::
  292. BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
  293. BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
  294. BPF_LD_MAP_FD(BPF_REG_1, 0),
  295. BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
  296. BPF_EXIT_INSN(),
  297. Error::
  298. 0: (bf) r2 = r10
  299. 1: (07) r2 += -8
  300. 2: (b7) r1 = 0x0
  301. 3: (85) call 1
  302. invalid indirect read from stack off -8+0 size 8
  303. Program that uses invalid map_fd=0 while calling to map_lookup_elem() function::
  304. BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
  305. BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
  306. BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
  307. BPF_LD_MAP_FD(BPF_REG_1, 0),
  308. BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
  309. BPF_EXIT_INSN(),
  310. Error::
  311. 0: (7a) *(u64 *)(r10 -8) = 0
  312. 1: (bf) r2 = r10
  313. 2: (07) r2 += -8
  314. 3: (b7) r1 = 0x0
  315. 4: (85) call 1
  316. fd 0 is not pointing to valid bpf_map
  317. Program that doesn't check return value of map_lookup_elem() before accessing
  318. map element::
  319. BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
  320. BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
  321. BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
  322. BPF_LD_MAP_FD(BPF_REG_1, 0),
  323. BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
  324. BPF_ST_MEM(BPF_DW, BPF_REG_0, 0, 0),
  325. BPF_EXIT_INSN(),
  326. Error::
  327. 0: (7a) *(u64 *)(r10 -8) = 0
  328. 1: (bf) r2 = r10
  329. 2: (07) r2 += -8
  330. 3: (b7) r1 = 0x0
  331. 4: (85) call 1
  332. 5: (7a) *(u64 *)(r0 +0) = 0
  333. R0 invalid mem access 'map_value_or_null'
  334. Program that correctly checks map_lookup_elem() returned value for NULL, but
  335. accesses the memory with incorrect alignment::
  336. BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
  337. BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
  338. BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
  339. BPF_LD_MAP_FD(BPF_REG_1, 0),
  340. BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
  341. BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 1),
  342. BPF_ST_MEM(BPF_DW, BPF_REG_0, 4, 0),
  343. BPF_EXIT_INSN(),
  344. Error::
  345. 0: (7a) *(u64 *)(r10 -8) = 0
  346. 1: (bf) r2 = r10
  347. 2: (07) r2 += -8
  348. 3: (b7) r1 = 1
  349. 4: (85) call 1
  350. 5: (15) if r0 == 0x0 goto pc+1
  351. R0=map_ptr R10=fp
  352. 6: (7a) *(u64 *)(r0 +4) = 0
  353. misaligned access off 4 size 8
  354. Program that correctly checks map_lookup_elem() returned value for NULL and
  355. accesses memory with correct alignment in one side of 'if' branch, but fails
  356. to do so in the other side of 'if' branch::
  357. BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
  358. BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
  359. BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
  360. BPF_LD_MAP_FD(BPF_REG_1, 0),
  361. BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
  362. BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 2),
  363. BPF_ST_MEM(BPF_DW, BPF_REG_0, 0, 0),
  364. BPF_EXIT_INSN(),
  365. BPF_ST_MEM(BPF_DW, BPF_REG_0, 0, 1),
  366. BPF_EXIT_INSN(),
  367. Error::
  368. 0: (7a) *(u64 *)(r10 -8) = 0
  369. 1: (bf) r2 = r10
  370. 2: (07) r2 += -8
  371. 3: (b7) r1 = 1
  372. 4: (85) call 1
  373. 5: (15) if r0 == 0x0 goto pc+2
  374. R0=map_ptr R10=fp
  375. 6: (7a) *(u64 *)(r0 +0) = 0
  376. 7: (95) exit
  377. from 5 to 8: R0=imm0 R10=fp
  378. 8: (7a) *(u64 *)(r0 +0) = 1
  379. R0 invalid mem access 'imm'
  380. Program that performs a socket lookup then sets the pointer to NULL without
  381. checking it::
  382. BPF_MOV64_IMM(BPF_REG_2, 0),
  383. BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_2, -8),
  384. BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
  385. BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
  386. BPF_MOV64_IMM(BPF_REG_3, 4),
  387. BPF_MOV64_IMM(BPF_REG_4, 0),
  388. BPF_MOV64_IMM(BPF_REG_5, 0),
  389. BPF_EMIT_CALL(BPF_FUNC_sk_lookup_tcp),
  390. BPF_MOV64_IMM(BPF_REG_0, 0),
  391. BPF_EXIT_INSN(),
  392. Error::
  393. 0: (b7) r2 = 0
  394. 1: (63) *(u32 *)(r10 -8) = r2
  395. 2: (bf) r2 = r10
  396. 3: (07) r2 += -8
  397. 4: (b7) r3 = 4
  398. 5: (b7) r4 = 0
  399. 6: (b7) r5 = 0
  400. 7: (85) call bpf_sk_lookup_tcp#65
  401. 8: (b7) r0 = 0
  402. 9: (95) exit
  403. Unreleased reference id=1, alloc_insn=7
  404. Program that performs a socket lookup but does not NULL-check the returned
  405. value::
  406. BPF_MOV64_IMM(BPF_REG_2, 0),
  407. BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_2, -8),
  408. BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
  409. BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
  410. BPF_MOV64_IMM(BPF_REG_3, 4),
  411. BPF_MOV64_IMM(BPF_REG_4, 0),
  412. BPF_MOV64_IMM(BPF_REG_5, 0),
  413. BPF_EMIT_CALL(BPF_FUNC_sk_lookup_tcp),
  414. BPF_EXIT_INSN(),
  415. Error::
  416. 0: (b7) r2 = 0
  417. 1: (63) *(u32 *)(r10 -8) = r2
  418. 2: (bf) r2 = r10
  419. 3: (07) r2 += -8
  420. 4: (b7) r3 = 4
  421. 5: (b7) r4 = 0
  422. 6: (b7) r5 = 0
  423. 7: (85) call bpf_sk_lookup_tcp#65
  424. 8: (95) exit
  425. Unreleased reference id=1, alloc_insn=7