Skip to contentSkip to conversation

smb: use kernel_connect() and kernel_bind()

PATCH In review Jordan Rife 3 participants 4 messages Oct 4, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 smb: use kernel_connect() and kernel_bind()

Recent changes to kernel_connect() and kernel_bind() ensure that callers are insulated from changes to the address parameter made by BPF SOCK_ADDR hooks. This patch wraps direct calls to ops->connect() and ops->bind() with kernel_connect() and kernel_bind() to ensure that SMB mounts do not see their mount address overwritten in such cases.

---
 fs/smb/client/connect.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
fs/smb/client/connect.c +5 -5
index 3902e90dca6b0..ce11165446cfb 100644
@@ -2895,9 +2895,9 @@ bind_socket(struct TCP_Server_Info *server)
 	if (server->srcaddr.ss_family != AF_UNSPEC) {
 		/* Bind to the specified local IP address */
 		struct socket *socket = server->ssocket;
-		rc = socket->ops->bind(socket,
-				       (struct sockaddr *) &server->srcaddr,
-				       sizeof(server->srcaddr));
+		rc = kernel_bind(socket,
+				 (struct sockaddr *) &server->srcaddr,
+				 sizeof(server->srcaddr));
 		if (rc < 0) {
 			struct sockaddr_in *saddr4;
 			struct sockaddr_in6 *saddr6;
@@ -3046,8 +3046,8 @@ generic_ip_connect(struct TCP_Server_Info *server)
 		 socket->sk->sk_sndbuf,
 		 socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo);
 
-	rc = socket->ops->connect(socket, saddr, slen,
-				  server->noblockcnt ? O_NONBLOCK : 0);
+	rc = kernel_connect(socket, saddr, slen,
+			    server->noblockcnt ? O_NONBLOCK : 0);
 	/*
 	 * When mounting SMB root file systems, we do not want to block in
 	 * connect. Otherwise bail out and then let cifs_reconnect() perform
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jordan Rife

Recent changes to kernel_connect() and kernel_bind() ensure that callers are insulated from changes to the address parameter made by BPF SOCK_ADDR hooks. This patch wraps direct calls to ops->connect() and ops->bind() with kernel_connect() and kernel_bind() to ensure that SMB mounts do not see their mount address overwritten in such cases.

Quoted 6 lines
---
 fs/smb/client/connect.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
#2 lore raw

tentatively merged into cifs-2.6.git for-next pending testing and additional review

Quoted 17 lines · Paulo Alcantara
Quoted 6 lines · Jordan Rife

Recent changes to kernel_connect() and kernel_bind() ensure that callers are insulated from changes to the address parameter made by BPF SOCK_ADDR hooks. This patch wraps direct calls to ops->connect() and ops->bind() with kernel_connect() and kernel_bind() to ensure that SMB mounts do not see their mount address overwritten in such cases.

Quoted 6 lines
---
 fs/smb/client/connect.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Signature · 3 lines
Thanks,

Steve
#3 lore raw
Quoted 25 lines · Steve French

tentatively merged into cifs-2.6.git for-next pending testing and additional review

Quoted 9 lines · Paulo Alcantara
Quoted 6 lines · Jordan Rife

Recent changes to kernel_connect() and kernel_bind() ensure that callers are insulated from changes to the address parameter made by BPF SOCK_ADDR hooks. This patch wraps direct calls to ops->connect() and ops->bind() with kernel_connect() and kernel_bind() to ensure that SMB mounts do not see their mount address overwritten in such cases.

Quoted 8 lines
Quoted 6 lines
---
 fs/smb/client/connect.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 6 lines

--
Thanks,

Steve

Do you want this to go through the cifs tree?

Yes. This was originally a part of a larger patch set destined for the
net tree (https://lore.kernel.org/netdev/[email protected]/T/#u).
It was ultimately decided
(https://lore.kernel.org/netdev/[email protected]/T/#m905ead9bdce794112a6cdc440f6887b787532023)
over there to try sending patches to the appropriate trees to avoid
merge conflicts.

Quoted 1 line

How urgent do you think it is (or should it wait for 6.7)?

Not super urgent, but ultimately it should be backported to stable kernels 4.19+ (all versions where it's possible to overwrite the address parameter with BPF hooks). The risk here is in environments where BPF hooks are used to rewrite the connect/bind addresses (common in systems like Kubernetes w/ Cilium). Doing so can break your mounts, since the original mount address is "forgotten" when a call to ops->connect() overwrites it (have confirmed this scenario myself). IME, this scenario is more common to see with NFS mounts, but still possible with SMB.

- Jordan