Eduard Zingerman
4bf79f9be4
bpf: Track equal scalars history on per-instruction level
...
Use bpf_verifier_state->jmp_history to track which registers were
updated by find_equal_scalars() (renamed to collect_linked_regs())
when conditional jump was verified. Use recorded information in
backtrack_insn() to propagate precision.
E.g. for the following program:
while verifying instructions
1: r1 = r0 |
2: if r1 < 8 goto ... | push r0,r1 as linked registers in jmp_history
3: if r0 > 16 goto ... | push r0,r1 as linked registers in jmp_history
4: r2 = r10 |
5: r2 += r0 v mark_chain_precision(r0)
while doing mark_chain_precision(r0)
5: r2 += r0 | mark r0 precise
4: r2 = r10 |
3: if r0 > 16 goto ... | mark r0,r1 as precise
2: if r1 < 8 goto ... | mark r0,r1 as precise
1: r1 = r0 v
Technically, do this as follows:
- Use 10 bits to identify each register that gains range because of
sync_linked_regs():
- 3 bits for frame number;
- 6 bits for register or stack slot number;
- 1 bit to indicate if register is spilled.
- Use u64 as a vector of 6 such records + 4 bits for vector length.
- Augment struct bpf_jmp_history_entry with a field 'linked_regs'
representing such vector.
- When doing check_cond_jmp_op() remember up to 6 registers that
gain range because of sync_linked_regs() in such a vector.
- Don't propagate range information and reset IDs for registers that
don't fit in 6-value vector.
- Push a pair {instruction index, linked registers vector}
to bpf_verifier_state->jmp_history.
- When doing backtrack_insn() check if any of recorded linked
registers is currently marked precise, if so mark all linked
registers as precise.
This also requires fixes for two test_verifier tests:
- precise: test 1
- precise: test 2
Both tests contain the following instruction sequence:
19: (bf) r2 = r9 ; R2=scalar(id=3) R9=scalar(id=3)
20: (a5) if r2 < 0x8 goto pc+1 ; R2=scalar(id=3,umin=8)
21: (95) exit
22: (07) r2 += 1 ; R2_w=scalar(id=3+1,...)
23: (bf) r1 = r10 ; R1_w=fp0 R10=fp0
24: (07) r1 += -8 ; R1_w=fp-8
25: (b7) r3 = 0 ; R3_w=0
26: (85) call bpf_probe_read_kernel#113
The call to bpf_probe_read_kernel() at (26) forces r2 to be precise.
Previously, this forced all registers with same id to become precise
immediately when mark_chain_precision() is called.
After this change, the precision is propagated to registers sharing
same id only when 'if' instruction is backtracked.
Hence verification log for both tests is changed:
regs=r2,r9 -> regs=r2 for instructions 25..20.
Fixes: 904e6ddf41 ("bpf: Use scalar ids in mark_chain_precision()")
Reported-by: Hao Sun <sunhao.th@gmail.com >
Suggested-by: Andrii Nakryiko <andrii@kernel.org >
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com >
Signed-off-by: Andrii Nakryiko <andrii@kernel.org >
Link: https://lore.kernel.org/bpf/20240718202357.1746514-2-eddyz87@gmail.com
Closes: https://lore.kernel.org/bpf/CAEf4BzZ0xidVCqB47XnkXcNhkPWF6_nTV7yt+_Lf0kcFEut2Mg@mail.gmail.com/
2024-07-29 12:53:10 -07:00
..
2024-06-05 15:52:34 +02:00
2024-07-15 08:02:26 -07:00
2024-07-03 15:16:54 +02:00
2024-07-10 09:41:57 +02:00
2024-07-15 08:49:59 -07:00
2024-07-19 12:39:34 -07:00
2024-07-03 15:16:54 +02:00
2024-07-02 11:40:37 +02:00
2024-06-23 09:53:32 +03:00
2024-07-03 15:16:54 +02:00
2024-06-30 11:29:24 +01:00
2024-07-22 13:52:05 -07:00
2024-07-18 09:34:02 -07:00
2024-07-04 12:29:07 +02:00
2024-07-19 11:57:55 -07:00
2024-05-16 08:56:49 -07:00
2024-05-27 13:39:51 +02:00
2024-07-05 09:35:51 +01:00
2024-07-03 14:07:14 +01:00
2024-07-20 03:07:55 +02:00
2024-07-05 18:30:00 -07:00
2024-06-12 09:20:13 +02:00
2024-06-26 20:09:28 +01:00
2024-05-23 12:04:36 -07:00
2024-07-25 10:42:22 -07:00
2024-07-25 10:42:22 -07:00
2024-07-25 10:42:22 -07:00
2024-07-03 15:16:54 +02:00
2024-07-18 17:17:30 -07:00
2024-07-10 13:56:22 +02:00
2024-07-22 13:52:05 -07:00
2024-07-17 21:05:18 -07:00
2024-07-25 10:42:22 -07:00
2024-07-25 10:42:22 -07:00
2024-07-04 16:45:25 +01:00
2024-07-13 21:31:57 -07:00
2024-07-03 10:21:16 -06:00
2024-07-03 10:21:15 -06:00
2024-05-21 15:29:01 -07:00
2024-07-19 09:32:49 -06:00
2024-07-03 10:21:15 -06:00
2024-07-19 09:32:49 -06:00
2024-07-22 11:32:05 -07:00
2024-07-29 12:53:10 -07:00
2024-07-21 17:15:46 -07:00
2024-07-14 20:38:34 -07:00
2024-07-09 17:01:46 +02:00
2024-07-03 19:29:59 -07:00
2024-07-08 01:51:05 -06:00
2024-07-10 10:19:59 -07:00
2024-07-21 17:56:22 -07:00
2024-06-17 17:45:34 +02:00
2024-05-15 10:05:24 -04:00
2024-07-22 11:32:05 -07:00
2024-06-24 22:25:02 -07:00
2024-07-16 16:42:37 -07:00
2024-06-24 22:25:02 -07:00
2024-06-03 11:18:50 +02:00
2024-06-03 11:18:50 +02:00
2024-07-10 09:53:39 -04:00
2024-06-24 18:29:20 +02:00
2024-05-09 09:25:08 -07:00
2024-06-14 19:08:32 +02:00
2024-05-22 14:12:11 -07:00
2024-07-18 10:33:14 -07:00
2024-07-21 17:56:22 -07:00
2024-06-17 20:42:57 +02:00
2024-05-08 09:53:00 -07:00
2024-06-24 22:25:02 -07:00
2024-06-24 22:25:02 -07:00
2024-07-21 17:56:22 -07:00
2024-07-09 17:58:20 +02:00
2024-07-15 15:03:09 -07:00
2024-06-17 17:45:31 +02:00
2024-06-24 22:25:01 -07:00
2024-07-21 17:56:22 -07:00
2024-07-10 13:19:50 -07:00
2024-07-03 19:30:13 -07:00
2024-07-15 11:39:44 -07:00
2024-06-30 12:27:16 +01:00
2024-06-12 11:29:36 -04:00
2024-07-19 10:48:44 -07:00
2024-06-20 12:51:42 +02:00
2024-05-14 11:43:40 +02:00
2024-07-03 15:16:54 +02:00
2024-06-25 17:15:06 -07:00
2024-07-10 15:38:14 +02:00
2024-06-11 12:57:49 -05:00
2024-05-27 09:50:05 +02:00
2024-07-12 15:52:20 -07:00
2024-05-06 13:28:59 -07:00
2024-06-19 20:05:34 +05:30
2024-05-20 10:23:39 -07:00
2024-05-09 19:00:29 +02:00
2024-06-21 15:40:55 +05:30
2024-07-12 10:06:01 +02:00
2024-07-03 15:16:54 +02:00
2024-05-25 10:48:57 -07:00
2024-07-15 08:02:30 -07:00
2024-05-14 00:31:43 -07:00
2024-05-28 15:57:23 +02:00
2024-07-10 23:15:36 +00:00
2024-07-17 21:05:18 -07:00
2024-05-27 11:08:31 +02:00
2024-06-28 10:36:45 +02:00
2024-07-09 17:01:46 +02:00
2024-05-21 15:29:01 -07:00
2024-05-06 11:06:04 +09:00
2024-06-07 23:14:45 +05:30
2024-06-19 13:32:04 -07:00
2024-05-19 14:36:17 -07:00
2024-07-02 06:20:49 +02:00
2024-07-15 14:20:22 -07:00
2024-07-03 10:36:14 +02:00
2024-07-03 15:16:54 +02:00
2024-06-05 09:52:38 +02:00
2024-06-18 16:25:50 +02:00
2024-07-24 20:59:29 +02:00
2024-07-03 15:16:54 +02:00
2024-07-03 19:29:52 -07:00
2024-05-27 16:50:03 +02:00
2024-07-03 15:16:54 +02:00
2024-07-21 17:15:46 -07:00
2024-06-27 11:00:45 +02:00
2024-07-03 19:30:06 -07:00
2024-07-06 11:53:19 -07:00
2024-07-12 15:52:23 -07:00
2024-07-17 21:08:54 -07:00
2024-06-16 13:41:53 +08:00
2024-06-03 20:25:28 -07:00
2024-05-29 12:52:26 -07:00
2024-07-03 15:16:54 +02:00
2024-05-13 16:13:19 +02:00
2024-07-25 10:42:22 -07:00
2024-06-12 13:04:25 +02:00
2024-07-12 16:39:52 -07:00
2024-07-08 16:22:49 -07:00
2024-06-21 14:52:12 +02:00
2024-05-31 16:28:19 +03:00
2024-07-08 11:40:57 -05:00
2024-07-22 13:52:05 -07:00
2024-07-15 13:49:10 -07:00
2024-07-03 15:45:47 +01:00
2024-05-19 09:21:03 -07:00
2024-07-19 09:59:58 -07:00
2024-05-28 11:14:14 -05:00
2024-05-07 13:29:45 +02:00
2024-07-04 09:25:59 +02:00
2024-06-17 20:46:39 +02:00
2024-05-15 17:02:08 -05:00
2024-07-15 15:13:56 +02:00
2024-07-21 17:15:46 -07:00
2024-06-24 22:24:56 -07:00
2024-06-17 12:30:07 -07:00
2024-06-24 22:25:02 -07:00
2024-05-19 14:02:03 -07:00
2024-05-22 11:53:02 -07:00
2024-07-03 19:30:22 -07:00
2024-07-03 19:30:23 -07:00
2024-05-16 07:23:30 +09:00
2024-06-05 19:19:26 -07:00
2024-07-16 09:51:36 -04:00
2024-07-04 17:07:01 +01:00
2024-07-04 11:52:32 +02:00
2024-06-13 23:05:27 +02:00
2024-07-10 12:14:54 -07:00
2024-05-09 15:48:01 +02:00
2024-06-24 16:41:22 -07:00
2024-06-24 16:41:22 -07:00
2024-07-14 19:00:16 -04:00
2024-07-18 17:27:43 -07:00
2024-07-16 14:50:44 -07:00
2024-07-03 15:16:54 +02:00
2024-05-07 15:17:52 -07:00
2024-06-10 19:52:44 -07:00
2024-07-01 19:28:58 +01:00
2024-07-03 15:16:54 +02:00
2024-07-03 15:16:54 +02:00
2024-07-21 17:15:46 -07:00
2024-07-10 12:14:54 -07:00
2024-07-12 15:52:09 -07:00
2024-07-03 19:30:18 -07:00
2024-07-12 15:52:20 -07:00
2024-07-03 15:16:54 +02:00
2024-07-25 10:42:22 -07:00
2024-07-03 19:30:12 -07:00
2024-07-06 11:53:20 -07:00
2024-07-15 08:02:26 -07:00
2024-06-24 22:24:59 -07:00
2024-07-12 06:45:23 -10:00
2024-07-21 17:15:46 -07:00
2024-07-24 20:59:29 +02:00
2024-07-06 11:44:41 -07:00
2024-05-22 11:31:10 +02:00
2024-07-23 11:43:40 -07:00
2024-05-14 00:31:43 -07:00
2024-07-03 15:16:54 +02:00
2024-05-15 17:02:08 -05:00
2024-07-22 14:02:19 -07:00
2024-06-05 17:03:57 +02:00
2024-07-03 15:16:54 +02:00
2024-07-15 08:02:26 -07:00
2024-05-13 18:19:09 -06:00
2024-06-24 16:41:23 -07:00
2024-07-11 18:11:31 -07:00
2024-05-28 14:34:15 +02:00
2024-06-10 13:15:40 +01:00
2024-07-08 13:47:25 -04:00
2024-07-08 13:47:27 -04:00
2024-05-20 11:09:20 -04:00
2024-07-08 13:47:51 -04:00
2024-07-08 13:47:26 -04:00
2024-05-08 08:41:29 -07:00
2024-06-24 22:25:02 -07:00
2024-06-28 10:37:29 +02:00
2024-06-16 10:17:57 +03:00
2024-07-21 17:56:22 -07:00
2024-07-15 14:20:22 -07:00
2024-06-10 11:14:52 +01:00
2024-07-08 17:40:30 -06:00
2024-05-19 22:29:43 -05:00
2024-07-12 15:52:20 -07:00
2024-07-03 22:40:38 -07:00
2024-07-03 19:30:20 -07:00
2024-07-23 15:15:16 -07:00
2024-06-24 22:25:05 -07:00
2024-07-03 16:44:22 +02:00
2024-06-28 09:52:05 +02:00
2024-07-19 12:39:34 -07:00
2024-07-04 14:40:53 +00:00
2024-07-25 10:42:22 -07:00
2024-06-12 13:20:56 +02:00
2024-07-25 10:42:22 -07:00
2024-06-17 15:15:46 +02:00
2024-06-17 15:15:46 +02:00
2024-07-03 19:30:02 -07:00
2024-06-24 22:25:02 -07:00
2024-07-24 20:59:29 +02:00
2024-07-17 21:05:19 -07:00
2024-07-12 15:52:15 -07:00
2024-07-25 10:42:22 -07:00
2024-06-18 13:28:26 +02:00
2024-05-27 10:34:35 +02:00
2024-07-21 17:56:22 -07:00
2024-06-26 11:17:20 +05:30
2024-07-03 15:16:54 +02:00
2024-07-21 17:56:22 -07:00
2024-06-26 17:32:00 +02:00
2024-06-05 16:52:36 +02:00
2024-07-25 13:18:41 -07:00
2024-06-24 22:25:02 -07:00
2024-06-07 19:46:39 +08:00
2024-05-12 04:09:30 -04:00
2024-07-10 17:52:47 +02:00
2024-07-13 21:36:36 -07:00
2024-06-03 17:26:26 -07:00
2024-07-21 17:56:22 -07:00
2024-07-10 23:05:45 +01:00
2024-07-02 19:49:54 +02:00
2024-05-13 18:09:56 -04:00
2024-07-03 15:16:54 +02:00
2024-07-03 19:30:18 -07:00
2024-07-19 09:39:32 -06:00
2024-07-10 07:59:03 +02:00
2024-07-21 17:56:22 -07:00
2024-07-03 15:16:54 +02:00
2024-06-18 14:04:03 +02:00
2024-07-24 20:59:29 +02:00
2024-06-24 22:25:02 -07:00
2024-06-24 16:14:48 +02:00
2024-06-24 16:09:37 +02:00
2024-07-03 15:16:54 +02:00
2024-06-28 10:48:23 +01:00
2024-07-12 15:52:21 -07:00
2024-07-02 18:59:33 -07:00
2024-07-21 17:15:46 -07:00
2024-07-12 15:52:20 -07:00
2024-07-21 17:15:46 -07:00
2024-07-03 15:16:54 +02:00
2024-07-16 19:28:34 -07:00
2024-06-05 16:52:36 +02:00
2024-07-20 12:41:03 -07:00
2024-06-20 15:19:17 -06:00
2024-05-04 18:57:21 +02:00
2024-07-05 09:35:51 +01:00
2024-06-24 22:25:02 -07:00
2024-06-06 08:55:20 -07:00
2024-07-06 11:44:41 -07:00
2024-07-12 15:52:15 -07:00
2024-07-10 07:59:03 +02:00
2024-06-10 15:03:30 -05:00
2024-07-18 12:19:20 -07:00
2024-07-24 20:59:29 +02:00
2024-06-04 15:56:45 +02:00
2024-07-04 02:02:33 -06:00
2024-07-09 13:26:34 +02:00
2024-07-03 15:16:54 +02:00
2024-07-03 15:16:54 +02:00
2024-07-12 15:14:56 +02:00
2024-05-06 17:39:09 +02:00
2024-06-21 18:10:15 +02:00
2024-06-03 11:18:51 +02:00
2024-06-24 22:25:02 -07:00
2024-07-05 02:12:27 +03:00
2024-06-04 10:37:44 -04:00
2024-06-24 22:25:02 -07:00
2024-06-17 20:42:57 +02:00
2024-05-04 18:45:11 +02:00
2024-05-06 12:05:00 +02:00
2024-07-01 15:46:36 +02:00
2024-05-15 12:34:46 -07:00
2024-06-12 08:44:28 +09:00
2024-07-10 13:58:24 +02:00
2024-07-19 20:22:12 +02:00
2024-06-21 12:47:01 -06:00
2024-05-31 15:15:51 -06:00
2024-07-17 05:20:58 -04:00
2024-07-04 11:00:31 -04:00
2024-07-03 15:16:54 +02:00
2024-07-24 20:59:29 +02:00
2024-05-27 13:51:29 +02:00
2024-06-24 20:36:08 +03:00
2024-06-24 18:16:44 +01:00
2024-07-21 17:56:22 -07:00
2024-07-24 20:59:29 +02:00
2024-05-19 09:21:03 -07:00
2024-07-10 10:25:54 +02:00
2024-07-10 12:14:55 -07:00