Skip to content

Commit

Permalink
udp: Prevent reuseport_select_sock from reading uninitialized socks
Browse files Browse the repository at this point in the history
reuse->socks[] is modified concurrently by reuseport_add_sock. To
prevent reading values that have not been fully initialized, only read
the array up until the last known safe index instead of incorrectly
re-reading the last index of the array.

Fixes: acdcecc ("udp: correct reuseport selection with connected sockets")
Signed-off-by: Baptiste Lepers <[email protected]>
Acked-by: Willem de Bruijn <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
BLepers authored and kuba-moo committed Jan 9, 2021
1 parent 53475c5 commit fd2ddef
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/core/sock_reuseport.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ struct sock *reuseport_select_sock(struct sock *sk,
i = j = reciprocal_scale(hash, socks);
while (reuse->socks[i]->sk_state == TCP_ESTABLISHED) {
i++;
if (i >= reuse->num_socks)
if (i >= socks)
i = 0;
if (i == j)
goto out;
Expand Down

0 comments on commit fd2ddef

Please sign in to comment.