bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf 0/2] bpf: fix an incorrect branch elimination by verifier
@ 2020-06-30 17:12 Yonghong Song
  2020-06-30 17:12 ` [PATCH bpf 1/2] " Yonghong Song
  2020-06-30 17:12 ` [PATCH bpf 2/2] bpf: add tests for PTR_TO_BTF_ID vs. null comparison Yonghong Song
  0 siblings, 2 replies; 13+ messages in thread
From: Yonghong Song @ 2020-06-30 17:12 UTC (permalink / raw)
  To: bpf; +Cc: Alexei Starovoitov, Daniel Borkmann, kernel-team

Wenbo reported an issue in [1] where a checking of null
pointer is evaluated as always false. In this particular
case, the program type is tp_btf and the pointer to
compare is a PTR_TO_BTF_ID.

As an illustration of original issue, consider the following
example:
 struct bpf_fentry_test_t {
     struct bpf_fentry_test_t *a;
 };
 int BPF_PROG(test8, struct bpf_fentry_test_t *arg)
 {
     if (arg->a == 0)
         test8_result = 1;
     return 0;
 }
In the xlated byte code, "arg->a == 0" condition is evaluted
always false and "test8_result = 1" is removed.

This is not right. Patch #1 shows why this happens and how to
fix it in verifier. Patch #2 added two subtests in test_progs
to catch such cases.

 [1]: https://lore.kernel.org/bpf/79dbb7c0-449d-83eb-5f4f-7af0cc269168@fb.com/T/

Yonghong Song (2):
  bpf: fix an incorrect branch elimination by verifier
  bpf: add tests for PTR_TO_BTF_ID vs. null comparison

 kernel/bpf/verifier.c                         |  3 +--
 net/bpf/test_run.c                            | 19 +++++++++++++++-
 .../selftests/bpf/prog_tests/fentry_fexit.c   |  2 +-
 .../testing/selftests/bpf/progs/fentry_test.c | 22 +++++++++++++++++++
 .../testing/selftests/bpf/progs/fexit_test.c  | 22 +++++++++++++++++++
 5 files changed, 64 insertions(+), 4 deletions(-)

-- 
2.24.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-06-30 20:35 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-30 17:12 [PATCH bpf 0/2] bpf: fix an incorrect branch elimination by verifier Yonghong Song
2020-06-30 17:12 ` [PATCH bpf 1/2] " Yonghong Song
2020-06-30 17:51   ` John Fastabend
2020-06-30 18:29     ` Yonghong Song
2020-06-30 18:35       ` John Fastabend
2020-06-30 19:16         ` Alexei Starovoitov
2020-06-30 19:20     ` Andrii Nakryiko
2020-06-30 19:18   ` Andrii Nakryiko
2020-06-30 20:35     ` Daniel Borkmann
2020-06-30 17:12 ` [PATCH bpf 2/2] bpf: add tests for PTR_TO_BTF_ID vs. null comparison Yonghong Song
2020-06-30 18:43   ` John Fastabend
2020-06-30 19:23   ` Andrii Nakryiko
2020-06-30 20:13     ` Yonghong Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).