udp6: fix potential access to stale information
Subsystems (3)
PATCH 1/1 udp6: fix potential access to stale information
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().
--- net/ipv6/udp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/ipv6/udp.c +5 -3
@@ -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; } }
Signature · 1 line
2.40.0.577.gac1e443424-goog
Quoted 52 lines · Eric Dumazet
lena wang reported an issue caused by
udpv6_sendmsg()manglingmsg->msg_nameandmsg->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 isAF_INETin order to calludp_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 <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Cc Maciej Żenczykowski <[email protected]>--- net/ipv6/udp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)net/ipv6/udp.c +5
-4@@ -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; } } --
Quoted 1 line
2.40.0.577.gac1e443424-goog
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 15 lines · On Wed, 12 Apr 2023 13:03:08 +0000 you wrote:
lena wang reported an issue caused by
udpv6_sendmsg()manglingmsg->msg_nameandmsg->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); }
Quoted 1 line
[...]
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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html