Skip to content

Commit 2660a54

Browse files
mmhalkuba-moo
authored andcommitted
net: Fix TOCTOU issue in sk_is_readable()
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]>
1 parent dc9c678 commit 2660a54

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
@@ -3010,8 +3010,11 @@ int sock_ioctl_inout(struct sock *sk, unsigned int cmd,
30103010
int sk_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
30113011
static inline bool sk_is_readable(struct sock *sk)
30123012
{
3013-
if (sk->sk_prot->sock_is_readable)
3014-
return sk->sk_prot->sock_is_readable(sk);
3013+
const struct proto *prot = READ_ONCE(sk->sk_prot);
3014+
3015+
if (prot->sock_is_readable)
3016+
return prot->sock_is_readable(sk);
3017+
30153018
return false;
30163019
}
30173020
#endif /* _SOCK_H */

0 commit comments

Comments
 (0)