net: Avoid address overwrite in kernel_connect
Subsystems (3)
PATCH 1/1 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.
--- net/socket.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/socket.c +5 -1
@@ -3519,7 +3519,11 @@ EXPORT_SYMBOL(kernel_accept);int kernel_connect (struct socket *sock,struct sockaddr *addr,int addrlen,int flags) { -return sock->ops->connect (sock, addr, addrlen, flags); +struct sockaddr_storage address; + +memcpy (&address, addr, addrlen); + +return sock->ops->connect (sock, (struct sockaddr *)&address, addrlen, flags); }EXPORT_SYMBOL (kernel_connect);
Signature · 1 line
2.42.0.rc1.204.g551eb34607-goog
From: Jordan Rife <[email protected]>
Date: Mon, 21 Aug 2023 05:00:06 -0500
Quoted 30 lines
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_connectsimply 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 <[email protected]>--- net/socket.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)net/socket.c +0
-0
net/socket.c EXPORT_SYMBOL(kernel_accept); · line 3526
Quoted 9 lines
net/socket.c +5
-1@@ -3519,7 +3519,11 @@ EXPORT_SYMBOL(kernel_accept);int kernel_connect (struct socket *sock,struct sockaddr *addr,int addrlen,int flags) { -return sock->ops->connect (sock, addr, addrlen, flags); +struct sockaddr_storage address; + +memcpy (&address, addr, addrlen); + +return sock->ops->connect (sock, (struct sockaddr *)&address, addrlen, flags);
Could you rebase on net-next.git ? I think this patch conflicts with 1ded5e5a5931 ("net: annotate data-races around sock->ops").
Quoted 5 lines
net/socket.c +0
-0}EXPORT_SYMBOL (kernel_connect);Signature · 1 line
2.42.0.rc1.204.g551eb34607-goog
PATCH v2 1/1 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.
---
V1 -> V2: Rebased on net-next
net/socket.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/socket.c +5 -1
@@ -3567,7 +3567,11 @@ 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);
Signature · 1 line
2.42.0.rc1.204.g551eb34607-goog
PATCH v3 1/1 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.
---
V2 -> V3: Broke up long line
V1 -> V2: Rebased on net-next
net/socket.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/socket.c +6 -1
@@ -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);
Signature · 1 line
2.42.0.rc1.204.g551eb34607-goog
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 20 lines · On Mon, 21 Aug 2023 16:45:23 -0500 you wrote:
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_connectsimply 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.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v3] net: Avoid address overwrite in kernel_connect
https://git.kernel.org/netdev/net-next/c/0bdf399342c5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html