Skip to content

Commit 4dfa9b4

Browse files
edumazetkuba-moo
authored andcommitted
tcp: resalt the secret every 10 seconds
In order to limit the ability for an observer to recognize the source ports sequence used to contact a set of destinations, we should periodically shuffle the secret. 10 seconds looks effective enough without causing particular issues. Cc: Moshe Kol <moshe.kol@mail.huji.ac.il> Cc: Yossi Gilad <yossi.gilad@mail.huji.ac.il> Cc: Amit Klein <aksecurity@gmail.com> Cc: Jason A. Donenfeld <Jason@zx2c4.com> Tested-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 9e9b70a commit 4dfa9b4

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

net/core/secure_seq.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
static siphash_aligned_key_t net_secret;
2323
static siphash_aligned_key_t ts_secret;
2424

25+
#define EPHEMERAL_PORT_SHUFFLE_PERIOD (10 * HZ)
26+
2527
static __always_inline void net_secret_init(void)
2628
{
2729
net_get_random_once(&net_secret, sizeof(net_secret));
@@ -100,11 +102,13 @@ u64 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
100102
const struct {
101103
struct in6_addr saddr;
102104
struct in6_addr daddr;
105+
unsigned int timeseed;
103106
__be16 dport;
104107
} __aligned(SIPHASH_ALIGNMENT) combined = {
105108
.saddr = *(struct in6_addr *)saddr,
106109
.daddr = *(struct in6_addr *)daddr,
107-
.dport = dport
110+
.timeseed = jiffies / EPHEMERAL_PORT_SHUFFLE_PERIOD,
111+
.dport = dport,
108112
};
109113
net_secret_init();
110114
return siphash(&combined, offsetofend(typeof(combined), dport),
@@ -145,8 +149,10 @@ EXPORT_SYMBOL_GPL(secure_tcp_seq);
145149
u64 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport)
146150
{
147151
net_secret_init();
148-
return siphash_3u32((__force u32)saddr, (__force u32)daddr,
149-
(__force u16)dport, &net_secret);
152+
return siphash_4u32((__force u32)saddr, (__force u32)daddr,
153+
(__force u16)dport,
154+
jiffies / EPHEMERAL_PORT_SHUFFLE_PERIOD,
155+
&net_secret);
150156
}
151157
EXPORT_SYMBOL_GPL(secure_ipv4_port_ephemeral);
152158
#endif

0 commit comments

Comments
 (0)