Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: sock_map, fix missing ulp check in sock hash case

sock_map and ULP only work together when ULP is loaded after the sock
map is loaded. In the sock_map case we added a check for this to fail
the load if ULP is already set. However, we missed the check on the
sock_hash side.

Add a ULP check to the sock_hash update path.

Fixes: 604326b41a6fb ("bpf, sockmap: convert to generic sk_msg interface")
Reported-by: syzbot+7a6ee4d0078eac6bf782@syzkaller.appspotmail.com
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

John Fastabend and committed by
David S. Miller
44580a01 ebe26aca

+3
+3
net/core/sock_map.c
··· 656 656 struct sock *sk, u64 flags) 657 657 { 658 658 struct bpf_htab *htab = container_of(map, struct bpf_htab, map); 659 + struct inet_connection_sock *icsk = inet_csk(sk); 659 660 u32 key_size = map->key_size, hash; 660 661 struct bpf_htab_elem *elem, *elem_new; 661 662 struct bpf_htab_bucket *bucket; ··· 666 665 667 666 WARN_ON_ONCE(!rcu_read_lock_held()); 668 667 if (unlikely(flags > BPF_EXIST)) 668 + return -EINVAL; 669 + if (unlikely(icsk->icsk_ulp_data)) 669 670 return -EINVAL; 670 671 671 672 link = sk_psock_init_link();