Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

udp: Prevent reuseport_select_sock from reading uninitialized socks

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: acdcecc61285f ("udp: correct reuseport selection with connected sockets")
Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>
Acked-by: Willem de Bruijn <willemb@google.com>
Link: https://lore.kernel.org/r/20210107051110.12247-1-baptiste.lepers@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Baptiste Lepers and committed by
Jakub Kicinski
fd2ddef0 53475c5d

+1 -1
+1 -1
net/core/sock_reuseport.c
··· 293 293 i = j = reciprocal_scale(hash, socks); 294 294 while (reuse->socks[i]->sk_state == TCP_ESTABLISHED) { 295 295 i++; 296 - if (i >= reuse->num_socks) 296 + if (i >= socks) 297 297 i = 0; 298 298 if (i == j) 299 299 goto out;