Revert "udp: annotate data-races around udp->encap_type"

This reverts commit 158b71f3a9 which is
commit 70a36f571362a8de8b8c02d21ae524fc776287f2 upstream.

It breaks the Android kernel abi and can be brought back in the future
in an abi-safe way if it is really needed.

Bug: 161946584
Change-Id: I516d935c83a8731f077b5b4e72e762c8a9a63bd1
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
Greg Kroah-Hartman 2024-01-15 11:37:36 +00:00
parent acd1add3c8
commit f9f95b82b2
6 changed files with 15 additions and 17 deletions

View File

@ -629,7 +629,7 @@ static void __gtp_encap_destroy(struct sock *sk)
gtp->sk0 = NULL;
else
gtp->sk1u = NULL;
WRITE_ONCE(udp_sk(sk)->encap_type, 0);
udp_sk(sk)->encap_type = 0;
rcu_assign_sk_user_data(sk, NULL);
release_sock(sk);
sock_put(sk);
@ -681,7 +681,7 @@ static int gtp_encap_recv(struct sock *sk, struct sk_buff *skb)
netdev_dbg(gtp->dev, "encap_recv sk=%p\n", sk);
switch (READ_ONCE(udp_sk(sk)->encap_type)) {
switch (udp_sk(sk)->encap_type) {
case UDP_ENCAP_GTP0:
netdev_dbg(gtp->dev, "received GTP0 packet\n");
ret = gtp0_udp_encap_recv(gtp, skb);

View File

@ -733,7 +733,7 @@ int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable)
iph->saddr, uh->source, skb->dev->ifindex,
inet_sdif(skb), udptable, NULL);
if (!sk || READ_ONCE(udp_sk(sk)->encap_type)) {
if (!sk || udp_sk(sk)->encap_type) {
/* No socket for error: try tunnels before discarding */
if (static_branch_unlikely(&udp_encap_needed_key)) {
sk = __udp4_lib_err_encap(net, iph, uh, udptable, sk, skb,
@ -2114,8 +2114,7 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb)
}
nf_reset_ct(skb);
if (static_branch_unlikely(&udp_encap_needed_key) &&
READ_ONCE(up->encap_type)) {
if (static_branch_unlikely(&udp_encap_needed_key) && up->encap_type) {
int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
/*
@ -2700,7 +2699,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
#endif
fallthrough;
case UDP_ENCAP_L2TPINUDP:
WRITE_ONCE(up->encap_type, val);
up->encap_type = val;
udp_tunnel_encap_enable(sk);
break;
default:
@ -2801,7 +2800,7 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname,
break;
case UDP_ENCAP:
val = READ_ONCE(up->encap_type);
val = up->encap_type;
break;
case UDP_NO_CHECK6_TX:

View File

@ -85,11 +85,11 @@ int xfrm4_udp_encap_rcv(struct sock *sk, struct sk_buff *skb)
struct udphdr *uh;
struct iphdr *iph;
int iphlen, len;
__u8 *udpdata;
__be32 *udpdata32;
u16 encap_type;
__u16 encap_type = up->encap_type;
encap_type = READ_ONCE(up->encap_type);
/* if this is not encapsulated socket, then just return now */
if (!encap_type)
return 1;

View File

@ -598,7 +598,7 @@ int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
sk = __udp6_lib_lookup(net, daddr, uh->dest, saddr, uh->source,
inet6_iif(skb), inet6_sdif(skb), udptable, NULL);
if (!sk || READ_ONCE(udp_sk(sk)->encap_type)) {
if (!sk || udp_sk(sk)->encap_type) {
/* No socket for error: try tunnels before discarding */
if (static_branch_unlikely(&udpv6_encap_needed_key)) {
sk = __udp6_lib_err_encap(net, hdr, offset, uh,
@ -712,8 +712,7 @@ static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb)
}
nf_reset_ct(skb);
if (static_branch_unlikely(&udpv6_encap_needed_key) &&
READ_ONCE(up->encap_type)) {
if (static_branch_unlikely(&udpv6_encap_needed_key) && up->encap_type) {
int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
/*

View File

@ -81,14 +81,14 @@ int xfrm6_udp_encap_rcv(struct sock *sk, struct sk_buff *skb)
struct ipv6hdr *ip6h;
int len;
int ip6hlen = sizeof(struct ipv6hdr);
__u8 *udpdata;
__be32 *udpdata32;
u16 encap_type;
__u16 encap_type = up->encap_type;
if (skb->protocol == htons(ETH_P_IP))
return xfrm4_udp_encap_rcv(sk, skb);
encap_type = READ_ONCE(up->encap_type);
/* if this is not encapsulated socket, then just return now */
if (!encap_type)
return 1;

View File

@ -1139,9 +1139,9 @@ static void l2tp_tunnel_destruct(struct sock *sk)
switch (tunnel->encap) {
case L2TP_ENCAPTYPE_UDP:
/* No longer an encapsulation socket. See net/ipv4/udp.c */
WRITE_ONCE(udp_sk(sk)->encap_type, 0);
udp_sk(sk)->encap_rcv = NULL;
udp_sk(sk)->encap_destroy = NULL;
(udp_sk(sk))->encap_type = 0;
(udp_sk(sk))->encap_rcv = NULL;
(udp_sk(sk))->encap_destroy = NULL;
break;
case L2TP_ENCAPTYPE_IP:
break;