-
Notifications
You must be signed in to change notification settings - Fork 5
bpf: Fix possible memleak when updating hash and local storage maps #6184
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: 1c64efc |
d564564
to
fd2f251
Compare
Upstream branch: 1c64efc |
671d50c
to
47aefc0
Compare
fd2f251
to
3faa79e
Compare
Upstream branch: 4e90776 |
47aefc0
to
6937a86
Compare
3faa79e
to
96c0f24
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 <[email protected]>
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 <[email protected]>
…_LOCK When updating local storage 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 'bpf_obj_free_fields()' after 'copy_map_value_locked()' to properly release the old fields. Fixes: 9db44fd ("bpf: Support kptrs in local storage maps") Signed-off-by: Leon Hwang <[email protected]>
…cgrp storage maps Add tests to verify that updating hash and local storage maps does not leak memory when BPF_KPTR_REF objects are involved. The tests perform 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. Probe-read the refcount and verify it is *1*. Signed-off-by: Leon Hwang <[email protected]>
Upstream branch: 881a9c9 |
6937a86
to
2914163
Compare
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1013677 expired. Closing PR. |
Pull request for series with
subject: bpf: Fix possible memleak when updating hash and local storage maps
version: 2
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1013677