Skip to contentSkip to conversation

udp: Prevent reuseport_select_sock from reading uninitialized socks

PATCH Applied Baptiste Lepers 3 participants 3 messages Jan 7, 2021 – Jan 9, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")

---
 net/core/sock_reuseport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/sock_reuseport.c +1 -1
index bbdd3c7b6cb5..b065f0a103ed 100644
@@ -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;
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Baptiste Lepers

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")

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 20 lines
---
 net/core/sock_reuseport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/sock_reuseport.c +1 -2
index bbdd3c7b6cb5..b065f0a103ed 100644
@@ -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

maintainer Applied
#2 lore raw
Quoted 12 lines · On Thu, 7 Jan 2021 00:27:07 -0500 Willem de Bruijn wrote:
Quoted 9 lines · Baptiste Lepers

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")

Quoted 6 lines

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!