Commit 1c5950fc authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

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().

Fixes: c71d8ebe ("net: Fix security_socket_sendmsg() bypass problem.")
Reported-by: default avatarlena wang <lena.wang@mediatek.com>
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarMaciej Żenczykowski <maze@google.com>
Link: https://lore.kernel.org/r/20230412130308.1202254-1-edumazet@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 306dc213
...@@ -1395,9 +1395,11 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -1395,9 +1395,11 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
msg->msg_name = &sin; msg->msg_name = &sin;
msg->msg_namelen = sizeof(sin); msg->msg_namelen = sizeof(sin);
do_udp_sendmsg: do_udp_sendmsg:
if (ipv6_only_sock(sk)) err = ipv6_only_sock(sk) ?
return -ENETUNREACH; -ENETUNREACH : udp_sendmsg(sk, msg, len);
return udp_sendmsg(sk, msg, len); msg->msg_name = sin6;
msg->msg_namelen = addr_len;
return err;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment