Commit 08a75f10 authored by Kuniyuki Iwashima's avatar Kuniyuki Iwashima Committed by David S. Miller

tcp: Fix data-races around sysctl_tcp_l3mdev_accept.

While reading sysctl_tcp_l3mdev_accept, it can be changed concurrently.
Thus, we need to add READ_ONCE() to its readers.

Fixes: 6dd9a14e ("net: Allow accepted sockets to be bound to l3mdev domain")
Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1a0008f9
...@@ -179,7 +179,7 @@ static inline bool inet_sk_bound_dev_eq(struct net *net, int bound_dev_if, ...@@ -179,7 +179,7 @@ static inline bool inet_sk_bound_dev_eq(struct net *net, int bound_dev_if,
int dif, int sdif) int dif, int sdif)
{ {
#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV) #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
return inet_bound_dev_eq(!!net->ipv4.sysctl_tcp_l3mdev_accept, return inet_bound_dev_eq(!!READ_ONCE(net->ipv4.sysctl_tcp_l3mdev_accept),
bound_dev_if, dif, sdif); bound_dev_if, dif, sdif);
#else #else
return inet_bound_dev_eq(true, bound_dev_if, dif, sdif); return inet_bound_dev_eq(true, bound_dev_if, dif, sdif);
......
...@@ -121,7 +121,7 @@ static inline int inet_request_bound_dev_if(const struct sock *sk, ...@@ -121,7 +121,7 @@ static inline int inet_request_bound_dev_if(const struct sock *sk,
#ifdef CONFIG_NET_L3_MASTER_DEV #ifdef CONFIG_NET_L3_MASTER_DEV
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
if (!bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept) if (!bound_dev_if && READ_ONCE(net->ipv4.sysctl_tcp_l3mdev_accept))
return l3mdev_master_ifindex_by_index(net, skb->skb_iif); return l3mdev_master_ifindex_by_index(net, skb->skb_iif);
#endif #endif
...@@ -133,7 +133,7 @@ static inline int inet_sk_bound_l3mdev(const struct sock *sk) ...@@ -133,7 +133,7 @@ static inline int inet_sk_bound_l3mdev(const struct sock *sk)
#ifdef CONFIG_NET_L3_MASTER_DEV #ifdef CONFIG_NET_L3_MASTER_DEV
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
if (!net->ipv4.sysctl_tcp_l3mdev_accept) if (!READ_ONCE(net->ipv4.sysctl_tcp_l3mdev_accept))
return l3mdev_master_ifindex_by_index(net, return l3mdev_master_ifindex_by_index(net,
sk->sk_bound_dev_if); sk->sk_bound_dev_if);
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment