All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch bpf-next] unix_bpf: check socket type in unix_bpf_update_proto()
@ 2021-07-31 19:50 Cong Wang
  2021-08-02  9:00 ` Jakub Sitnicki
  2021-08-03 11:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Cong Wang @ 2021-07-31 19:50 UTC (permalink / raw)
  To: netdev
  Cc: bpf, jiang.wang, Cong Wang, Jakub Sitnicki, John Fastabend,
	Daniel Borkmann, Lorenz Bauer

From: Cong Wang <cong.wang@bytedance.com>

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()")
Reported-by: Jakub Sitnicki <jakub@cloudflare.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
---
 net/unix/unix_bpf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/unix/unix_bpf.c b/net/unix/unix_bpf.c
index 177e883f451e..20f53575b5c9 100644
--- a/net/unix/unix_bpf.c
+++ b/net/unix/unix_bpf.c
@@ -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.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch bpf-next] unix_bpf: check socket type in unix_bpf_update_proto()
  2021-07-31 19:50 [Patch bpf-next] unix_bpf: check socket type in unix_bpf_update_proto() Cong Wang
@ 2021-08-02  9:00 ` Jakub Sitnicki
  2021-08-03 11:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Sitnicki @ 2021-08-02  9:00 UTC (permalink / raw)
  To: Cong Wang
  Cc: netdev, bpf, jiang.wang, Cong Wang, John Fastabend,
	Daniel Borkmann, Lorenz Bauer

On Sat, Jul 31, 2021 at 09:50 PM CEST, Cong Wang wrote:
> From: Cong Wang <cong.wang@bytedance.com>
>
> 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()")
> Reported-by: Jakub Sitnicki <jakub@cloudflare.com>
> Cc: John Fastabend <john.fastabend@gmail.com>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Lorenz Bauer <lmb@cloudflare.com>
> Signed-off-by: Cong Wang <cong.wang@bytedance.com>
> ---
>  net/unix/unix_bpf.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/net/unix/unix_bpf.c b/net/unix/unix_bpf.c
> index 177e883f451e..20f53575b5c9 100644
> --- a/net/unix/unix_bpf.c
> +++ b/net/unix/unix_bpf.c
> @@ -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);

Acked-by: Jakub Sitnicki <jakub@cloudflare.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch bpf-next] unix_bpf: check socket type in unix_bpf_update_proto()
  2021-07-31 19:50 [Patch bpf-next] unix_bpf: check socket type in unix_bpf_update_proto() Cong Wang
  2021-08-02  9:00 ` Jakub Sitnicki
@ 2021-08-03 11:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-08-03 11:00 UTC (permalink / raw)
  To: Cong Wang
  Cc: netdev, bpf, jiang.wang, cong.wang, jakub, john.fastabend, daniel, lmb

Hello:

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

On Sat, 31 Jul 2021 12:50:38 -0700 you wrote:
> From: Cong Wang <cong.wang@bytedance.com>
> 
> 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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-03 11:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-31 19:50 [Patch bpf-next] unix_bpf: check socket type in unix_bpf_update_proto() Cong Wang
2021-08-02  9:00 ` Jakub Sitnicki
2021-08-03 11:00 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.