* [PATCH net] udp6: fix potential access to stale information
@ 2023-04-12 13:03 Eric Dumazet
2023-04-12 13:08 ` Maciej Żenczykowski
2023-04-13 17:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2023-04-12 13:03 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, eric.dumazet, Eric Dumazet, lena wang,
Maciej Żenczykowski
lena wang reported an issue caused by udpv6_sendmsg()
mangling msg->msg_name and msg->msg_namelen, which
are later read from ____sys_sendmsg() :
/*
* If this is sendmmsg() and sending to current destination address was
* successful, remember it.
*/
if (used_address && err >= 0) {
used_address->name_len = msg_sys->msg_namelen;
if (msg_sys->msg_name)
memcpy(&used_address->name, msg_sys->msg_name,
used_address->name_len);
}
udpv6_sendmsg() wants to pretend the remote address family
is AF_INET in order to call udp_sendmsg().
A fix would be to modify the address in-place, instead
of using a local variable, but this could have other side effects.
Instead, restore initial values before we return from udpv6_sendmsg().
Fixes: c71d8ebe7a44 ("net: Fix security_socket_sendmsg() bypass problem.")
Reported-by: lena wang <lena.wang@mediatek.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Maciej Żenczykowski <maze@google.com>
---
net/ipv6/udp.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 9fb2f33ee3a76a09bbe15a9aaf1371a804f91ee2..a675acfb901d102ce56563b1d50ae827d9e04859 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -1395,9 +1395,11 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
msg->msg_name = &sin;
msg->msg_namelen = sizeof(sin);
do_udp_sendmsg:
- if (ipv6_only_sock(sk))
- return -ENETUNREACH;
- return udp_sendmsg(sk, msg, len);
+ err = ipv6_only_sock(sk) ?
+ -ENETUNREACH : udp_sendmsg(sk, msg, len);
+ msg->msg_name = sin6;
+ msg->msg_namelen = addr_len;
+ return err;
}
}
--
2.40.0.577.gac1e443424-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] udp6: fix potential access to stale information
2023-04-12 13:03 [PATCH net] udp6: fix potential access to stale information Eric Dumazet
@ 2023-04-12 13:08 ` Maciej Żenczykowski
2023-04-13 17:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Maciej Żenczykowski @ 2023-04-12 13:08 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
eric.dumazet, lena wang
On Wed, Apr 12, 2023 at 3:03 PM Eric Dumazet <edumazet@google.com> wrote:
>
> lena wang reported an issue caused by udpv6_sendmsg()
> mangling msg->msg_name and msg->msg_namelen, which
> are later read from ____sys_sendmsg() :
>
> /*
> * If this is sendmmsg() and sending to current destination address was
> * successful, remember it.
> */
> if (used_address && err >= 0) {
> used_address->name_len = msg_sys->msg_namelen;
> if (msg_sys->msg_name)
> memcpy(&used_address->name, msg_sys->msg_name,
> used_address->name_len);
> }
>
> udpv6_sendmsg() wants to pretend the remote address family
> is AF_INET in order to call udp_sendmsg().
>
> A fix would be to modify the address in-place, instead
> of using a local variable, but this could have other side effects.
>
> Instead, restore initial values before we return from udpv6_sendmsg().
>
> Fixes: c71d8ebe7a44 ("net: Fix security_socket_sendmsg() bypass problem.")
> Reported-by: lena wang <lena.wang@mediatek.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Maciej Żenczykowski <maze@google.com>
> ---
> net/ipv6/udp.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
> index 9fb2f33ee3a76a09bbe15a9aaf1371a804f91ee2..a675acfb901d102ce56563b1d50ae827d9e04859 100644
> --- a/net/ipv6/udp.c
> +++ b/net/ipv6/udp.c
> @@ -1395,9 +1395,11 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
> msg->msg_name = &sin;
> msg->msg_namelen = sizeof(sin);
> do_udp_sendmsg:
> - if (ipv6_only_sock(sk))
> - return -ENETUNREACH;
> - return udp_sendmsg(sk, msg, len);
> + err = ipv6_only_sock(sk) ?
> + -ENETUNREACH : udp_sendmsg(sk, msg, len);
> + msg->msg_name = sin6;
> + msg->msg_namelen = addr_len;
> + return err;
> }
> }
>
> --
> 2.40.0.577.gac1e443424-goog
Reviewed-by: Maciej Żenczykowski <maze@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] udp6: fix potential access to stale information
2023-04-12 13:03 [PATCH net] udp6: fix potential access to stale information Eric Dumazet
2023-04-12 13:08 ` Maciej Żenczykowski
@ 2023-04-13 17:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-04-13 17:20 UTC (permalink / raw)
To: Eric Dumazet; +Cc: davem, kuba, pabeni, netdev, eric.dumazet, lena.wang, maze
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 12 Apr 2023 13:03:08 +0000 you wrote:
> lena wang reported an issue caused by udpv6_sendmsg()
> mangling msg->msg_name and msg->msg_namelen, which
> are later read from ____sys_sendmsg() :
>
> /*
> * If this is sendmmsg() and sending to current destination address was
> * successful, remember it.
> */
> if (used_address && err >= 0) {
> used_address->name_len = msg_sys->msg_namelen;
> if (msg_sys->msg_name)
> memcpy(&used_address->name, msg_sys->msg_name,
> used_address->name_len);
> }
>
> [...]
Here is the summary with links:
- [net] udp6: fix potential access to stale information
https://git.kernel.org/netdev/net/c/1c5950fc6fe9
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-13 17:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-12 13:03 [PATCH net] udp6: fix potential access to stale information Eric Dumazet
2023-04-12 13:08 ` Maciej Żenczykowski
2023-04-13 17:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox