Skip to content

Commit

Permalink
l2tp: use add READ_ONCE() to fetch sk->sk_bound_dev_if
Browse files Browse the repository at this point in the history
Use READ_ONCE() in paths not holding the socket lock.

Signed-off-by: Eric Dumazet <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and davem330 committed May 16, 2022
1 parent 70f87de commit ff00940
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion net/l2tp/l2tp_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ static struct sock *__l2tp_ip_bind_lookup(const struct net *net, __be32 laddr,
sk_for_each_bound(sk, &l2tp_ip_bind_table) {
const struct l2tp_ip_sock *l2tp = l2tp_ip_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
int bound_dev_if;

if (!net_eq(sock_net(sk), net))
continue;

if (sk->sk_bound_dev_if && dif && sk->sk_bound_dev_if != dif)
bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
if (bound_dev_if && dif && bound_dev_if != dif)
continue;

if (inet->inet_rcv_saddr && laddr &&
Expand Down
8 changes: 5 additions & 3 deletions net/l2tp/l2tp_ip6.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ static struct sock *__l2tp_ip6_bind_lookup(const struct net *net,
const struct in6_addr *sk_laddr = inet6_rcv_saddr(sk);
const struct in6_addr *sk_raddr = &sk->sk_v6_daddr;
const struct l2tp_ip6_sock *l2tp = l2tp_ip6_sk(sk);
int bound_dev_if;

if (!net_eq(sock_net(sk), net))
continue;

if (sk->sk_bound_dev_if && dif && sk->sk_bound_dev_if != dif)
bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
if (bound_dev_if && dif && bound_dev_if != dif)
continue;

if (sk_laddr && !ipv6_addr_any(sk_laddr) &&
Expand Down Expand Up @@ -445,7 +447,7 @@ static int l2tp_ip6_getname(struct socket *sock, struct sockaddr *uaddr,
lsa->l2tp_conn_id = lsk->conn_id;
}
if (ipv6_addr_type(&lsa->l2tp_addr) & IPV6_ADDR_LINKLOCAL)
lsa->l2tp_scope_id = sk->sk_bound_dev_if;
lsa->l2tp_scope_id = READ_ONCE(sk->sk_bound_dev_if);
return sizeof(*lsa);
}

Expand Down Expand Up @@ -560,7 +562,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
}

if (fl6.flowi6_oif == 0)
fl6.flowi6_oif = sk->sk_bound_dev_if;
fl6.flowi6_oif = READ_ONCE(sk->sk_bound_dev_if);

if (msg->msg_controllen) {
opt = &opt_space;
Expand Down

0 comments on commit ff00940

Please sign in to comment.