Skip to content

Commit e816134

Browse files
wtarreaukuba-moo
authored andcommitted
tcp: drop the hash_32() part from the index calculation
In commit 190cc82 ("tcp: change source port randomizarion at connect() time"), the table_perturb[] array was introduced and an index was taken from the port_offset via hash_32(). But it turns out that hash_32() performs a multiplication while the input here comes from the output of SipHash in secure_seq, that is well distributed enough to avoid the need for yet another hash. Suggested-by: Amit Klein <aksecurity@gmail.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 4c2c8f0 commit e816134

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

net/ipv4/inet_hashtables.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
778778

779779
net_get_random_once(table_perturb,
780780
INET_TABLE_PERTURB_SIZE * sizeof(*table_perturb));
781-
index = hash_32(port_offset, INET_TABLE_PERTURB_SHIFT);
781+
index = port_offset & (INET_TABLE_PERTURB_SIZE - 1);
782782

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

0 commit comments

Comments
 (0)