Skip to content

Commit 8299559

Browse files
Byte-Labborkmann
authored andcommitted
bpf: Fix verifier log for async callback return values
The verifier, as part of check_return_code(), verifies that async callbacks such as from e.g. timers, will return 0. It does this by correctly checking that R0->var_off is in tnum_const(0), which effectively checks that it's in a range of 0. If this condition fails, however, it prints an error message which says that the value should have been in (0x0; 0x1). This results in possibly confusing output such as the following in which an async callback returns 1: At async callback the register R0 has value (0x1; 0x0) should have been in (0x0; 0x1) The fix is easy -- we should just pass the tnum_const(0) as the correct range to verbose_invalid_scalar(), which will then print the following: At async callback the register R0 has value (0x1; 0x0) should have been in (0x0; 0x0) Fixes: bfc6bb7 ("bpf: Implement verifier support for validation of async callbacks.") Signed-off-by: David Vernet <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent a12bbb3 commit 8299559

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

kernel/bpf/verifier.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14479,7 +14479,7 @@ static int check_return_code(struct bpf_verifier_env *env)
1447914479
struct tnum enforce_attach_type_range = tnum_unknown;
1448014480
const struct bpf_prog *prog = env->prog;
1448114481
struct bpf_reg_state *reg;
14482-
struct tnum range = tnum_range(0, 1);
14482+
struct tnum range = tnum_range(0, 1), const_0 = tnum_const(0);
1448314483
enum bpf_prog_type prog_type = resolve_prog_type(env->prog);
1448414484
int err;
1448514485
struct bpf_func_state *frame = env->cur_state->frame[0];
@@ -14527,8 +14527,8 @@ static int check_return_code(struct bpf_verifier_env *env)
1452714527
return -EINVAL;
1452814528
}
1452914529

14530-
if (!tnum_in(tnum_const(0), reg->var_off)) {
14531-
verbose_invalid_scalar(env, reg, &range, "async callback", "R0");
14530+
if (!tnum_in(const_0, reg->var_off)) {
14531+
verbose_invalid_scalar(env, reg, &const_0, "async callback", "R0");
1453214532
return -EINVAL;
1453314533
}
1453414534
return 0;

0 commit comments

Comments
 (0)