diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2023-07-06 09:15:25 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2023-07-06 09:15:25 +0000 |
commit | 533aca685f5b80860ef02212a05256572bda2f7c (patch) | |
tree | 1da89e05ae1e9890e60ee3100e84c008ab33357c /sys/netinet/tcp_subr.c | |
parent | 911f6527d0931141ac5c6e4450bca95d45b3b984 (diff) |
Convert tcp_now() time counter to 64 bit.
After changing tcp now tick to milliseconds, 32 bits will wrap
around after 49 days of uptime. That may be a problem in some
places of our stack. Better use a 64 bit counter.
As timestamp option is 32 bit in TCP protocol, use the lower 32 bit
there. There are casts to 32 bits that should behave correctly.
Start with random 63 bit offset to avoid uptime leakage. 2^63
milliseconds result in 2.9*10^8 years of possible uptime.
OK yasuoka@
Diffstat (limited to 'sys/netinet/tcp_subr.c')
-rw-r--r-- | sys/netinet/tcp_subr.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index ad8f7eae1b0..7c68c484e31 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_subr.c,v 1.191 2023/05/10 12:07:16 bluhm Exp $ */ +/* $OpenBSD: tcp_subr.c,v 1.192 2023/07/06 09:15:24 bluhm Exp $ */ /* $NetBSD: tcp_subr.c,v 1.22 1996/02/13 23:44:00 christos Exp $ */ /* @@ -137,6 +137,7 @@ struct cpumem *tcpcounters; /* tcp statistics */ u_char tcp_secret[16]; /* [I] */ SHA2_CTX tcp_secret_ctx; /* [I] */ tcp_seq tcp_iss; /* [T] updated by timer and connection */ +uint64_t tcp_starttime; /* [I] random offset for tcp_now() */ /* * Tcp initialization @@ -145,6 +146,9 @@ void tcp_init(void) { tcp_iss = 1; /* wrong */ + /* 0 is treated special so add 1, 63 bits to count is enough */ + arc4random_buf(&tcp_starttime, sizeof(tcp_starttime)); + tcp_starttime = 1ULL + (tcp_starttime / 2); pool_init(&tcpcb_pool, sizeof(struct tcpcb), 0, IPL_SOFTNET, 0, "tcpcb", NULL); pool_init(&tcpqe_pool, sizeof(struct tcpqent), 0, IPL_SOFTNET, 0, @@ -289,7 +293,7 @@ tcp_template(struct tcpcb *tp) */ void tcp_respond(struct tcpcb *tp, caddr_t template, struct tcphdr *th0, - tcp_seq ack, tcp_seq seq, int flags, u_int rtableid, uint32_t now) + tcp_seq ack, tcp_seq seq, int flags, u_int rtableid, uint64_t now) { int tlen; int win = 0; |