Rename verifier internal flag BPF_F_TEST_SANITY_STRICT to more neutral BPF_F_TEST_REG_INVARIANTS. This is a follow up to [0]. A few selftests and veristat need to be adjusted in the same patch as well. [0] https://patchwork.kernel.org/project/netdevbpf/patch/20231112010609.848406-5-andrii@kernel.org/
Unified · Split
| @@ -602,7 +602,7 @@ struct bpf_verifier_env { · 601 unmodified lines | |||
| 602 | int stack_size; /* number of states to be processed */ | 602 | int stack_size; /* number of states to be processed */ |
| 603 | bool strict_alignment; /* perform strict pointer alignment checks */ | 603 | bool strict_alignment; /* perform strict pointer alignment checks */ |
| 604 | bool test_state_freq; /* test verifier with different pruning frequency */ | 604 | bool test_state_freq; /* test verifier with different pruning frequency */ |
| 605 | bool test_sanity_strict; /* fail verification on sanity violations */ | 605 | bool test_reg_invariants; /* fail verification on register invariants violations */ |
| 606 | struct bpf_verifier_state *cur_state; /* current verifier state */ | 606 | struct bpf_verifier_state *cur_state; /* current verifier state */ |
| 607 | struct bpf_verifier_state_list **explored_states; /* search pruning optimization */ | 607 | struct bpf_verifier_state_list **explored_states; /* search pruning optimization */ |
| 608 | struct bpf_verifier_state_list *free_list; | 608 | struct bpf_verifier_state_list *free_list; |
| @@ -1201,7 +1201,7 @@ enum bpf_perf_event_type { · 1200 unmodified lines | |||
| 1201 | #define BPF_F_XDP_DEV_BOUND_ONLY (1U << 6) | 1201 | #define BPF_F_XDP_DEV_BOUND_ONLY (1U << 6) |
| 1202 | 1202 | ||
| 1203 | /* The verifier internal test flag. Behavior is undefined */ | 1203 | /* The verifier internal test flag. Behavior is undefined */ |
| 1204 | #define BPF_F_TEST_SANITY_STRICT (1U << 7) | 1204 | #define BPF_F_TEST_REG_INVARIANTS (1U << 7) |
| 1205 | 1205 | ||
| 1206 | /* link_create.kprobe_multi.flags used in LINK_CREATE command for | 1206 | /* link_create.kprobe_multi.flags used in LINK_CREATE command for |
| 1207 | * BPF_TRACE_KPROBE_MULTI attach type to create return probe. | 1207 | * BPF_TRACE_KPROBE_MULTI attach type to create return probe. |
| @@ -2574,7 +2574,7 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size) · 2573 unmodified lines | |||
| 2574 | BPF_F_TEST_RND_HI32 | | 2574 | BPF_F_TEST_RND_HI32 | |
| 2575 | BPF_F_XDP_HAS_FRAGS | | 2575 | BPF_F_XDP_HAS_FRAGS | |
| 2576 | BPF_F_XDP_DEV_BOUND_ONLY | | 2576 | BPF_F_XDP_DEV_BOUND_ONLY | |
| 2577 | BPF_F_TEST_SANITY_STRICT)) | 2577 | BPF_F_TEST_REG_INVARIANTS)) |
| 2578 | return -EINVAL; | 2578 | return -EINVAL; |
| 2579 | 2579 | ||
| 2580 | if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && | 2580 | if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && |
| @@ -2608,14 +2608,14 @@ static int reg_bounds_sanity_check(struct bpf_verifier_env *env, · 2607 unmodified lines | |||
| 2608 | 2608 | ||
| 2609 | return 0; | 2609 | return 0; |
| 2610 | out: | 2610 | out: |
| 2611 | verbose(env, "REG SANITY VIOLATION (%s): %s u64=[%#llx, %#llx] " | 2611 | verbose(env, "REG INVARIANTS VIOLATION (%s): %s u64=[%#llx, %#llx] " |
| 2612 | "s64=[%#llx, %#llx] u32=[%#x, %#x] s32=[%#x, %#x] var_off=(%#llx, %#llx)\n", | 2612 | "s64=[%#llx, %#llx] u32=[%#x, %#x] s32=[%#x, %#x] var_off=(%#llx, %#llx)\n", |
| 2613 | ctx, msg, reg->umin_value, reg->umax_value, | 2613 | ctx, msg, reg->umin_value, reg->umax_value, |
| 2614 | reg->smin_value, reg->smax_value, | 2614 | reg->smin_value, reg->smax_value, |
| 2615 | reg->u32_min_value, reg->u32_max_value, | 2615 | reg->u32_min_value, reg->u32_max_value, |
| 2616 | reg->s32_min_value, reg->s32_max_value, | 2616 | reg->s32_min_value, reg->s32_max_value, |
| 2617 | reg->var_off.value, reg->var_off.mask); | 2617 | reg->var_off.value, reg->var_off.mask); |
| 2618 | if (env->test_sanity_strict) | 2618 | if (env->test_reg_invariants) |
| 2619 | return -EFAULT; | 2619 | return -EFAULT; |
| 2620 | __mark_reg_unbounded(reg); | 2620 | __mark_reg_unbounded(reg); |
| 2621 | return 0; | 2621 | return 0; |
| @@ -20791,7 +20791,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u3 · 18169 unmodified lines | |||
| 20791 | 20791 | ||
| 20792 | if (is_priv) | 20792 | if (is_priv) |
| 20793 | env->test_state_freq = attr->prog_flags & BPF_F_TEST_STATE_FREQ; | 20793 | env->test_state_freq = attr->prog_flags & BPF_F_TEST_STATE_FREQ; |
| 20794 | env->test_sanity_strict = attr->prog_flags & BPF_F_TEST_SANITY_STRICT; | 20794 | env->test_reg_invariants = attr->prog_flags & BPF_F_TEST_REG_INVARIANTS; |
| 20795 | 20795 | ||
| 20796 | env->explored_states = kvcalloc(state_htab_size(env), | 20796 | env->explored_states = kvcalloc(state_htab_size(env), |
| 20797 | sizeof(struct bpf_verifier_state_list *), | 20797 | sizeof(struct bpf_verifier_state_list *), |
| @@ -1201,7 +1201,7 @@ enum bpf_perf_event_type { · 1200 unmodified lines | |||
| 1201 | #define BPF_F_XDP_DEV_BOUND_ONLY (1U << 6) | 1201 | #define BPF_F_XDP_DEV_BOUND_ONLY (1U << 6) |
| 1202 | 1202 | ||
| 1203 | /* The verifier internal test flag. Behavior is undefined */ | 1203 | /* The verifier internal test flag. Behavior is undefined */ |
| 1204 | #define BPF_F_TEST_SANITY_STRICT (1U << 7) | 1204 | #define BPF_F_TEST_REG_INVARIANTS (1U << 7) |
| 1205 | 1205 | ||
| 1206 | /* link_create.kprobe_multi.flags used in LINK_CREATE command for | 1206 | /* link_create.kprobe_multi.flags used in LINK_CREATE command for |
| 1207 | * BPF_TRACE_KPROBE_MULTI attach type to create return probe. | 1207 | * BPF_TRACE_KPROBE_MULTI attach type to create return probe. |
| @@ -35,7 +35,7 @@ static int check_load(const char *file, enum bpf_prog_type type) · 34 unmodified lines | |||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | bpf_program__set_type(prog, type); | 37 | bpf_program__set_type(prog, type); |
| 38 | bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32 | BPF_F_TEST_SANITY_STRICT); | 38 | bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS); |
| 39 | bpf_program__set_log_level(prog, 4 | extra_prog_load_log_flags); | 39 | bpf_program__set_log_level(prog, 4 | extra_prog_load_log_flags); |
| 40 | 40 | ||
| 41 | err = bpf_object__load(obj); | 41 | err = bpf_object__load(obj); |
| @@ -838,7 +838,7 @@ static int load_range_cmp_prog(struct range x, struct range y, enum op op, · 837 unmodified lines | |||
| 838 | .log_level = 2, | 838 | .log_level = 2, |
| 839 | .log_buf = log_buf, | 839 | .log_buf = log_buf, |
| 840 | .log_size = log_sz, | 840 | .log_size = log_sz, |
| 841 | .prog_flags = BPF_F_TEST_SANITY_STRICT, | 841 | .prog_flags = BPF_F_TEST_REG_INVARIANTS, |
| 842 | ); | 842 | ); |
| 843 | 843 | ||
| 844 | /* ; skip exit block below | 844 | /* ; skip exit block below |
| @@ -965,7 +965,7 @@ l0_%=: r0 = 0; \ · 964 unmodified lines | |||
| 965 | SEC("xdp") | 965 | SEC("xdp") |
| 966 | __description("bound check with JMP_JSLT for crossing 64-bit signed boundary") | 966 | __description("bound check with JMP_JSLT for crossing 64-bit signed boundary") |
| 967 | __success __retval(0) | 967 | __success __retval(0) |
| 968 | __flag(!BPF_F_TEST_SANITY_STRICT) /* known sanity violation */ | 968 | __flag(!BPF_F_TEST_REG_INVARIANTS) /* known invariants violation */ |
| 969 | __naked void crossing_64_bit_signed_boundary_2(void) | 969 | __naked void crossing_64_bit_signed_boundary_2(void) |
| 970 | { | 970 | { |
| 971 | asm volatile (" \ | 971 | asm volatile (" \ |
| @@ -1047,7 +1047,7 @@ l0_%=: r0 = 0; \ · 75 unmodified lines | |||
| 1047 | SEC("xdp") | 1047 | SEC("xdp") |
| 1048 | __description("bound check with JMP32_JSLT for crossing 32-bit signed boundary") | 1048 | __description("bound check with JMP32_JSLT for crossing 32-bit signed boundary") |
| 1049 | __success __retval(0) | 1049 | __success __retval(0) |
| 1050 | __flag(!BPF_F_TEST_SANITY_STRICT) /* known sanity violation */ | 1050 | __flag(!BPF_F_TEST_REG_INVARIANTS) /* known invariants violation */ |
| 1051 | __naked void crossing_32_bit_signed_boundary_2(void) | 1051 | __naked void crossing_32_bit_signed_boundary_2(void) |
| 1052 | { | 1052 | { |
| 1053 | asm volatile (" \ | 1053 | asm volatile (" \ |
| @@ -179,7 +179,7 @@ static int parse_test_spec(struct test_loader *tester, · 178 unmodified lines | |||
| 179 | memset(spec, 0, sizeof(*spec)); | 179 | memset(spec, 0, sizeof(*spec)); |
| 180 | 180 | ||
| 181 | spec->prog_name = bpf_program__name(prog); | 181 | spec->prog_name = bpf_program__name(prog); |
| 182 | spec->prog_flags = BPF_F_TEST_SANITY_STRICT; /* by default be strict */ | 182 | spec->prog_flags = BPF_F_TEST_REG_INVARIANTS; /* by default be strict */ |
| 183 | 183 | ||
| 184 | btf = bpf_object__btf(obj); | 184 | btf = bpf_object__btf(obj); |
| 185 | if (!btf) { | 185 | if (!btf) { |
| @@ -280,8 +280,8 @@ static int parse_test_spec(struct test_loader *tester, · 94 unmodified lines | |||
| 280 | update_flags(&spec->prog_flags, BPF_F_SLEEPABLE, clear); | 280 | update_flags(&spec->prog_flags, BPF_F_SLEEPABLE, clear); |
| 281 | } else if (strcmp(val, "BPF_F_XDP_HAS_FRAGS") == 0) { | 281 | } else if (strcmp(val, "BPF_F_XDP_HAS_FRAGS") == 0) { |
| 282 | update_flags(&spec->prog_flags, BPF_F_XDP_HAS_FRAGS, clear); | 282 | update_flags(&spec->prog_flags, BPF_F_XDP_HAS_FRAGS, clear); |
| 283 | } else if (strcmp(val, "BPF_F_TEST_SANITY_STRICT") == 0) { | 283 | } else if (strcmp(val, "BPF_F_TEST_REG_INVARIANTS") == 0) { |
| 284 | update_flags(&spec->prog_flags, BPF_F_TEST_SANITY_STRICT, clear); | 284 | update_flags(&spec->prog_flags, BPF_F_TEST_REG_INVARIANTS, clear); |
| 285 | } else /* assume numeric value */ { | 285 | } else /* assume numeric value */ { |
| 286 | err = parse_int(val, &flags, "test prog flags"); | 286 | err = parse_int(val, &flags, "test prog flags"); |
| 287 | if (err) | 287 | if (err) |
| @@ -679,8 +679,7 @@ static int load_path(const struct sock_addr_test *test, const char *path) · 678 unmodified lines | |||
| 679 | 679 | ||
| 680 | bpf_program__set_type(prog, BPF_PROG_TYPE_CGROUP_SOCK_ADDR); | 680 | bpf_program__set_type(prog, BPF_PROG_TYPE_CGROUP_SOCK_ADDR); |
| 681 | bpf_program__set_expected_attach_type(prog, test->expected_attach_type); | 681 | bpf_program__set_expected_attach_type(prog, test->expected_attach_type); |
| 682 | bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32); | 682 | bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS); |
| 683 | bpf_program__set_flags(prog, BPF_F_TEST_SANITY_STRICT); | ||
| 684 | 683 | ||
| 685 | err = bpf_object__load(obj); | 684 | err = bpf_object__load(obj); |
| 686 | if (err) { | 685 | if (err) { |
| @@ -1588,7 +1588,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv, · 1587 unmodified lines | |||
| 1588 | if (fixup_skips != skips) | 1588 | if (fixup_skips != skips) |
| 1589 | return; | 1589 | return; |
| 1590 | 1590 | ||
| 1591 | pflags = BPF_F_TEST_RND_HI32 | BPF_F_TEST_SANITY_STRICT; | 1591 | pflags = BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS; |
| 1592 | if (test->flags & F_LOAD_WITH_STRICT_ALIGNMENT) | 1592 | if (test->flags & F_LOAD_WITH_STRICT_ALIGNMENT) |
| 1593 | pflags |= BPF_F_STRICT_ALIGNMENT; | 1593 | pflags |= BPF_F_STRICT_ALIGNMENT; |
| 1594 | if (test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS) | 1594 | if (test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS) |
| @@ -276,7 +276,7 @@ int bpf_prog_test_load(const char *file, enum bpf_prog_type type, · 275 unmodified lines | |||
| 276 | if (type != BPF_PROG_TYPE_UNSPEC && bpf_program__type(prog) != type) | 276 | if (type != BPF_PROG_TYPE_UNSPEC && bpf_program__type(prog) != type) |
| 277 | bpf_program__set_type(prog, type); | 277 | bpf_program__set_type(prog, type); |
| 278 | 278 | ||
| 279 | flags = bpf_program__flags(prog) | BPF_F_TEST_RND_HI32 | BPF_F_TEST_SANITY_STRICT; | 279 | flags = bpf_program__flags(prog) | BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS; |
| 280 | bpf_program__set_flags(prog, flags); | 280 | bpf_program__set_flags(prog, flags); |
| 281 | 281 | ||
| 282 | err = bpf_object__load(obj); | 282 | err = bpf_object__load(obj); |
| @@ -299,7 +299,7 @@ int bpf_test_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, · 16 unmodified lines | |||
| 299 | { | 299 | { |
| 300 | LIBBPF_OPTS(bpf_prog_load_opts, opts, | 300 | LIBBPF_OPTS(bpf_prog_load_opts, opts, |
| 301 | .kern_version = kern_version, | 301 | .kern_version = kern_version, |
| 302 | .prog_flags = BPF_F_TEST_RND_HI32 | BPF_F_TEST_SANITY_STRICT, | 302 | .prog_flags = BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS, |
| 303 | .log_level = extra_prog_load_log_flags, | 303 | .log_level = extra_prog_load_log_flags, |
| 304 | .log_buf = log_buf, | 304 | .log_buf = log_buf, |
| 305 | .log_size = log_buf_sz, | 305 | .log_size = log_buf_sz, |
| @@ -145,7 +145,7 @@ static struct env { · 144 unmodified lines | |||
| 145 | bool debug; | 145 | bool debug; |
| 146 | bool quiet; | 146 | bool quiet; |
| 147 | bool force_checkpoints; | 147 | bool force_checkpoints; |
| 148 | bool strict_range_sanity; | 148 | bool force_reg_invariants; |
| 149 | enum resfmt out_fmt; | 149 | enum resfmt out_fmt; |
| 150 | bool show_version; | 150 | bool show_version; |
| 151 | bool comparison_mode; | 151 | bool comparison_mode; |
| @@ -225,8 +225,8 @@ static const struct argp_option opts[] = { · 73 unmodified lines | |||
| 225 | { "filter", 'f', "FILTER", 0, "Filter expressions (or @filename for file with expressions)." }, | 225 | { "filter", 'f', "FILTER", 0, "Filter expressions (or @filename for file with expressions)." }, |
| 226 | { "test-states", 't', NULL, 0, | 226 | { "test-states", 't', NULL, 0, |
| 227 | "Force frequent BPF verifier state checkpointing (set BPF_F_TEST_STATE_FREQ program flag)" }, | 227 | "Force frequent BPF verifier state checkpointing (set BPF_F_TEST_STATE_FREQ program flag)" }, |
| 228 | { "test-sanity", 'r', NULL, 0, | 228 | { "test-reg-invariants", 'r', NULL, 0, |
| 229 | "Force strict BPF verifier register sanity behavior (BPF_F_TEST_SANITY_STRICT program flag)" }, | 229 | "Force BPF verifier failure on register invariant violation (BPF_F_TEST_REG_INVARIANTS program flag)" }, |
| 230 | {}, | 230 | {}, |
| 231 | }; | 231 | }; |
| 232 | 232 | ||
| @@ -299,7 +299,7 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) · 66 unmodified lines | |||
| 299 | env.force_checkpoints = true; | 299 | env.force_checkpoints = true; |
| 300 | break; | 300 | break; |
| 301 | case 'r': | 301 | case 'r': |
| 302 | env.strict_range_sanity = true; | 302 | env.force_reg_invariants = true; |
| 303 | break; | 303 | break; |
| 304 | case 'n': | 304 | case 'n': |
| 305 | errno = 0; | 305 | errno = 0; |
| @@ -1028,8 +1028,8 @@ static int process_prog(const char *filename, struct bpf_object *obj, struct bpf · 722 unmodified lines | |||
| 1028 | 1028 | ||
| 1029 | if (env.force_checkpoints) | 1029 | if (env.force_checkpoints) |
| 1030 | bpf_program__set_flags(prog, bpf_program__flags(prog) | BPF_F_TEST_STATE_FREQ); | 1030 | bpf_program__set_flags(prog, bpf_program__flags(prog) | BPF_F_TEST_STATE_FREQ); |
| 1031 | if (env.strict_range_sanity) | 1031 | if (env.force_reg_invariants) |
| 1032 | bpf_program__set_flags(prog, bpf_program__flags(prog) | BPF_F_TEST_SANITY_STRICT); | 1032 | bpf_program__set_flags(prog, bpf_program__flags(prog) | BPF_F_TEST_REG_INVARIANTS); |
| 1033 | 1033 | ||
| 1034 | err = bpf_object__load(obj); | 1034 | err = bpf_object__load(obj); |
| 1035 | env.progs_processed++; | 1035 | env.progs_processed++; |