]> git.baikalelectronics.ru Git - kernel.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)
committerDavid S. Miller <davem@davemloft.net>
Sat, 7 Dec 2019 05:05:14 +0000 (21:05 -0800)
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>
include/net/tcp.h

index 43e04e14c41ea076bde5e7e80307e50b853659e8..86b9a8766648824c0f122f6c01f55d59bd0d7d72 100644 (file)
@@ -501,9 +501,9 @@ static inline void tcp_synq_overflow(const struct sock *sk)
                }
        }
 
-       last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp;
+       last_overflow = READ_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp);
        if (!time_between32(now, last_overflow, last_overflow + HZ))
-               tcp_sk(sk)->rx_opt.ts_recent_stamp = now;
+               WRITE_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp, now);
 }
 
 /* syncookies: no recent synqueue overflow on this listening socket? */
@@ -524,7 +524,7 @@ static inline bool tcp_synq_no_recent_overflow(const struct sock *sk)
                }
        }
 
-       last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp;
+       last_overflow = READ_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp);
 
        /* If last_overflow <= jiffies <= last_overflow + TCP_SYNCOOKIE_VALID,
         * then we're under synflood. However, we have to use