bpf: Fix possible memleak when updating hash maps#10012
bpf: Fix possible memleak when updating hash maps#10012kernel-patches-daemon-bpf[bot] wants to merge 3 commits intobpf_basefrom
Conversation
|
Upstream branch: 5fb750e |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
|
Forwarding comment 3411425561 via email |
f474174 to
196da5a
Compare
|
Upstream branch: 0c1999e |
9797b8f to
34302d7
Compare
196da5a to
6506680
Compare
|
Upstream branch: 8adc470 |
34302d7 to
dab4013
Compare
6506680 to
fd52e6f
Compare
|
Upstream branch: f6fddc6 |
dab4013 to
d17449d
Compare
fd52e6f to
a36ad11
Compare
|
Upstream branch: f6fddc6 |
d17449d to
9053aa7
Compare
a36ad11 to
b1f9967
Compare
|
Upstream branch: a1e83d4 |
9053aa7 to
9f1d94d
Compare
b1f9967 to
9761e9e
Compare
|
Upstream branch: a1e83d4 |
9f1d94d to
46b36c7
Compare
9761e9e to
2cf3f91
Compare
As [lru_,]percpu_hash maps support BPF_KPTR_{REF,PERCPU}, missing
calls to 'bpf_obj_free_fields()' in 'pcpu_copy_value()' can leak memory
referenced by BPF_KPTR_{REF,PERCPU} fields.
Fix this by calling 'bpf_obj_free_fields()' after
'copy_map_value[,_long]()' in 'pcpu_copy_value()'.
Fixes: 65334e6 ("bpf: Support kptrs in percpu hashmap and percpu LRU hashmap")
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
When updating hash maps with BPF_F_LOCK, the special fields were not
freed after being replaced. This could cause memory referenced by
BPF_KPTR_{REF,PERCPU} fields to leak.
Fix this by calling 'check_and_free_fields()' after
'copy_map_value_locked()' to properly release the old fields.
Fixes: 14a324f ("bpf: Wire up freeing of referenced kptr")
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Add two tests to verify that updating hash maps does not leak memory when BPF_KPTR_REF objects are involved. The test performs the following steps: 1. Call update_elem() to insert an initial value. 2. Use bpf_refcount_acquire() to increment the refcount. 3. Store the node pointer in the map value. 4. Add the node to a linked list. 5. Probe-read the refcount and verify it is *2*. 6. Call update_elem() again to trigger refcount decrement. 7. Verify that the field has been reset. Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
|
Upstream branch: 1c64efc |
46b36c7 to
b19963c
Compare
|
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1012411 expired. Closing PR. |
Pull request for series with
subject: bpf: Fix possible memleak when updating hash maps
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1012411