Skip to content

Commit f3e93a7

Browse files
committed
Revert "bpf: precise scalar_value tracking"
ANBZ: torvalds#342 This reverts commit 074d356. The commit 565c32b ("bpf: track spill/fill of constants") is backported from upstream kernel-4.19.y stable branch to fix cve, but it suffer serious degradation in the number of states processed and corresponding verification time increase. Loading cilium's bpf_lxc.o would fail beacause insn_processed exceeded BPF_COMPLEXITY_LIMIT_INSNS due to such degradation. To fix this problem, follow-up optimization patch 074d356 ("bpf:precise scalar_value tracking") was introduced. However, subsequent bug-fix patches was forgotten, caused bpf verifier incorrectly prune states, and some bpf instructions was misjudged as dead code, so the kernel was eventually soft lockup due to bpf verifier's dead-code overwritten. There are 3 ways to fix dead-code misjudgment problem: 1. backport follow-up bug-fix patches. 2. increase the number of BPF_COMPLEXITY_LIMIT_INSNS. 3. revert the cve-fix patches The first ways is more elegant, but is more risky. The bug-fix patches are: - a3ce685 ("bpf: fix precision tracking") - b3b50f0 ("bpf: fix precision bit propagation for BPF_ST instructions") - 6754172 ("bpf: fix precision tracking in presence of bpf2bpf calls") - 2339cd6 ("bpf: fix precision tracking of stack slots") - f54c789 ("bpf: Fix precision tracking for unbounded scalars") To make these patches work, one more seems irrelevant patch need to be backported too: 9242b5f ("bpf: add self-check logic to liveness analysis"). These patches modified too much code, and it is hard to ensure they won't introduce other bugs, so it is a risky solution. The second way could mitigate such degradation a little. Processing cilium bpf_lxc.o with 2900+ instructions, the statistics data is: cve-not-fixed cve-fixed fixed-with-optimization processed-insns 39024 293776 212987 verify-time 150+ms 3.6s 2.5s So the most practical solution is third way. Signed-off-by: Qiao Ma <[email protected]> Acked-by: Mao Wenan <[email protected]> Acked-by: Tony Lu <[email protected]>
1 parent f807751 commit f3e93a7

File tree

2 files changed

+14
-519
lines changed

2 files changed

+14
-519
lines changed

include/linux/bpf_verifier.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ struct bpf_reg_state {
8989
*/
9090
u32 frameno;
9191
enum bpf_reg_liveness live;
92-
/* if (!precise && SCALAR_VALUE) min/max/tnum don't affect safety */
93-
bool precise;
9492
};
9593

9694
enum bpf_stack_slot_type {
@@ -134,31 +132,14 @@ struct bpf_id_pair {
134132
u32 cur;
135133
};
136134

137-
struct bpf_idx_pair {
138-
u32 prev_idx;
139-
u32 idx;
140-
};
141-
142135
/* Maximum number of register states that can exist at once */
143136
#define BPF_ID_MAP_SIZE (MAX_BPF_REG + MAX_BPF_STACK / BPF_REG_SIZE)
144137
#define MAX_CALL_FRAMES 8
145138
struct bpf_verifier_state {
146139
/* call stack tracking */
147140
struct bpf_func_state *frame[MAX_CALL_FRAMES];
148-
struct bpf_verifier_state *parent;
149141
u32 curframe;
150142
bool speculative;
151-
152-
/* first and last insn idx of this verifier state */
153-
u32 first_insn_idx;
154-
u32 last_insn_idx;
155-
/* jmp history recorded from first to last.
156-
* backtracking is using it to go from last to first.
157-
* For most states jmp_history_cnt is [0-3].
158-
* For loops can go up to ~40.
159-
*/
160-
struct bpf_idx_pair *jmp_history;
161-
u32 jmp_history_cnt;
162143
};
163144

164145
/* linked list of verifier states used to prune search */

0 commit comments

Comments
 (0)