Skip to content

Commit 01b2885

Browse files
Marc Dionnedavem330
authored andcommitted
net: Save and restore msg_namelen in sock_sendmsg
Commit 86a7e0b ("net: prevent rewrite of msg_name in sock_sendmsg()") made sock_sendmsg save the incoming msg_name pointer and restore it before returning, to insulate the caller against msg_name being changed by the called code. If the address length was also changed however, we may return with an inconsistent structure where the length doesn't match the address, and attempts to reuse it may lead to lost packets. For example, a kernel that doesn't have commit 1c5950f ("udp6: fix potential access to stale information") will replace a v4 mapped address with its ipv4 equivalent, and shorten namelen accordingly from 28 to 16. If the caller attempts to reuse the resulting msg structure, it will have the original ipv6 (v4 mapped) address but an incorrect v4 length. Fixes: 86a7e0b ("net: prevent rewrite of msg_name in sock_sendmsg()") Signed-off-by: Marc Dionne <marc.dionne@auristor.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e584f2f commit 01b2885

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

net/socket.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ int sock_sendmsg(struct socket *sock, struct msghdr *msg)
757757
{
758758
struct sockaddr_storage *save_addr = (struct sockaddr_storage *)msg->msg_name;
759759
struct sockaddr_storage address;
760+
int save_len = msg->msg_namelen;
760761
int ret;
761762

762763
if (msg->msg_name) {
@@ -766,6 +767,7 @@ int sock_sendmsg(struct socket *sock, struct msghdr *msg)
766767

767768
ret = __sock_sendmsg(sock, msg);
768769
msg->msg_name = save_addr;
770+
msg->msg_namelen = save_len;
769771

770772
return ret;
771773
}

0 commit comments

Comments
 (0)