History

l2tp: use add READ_ONCE() to fetch sk->sk_bound_dev_if

Use READ_ONCE() in paths not holding the socket lock.

Eric Dumazet committed 4 years ago

Commit ff009401 parent 70f87de2 files · +8 −4Browse files

Unified · Split

2 files
  1. net/l2tp/l2tp_ip.c +3 −1
  2. net/l2tp/l2tp_ip6.c +5 −3
net/l2tp/l2tp_ip.c+3−1
@@ -50,11 +50,13 @@ static struct sock *__l2tp_ip_bind_lookup(const struct net *net, __be32 laddr, · 49 unmodified lines
5050 sk_for_each_bound(sk, &l2tp_ip_bind_table) {
5151 const struct l2tp_ip_sock *l2tp = l2tp_ip_sk(sk);
5252 const struct inet_sock *inet = inet_sk(sk);
53+ int bound_dev_if;
5354
5455 if (!net_eq(sock_net(sk), net))
5556 continue;
5657
57− if (sk->sk_bound_dev_if && dif && sk->sk_bound_dev_if != dif)
58+ bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
59+ if (bound_dev_if && dif && bound_dev_if != dif)
5860 continue;
5961
6062 if (inet->inet_rcv_saddr && laddr &&
net/l2tp/l2tp_ip6.c+5−3
@@ -62,11 +62,13 @@ static struct sock *__l2tp_ip6_bind_lookup(const struct net *net, · 61 unmodified lines
6262 const struct in6_addr *sk_laddr = inet6_rcv_saddr(sk);
6363 const struct in6_addr *sk_raddr = &sk->sk_v6_daddr;
6464 const struct l2tp_ip6_sock *l2tp = l2tp_ip6_sk(sk);
65+ int bound_dev_if;
6566
6667 if (!net_eq(sock_net(sk), net))
6768 continue;
6869
69− if (sk->sk_bound_dev_if && dif && sk->sk_bound_dev_if != dif)
70+ bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
71+ if (bound_dev_if && dif && bound_dev_if != dif)
7072 continue;
7173
7274 if (sk_laddr && !ipv6_addr_any(sk_laddr) &&
@@ -445,7 +447,7 @@ static int l2tp_ip6_getname(struct socket *sock, struct sockaddr *uaddr, · 372 unmodified lines
445447 lsa->l2tp_conn_id = lsk->conn_id;
446448 }
447449 if (ipv6_addr_type(&lsa->l2tp_addr) & IPV6_ADDR_LINKLOCAL)
448− lsa->l2tp_scope_id = sk->sk_bound_dev_if;
450+ lsa->l2tp_scope_id = READ_ONCE(sk->sk_bound_dev_if);
449451 return sizeof(*lsa);
450452 }
451453
@@ -560,7 +562,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · 108 unmodified lines
560562 }
561563
562564 if (fl6.flowi6_oif == 0)
563− fl6.flowi6_oif = sk->sk_bound_dev_if;
565+ fl6.flowi6_oif = READ_ONCE(sk->sk_bound_dev_if);
564566
565567 if (msg->msg_controllen) {
566568 opt = &opt_space;