bpf: provide correct register name for exception callback retval check
authorAndrii Nakryiko <andrii@kernel.org>
Sat, 2 Dec 2023 17:56:56 +0000 (09:56 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 2 Dec 2023 19:36:50 +0000 (11:36 -0800)
bpf_throw() is checking R1, so let's report R1 in the log.

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Acked-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20231202175705.885270-3-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c
tools/testing/selftests/bpf/progs/exceptions_assert.c
tools/testing/selftests/bpf/progs/exceptions_fail.c

index 8e7b6072e3f4dbabc1fdc4f0e48362db62e1d5ed..25b9d470957eadd8c17035c8fcbe77735e37b3f0 100644 (file)
@@ -11805,7 +11805,7 @@ static int fetch_kfunc_meta(struct bpf_verifier_env *env,
        return 0;
 }
 
-static int check_return_code(struct bpf_verifier_env *env, int regno);
+static int check_return_code(struct bpf_verifier_env *env, int regno, const char *reg_name);
 
 static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
                            int *insn_idx_p)
@@ -11942,7 +11942,7 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
                 * to bpf_throw becomes the return value of the program.
                 */
                if (!env->exception_callback_subprog) {
-                       err = check_return_code(env, BPF_REG_1);
+                       err = check_return_code(env, BPF_REG_1, "R1");
                        if (err < 0)
                                return err;
                }
@@ -14972,7 +14972,7 @@ static int check_ld_abs(struct bpf_verifier_env *env, struct bpf_insn *insn)
        return 0;
 }
 
-static int check_return_code(struct bpf_verifier_env *env, int regno)
+static int check_return_code(struct bpf_verifier_env *env, int regno, const char *reg_name)
 {
        struct tnum enforce_attach_type_range = tnum_unknown;
        const struct bpf_prog *prog = env->prog;
@@ -15026,7 +15026,7 @@ static int check_return_code(struct bpf_verifier_env *env, int regno)
                }
 
                if (!tnum_in(const_0, reg->var_off)) {
-                       verbose_invalid_scalar(env, reg, &const_0, "async callback", "R0");
+                       verbose_invalid_scalar(env, reg, &const_0, "async callback", reg_name);
                        return -EINVAL;
                }
                return 0;
@@ -15126,7 +15126,7 @@ static int check_return_code(struct bpf_verifier_env *env, int regno)
        }
 
        if (!tnum_in(range, reg->var_off)) {
-               verbose_invalid_scalar(env, reg, &range, "program exit", "R0");
+               verbose_invalid_scalar(env, reg, &range, "program exit", reg_name);
                if (prog->expected_attach_type == BPF_LSM_CGROUP &&
                    prog_type == BPF_PROG_TYPE_LSM &&
                    !prog->aux->attach_func_proto->type)
@@ -17410,7 +17410,7 @@ process_bpf_exit_full:
                                        continue;
                                }
 
-                               err = check_return_code(env, BPF_REG_0);
+                               err = check_return_code(env, BPF_REG_0, "R0");
                                if (err)
                                        return err;
 process_bpf_exit:
index 49efaed143fc2b7396ae320487d33b7c20be0372..575e7dd719c4b2fce3195fc840a9e577ec2fd533 100644 (file)
@@ -125,7 +125,7 @@ int check_assert_generic(struct __sk_buff *ctx)
 }
 
 SEC("?fentry/bpf_check")
-__failure __msg("At program exit the register R0 has value (0x40; 0x0)")
+__failure __msg("At program exit the register R1 has value (0x40; 0x0)")
 int check_assert_with_return(void *ctx)
 {
        bpf_assert_with(!ctx, 64);
index 8c0ef2742208ae929293a0aa7f24269d52c7a94a..81ead7512ba25ec2929beb9435b122888cf97af0 100644 (file)
@@ -308,7 +308,7 @@ int reject_set_exception_cb_bad_ret1(void *ctx)
 }
 
 SEC("?fentry/bpf_check")
-__failure __msg("At program exit the register R0 has value (0x40; 0x0) should")
+__failure __msg("At program exit the register R1 has value (0x40; 0x0) should")
 int reject_set_exception_cb_bad_ret2(void *ctx)
 {
        bpf_throw(64);