From: Paolo Abeni <pabeni@redhat.com>
To: Vladislav Efanov <VEfanov@ispras.ru>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
lvc-project@linuxtesting.org
Subject: Re: [PATCH] udp6: Fix race condition in udp6_sendmsg & connect
Date: Fri, 26 May 2023 17:33:33 +0200 [thread overview]
Message-ID: <27614af23cd7ae4433b909194062c553a6ae16ac.camel@redhat.com> (raw)
In-Reply-To: <20230526150806.1457828-1-VEfanov@ispras.ru>
On Fri, 2023-05-26 at 18:08 +0300, Vladislav Efanov wrote:
> Syzkaller got the following report:
> BUG: KASAN: use-after-free in sk_setup_caps+0x621/0x690 net/core/sock.c:2018
> Read of size 8 at addr ffff888027f82780 by task syz-executor276/3255
>
> The function sk_setup_caps (called by ip6_sk_dst_store_flow->
> ip6_dst_store) referenced already freed memory as this memory was
> freed by parallel task in udpv6_sendmsg->ip6_sk_dst_lookup_flow->
> sk_dst_check.
>
> task1 (connect) task2 (udp6_sendmsg)
> sk_setup_caps->sk_dst_set |
> | sk_dst_check->
> | sk_dst_set
> | dst_release
> sk_setup_caps references |
> to already freed dst_entry|
>
> The reason for this race condition is: udp6_sendmsg() calls
> ip6_sk_dst_lookup() without lock for sock structure and tries to
> allocate/add dst_entry structure to sock structure in parallel with
> "connect" task.
>
> Found by Linux Verification Center (linuxtesting.org) with syzkaller.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Vladislav Efanov <VEfanov@ispras.ru>
Thank you for the detailed report!
> ---
> net/ipv6/udp.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
> index e5a337e6b970..a5ecd5d93b0a 100644
> --- a/net/ipv6/udp.c
> +++ b/net/ipv6/udp.c
> @@ -1563,12 +1563,15 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
>
> fl6->flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6->flowlabel);
>
> + lock_sock(sk);
Acquiring the socket lock in this fast-path is going to kill the xmit
performances, I think we can't do that.
What about something like the following instead? Does that addresses
the UaF? (completely untested, not even built ;) If so, feel free to
take it over.
Thanks.
Paolo
---
diff --git a/net/core/sock.c b/net/core/sock.c
index 5440e67bcfe3..24f2761bdb1d 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2381,7 +2381,6 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
{
u32 max_segs = 1;
- sk_dst_set(sk, dst);
sk->sk_route_caps = dst->dev->features;
if (sk_is_tcp(sk))
sk->sk_route_caps |= NETIF_F_GSO;
@@ -2400,6 +2399,7 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
}
}
sk->sk_gso_max_segs = max_segs;
+ sk_dst_set(sk, dst);
}
EXPORT_SYMBOL_GPL(sk_setup_caps);
next prev parent reply other threads:[~2023-05-26 15:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-26 15:08 Vladislav Efanov
2023-05-26 15:29 ` Eric Dumazet
2023-05-26 15:49 ` Ефанов Владислав Александрович
2023-05-26 16:09 ` Vlad Efanov
2023-05-26 16:46 ` Eric Dumazet
2023-05-26 16:57 ` Vlad Efanov
2023-05-26 15:33 ` Paolo Abeni [this message]
2023-05-26 15:58 ` Ефанов Владислав Александрович
2023-05-26 16:00 ` Eric Dumazet
2023-05-26 16:41 ` Vlad Efanov
2023-05-26 16:47 ` Eric Dumazet
2023-05-26 17:00 ` Vlad Efanov
2023-05-26 18:13 ` Paolo Abeni
2023-05-29 14:13 ` Vlad Efanov
2023-05-30 11:39 ` [PATCH v2] " Vladislav Efanov
2023-05-31 9:40 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=27614af23cd7ae4433b909194062c553a6ae16ac.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=VEfanov@ispras.ru \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=netdev@vger.kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®