Skip to content

Commit 10d274e

Browse files
Alexei Starovoitovborkmann
authored andcommitted
bpf: introduce verifier internal test flag
Introduce BPF_F_TEST_STATE_FREQ flag to stress test parentage chain and state pruning. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 0bb52b0 commit 10d274e

4 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎include/linux/bpf_verifier.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ struct bpf_verifier_env {
355355
struct bpf_verifier_stack_elem *head; /* stack of verifier states to be processed */
356356
int stack_size; /* number of states to be processed */
357357
bool strict_alignment; /* perform strict pointer alignment checks */
358+
bool test_state_freq; /* test verifier with different pruning frequency */
358359
struct bpf_verifier_state *cur_state; /* current verifier state */
359360
struct bpf_verifier_state_list **explored_states; /* search pruning optimization */
360361
struct bpf_verifier_state_list *free_list;

‎include/uapi/linux/bpf.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ enum bpf_attach_type {
285285
*/
286286
#define BPF_F_TEST_RND_HI32 (1U << 2)
287287

288+
/* The verifier internal test flag. Behavior is undefined */
289+
#define BPF_F_TEST_STATE_FREQ (1U << 3)
290+
288291
/* When BPF ldimm64's insn[0].src_reg != 0 then this can have
289292
* two extensions:
290293
*

‎kernel/bpf/syscall.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,7 @@ static int bpf_prog_load(union bpf_attr *attr, union bpf_attr __user *uattr)
16291629

16301630
if (attr->prog_flags & ~(BPF_F_STRICT_ALIGNMENT |
16311631
BPF_F_ANY_ALIGNMENT |
1632+
BPF_F_TEST_STATE_FREQ |
16321633
BPF_F_TEST_RND_HI32))
16331634
return -EINVAL;
16341635

‎kernel/bpf/verifier.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7222,7 +7222,7 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx)
72227222
struct bpf_verifier_state_list *sl, **pprev;
72237223
struct bpf_verifier_state *cur = env->cur_state, *new;
72247224
int i, j, err, states_cnt = 0;
7225-
bool add_new_state = false;
7225+
bool add_new_state = env->test_state_freq ? true : false;
72267226

72277227
cur->last_insn_idx = env->prev_insn_idx;
72287228
if (!env->insn_aux_data[insn_idx].prune_point)
@@ -9262,6 +9262,9 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr,
92629262

92639263
env->allow_ptr_leaks = is_priv;
92649264

9265+
if (is_priv)
9266+
env->test_state_freq = attr->prog_flags & BPF_F_TEST_STATE_FREQ;
9267+
92659268
ret = replace_map_fd_with_map_ptr(env);
92669269
if (ret < 0)
92679270
goto skip_full_check;

0 commit comments

Comments
 (0)