Skip to contentSkip to conversation

unix_bpf: check socket type in unix_bpf_update_proto()

PATCH Applied Cong Wang 3 participants 3 messages Jul 31, 2021 – Aug 3, 2021

Subsystems (5)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 unix_bpf: check socket type in unix_bpf_update_proto()

From: Cong Wang <[email protected]>

As of now, only AF_UNIX datagram socket supports sockmap. But unix_proto is shared for all kinds of AF_UNIX sockets, so we have to check the socket type in unix_bpf_update_proto() to explicitly reject other types, otherwise they could be added into sockmap too.

Fixes c63829182c37 ("af_unix: Implement ->psock_update_sk_prot()")
Cc John Fastabend <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Lorenz Bauer <[email protected]>
---
 net/unix/unix_bpf.c | 3 +++
 1 file changed, 3 insertions(+)
net/unix/unix_bpf.c +3 -0
index 177e883f451e..20f53575b5c9 100644
@@ -105,6 +105,9 @@ static void unix_bpf_check_needs_rebuild(struct proto *ops)
 
 int unix_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
 {
+	if (sk->sk_type != SOCK_DGRAM)
+		return -EOPNOTSUPP;
+
 	if (restore) {
 		sk->sk_write_space = psock->saved_write_space;
 		WRITE_ONCE(sk->sk_prot, psock->sk_proto);
Signature · 1 line
2.27.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 23 lines · Cong Wang

From: Cong Wang <[email protected]>

As of now, only AF_UNIX datagram socket supports sockmap. But unix_proto is shared for all kinds of AF_UNIX sockets, so we have to check the socket type in unix_bpf_update_proto() to explicitly reject other types, otherwise they could be added into sockmap too.

Fixes c63829182c37 ("af_unix: Implement ->psock_update_sk_prot()")
Cc John Fastabend <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Lorenz Bauer <[email protected]>
---
 net/unix/unix_bpf.c | 3 +++
 1 file changed, 3 insertions(+)
net/unix/unix_bpf.c +0 -0
index 177e883f451e..20f53575b5c9 100644

net/unix/unix_bpf.c static void unix_bpf_check_needs_rebuild(struct proto *ops) · line 113

Quoted 9 lines
net/unix/unix_bpf.c +3 -0
@@ -105,6 +105,9 @@ static void unix_bpf_check_needs_rebuild(struct proto *ops)
 
 int unix_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
 {
+	if (sk->sk_type != SOCK_DGRAM)
+		return -EOPNOTSUPP;
+
 	if (restore) {
 		sk->sk_write_space = psock->saved_write_space;
 		WRITE_ONCE(sk->sk_prot, psock->sk_proto);
#2 lore raw
In reply to Cong Wang
This patch was applied to bpf/bpf-next.git (refs/heads/master):

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

Quoted 9 lines · On Sat, 31 Jul 2021 12:50:38 -0700 you wrote:

From: Cong Wang <[email protected]>

As of now, only AF_UNIX datagram socket supports sockmap. But unix_proto is shared for all kinds of AF_UNIX sockets, so we have to check the socket type in unix_bpf_update_proto() to explicitly reject other types, otherwise they could be added into sockmap too.

[...]

Here is the summary with links:
- [bpf-next] unix_bpf: check socket type in unix_bpf_update_proto()

    https://git.kernel.org/bpf/bpf-next/c/83f31535565c

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html