aboutsummaryrefslogtreecommitdiff
path: root/net/socket.c
diff options
context:
space:
mode:
authorGravatar Jordan Rife <jrife@google.com> 2023-08-21 16:45:23 -0500
committerGravatar David S. Miller <davem@davemloft.net> 2023-08-23 09:42:05 +0100
commit0bdf399342c5acbd817c9098b6c7ed21f1974312 (patch)
treeb1eb3470808dfb1e586daa68af441016be3b0550 /net/socket.c
parentvirtio_net: Introduce skb_vnet_common_hdr to avoid typecasting (diff)
downloadlinux-0bdf399342c5acbd817c9098b6c7ed21f1974312.tar.gz
linux-0bdf399342c5acbd817c9098b6c7ed21f1974312.tar.bz2
linux-0bdf399342c5acbd817c9098b6c7ed21f1974312.zip
net: Avoid address overwrite in kernel_connect
BPF programs that run on connect can rewrite the connect address. For the connect system call this isn't a problem, because a copy of the address is made when it is moved into kernel space. However, kernel_connect simply passes through the address it is given, so the caller may observe its address value unexpectedly change. A practical example where this is problematic is where NFS is combined with a system such as Cilium which implements BPF-based load balancing. A common pattern in software-defined storage systems is to have an NFS mount that connects to a persistent virtual IP which in turn maps to an ephemeral server IP. This is usually done to achieve high availability: if your server goes down you can quickly spin up a replacement and remap the virtual IP to that endpoint. With BPF-based load balancing, mounts will forget the virtual IP address when the address rewrite occurs because a pointer to the only copy of that address is passed down the stack. Server failover then breaks, because clients have forgotten the virtual IP address. Reconnects fail and mounts remain broken. This patch was tested by setting up a scenario like this and ensuring that NFS reconnects worked after applying the patch. Signed-off-by: Jordan Rife <jrife@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/socket.c')
-rw-r--r--net/socket.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/net/socket.c b/net/socket.c
index fdb5233bf560..848116d06b51 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -3567,7 +3567,12 @@ EXPORT_SYMBOL(kernel_accept);
int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen,
int flags)
{
- return READ_ONCE(sock->ops)->connect(sock, addr, addrlen, flags);
+ struct sockaddr_storage address;
+
+ memcpy(&address, addr, addrlen);
+
+ return READ_ONCE(sock->ops)->connect(sock, (struct sockaddr *)&address,
+ addrlen, flags);
}
EXPORT_SYMBOL(kernel_connect);