diff mbox series

[net,1/2] udp: Copy has_conns in reuseport_grow().

Message ID 20200721061531.94236-2-kuniyu@amazon.co.jp
State Accepted
Delegated to: David Miller
Headers show
Series udp: Fix reuseport selection with connected sockets. | expand

Commit Message

Kuniyuki Iwashima July 21, 2020, 6:15 a.m. UTC
If an unconnected socket in a UDP reuseport group connect()s, has_conns is
set to 1. Then, when a packet is received, udp[46]_lib_lookup2() scans all
sockets in udp_hslot looking for the connected socket with the highest
score.

However, when the number of sockets bound to the port exceeds max_socks,
reuseport_grow() resets has_conns to 0. It can cause udp[46]_lib_lookup2()
to return without scanning all sockets, resulting in that packets sent to
connected sockets may be distributed to unconnected sockets.

Therefore, reuseport_grow() should copy has_conns.

Fixes: acdcecc61285 ("udp: correct reuseport selection with connected sockets")
CC: Willem de Bruijn <willemb@google.com>
Reviewed-by: Benjamin Herrenschmidt <benh@amazon.com>
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
---
 net/core/sock_reuseport.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Willem de Bruijn July 21, 2020, 12:25 p.m. UTC | #1
On Tue, Jul 21, 2020 at 2:16 AM Kuniyuki Iwashima <kuniyu@amazon.co.jp> wrote:
>
> If an unconnected socket in a UDP reuseport group connect()s, has_conns is
> set to 1. Then, when a packet is received, udp[46]_lib_lookup2() scans all
> sockets in udp_hslot looking for the connected socket with the highest
> score.
>
> However, when the number of sockets bound to the port exceeds max_socks,
> reuseport_grow() resets has_conns to 0. It can cause udp[46]_lib_lookup2()
> to return without scanning all sockets, resulting in that packets sent to
> connected sockets may be distributed to unconnected sockets.
>
> Therefore, reuseport_grow() should copy has_conns.
>
> Fixes: acdcecc61285 ("udp: correct reuseport selection with connected sockets")
> CC: Willem de Bruijn <willemb@google.com>
> Reviewed-by: Benjamin Herrenschmidt <benh@amazon.com>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>

Acked-by: Willem de Bruijn <willemb@google.com>

Thanks. Yes, I missed this resize operation when adding the field.
diff mbox series

Patch

diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
index adcb3aea576d..bbdd3c7b6cb5 100644
--- a/net/core/sock_reuseport.c
+++ b/net/core/sock_reuseport.c
@@ -101,6 +101,7 @@  static struct sock_reuseport *reuseport_grow(struct sock_reuseport *reuse)
 	more_reuse->prog = reuse->prog;
 	more_reuse->reuseport_id = reuse->reuseport_id;
 	more_reuse->bind_inany = reuse->bind_inany;
+	more_reuse->has_conns = reuse->has_conns;
 
 	memcpy(more_reuse->socks, reuse->socks,
 	       reuse->num_socks * sizeof(struct sock *));