[PATCH v2 net 2/7] tcp: use different parts of the port_offset for index and offset

From: Willy Tarreau
Date: Thu Apr 28 2022 - 08:41:17 EST


Amit Klein suggests that we use different parts of port_offset for the
table's index and the port offset so that there is no direct relation
between them.

Cc: Jason A. Donenfeld <Jason@xxxxxxxxx>
Cc: Moshe Kol <moshe.kol@xxxxxxxxxxxxxxx>
Cc: Yossi Gilad <yossi.gilad@xxxxxxxxxxxxxxx>
Cc: Amit Klein <aksecurity@xxxxxxxxx>
Reviewed-by: Eric Dumazet <edumazet@xxxxxxxxxx>
Signed-off-by: Willy Tarreau <w@xxxxxx>
---
net/ipv4/inet_hashtables.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 9d24d9319f3d..29c701cd8312 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -777,7 +777,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
net_get_random_once(table_perturb, sizeof(table_perturb));
index = hash_32(port_offset, INET_TABLE_PERTURB_SHIFT);

- offset = READ_ONCE(table_perturb[index]) + port_offset;
+ offset = READ_ONCE(table_perturb[index]) + (port_offset >> 32);
offset %= remaining;

/* In first pass we try ports of @low parity.
--
2.17.5