]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - include/net/tcp.h
nfsd: Allow nfsd_vfs_write() to take the nfsd_file as an argument
[linux.git] / include / net / tcp.h
index 36f195fb576a26237e81a5890c5a2e9d9e304722..86b9a8766648824c0f122f6c01f55d59bd0d7d72 100644 (file)
@@ -494,15 +494,16 @@ static inline void tcp_synq_overflow(const struct sock *sk)
                reuse = rcu_dereference(sk->sk_reuseport_cb);
                if (likely(reuse)) {
                        last_overflow = READ_ONCE(reuse->synq_overflow_ts);
-                       if (time_after32(now, last_overflow + HZ))
+                       if (!time_between32(now, last_overflow,
+                                           last_overflow + HZ))
                                WRITE_ONCE(reuse->synq_overflow_ts, now);
                        return;
                }
        }
 
-       last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp;
-       if (time_after32(now, last_overflow + HZ))
-               tcp_sk(sk)->rx_opt.ts_recent_stamp = now;
+       last_overflow = READ_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp);
+       if (!time_between32(now, last_overflow, last_overflow + HZ))
+               WRITE_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp, now);
 }
 
 /* syncookies: no recent synqueue overflow on this listening socket? */
@@ -517,13 +518,23 @@ static inline bool tcp_synq_no_recent_overflow(const struct sock *sk)
                reuse = rcu_dereference(sk->sk_reuseport_cb);
                if (likely(reuse)) {
                        last_overflow = READ_ONCE(reuse->synq_overflow_ts);
-                       return time_after32(now, last_overflow +
-                                           TCP_SYNCOOKIE_VALID);
+                       return !time_between32(now, last_overflow - HZ,
+                                              last_overflow +
+                                              TCP_SYNCOOKIE_VALID);
                }
        }
 
-       last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp;
-       return time_after32(now, last_overflow + TCP_SYNCOOKIE_VALID);
+       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
+        * 'last_overflow - HZ' as lower bound. That's because a concurrent
+        * tcp_synq_overflow() could update .ts_recent_stamp after we read
+        * jiffies but before we store .ts_recent_stamp into last_overflow,
+        * which could lead to rejecting a valid syncookie.
+        */
+       return !time_between32(now, last_overflow - HZ,
+                              last_overflow + TCP_SYNCOOKIE_VALID);
 }
 
 static inline u32 tcp_cookie_time(void)