Skip to content

Commit 721c8da

Browse files
Guillaume Naultdavem330
authored andcommitted
tcp: Protect accesses to .ts_recent_stamp with {READ,WRITE}_ONCE()
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 <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cb44a08 commit 721c8da

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/net/tcp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,9 @@ static inline void tcp_synq_overflow(const struct sock *sk)
501501
}
502502
}
503503

504-
last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp;
504+
last_overflow = READ_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp);
505505
if (!time_between32(now, last_overflow, last_overflow + HZ))
506-
tcp_sk(sk)->rx_opt.ts_recent_stamp = now;
506+
WRITE_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp, now);
507507
}
508508

509509
/* 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)
524524
}
525525
}
526526

527-
last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp;
527+
last_overflow = READ_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp);
528528

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

0 commit comments

Comments
 (0)