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

Configure Feed

Select the types of activity you want to include in your feed.

net: annotate data races around sk->sk_prot

inet_sendmsg() and inet_recvmsg() access sk->sk_prot without
lock_sock() or any other synchronization.

sock_replace_proto() (used by sockmap), TLS and MPTCP can change
sk->sk_prot under us, so these functions need READ_ONCE() to avoid
load tearing.

Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260304064253.16955-1-jiayuan.chen@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Jiayuan Chen and committed by
Jakub Kicinski
ad4c9559 260d27b3

+6 -2
+6 -2
net/ipv4/af_inet.c
··· 852 852 int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) 853 853 { 854 854 struct sock *sk = sock->sk; 855 + const struct proto *prot; 855 856 856 857 if (unlikely(inet_send_prepare(sk))) 857 858 return -EAGAIN; 858 859 859 - return INDIRECT_CALL_2(sk->sk_prot->sendmsg, tcp_sendmsg, udp_sendmsg, 860 + prot = READ_ONCE(sk->sk_prot); 861 + return INDIRECT_CALL_2(prot->sendmsg, tcp_sendmsg, udp_sendmsg, 860 862 sk, msg, size); 861 863 } 862 864 EXPORT_SYMBOL(inet_sendmsg); ··· 884 882 int flags) 885 883 { 886 884 struct sock *sk = sock->sk; 885 + const struct proto *prot; 887 886 888 887 if (likely(!(flags & MSG_ERRQUEUE))) 889 888 sock_rps_record_flow(sk); 890 889 891 - return INDIRECT_CALL_2(sk->sk_prot->recvmsg, tcp_recvmsg, udp_recvmsg, 890 + prot = READ_ONCE(sk->sk_prot); 891 + return INDIRECT_CALL_2(prot->recvmsg, tcp_recvmsg, udp_recvmsg, 892 892 sk, msg, size, flags); 893 893 } 894 894 EXPORT_SYMBOL(inet_recvmsg);