Skip to content

bpf: fix an incorrect branch elimination by verifier

Yonghong Song bpf 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 10 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf: fix an incorrect branch elimination by verifierkernel/bpf/verifier.c+1 -27 replies
2/2bpf: add tests for PTR_TO_BTF_ID vs. null comparisonnet/bpf/test_run.c tools/testing/selftests/bpf/prog_tests/fentry_fexit.c tools/testing/selftests/bpf/progs/fentry_test.c +1 more+63 -23 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchJohn FastabendAndrii Nakryiko
1/2A-b A-b
2/2A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH bpf 0/2] bpf: fix an incorrect branch elimination by verifier

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/[email protected]/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(-)
Signature · 1 line
2.24.1