[PATCH] udp: Prevent reuseport_select_sock from reading uninitialized socks

Subsystems: networking [general], networking [sockets], the rest

STALE2069d LANDED

Landed in mainline as fd2ddef04359 on 2021-01-09.

3 messages, 3 authors, 2021-01-09 · open the first message on its own page

[PATCH] udp: Prevent reuseport_select_sock from reading uninitialized socks

From: Baptiste Lepers <hidden>
Date: 2021-01-07 05:12:24

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 <redacted>
---
 net/core/sock_reuseport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
index bbdd3c7b6cb5..b065f0a103ed 100644
--- a/net/core/sock_reuseport.c
+++ b/net/core/sock_reuseport.c
@@ -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;
-- 
2.17.1

Re: [PATCH] udp: Prevent reuseport_select_sock from reading uninitialized socks

From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: 2021-01-07 05:28:28

On Thu, Jan 7, 2021 at 12:11 AM Baptiste Lepers
[off-list ref] wrote:
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 <redacted>
Acked-by: Willem de Bruijn <willemb@google.com>

Thanks. This also matches local variable socks as used to calculate i
and j with reciprocal_scale immediately above.

Please mark fixes [PATCH net] in the future.
quoted hunk
---
 net/core/sock_reuseport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
index bbdd3c7b6cb5..b065f0a103ed 100644
--- a/net/core/sock_reuseport.c
+++ b/net/core/sock_reuseport.c
@@ -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;
--
2.17.1

Re: [PATCH] udp: Prevent reuseport_select_sock from reading uninitialized socks

From: Jakub Kicinski <kuba@kernel.org>
Date: 2021-01-09 03:17:40

On Thu, 7 Jan 2021 00:27:07 -0500 Willem de Bruijn wrote:
On Thu, Jan 7, 2021 at 12:11 AM Baptiste Lepers
[off-list ref] wrote:
quoted
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 <redacted>  
Acked-by: Willem de Bruijn <willemb@google.com>

Thanks. This also matches local variable socks as used to calculate i
and j with reciprocal_scale immediately above.

Please mark fixes [PATCH net] in the future.
And please don't wrap the fixes tags.

Applied, thanks!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help