Skip to content

Commit bc2591d

Browse files
yonghong-songAlexei Starovoitov
authored andcommitted
bpf: Factor out verbose_invalid_scalar()
Factor out the function verbose_invalid_scalar() to verbose print if a scalar is not in a tnum range. There is no functionality change and the function will be used by later patch which introduced bpf_for_each_map_elem(). Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent efdb22d commit bc2591d

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

kernel/bpf/verifier.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,24 @@ __printf(3, 4) static void verbose_linfo(struct bpf_verifier_env *env,
390390
env->prev_linfo = linfo;
391391
}
392392

393+
static void verbose_invalid_scalar(struct bpf_verifier_env *env,
394+
struct bpf_reg_state *reg,
395+
struct tnum *range, const char *ctx,
396+
const char *reg_name)
397+
{
398+
char tn_buf[48];
399+
400+
verbose(env, "At %s the register %s ", ctx, reg_name);
401+
if (!tnum_is_unknown(reg->var_off)) {
402+
tnum_strn(tn_buf, sizeof(tn_buf), reg->var_off);
403+
verbose(env, "has value %s", tn_buf);
404+
} else {
405+
verbose(env, "has unknown scalar value");
406+
}
407+
tnum_strn(tn_buf, sizeof(tn_buf), *range);
408+
verbose(env, " should have been in %s\n", tn_buf);
409+
}
410+
393411
static bool type_is_pkt_pointer(enum bpf_reg_type type)
394412
{
395413
return type == PTR_TO_PACKET ||
@@ -8455,17 +8473,7 @@ static int check_return_code(struct bpf_verifier_env *env)
84558473
}
84568474

84578475
if (!tnum_in(range, reg->var_off)) {
8458-
char tn_buf[48];
8459-
8460-
verbose(env, "At program exit the register R0 ");
8461-
if (!tnum_is_unknown(reg->var_off)) {
8462-
tnum_strn(tn_buf, sizeof(tn_buf), reg->var_off);
8463-
verbose(env, "has value %s", tn_buf);
8464-
} else {
8465-
verbose(env, "has unknown scalar value");
8466-
}
8467-
tnum_strn(tn_buf, sizeof(tn_buf), range);
8468-
verbose(env, " should have been in %s\n", tn_buf);
8476+
verbose_invalid_scalar(env, reg, &range, "program exit", "R0");
84698477
return -EINVAL;
84708478
}
84718479

0 commit comments

Comments
 (0)