diff mbox series

[bpf] bpf: Only print ref_obj_id for refcounted reg

Message ID 20190318173713.1413282-1-kafai@fb.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [bpf] bpf: Only print ref_obj_id for refcounted reg | expand

Commit Message

Martin KaFai Lau March 18, 2019, 5:37 p.m. UTC
Naresh reported that test_align fails because of the mismatch at the
verbose printout of the register states.  The reason is due to the newly
added ref_obj_id.

ref_obj_id is only useful for refcounted reg.  Thus, this patch fixes it
by only printing ref_obj_id for refcounted reg.  While at it, it also uses
comma instead of space to separate between "id" and "ref_obj_id".

Fixes: 1b986589680a ("bpf: Fix bpf_tcp_sock and bpf_sk_fullsock issue related to bpf_sk_release")
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
---
 kernel/bpf/verifier.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Andrii Nakryiko March 18, 2019, 7:26 p.m. UTC | #1
On Mon, Mar 18, 2019 at 10:37 AM Martin KaFai Lau <kafai@fb.com> wrote:
>
> Naresh reported that test_align fails because of the mismatch at the
> verbose printout of the register states.  The reason is due to the newly
> added ref_obj_id.
>
> ref_obj_id is only useful for refcounted reg.  Thus, this patch fixes it
> by only printing ref_obj_id for refcounted reg.  While at it, it also uses
> comma instead of space to separate between "id" and "ref_obj_id".
>
> Fixes: 1b986589680a ("bpf: Fix bpf_tcp_sock and bpf_sk_fullsock issue related to bpf_sk_release")
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Signed-off-by: Martin KaFai Lau <kafai@fb.com>
> ---
>  kernel/bpf/verifier.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 86f9cd5d1c4e..5aa810882583 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -352,6 +352,14 @@ static bool reg_may_point_to_spin_lock(const struct bpf_reg_state *reg)
>                 map_value_has_spin_lock(reg->map_ptr);
>  }
>
> +static bool reg_type_may_be_refcounted_or_null(enum bpf_reg_type type)
> +{
> +       return type == PTR_TO_SOCKET ||
> +               type == PTR_TO_SOCKET_OR_NULL ||
> +               type == PTR_TO_TCP_SOCK ||
> +               type == PTR_TO_TCP_SOCK_OR_NULL;
> +}
> +
>  static bool arg_type_may_be_refcounted(enum bpf_arg_type type)
>  {
>         return type == ARG_PTR_TO_SOCK_COMMON;
> @@ -451,8 +459,9 @@ static void print_verifier_state(struct bpf_verifier_env *env,
>                         if (t == PTR_TO_STACK)
>                                 verbose(env, ",call_%d", func(env, reg)->callsite);
>                 } else {
> -                       verbose(env, "(id=%d ref_obj_id=%d", reg->id,
> -                               reg->ref_obj_id);
> +                       verbose(env, "(id=%d", reg->id);
> +                       if (reg_type_may_be_refcounted_or_null(t))
> +                               verbose(env, ",ref_obj_id=%d", reg->ref_obj_id);
>                         if (t != SCALAR_VALUE)
>                                 verbose(env, ",off=%d", reg->off);
>                         if (type_is_pkt_pointer(t))
> --
> 2.17.1
>

lgtm

Acked-by: Andrii Nakryiko <andriin@fb.com>
Alexei Starovoitov March 21, 2019, 1:28 a.m. UTC | #2
On Mon, Mar 18, 2019 at 10:37:13AM -0700, Martin KaFai Lau wrote:
> Naresh reported that test_align fails because of the mismatch at the
> verbose printout of the register states.  The reason is due to the newly
> added ref_obj_id.
> 
> ref_obj_id is only useful for refcounted reg.  Thus, this patch fixes it
> by only printing ref_obj_id for refcounted reg.  While at it, it also uses
> comma instead of space to separate between "id" and "ref_obj_id".
> 
> Fixes: 1b986589680a ("bpf: Fix bpf_tcp_sock and bpf_sk_fullsock issue related to bpf_sk_release")
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Signed-off-by: Martin KaFai Lau <kafai@fb.com>

Applied, Thanks
diff mbox series

Patch

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 86f9cd5d1c4e..5aa810882583 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -352,6 +352,14 @@  static bool reg_may_point_to_spin_lock(const struct bpf_reg_state *reg)
 		map_value_has_spin_lock(reg->map_ptr);
 }
 
+static bool reg_type_may_be_refcounted_or_null(enum bpf_reg_type type)
+{
+	return type == PTR_TO_SOCKET ||
+		type == PTR_TO_SOCKET_OR_NULL ||
+		type == PTR_TO_TCP_SOCK ||
+		type == PTR_TO_TCP_SOCK_OR_NULL;
+}
+
 static bool arg_type_may_be_refcounted(enum bpf_arg_type type)
 {
 	return type == ARG_PTR_TO_SOCK_COMMON;
@@ -451,8 +459,9 @@  static void print_verifier_state(struct bpf_verifier_env *env,
 			if (t == PTR_TO_STACK)
 				verbose(env, ",call_%d", func(env, reg)->callsite);
 		} else {
-			verbose(env, "(id=%d ref_obj_id=%d", reg->id,
-				reg->ref_obj_id);
+			verbose(env, "(id=%d", reg->id);
+			if (reg_type_may_be_refcounted_or_null(t))
+				verbose(env, ",ref_obj_id=%d", reg->ref_obj_id);
 			if (t != SCALAR_VALUE)
 				verbose(env, ",off=%d", reg->off);
 			if (type_is_pkt_pointer(t))