Commit bcbc1b1d authored by Eric Dumazet's avatar Eric Dumazet Committed by Paolo Abeni

udp: move udp->no_check6_rx to udp->udp_flags

syzbot reported that udp->no_check6_rx can be read locklessly.
Use one atomic bit from udp->udp_flags.

Fixes: 1c19448c ("net: Make enabling of zero UDP6 csums more restrictive")
Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent a0002127
...@@ -35,6 +35,7 @@ static inline u32 udp_hashfn(const struct net *net, u32 num, u32 mask) ...@@ -35,6 +35,7 @@ static inline u32 udp_hashfn(const struct net *net, u32 num, u32 mask)
enum { enum {
UDP_FLAGS_CORK, /* Cork is required */ UDP_FLAGS_CORK, /* Cork is required */
UDP_FLAGS_NO_CHECK6_TX, /* Send zero UDP6 checksums on TX? */ UDP_FLAGS_NO_CHECK6_TX, /* Send zero UDP6 checksums on TX? */
UDP_FLAGS_NO_CHECK6_RX, /* Allow zero UDP6 checksums on RX? */
}; };
struct udp_sock { struct udp_sock {
...@@ -48,8 +49,7 @@ struct udp_sock { ...@@ -48,8 +49,7 @@ struct udp_sock {
int pending; /* Any pending frames ? */ int pending; /* Any pending frames ? */
__u8 encap_type; /* Is this an Encapsulation socket? */ __u8 encap_type; /* Is this an Encapsulation socket? */
unsigned char no_check6_rx:1,/* Allow zero UDP6 checksums on RX? */ unsigned char encap_enabled:1, /* This socket enabled encap
encap_enabled:1, /* This socket enabled encap
* processing; UDP tunnels and * processing; UDP tunnels and
* different encapsulation layer set * different encapsulation layer set
* this * this
...@@ -120,7 +120,7 @@ static inline void udp_set_no_check6_tx(struct sock *sk, bool val) ...@@ -120,7 +120,7 @@ static inline void udp_set_no_check6_tx(struct sock *sk, bool val)
static inline void udp_set_no_check6_rx(struct sock *sk, bool val) static inline void udp_set_no_check6_rx(struct sock *sk, bool val)
{ {
udp_sk(sk)->no_check6_rx = val; udp_assign_bit(NO_CHECK6_RX, sk, val);
} }
static inline bool udp_get_no_check6_tx(const struct sock *sk) static inline bool udp_get_no_check6_tx(const struct sock *sk)
...@@ -128,9 +128,9 @@ static inline bool udp_get_no_check6_tx(const struct sock *sk) ...@@ -128,9 +128,9 @@ static inline bool udp_get_no_check6_tx(const struct sock *sk)
return udp_test_bit(NO_CHECK6_TX, sk); return udp_test_bit(NO_CHECK6_TX, sk);
} }
static inline bool udp_get_no_check6_rx(struct sock *sk) static inline bool udp_get_no_check6_rx(const struct sock *sk)
{ {
return udp_sk(sk)->no_check6_rx; return udp_test_bit(NO_CHECK6_RX, sk);
} }
static inline void udp_cmsg_recv(struct msghdr *msg, struct sock *sk, static inline void udp_cmsg_recv(struct msghdr *msg, struct sock *sk,
......
...@@ -2698,7 +2698,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname, ...@@ -2698,7 +2698,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
break; break;
case UDP_NO_CHECK6_RX: case UDP_NO_CHECK6_RX:
up->no_check6_rx = valbool; udp_set_no_check6_rx(sk, valbool);
break; break;
case UDP_SEGMENT: case UDP_SEGMENT:
...@@ -2795,7 +2795,7 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname, ...@@ -2795,7 +2795,7 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname,
break; break;
case UDP_NO_CHECK6_RX: case UDP_NO_CHECK6_RX:
val = up->no_check6_rx; val = udp_get_no_check6_rx(sk);
break; break;
case UDP_SEGMENT: case UDP_SEGMENT:
......
...@@ -858,7 +858,7 @@ static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb, ...@@ -858,7 +858,7 @@ static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
/* If zero checksum and no_check is not on for /* If zero checksum and no_check is not on for
* the socket then skip it. * the socket then skip it.
*/ */
if (!uh->check && !udp_sk(sk)->no_check6_rx) if (!uh->check && !udp_get_no_check6_rx(sk))
continue; continue;
if (!first) { if (!first) {
first = sk; first = sk;
...@@ -980,7 +980,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, ...@@ -980,7 +980,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
if (unlikely(rcu_dereference(sk->sk_rx_dst) != dst)) if (unlikely(rcu_dereference(sk->sk_rx_dst) != dst))
udp6_sk_rx_dst_set(sk, dst); udp6_sk_rx_dst_set(sk, dst);
if (!uh->check && !udp_sk(sk)->no_check6_rx) { if (!uh->check && !udp_get_no_check6_rx(sk)) {
if (refcounted) if (refcounted)
sock_put(sk); sock_put(sk);
goto report_csum_error; goto report_csum_error;
...@@ -1002,7 +1002,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, ...@@ -1002,7 +1002,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
/* Unicast */ /* Unicast */
sk = __udp6_lib_lookup_skb(skb, uh->source, uh->dest, udptable); sk = __udp6_lib_lookup_skb(skb, uh->source, uh->dest, udptable);
if (sk) { if (sk) {
if (!uh->check && !udp_sk(sk)->no_check6_rx) if (!uh->check && !udp_get_no_check6_rx(sk))
goto report_csum_error; goto report_csum_error;
return udp6_unicast_rcv_skb(sk, skb, uh); return udp6_unicast_rcv_skb(sk, skb, uh);
} }
......
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