diff mbox series

udp: Prevent reuseport_select_sock from reading uninitialized socks

Message ID 20210107051110.12247-1-baptiste.lepers@gmail.com (mailing list archive)
State Accepted
Delegated to: Netdev Maintainers
Headers show
Series udp: Prevent reuseport_select_sock from reading uninitialized socks | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers warning 5 maintainers not CCed: kuniyu@amazon.co.jp benh@amazon.com kraig@google.com jakub@cloudflare.com pabeni@redhat.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes fail Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Baptiste Lepers Jan. 7, 2021, 5:11 a.m. UTC
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>
---
 net/core/sock_reuseport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Willem de Bruijn Jan. 7, 2021, 5:27 a.m. UTC | #1
On Thu, Jan 7, 2021 at 12:11 AM Baptiste Lepers
<baptiste.lepers@gmail.com> 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 <baptiste.lepers@gmail.com>

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.

> ---
>  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
>
Jakub Kicinski Jan. 9, 2021, 3:16 a.m. UTC | #2
On Thu, 7 Jan 2021 00:27:07 -0500 Willem de Bruijn wrote:
> On Thu, Jan 7, 2021 at 12:11 AM Baptiste Lepers
> <baptiste.lepers@gmail.com> 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 <baptiste.lepers@gmail.com>  
> 
> 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!
diff mbox series

Patch

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;