bpf: Reject access to unix_sk(sk)->{peer,listener}.#10984
Closed
kernel-patches-daemon-bpf[bot] wants to merge 2 commits intobpf_basefrom
Closed
bpf: Reject access to unix_sk(sk)->{peer,listener}.#10984kernel-patches-daemon-bpf[bot] wants to merge 2 commits intobpf_basefrom
kernel-patches-daemon-bpf[bot] wants to merge 2 commits intobpf_basefrom
Conversation
Author
|
Upstream branch: 2687c84 |
3ccff98 to
cb877fa
Compare
Author
|
Upstream branch: 05f7e89 |
Michal Luczaj reported use-after-free of unix_sk(sk)->peer by bpf_skc_to_unix_sock(). [0] Accessing unix_sk(sk)->peer is safe only under unix_state_lock(), but there are many functions where bpf prog can access the field locklessly via fentry/fexit. unix_dgram_connect() could clear unix_sk(sk)->peer and release the last refcnt of the peer sk while a bpf prog is accessing it, resulting in use-after-free. Another problematic scenario is that unix_sk(sk)->peer could go away while being passed to bpf_setsockopt() in bpf iter. To avoid such issues, let's reject access to unix_sk(sk)->peer by marking the pointer with PTR_UNTRUSTED. If needed, we could add a new helper later that uses unix_peer_get() and requires bpf_sk_release(). [0]: BUG: KASAN: slab-use-after-free in bpf_skc_to_unix_sock+0xa4/0xb0 Read of size 2 at addr ffff888147d38890 by task test_progs/2495 Call Trace: dump_stack_lvl+0x5d/0x80 print_report+0x170/0x4f3 kasan_report+0xe1/0x180 bpf_skc_to_unix_sock+0xa4/0xb0 bpf_prog_564a1c39c35d86a2_unix_shutdown_entry+0x8a/0x8e bpf_trampoline_6442564662+0x47/0xab unix_shutdown+0x9/0x880 __sys_shutdown+0xe1/0x160 __x64_sys_shutdown+0x52/0x90 do_syscall_64+0x6b/0x3a0 entry_SYSCALL_64_after_hwframe+0x76/0x7e Fixes: 9eeb3aa ("bpf: Add bpf_skc_to_unix_sock() helper") Reported-by: Michal Luczaj <mhal@rbox.co> Closes: https://lore.kernel.org/all/408569e7-2b82-4eff-b767-79ce6ef6cae0@rbox.co/ Suggested-by: Martin KaFai Lau <martin.lau@kernel.org> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
With the previous patch, bpf prog cannot access unix_sk(sk)->peer. struct unix_sock has two pointers to struct sock, and another pointer unix_sk(sk)->listener also has the same problem mentioned in the previous patch. unix_sk(sk)->listener is set by unix_stream_connect() and cleared by unix_update_edges() during accept(), and both are done under unix_state_lock(). There are some functions where unix_sk(sk)->peer is passed and bpf prog can access unix_sk(unix_sk(sk)->peer)->listener locklessly, which is unsafe. (e.g. unix_maybe_add_creds()) Let's reject bpf access to unix_sk(sk)->listener too. Fixes: aed6ece ("af_unix: Save listener for embryo socket.") Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
ed6a4a2 to
a2b38f9
Compare
Author
|
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1051930 expired. Closing PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request for series with
subject: bpf: Reject access to unix_sk(sk)->{peer,listener}.
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1051930