Thread (32 messages) 32 messages, 4 authors, 2021-02-26

Re: [PATCH bpf-next v3 02/11] bpf: factor out verbose_invalid_scalar()

From: Andrii Nakryiko <hidden>
Date: 2021-02-25 21:58:51

On Thu, Feb 25, 2021 at 1:35 AM Yonghong Song [off-list ref] wrote:
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 <redacted>
---
Acked-by: Andrii Nakryiko <andrii@kernel.org>
quoted hunk ↗ jump to hunk
 kernel/bpf/verifier.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 9cb182e91162..a657860ecba5 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -390,6 +390,25 @@ __printf(3, 4) static void verbose_linfo(struct bpf_verifier_env *env,
        env->prev_linfo = linfo;
 }

+static void verbose_invalid_scalar(struct bpf_verifier_env *env,
+                                  struct bpf_reg_state *reg,
+                                  struct tnum *range, const char *ctx,
+                                  const char *reg_name)
+{
+       char tn_buf[48];
+
+       verbose(env, "At %s the register %s ", ctx, reg_name);
+       if (!tnum_is_unknown(reg->var_off)) {
+               tnum_strn(tn_buf, sizeof(tn_buf), reg->var_off);
+               verbose(env, "has value %s", tn_buf);
+       } else {
+               verbose(env, "has unknown scalar value");
+       }
+       tnum_strn(tn_buf, sizeof(tn_buf), *range);
+       verbose(env, " should have been in %s\n", tn_buf);
+}
+
+
nit: double empty line
quoted hunk ↗ jump to hunk
 static bool type_is_pkt_pointer(enum bpf_reg_type type)
 {
        return type == PTR_TO_PACKET ||
@@ -8455,17 +8474,7 @@ static int check_return_code(struct bpf_verifier_env *env)
        }

        if (!tnum_in(range, reg->var_off)) {
-               char tn_buf[48];
-
-               verbose(env, "At program exit the register R0 ");
-               if (!tnum_is_unknown(reg->var_off)) {
-                       tnum_strn(tn_buf, sizeof(tn_buf), reg->var_off);
-                       verbose(env, "has value %s", tn_buf);
-               } else {
-                       verbose(env, "has unknown scalar value");
-               }
-               tnum_strn(tn_buf, sizeof(tn_buf), range);
-               verbose(env, " should have been in %s\n", tn_buf);
+               verbose_invalid_scalar(env, reg, &range, "program exit", "R0");
                return -EINVAL;
        }

--
2.24.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help