From: Baptiste Lepers Date: Thu, 7 Jan 2021 05:11:10 +0000 (+1100) Subject: udp: Prevent reuseport_select_sock from reading uninitialized socks X-Git-Tag: v4.19.170~17 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=4669452b4c66268a184a51c543b525533013c14e;p=users%2Fdwmw2%2Flinux.git udp: Prevent reuseport_select_sock from reading uninitialized socks [ Upstream commit fd2ddef043592e7de80af53f47fa46fd3573086e ] 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 Acked-by: Willem de Bruijn Link: https://lore.kernel.org/r/20210107051110.12247-1-baptiste.lepers@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c index 9c85ef2b7e1d0..375a3bbe64856 100644 --- a/net/core/sock_reuseport.c +++ b/net/core/sock_reuseport.c @@ -299,7 +299,7 @@ select_by_hash: 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;