Skip to content

Commit

Permalink
udp: move udp->accept_udp_{l4|fraglist} to udp->udp_flags
Browse files Browse the repository at this point in the history
[ Upstream commit f5f52f0 ]

These are read locklessly, move them to udp_flags to fix data-races.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Stable-dep-of: 70a36f5 ("udp: annotate data-races around udp->encap_type")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Eric Dumazet authored and gregkh committed Jan 10, 2024
1 parent 753886c commit b680a90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions include/linux/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ enum {
UDP_FLAGS_NO_CHECK6_TX, /* Send zero UDP6 checksums on TX? */
UDP_FLAGS_NO_CHECK6_RX, /* Allow zero UDP6 checksums on RX? */
UDP_FLAGS_GRO_ENABLED, /* Request GRO aggregation */
UDP_FLAGS_ACCEPT_FRAGLIST,
UDP_FLAGS_ACCEPT_L4,
};

struct udp_sock {
Expand All @@ -48,13 +50,11 @@ struct udp_sock {

int pending; /* Any pending frames ? */
__u8 encap_type; /* Is this an Encapsulation socket? */
unsigned char encap_enabled:1, /* This socket enabled encap
unsigned char encap_enabled:1; /* This socket enabled encap
* processing; UDP tunnels and
* different encapsulation layer set
* this
*/
accept_udp_l4:1,
accept_udp_fraglist:1;
/* indicator bits used by pcflag: */
#define UDPLITE_BIT 0x1 /* set by udplite proto init function */
#define UDPLITE_SEND_CC 0x2 /* set via udplite setsockopt */
Expand Down Expand Up @@ -146,19 +146,21 @@ static inline bool udp_unexpected_gso(struct sock *sk, struct sk_buff *skb)
if (!skb_is_gso(skb))
return false;

if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4 && !udp_sk(sk)->accept_udp_l4)
if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4 &&
!udp_test_bit(ACCEPT_L4, sk))
return true;

if (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST && !udp_sk(sk)->accept_udp_fraglist)
if (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST &&
!udp_test_bit(ACCEPT_FRAGLIST, sk))
return true;

return false;
}

static inline void udp_allow_gso(struct sock *sk)
{
udp_sk(sk)->accept_udp_l4 = 1;
udp_sk(sk)->accept_udp_fraglist = 1;
udp_set_bit(ACCEPT_L4, sk);
udp_set_bit(ACCEPT_FRAGLIST, sk);
}

#define udp_portaddr_for_each_entry(__sk, list) \
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2731,7 +2731,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
if (valbool)
udp_tunnel_encap_enable(sk->sk_socket);
udp_assign_bit(GRO_ENABLED, sk, valbool);
up->accept_udp_l4 = valbool;
udp_assign_bit(ACCEPT_L4, sk, valbool);
release_sock(sk);
break;

Expand Down

0 comments on commit b680a90

Please sign in to comment.