mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-19 20:05:08 +00:00
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/20231112010609.848406-5-andrii@kernel.org/ Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20231117171404.225508-1-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
5fa201f37c
commit
ff8867af01
@ -602,7 +602,7 @@ struct bpf_verifier_env {
|
||||
int stack_size; /* number of states to be processed */
|
||||
bool strict_alignment; /* perform strict pointer alignment checks */
|
||||
bool test_state_freq; /* test verifier with different pruning frequency */
|
||||
bool test_sanity_strict; /* fail verification on sanity violations */
|
||||
bool test_reg_invariants; /* fail verification on register invariants violations */
|
||||
struct bpf_verifier_state *cur_state; /* current verifier state */
|
||||
struct bpf_verifier_state_list **explored_states; /* search pruning optimization */
|
||||
struct bpf_verifier_state_list *free_list;
|
||||
|
@ -1201,7 +1201,7 @@ enum bpf_perf_event_type {
|
||||
#define BPF_F_XDP_DEV_BOUND_ONLY (1U << 6)
|
||||
|
||||
/* The verifier internal test flag. Behavior is undefined */
|
||||
#define BPF_F_TEST_SANITY_STRICT (1U << 7)
|
||||
#define BPF_F_TEST_REG_INVARIANTS (1U << 7)
|
||||
|
||||
/* link_create.kprobe_multi.flags used in LINK_CREATE command for
|
||||
* 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)
|
||||
BPF_F_TEST_RND_HI32 |
|
||||
BPF_F_XDP_HAS_FRAGS |
|
||||
BPF_F_XDP_DEV_BOUND_ONLY |
|
||||
BPF_F_TEST_SANITY_STRICT))
|
||||
BPF_F_TEST_REG_INVARIANTS))
|
||||
return -EINVAL;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) &&
|
||||
|
@ -2608,14 +2608,14 @@ static int reg_bounds_sanity_check(struct bpf_verifier_env *env,
|
||||
|
||||
return 0;
|
||||
out:
|
||||
verbose(env, "REG SANITY VIOLATION (%s): %s u64=[%#llx, %#llx] "
|
||||
verbose(env, "REG INVARIANTS VIOLATION (%s): %s u64=[%#llx, %#llx] "
|
||||
"s64=[%#llx, %#llx] u32=[%#x, %#x] s32=[%#x, %#x] var_off=(%#llx, %#llx)\n",
|
||||
ctx, msg, reg->umin_value, reg->umax_value,
|
||||
reg->smin_value, reg->smax_value,
|
||||
reg->u32_min_value, reg->u32_max_value,
|
||||
reg->s32_min_value, reg->s32_max_value,
|
||||
reg->var_off.value, reg->var_off.mask);
|
||||
if (env->test_sanity_strict)
|
||||
if (env->test_reg_invariants)
|
||||
return -EFAULT;
|
||||
__mark_reg_unbounded(reg);
|
||||
return 0;
|
||||
@ -20791,7 +20791,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u3
|
||||
|
||||
if (is_priv)
|
||||
env->test_state_freq = attr->prog_flags & BPF_F_TEST_STATE_FREQ;
|
||||
env->test_sanity_strict = attr->prog_flags & BPF_F_TEST_SANITY_STRICT;
|
||||
env->test_reg_invariants = attr->prog_flags & BPF_F_TEST_REG_INVARIANTS;
|
||||
|
||||
env->explored_states = kvcalloc(state_htab_size(env),
|
||||
sizeof(struct bpf_verifier_state_list *),
|
||||
|
@ -1201,7 +1201,7 @@ enum bpf_perf_event_type {
|
||||
#define BPF_F_XDP_DEV_BOUND_ONLY (1U << 6)
|
||||
|
||||
/* The verifier internal test flag. Behavior is undefined */
|
||||
#define BPF_F_TEST_SANITY_STRICT (1U << 7)
|
||||
#define BPF_F_TEST_REG_INVARIANTS (1U << 7)
|
||||
|
||||
/* link_create.kprobe_multi.flags used in LINK_CREATE command for
|
||||
* 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)
|
||||
}
|
||||
|
||||
bpf_program__set_type(prog, type);
|
||||
bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32 | BPF_F_TEST_SANITY_STRICT);
|
||||
bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS);
|
||||
bpf_program__set_log_level(prog, 4 | extra_prog_load_log_flags);
|
||||
|
||||
err = bpf_object__load(obj);
|
||||
|
@ -838,7 +838,7 @@ static int load_range_cmp_prog(struct range x, struct range y, enum op op,
|
||||
.log_level = 2,
|
||||
.log_buf = log_buf,
|
||||
.log_size = log_sz,
|
||||
.prog_flags = BPF_F_TEST_SANITY_STRICT,
|
||||
.prog_flags = BPF_F_TEST_REG_INVARIANTS,
|
||||
);
|
||||
|
||||
/* ; skip exit block below
|
||||
|
@ -965,7 +965,7 @@ l0_%=: r0 = 0; \
|
||||
SEC("xdp")
|
||||
__description("bound check with JMP_JSLT for crossing 64-bit signed boundary")
|
||||
__success __retval(0)
|
||||
__flag(!BPF_F_TEST_SANITY_STRICT) /* known sanity violation */
|
||||
__flag(!BPF_F_TEST_REG_INVARIANTS) /* known invariants violation */
|
||||
__naked void crossing_64_bit_signed_boundary_2(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
@ -1047,7 +1047,7 @@ l0_%=: r0 = 0; \
|
||||
SEC("xdp")
|
||||
__description("bound check with JMP32_JSLT for crossing 32-bit signed boundary")
|
||||
__success __retval(0)
|
||||
__flag(!BPF_F_TEST_SANITY_STRICT) /* known sanity violation */
|
||||
__flag(!BPF_F_TEST_REG_INVARIANTS) /* known invariants violation */
|
||||
__naked void crossing_32_bit_signed_boundary_2(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
|
@ -179,7 +179,7 @@ static int parse_test_spec(struct test_loader *tester,
|
||||
memset(spec, 0, sizeof(*spec));
|
||||
|
||||
spec->prog_name = bpf_program__name(prog);
|
||||
spec->prog_flags = BPF_F_TEST_SANITY_STRICT; /* by default be strict */
|
||||
spec->prog_flags = BPF_F_TEST_REG_INVARIANTS; /* by default be strict */
|
||||
|
||||
btf = bpf_object__btf(obj);
|
||||
if (!btf) {
|
||||
@ -280,8 +280,8 @@ static int parse_test_spec(struct test_loader *tester,
|
||||
update_flags(&spec->prog_flags, BPF_F_SLEEPABLE, clear);
|
||||
} else if (strcmp(val, "BPF_F_XDP_HAS_FRAGS") == 0) {
|
||||
update_flags(&spec->prog_flags, BPF_F_XDP_HAS_FRAGS, clear);
|
||||
} else if (strcmp(val, "BPF_F_TEST_SANITY_STRICT") == 0) {
|
||||
update_flags(&spec->prog_flags, BPF_F_TEST_SANITY_STRICT, clear);
|
||||
} else if (strcmp(val, "BPF_F_TEST_REG_INVARIANTS") == 0) {
|
||||
update_flags(&spec->prog_flags, BPF_F_TEST_REG_INVARIANTS, clear);
|
||||
} else /* assume numeric value */ {
|
||||
err = parse_int(val, &flags, "test prog flags");
|
||||
if (err)
|
||||
|
@ -679,8 +679,7 @@ static int load_path(const struct sock_addr_test *test, const char *path)
|
||||
|
||||
bpf_program__set_type(prog, BPF_PROG_TYPE_CGROUP_SOCK_ADDR);
|
||||
bpf_program__set_expected_attach_type(prog, test->expected_attach_type);
|
||||
bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32);
|
||||
bpf_program__set_flags(prog, BPF_F_TEST_SANITY_STRICT);
|
||||
bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS);
|
||||
|
||||
err = bpf_object__load(obj);
|
||||
if (err) {
|
||||
|
@ -1588,7 +1588,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
|
||||
if (fixup_skips != skips)
|
||||
return;
|
||||
|
||||
pflags = BPF_F_TEST_RND_HI32 | BPF_F_TEST_SANITY_STRICT;
|
||||
pflags = BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS;
|
||||
if (test->flags & F_LOAD_WITH_STRICT_ALIGNMENT)
|
||||
pflags |= BPF_F_STRICT_ALIGNMENT;
|
||||
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,
|
||||
if (type != BPF_PROG_TYPE_UNSPEC && bpf_program__type(prog) != type)
|
||||
bpf_program__set_type(prog, type);
|
||||
|
||||
flags = bpf_program__flags(prog) | BPF_F_TEST_RND_HI32 | BPF_F_TEST_SANITY_STRICT;
|
||||
flags = bpf_program__flags(prog) | BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS;
|
||||
bpf_program__set_flags(prog, flags);
|
||||
|
||||
err = bpf_object__load(obj);
|
||||
@ -299,7 +299,7 @@ int bpf_test_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
|
||||
{
|
||||
LIBBPF_OPTS(bpf_prog_load_opts, opts,
|
||||
.kern_version = kern_version,
|
||||
.prog_flags = BPF_F_TEST_RND_HI32 | BPF_F_TEST_SANITY_STRICT,
|
||||
.prog_flags = BPF_F_TEST_RND_HI32 | BPF_F_TEST_REG_INVARIANTS,
|
||||
.log_level = extra_prog_load_log_flags,
|
||||
.log_buf = log_buf,
|
||||
.log_size = log_buf_sz,
|
||||
|
@ -145,7 +145,7 @@ static struct env {
|
||||
bool debug;
|
||||
bool quiet;
|
||||
bool force_checkpoints;
|
||||
bool strict_range_sanity;
|
||||
bool force_reg_invariants;
|
||||
enum resfmt out_fmt;
|
||||
bool show_version;
|
||||
bool comparison_mode;
|
||||
@ -225,8 +225,8 @@ static const struct argp_option opts[] = {
|
||||
{ "filter", 'f', "FILTER", 0, "Filter expressions (or @filename for file with expressions)." },
|
||||
{ "test-states", 't', NULL, 0,
|
||||
"Force frequent BPF verifier state checkpointing (set BPF_F_TEST_STATE_FREQ program flag)" },
|
||||
{ "test-sanity", 'r', NULL, 0,
|
||||
"Force strict BPF verifier register sanity behavior (BPF_F_TEST_SANITY_STRICT program flag)" },
|
||||
{ "test-reg-invariants", 'r', NULL, 0,
|
||||
"Force BPF verifier failure on register invariant violation (BPF_F_TEST_REG_INVARIANTS program flag)" },
|
||||
{},
|
||||
};
|
||||
|
||||
@ -299,7 +299,7 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
|
||||
env.force_checkpoints = true;
|
||||
break;
|
||||
case 'r':
|
||||
env.strict_range_sanity = true;
|
||||
env.force_reg_invariants = true;
|
||||
break;
|
||||
case 'n':
|
||||
errno = 0;
|
||||
@ -1028,8 +1028,8 @@ static int process_prog(const char *filename, struct bpf_object *obj, struct bpf
|
||||
|
||||
if (env.force_checkpoints)
|
||||
bpf_program__set_flags(prog, bpf_program__flags(prog) | BPF_F_TEST_STATE_FREQ);
|
||||
if (env.strict_range_sanity)
|
||||
bpf_program__set_flags(prog, bpf_program__flags(prog) | BPF_F_TEST_SANITY_STRICT);
|
||||
if (env.force_reg_invariants)
|
||||
bpf_program__set_flags(prog, bpf_program__flags(prog) | BPF_F_TEST_REG_INVARIANTS);
|
||||
|
||||
err = bpf_object__load(obj);
|
||||
env.progs_processed++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user