Skip to content

Commit d317809

Browse files
Guillaume Naultgregkh
authored andcommitted
tcp: Protect accesses to .ts_recent_stamp with {READ,WRITE}_ONCE()
[ Upstream commit 721c8da ] 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 a0f82f6 ("syncookies: remove last_synq_overflow from struct tcp_sock"). But unprotected accesses were already there when timestamp was stored in .last_synq_overflow. Fixes: 1da177e ("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>
1 parent e0082ab commit d317809

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎include/net/tcp.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,9 @@ static inline void tcp_synq_overflow(const struct sock *sk)
491491
}
492492
}
493493

494-
last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp;
494+
last_overflow = READ_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp);
495495
if (!time_between32(now, last_overflow, last_overflow + HZ))
496-
tcp_sk(sk)->rx_opt.ts_recent_stamp = now;
496+
WRITE_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp, now);
497497
}
498498

499499
/* syncookies: no recent synqueue overflow on this listening socket? */
@@ -514,7 +514,7 @@ static inline bool tcp_synq_no_recent_overflow(const struct sock *sk)
514514
}
515515
}
516516

517-
last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp;
517+
last_overflow = READ_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp);
518518

519519
/* If last_overflow <= jiffies <= last_overflow + TCP_SYNCOOKIE_VALID,
520520
* then we're under synflood. However, we have to use

0 commit comments

Comments
 (0)