]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tcp: Protect accesses to .ts_recent_stamp with {READ,WRITE}_ONCE()
authorGuillaume Nault <gnault@redhat.com>
Fri, 6 Dec 2019 11:38:49 +0000 (12:38 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 11 Feb 2020 20:03:56 +0000 (20:03 +0000)
commit 721c8dafad26ccfa90ff659ee19755e3377b829d upstream.

Syncookies borrow the ->rx_opt.ts_recent_stamp field to store the
timestamp of the last synflood. Protect them with READ_ONCE() and
WRITE_ONCE() since reads and writes aren't serialised.

Use of .rx_opt.ts_recent_stamp for storing the synflood timestamp was
introduced by a0f82f64e269 ("syncookies: remove last_synq_overflow from
struct tcp_sock"). But unprotected accesses were already there when
timestamp was stored in .last_synq_overflow.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[bwh: Backported to 3.16: Use ACCESS_ONCE() instead of {READ,WRITE}_ONCE()]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
include/net/tcp.h

index 4aab231b119c264f6dfd523702c3b7555af47f02..417460d2b217c63e82a8511eac149071728a3f52 100644 (file)
@@ -482,17 +482,17 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
  */
 static inline void tcp_synq_overflow(struct sock *sk)
 {
-       unsigned long last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp;
+       unsigned long last_overflow = ACCESS_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp);
        unsigned long now = jiffies;
 
        if (!time_between32(now, last_overflow, last_overflow + HZ))
-               tcp_sk(sk)->rx_opt.ts_recent_stamp = now;
+               ACCESS_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp) = now;
 }
 
 /* syncookies: no recent synqueue overflow on this listening socket? */
 static inline bool tcp_synq_no_recent_overflow(const struct sock *sk)
 {
-       unsigned long last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp;
+       unsigned long last_overflow = ACCESS_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp);
 
        return time_after(jiffies, last_overflow + TCP_SYNCOOKIE_VALID);
 }