aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorMartin KaFai Lau <kafai@fb.com>2019-03-18 13:37:13 -0400
committerAlexei Starovoitov <ast@kernel.org>2019-03-20 21:24:35 -0400
commitcba368c1f01c27ed62fca7a853531845d263bb01 (patch)
treeb1e5d98d11f78bdb37b2746c2b74fae29d1c4f83 /kernel
parentf01a7dbe98ae4265023fa5d3af0f076f0b18a647 (diff)
bpf: Only print ref_obj_id for refcounted reg
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> Acked-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/bpf/verifier.c13
1 files 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)
352 map_value_has_spin_lock(reg->map_ptr); 352 map_value_has_spin_lock(reg->map_ptr);
353} 353}
354 354
355static bool reg_type_may_be_refcounted_or_null(enum bpf_reg_type type)
356{
357 return type == PTR_TO_SOCKET ||
358 type == PTR_TO_SOCKET_OR_NULL ||
359 type == PTR_TO_TCP_SOCK ||
360 type == PTR_TO_TCP_SOCK_OR_NULL;
361}
362
355static bool arg_type_may_be_refcounted(enum bpf_arg_type type) 363static bool arg_type_may_be_refcounted(enum bpf_arg_type type)
356{ 364{
357 return type == ARG_PTR_TO_SOCK_COMMON; 365 return type == ARG_PTR_TO_SOCK_COMMON;
@@ -451,8 +459,9 @@ static void print_verifier_state(struct bpf_verifier_env *env,
451 if (t == PTR_TO_STACK) 459 if (t == PTR_TO_STACK)
452 verbose(env, ",call_%d", func(env, reg)->callsite); 460 verbose(env, ",call_%d", func(env, reg)->callsite);
453 } else { 461 } else {
454 verbose(env, "(id=%d ref_obj_id=%d", reg->id, 462 verbose(env, "(id=%d", reg->id);
455 reg->ref_obj_id); 463 if (reg_type_may_be_refcounted_or_null(t))
464 verbose(env, ",ref_obj_id=%d", reg->ref_obj_id);
456 if (t != SCALAR_VALUE) 465 if (t != SCALAR_VALUE)
457 verbose(env, ",off=%d", reg->off); 466 verbose(env, ",off=%d", reg->off);
458 if (type_is_pkt_pointer(t)) 467 if (type_is_pkt_pointer(t))