-
Notifications
You must be signed in to change notification settings - Fork 131
bpf: make reg_not_null() true for CONST_PTR_TO_MAP #9042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Upstream branch: cd2e103 |
Upstream branch: cd2e103 |
4bc77dd
to
95c5ea2
Compare
810d3c3
to
8af34a9
Compare
Upstream branch: 7fdaba9 |
95c5ea2
to
b8de394
Compare
8af34a9
to
efe09e8
Compare
Upstream branch: 919319b |
b8de394
to
e8bb226
Compare
efe09e8
to
ccbb215
Compare
Upstream branch: 97744b4 |
e8bb226
to
016ad84
Compare
ccbb215
to
de55d92
Compare
Upstream branch: a570f38 |
016ad84
to
ff5d226
Compare
de55d92
to
6d7073a
Compare
When reg->type is CONST_PTR_TO_MAP, it can not be null. However the verifier explores the branches under rX == 0 in check_cond_jmp_op() even if reg->type is CONST_PTR_TO_MAP, because it was not checked for in reg_not_null(). Fix this by adding CONST_PTR_TO_MAP to the set of types that are considered non nullable in reg_not_null(). An old "unpriv: cmp map pointer with zero" selftest fails with this change, because now early out correctly triggers in check_cond_jmp_op(), making the verification to pass. In practice verifier may allow pointer to null comparison in unpriv, since in many cases the relevant branch and comparison op are removed as dead code. So change the expected test result to __success_unpriv. Signed-off-by: Ihor Solodrai <[email protected]> Acked-by: Andrii Nakryiko <[email protected]>
Add a test for CONST_PTR_TO_MAP comparison with a non-0 constant. A BPF program with this code must not pass verification in unpriv. Signed-off-by: Ihor Solodrai <[email protected]>
A test requires the following to happen: * CONST_PTR_TO_MAP value is put on the stack * then this value is checked for null * the code in the null branch fails verification I was able to achieve this by using a stack allocated array of maps, populated with values from a global map. This is the first test case: map_ptr_is_never_null. The second test case (map_ptr_is_never_null_rb) involves an array of ringbufs and attempts to recreate a common coding pattern [1]. [1] https://lore.kernel.org/bpf/CAEf4BzZNU0gX_sQ8k8JaLe1e+Veth3Rk=4x7MDhv=hQxvO8EDw@mail.gmail.com/ Suggested-by: Andrii Nakryiko <[email protected]> Signed-off-by: Ihor Solodrai <[email protected]> Acked-by: Andrii Nakryiko <[email protected]>
Upstream branch: 64a064c |
ff5d226
to
ca2c2d4
Compare
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=968739 expired. Closing PR. |
Pull request for series with
subject: bpf: make reg_not_null() true for CONST_PTR_TO_MAP
version: 2
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=968449