History

tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if()

inet_request_bound_dev_if() reads sk->sk_bound_dev_if twice while listener socket is not locked. Another cpu could change this field under us.

Eric Dumazet committed 4 years ago

Commit fdb5fd71 parent a20ea291 file · +3 −2Browse files

Unified · Split

include/net/inet_sock.h+3−2
@@ -116,14 +116,15 @@ static inline u32 inet_request_mark(const struct sock *sk, struct sk_buff *skb) · 115 unmodified lines
116116 static inline int inet_request_bound_dev_if(const struct sock *sk,
117117 struct sk_buff *skb)
118118 {
119+ int bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
119120 #ifdef CONFIG_NET_L3_MASTER_DEV
120121 struct net *net = sock_net(sk);
121122
122− if (!sk->sk_bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept)
123+ if (!bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept)
123124 return l3mdev_master_ifindex_by_index(net, skb->skb_iif);
124125 #endif
125126
126− return sk->sk_bound_dev_if;
127+ return bound_dev_if;
127128 }
128129
129130 static inline int inet_sk_bound_l3mdev(const struct sock *sk)