bpf: Fix refcount_acquire handling for borrowed kptrs - #13284
bpf: Fix refcount_acquire handling for borrowed kptrs#13284kernel-patches-daemon-bpf[bot] wants to merge 5 commits into
Conversation
|
Upstream branch: 806c1a1 |
6220a54 to
fa81f18
Compare
|
Upstream branch: aacd13e |
ce47b90 to
496d0eb
Compare
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
fa81f18 to
fdd9d75
Compare
|
Upstream branch: 259d60f |
496d0eb to
ba72662
Compare
|
Forwarding comment 5286949115 via email |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
|
Forwarding comment 5286983291 via email |
|
Forwarding comment 5286997579 via email |
fdd9d75 to
c66e1e2
Compare
|
Upstream branch: 4d9551b |
ba72662 to
50db7d8
Compare
c66e1e2 to
114cb6a
Compare
|
Upstream branch: 409a9bd |
50db7d8 to
06d21ca
Compare
114cb6a to
ddff495
Compare
|
Upstream branch: c7e6175 |
06d21ca to
2c67d2c
Compare
97257fa to
93af0f7
Compare
93097fe to
b51acce
Compare
|
Upstream branch: d99bda7 |
93af0f7 to
4770caa
Compare
b51acce to
b27c6f9
Compare
|
Upstream branch: 34e0eb7 |
4770caa to
846c763
Compare
b27c6f9 to
5d621a7
Compare
|
Upstream branch: 5fe7007 |
846c763 to
7a285d3
Compare
5d621a7 to
81e4232
Compare
|
Upstream branch: 77877bf |
7a285d3 to
10c724f
Compare
81e4232 to
f0e6afe
Compare
|
Upstream branch: adb7719 |
10c724f to
a94fd36
Compare
f0e6afe to
7ac20a0
Compare
|
Upstream branch: 6b0835a |
The verifier can mistake an RCU-loaded map kptr for an owned reference and assume bpf_refcount_acquire() cannot return NULL. The kfunc uses refcount_inc_not_zero(), so it can return NULL after the last reference is dropped. Passing that unchecked result to bpf_obj_drop() can crash the kernel. Only treat the argument as owned when the verifier tracks an acquired reference for it. Borrowed pointers remain nullable, while owned pointers keep the existing behavior. Fixes: 1b12171 ("bpf: Mark direct ld of stashed bpf_{rb,list}_node as non-owning ref") Assisted-by: Codex:gpt-5.5 Assisted-by: ChatGPT:GPT-5.6-Thinking Signed-off-by: Ning Ding <dingning04@gmail.com>
The verifier could accept an unchecked bpf_refcount_acquire() result for a borrowed RCU-loaded map kptr. If the call returns NULL, passing the result to bpf_obj_drop() can crash the kernel. Add tests showing that an owned input remains non-NULL, a checked borrowed result is accepted, and an unchecked borrowed result is rejected. Assisted-by: Codex:gpt-5.5 Assisted-by: ChatGPT:GPT-5.6-Thinking Signed-off-by: Ning Ding <dingning04@gmail.com>
type_is_ptr_alloc_obj() currently treats PTR_UNTRUSTED pointers as valid allocated objects. This allows a pointer that is no longer protected by RCU to be passed to bpf_refcount_acquire(). If the object was freed and its address reused, the verifier may acquire a reference through stale memory. Make type_is_ptr_alloc_obj() reject PTR_UNTRUSTED. Add type_is_untrusted_ptr_alloc_obj() for the read path, where these pointers are still allowed for BPF_PROBE_MEM reads. This keeps checks strict without breaking safe reads. Fixes: 1b12171 ("bpf: Mark direct ld of stashed bpf_{rb,list}_node as non-owning ref") Reported-by: sashiko-bot@kernel.org Link: https://lore.kernel.org/r/20260726021304.97ED91F000E9@smtp.kernel.org Assisted-by: Codex:gpt-5 Signed-off-by: Ning Ding <dingning04@gmail.com>
The verifier previously allowed pointers used after RCU protection ended to reach bpf_refcount_acquire() and, for one object layout, a direct write. If the object was freed and reused, these operations could access stale memory. Add tests that keep BPF_PROBE_MEM reads accepted but reject reference acquisition and direct writes after RCU protection ends. Cover both tested object layouts. Reported-by: sashiko-bot@kernel.org Link: https://lore.kernel.org/r/20260726021304.97ED91F000E9@smtp.kernel.org Assisted-by: Codex:gpt-5 Signed-off-by: Ning Ding <dingning04@gmail.com>
a94fd36 to
62cf468
Compare
7ac20a0 to
fd7f5fa
Compare
|
Upstream branch: 6ab6a94 Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/netdevbpf/list/?series=1145728 conflict: |
Pull request for series with
subject: bpf: Fix refcount_acquire handling for borrowed kptrs
version: 4
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1145728