Skip to contentSkip to conversation

smb/client: use sock_create_kern() in generic_ip_connect()

PATCH In review [email protected] 4 participants 5 messages May 28, 2025 – May 30, 2025

Subsystems (2)
lore
Share & tools
lore

[email protected]

author reviewer
#0 lore raw

PATCH 1/1 smb/client: use sock_create_kern() in generic_ip_connect()

From: ChenXiaoSong <[email protected]>

Change __sock_create() to sock_create_kern() for explicitness.

---
 fs/smb/client/connect.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/smb/client/connect.c +1 -2
index 6bf04d9a5491..3275f2ff84cb 100644
@@ -3350,8 +3350,7 @@ generic_ip_connect(struct TCP_Server_Info *server)
 		struct net *net = cifs_net_ns(server);
 		struct sock *sk;
 
-		rc = __sock_create(net, sfamily, SOCK_STREAM,
-				   IPPROTO_TCP, &server->ssocket, 1);
+		rc = sock_create_kern(net, sfamily, SOCK_STREAM, IPPROTO_TCP, &server->ssocket);
 		if (rc < 0) {
 			cifs_server_dbg(VFS, "Error %d creating socket\n", rc);
 			return rc;
Signature · 1 line
2.34.1
#1 lore raw

Weren't there issues brought up earlier with using sock_create_kern due to network namespaces and refcounts?

Quoted 28 lines · On Tue, May 27, 2025 at 10:18 PM <[email protected]> wrote:

From: ChenXiaoSong <[email protected]>

Change __sock_create() to sock_create_kern() for explicitness.

---
 fs/smb/client/connect.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/smb/client/connect.c +1 -3
index 6bf04d9a5491..3275f2ff84cb 100644
@@ -3350,8 +3350,7 @@ generic_ip_connect(struct TCP_Server_Info *server)
                struct net *net = cifs_net_ns(server);
                struct sock *sk;
 
-               rc = __sock_create(net, sfamily, SOCK_STREAM,
-                                  IPPROTO_TCP, &server->ssocket, 1);
+               rc = sock_create_kern(net, sfamily, SOCK_STREAM, IPPROTO_TCP, &server->ssocket);
                if (rc < 0) {
                        cifs_server_dbg(VFS, "Error %d creating socket\n", rc);
                        return rc;
--

2.34.1

Signature · 3 lines
Thanks,

Steve
author reviewer
#2 lore raw

This patch is simply a cleanup that wraps the original code for explicitness, the last argument of __sock_create(..., 1) specifies that the socket is created in kernel space.

Quoted 34 lines · Steve French

Weren't there issues brought up earlier with using sock_create_kern due to network namespaces and refcounts?

Quoted 28 lines · On Tue, May 27, 2025 at 10:18 PM <[email protected]> wrote:

From: ChenXiaoSong <[email protected]>

Change __sock_create() to sock_create_kern() for explicitness.

---
  fs/smb/client/connect.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
fs/smb/client/connect.c +1 -3
index 6bf04d9a5491..3275f2ff84cb 100644
@@ -3350,8 +3350,7 @@ generic_ip_connect(struct TCP_Server_Info *server)
                 struct net *net = cifs_net_ns(server);
                 struct sock *sk;
 
-               rc = __sock_create(net, sfamily, SOCK_STREAM,
-                                  IPPROTO_TCP, &server->ssocket, 1);
+               rc = sock_create_kern(net, sfamily, SOCK_STREAM, IPPROTO_TCP, &server->ssocket);
                 if (rc < 0) {
                         cifs_server_dbg(VFS, "Error %d creating socket\n", rc);
                         return rc;
--

2.34.1

#3 lore raw
Quoted 7 lines · On Wed, 28 May 2025 12:09:01 +0800 ChenXiaoSong…
Quoted 2 lines · Steve French

Weren't there issues brought up earlier with using sock_create_kern due to network namespaces and refcounts?

This patch is simply a cleanup that wraps the original code for explicitness, the last argument of __sock_create(..., 1) specifies that the socket is created in kernel space.

Except that 'kernel space' doesn't really mean anything. IIRC it does two separate things:
1) Skips some 'permission' checks on the current process.
2) Doesn't 'hold' the network namespace.

The extra permission checks might be relevant even if the socket is only indirectly accessible from a process.

But code like smb doesn't want the extra checks but does need the namespace held (or it has to go through 'hoops' to request a callback when the namespace is removed and delete the connection from the callback).

Maybe there should be a 'kernel_socket()' (cf kernel_sendmsg()) that code like smb should use.

David

Quoted 35 lines
Quoted 33 lines · On Tue, May 27, 2025 at 10:18 PM <[email protected]> wrote:
Quoted 28 lines

From: ChenXiaoSong <[email protected]>

Change __sock_create() to sock_create_kern() for explicitness.

---
  fs/smb/client/connect.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
fs/smb/client/connect.c +1 -3
index 6bf04d9a5491..3275f2ff84cb 100644
@@ -3350,8 +3350,7 @@ generic_ip_connect(struct TCP_Server_Info *server)
                 struct net *net = cifs_net_ns(server);
                 struct sock *sk;
 
-               rc = __sock_create(net, sfamily, SOCK_STREAM,
-                                  IPPROTO_TCP, &server->ssocket, 1);
+               rc = sock_create_kern(net, sfamily, SOCK_STREAM, IPPROTO_TCP, &server->ssocket);
                 if (rc < 0) {
                         cifs_server_dbg(VFS, "Error %d creating socket\n", rc);
                         return rc;
--

2.34.1

#4 lore raw
In reply to ChenXiaoSong

Thanks for CCing me, Steve.

From: ChenXiaoSong <[email protected]>
Date: Wed, 28 May 2025 12:09:01 +0800

Quoted 3 lines

This patch is simply a cleanup that wraps the original code for explicitness, the last argument of __sock_create(..., 1) specifies that the socket is created in kernel space.

Not sure how you came up with this patch, maybe coincidence, but I'm trying to clean these up at once on the netdev side, so it would be appreciated if this is kept as is to avoid unnecessary conflicts.

https://lore.kernel.org/netdev/[email protected]/

Quoted 36 lines · Steve French
Quoted 34 lines

Weren't there issues brought up earlier with using sock_create_kern due to network namespaces and refcounts?

Quoted 28 lines · On Tue, May 27, 2025 at 10:18 PM <[email protected]> wrote:

From: ChenXiaoSong <[email protected]>

Change __sock_create() to sock_create_kern() for explicitness.

---
  fs/smb/client/connect.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
fs/smb/client/connect.c +1 -3
index 6bf04d9a5491..3275f2ff84cb 100644
@@ -3350,8 +3350,7 @@ generic_ip_connect(struct TCP_Server_Info *server)
                 struct net *net = cifs_net_ns(server);
                 struct sock *sk;
 
-               rc = __sock_create(net, sfamily, SOCK_STREAM,
-                                  IPPROTO_TCP, &server->ssocket, 1);
+               rc = sock_create_kern(net, sfamily, SOCK_STREAM, IPPROTO_TCP, &server->ssocket);
                 if (rc < 0) {
                         cifs_server_dbg(VFS, "Error %d creating socket\n", rc);
                         return rc;
--

2.34.1