diff options
Diffstat (limited to 'include/net')
| -rw-r--r-- | include/net/tcp.h | 27 | 
1 files changed, 19 insertions, 8 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h index 36f195fb576a..86b9a8766648 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -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)  | 
