mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-05 16:37:50 +00:00
bpf, unix: Check socket type in unix_bpf_update_proto()
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: c63829182c
("af_unix: Implement ->psock_update_sk_prot()")
Reported-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jakub Sitnicki <jakub@cloudflare.com>
Link: https://lore.kernel.org/bpf/20210731195038.8084-1-xiyou.wangcong@gmail.com
This commit is contained in:
parent
b61a28cf11
commit
83f3153556
1 changed files with 3 additions and 0 deletions
|
@ -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)
|
int unix_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
|
||||||
{
|
{
|
||||||
|
if (sk->sk_type != SOCK_DGRAM)
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
if (restore) {
|
if (restore) {
|
||||||
sk->sk_write_space = psock->saved_write_space;
|
sk->sk_write_space = psock->saved_write_space;
|
||||||
WRITE_ONCE(sk->sk_prot, psock->sk_proto);
|
WRITE_ONCE(sk->sk_prot, psock->sk_proto);
|
||||||
|
|
Loading…
Reference in a new issue