Skip to content

Commit ff8867a

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
bpf: rename BPF_F_TEST_SANITY_STRICT to BPF_F_TEST_REG_INVARIANTS
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/[email protected]/ Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 5fa201f commit ff8867a

File tree

13 files changed

+24
-25
lines changed

13 files changed

+24
-25
lines changed

include/linux/bpf_verifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ struct bpf_verifier_env {
602602
int stack_size; /* number of states to be processed */
603603
bool strict_alignment; /* perform strict pointer alignment checks */
604604
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 */
606606
struct bpf_verifier_state *cur_state; /* current verifier state */
607607
struct bpf_verifier_state_list **explored_states; /* search pruning optimization */
608608
struct bpf_verifier_state_list *free_list;

include/uapi/linux/bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ enum bpf_perf_event_type {
12011201
#define BPF_F_XDP_DEV_BOUND_ONLY (1U << 6)
12021202

12031203
/* 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)
12051205

12061206
/* link_create.kprobe_multi.flags used in LINK_CREATE command for
12071207
* BPF_TRACE_KPROBE_MULTI attach type to create return probe.

kernel/bpf/syscall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2574,7 +2574,7 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size)
25742574
BPF_F_TEST_RND_HI32 |
25752575
BPF_F_XDP_HAS_FRAGS |
25762576
BPF_F_XDP_DEV_BOUND_ONLY |
2577-
BPF_F_TEST_SANITY_STRICT))
2577+
BPF_F_TEST_REG_INVARIANTS))
25782578
return -EINVAL;
25792579

25802580
if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) &&

kernel/bpf/verifier.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,14 +2608,14 @@ static int reg_bounds_sanity_check(struct bpf_verifier_env *env,
26082608

26092609
return 0;
26102610
out:
2611-
verbose(env, "REG SANITY VIOLATION (%s): %s u64=[%#llx, %#llx] "
2611+
verbose(env, "REG INVARIANTS VIOLATION (%s): %s u64=[%#llx, %#llx] "
26122612
"s64=[%#llx, %#llx] u32=[%#x, %#x] s32=[%#x, %#x] var_off=(%#llx, %#llx)\n",
26132613
ctx, msg, reg->umin_value, reg->umax_value,
26142614
reg->smin_value, reg->smax_value,
26152615
reg->u32_min_value, reg->u32_max_value,
26162616
reg->s32_min_value, reg->s32_max_value,
26172617
reg->var_off.value, reg->var_off.mask);
2618-
if (env->test_sanity_strict)
2618+
if (env->test_reg_invariants)
26192619
return -EFAULT;
26202620
__mark_reg_unbounded(reg);
26212621
return 0;
@@ -20791,7 +20791,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u3
2079120791

2079220792
if (is_priv)
2079320793
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;
2079520795

2079620796
env->explored_states = kvcalloc(state_htab_size(env),
2079720797
sizeof(struct bpf_verifier_state_list *),

tools/include/uapi/linux/bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ enum bpf_perf_event_type {
12011201
#define BPF_F_XDP_DEV_BOUND_ONLY (1U << 6)
12021202

12031203
/* 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)
12051205

12061206
/* link_create.kprobe_multi.flags used in LINK_CREATE command for
12071207
* BPF_TRACE_KPROBE_MULTI attach type to create return probe.

tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static int check_load(const char *file, enum bpf_prog_type type)
3535
}
3636

3737
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);
3939
bpf_program__set_log_level(prog, 4 | extra_prog_load_log_flags);
4040

4141
err = bpf_object__load(obj);

tools/testing/selftests/bpf/prog_tests/reg_bounds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ static int load_range_cmp_prog(struct range x, struct range y, enum op op,
838838
.log_level = 2,
839839
.log_buf = log_buf,
840840
.log_size = log_sz,
841-
.prog_flags = BPF_F_TEST_SANITY_STRICT,
841+
.prog_flags = BPF_F_TEST_REG_INVARIANTS,
842842
);
843843

844844
/* ; skip exit block below

tools/testing/selftests/bpf/progs/verifier_bounds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ l0_%=: r0 = 0; \
965965
SEC("xdp")
966966
__description("bound check with JMP_JSLT for crossing 64-bit signed boundary")
967967
__success __retval(0)
968-
__flag(!BPF_F_TEST_SANITY_STRICT) /* known sanity violation */
968+
__flag(!BPF_F_TEST_REG_INVARIANTS) /* known invariants violation */
969969
__naked void crossing_64_bit_signed_boundary_2(void)
970970
{
971971
asm volatile (" \
@@ -1047,7 +1047,7 @@ l0_%=: r0 = 0; \
10471047
SEC("xdp")
10481048
__description("bound check with JMP32_JSLT for crossing 32-bit signed boundary")
10491049
__success __retval(0)
1050-
__flag(!BPF_F_TEST_SANITY_STRICT) /* known sanity violation */
1050+
__flag(!BPF_F_TEST_REG_INVARIANTS) /* known invariants violation */
10511051
__naked void crossing_32_bit_signed_boundary_2(void)
10521052
{
10531053
asm volatile (" \

tools/testing/selftests/bpf/test_loader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static int parse_test_spec(struct test_loader *tester,
179179
memset(spec, 0, sizeof(*spec));
180180

181181
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 */
183183

184184
btf = bpf_object__btf(obj);
185185
if (!btf) {
@@ -280,8 +280,8 @@ static int parse_test_spec(struct test_loader *tester,
280280
update_flags(&spec->prog_flags, BPF_F_SLEEPABLE, clear);
281281
} else if (strcmp(val, "BPF_F_XDP_HAS_FRAGS") == 0) {
282282
update_flags(&spec->prog_flags, BPF_F_XDP_HAS_FRAGS, clear);
283-
} else if (strcmp(val, "BPF_F_TEST_SANITY_STRICT") == 0) {
284-
update_flags(&spec->prog_flags, BPF_F_TEST_SANITY_STRICT, clear);
283+
} else if (strcmp(val, "BPF_F_TEST_REG_INVARIANTS") == 0) {
284+
update_flags(&spec->prog_flags, BPF_F_TEST_REG_INVARIANTS, clear);
285285
} else /* assume numeric value */ {
286286
err = parse_int(val, &flags, "test prog flags");
287287
if (err)

tools/testing/selftests/bpf/test_sock_addr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,7 @@ static int load_path(const struct sock_addr_test *test, const char *path)
679679

680680
bpf_program__set_type(prog, BPF_PROG_TYPE_CGROUP_SOCK_ADDR);
681681
bpf_program__set_expected_attach_type(prog, test->expected_attach_type);
682-
bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32);
683-
bpf_program__set_flags(prog, BPF_F_TEST_SANITY_STRICT);
682+
bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS);
684683

685684
err = bpf_object__load(obj);
686685
if (err) {

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
15881588
if (fixup_skips != skips)
15891589
return;
15901590

1591-
pflags = BPF_F_TEST_RND_HI32 | BPF_F_TEST_SANITY_STRICT;
1591+
pflags = BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS;
15921592
if (test->flags & F_LOAD_WITH_STRICT_ALIGNMENT)
15931593
pflags |= BPF_F_STRICT_ALIGNMENT;
15941594
if (test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS)

tools/testing/selftests/bpf/testing_helpers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ int bpf_prog_test_load(const char *file, enum bpf_prog_type type,
276276
if (type != BPF_PROG_TYPE_UNSPEC && bpf_program__type(prog) != type)
277277
bpf_program__set_type(prog, type);
278278

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;
280280
bpf_program__set_flags(prog, flags);
281281

282282
err = bpf_object__load(obj);
@@ -299,7 +299,7 @@ int bpf_test_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
299299
{
300300
LIBBPF_OPTS(bpf_prog_load_opts, opts,
301301
.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,
303303
.log_level = extra_prog_load_log_flags,
304304
.log_buf = log_buf,
305305
.log_size = log_buf_sz,

tools/testing/selftests/bpf/veristat.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static struct env {
145145
bool debug;
146146
bool quiet;
147147
bool force_checkpoints;
148-
bool strict_range_sanity;
148+
bool force_reg_invariants;
149149
enum resfmt out_fmt;
150150
bool show_version;
151151
bool comparison_mode;
@@ -225,8 +225,8 @@ static const struct argp_option opts[] = {
225225
{ "filter", 'f', "FILTER", 0, "Filter expressions (or @filename for file with expressions)." },
226226
{ "test-states", 't', NULL, 0,
227227
"Force frequent BPF verifier state checkpointing (set BPF_F_TEST_STATE_FREQ program flag)" },
228-
{ "test-sanity", 'r', NULL, 0,
229-
"Force strict BPF verifier register sanity behavior (BPF_F_TEST_SANITY_STRICT program flag)" },
228+
{ "test-reg-invariants", 'r', NULL, 0,
229+
"Force BPF verifier failure on register invariant violation (BPF_F_TEST_REG_INVARIANTS program flag)" },
230230
{},
231231
};
232232

@@ -299,7 +299,7 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
299299
env.force_checkpoints = true;
300300
break;
301301
case 'r':
302-
env.strict_range_sanity = true;
302+
env.force_reg_invariants = true;
303303
break;
304304
case 'n':
305305
errno = 0;
@@ -1028,8 +1028,8 @@ static int process_prog(const char *filename, struct bpf_object *obj, struct bpf
10281028

10291029
if (env.force_checkpoints)
10301030
bpf_program__set_flags(prog, bpf_program__flags(prog) | BPF_F_TEST_STATE_FREQ);
1031-
if (env.strict_range_sanity)
1032-
bpf_program__set_flags(prog, bpf_program__flags(prog) | BPF_F_TEST_SANITY_STRICT);
1031+
if (env.force_reg_invariants)
1032+
bpf_program__set_flags(prog, bpf_program__flags(prog) | BPF_F_TEST_REG_INVARIANTS);
10331033

10341034
err = bpf_object__load(obj);
10351035
env.progs_processed++;

0 commit comments

Comments
 (0)