Skip to content

Commit 1b367ba

Browse files
mmhalgregkh
authored andcommitted
net: Fix TOCTOU issue in sk_is_readable()
[ Upstream commit 2660a54 ] sk->sk_prot->sock_is_readable is a valid function pointer when sk resides in a sockmap. After the last sk_psock_put() (which usually happens when socket is removed from sockmap), sk->sk_prot gets restored and sk->sk_prot->sock_is_readable becomes NULL. This makes sk_is_readable() racy, if the value of sk->sk_prot is reloaded after the initial check. Which in turn may lead to a null pointer dereference. Ensure the function pointer does not turn NULL after the check. Fixes: 8934ce2 ("bpf: sockmap redirect ingress support") Suggested-by: Jakub Sitnicki <[email protected]> Signed-off-by: Michal Luczaj <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 1a677d0 commit 1b367ba

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

include/net/sock.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2978,8 +2978,11 @@ int sock_ioctl_inout(struct sock *sk, unsigned int cmd,
29782978
int sk_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
29792979
static inline bool sk_is_readable(struct sock *sk)
29802980
{
2981-
if (sk->sk_prot->sock_is_readable)
2982-
return sk->sk_prot->sock_is_readable(sk);
2981+
const struct proto *prot = READ_ONCE(sk->sk_prot);
2982+
2983+
if (prot->sock_is_readable)
2984+
return prot->sock_is_readable(sk);
2985+
29832986
return false;
29842987
}
29852988
#endif /* _SOCK_H */

0 commit comments

Comments
 (0)