smb/server: use sock_create_kern() in create_socket()
Subsystems (4)
[email protected]
reviewerPATCH 1/1 smb/server: use sock_create_kern() in create_socket()
From: ChenXiaoSong <[email protected]>
The socket resides in kernel space, so use sock_create_kern() instead of sock_create().
--- fs/smb/server/transport_tcp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/smb/server/transport_tcp.c +4 -3
@@ -429,12 +429,13 @@ static int create_socket(struct interface *iface)struct socket *ksmbd_socket;bool ipv4 = false; - ret =sock_create (PF_INET6 ,SOCK_STREAM ,IPPROTO_TCP , &ksmbd_socket); + ret =sock_create_kern (current->nsproxy->net_ns,PF_INET6 ,SOCK_STREAM , +IPPROTO_TCP , &ksmbd_socket);if (ret) {if (ret != -EAFNOSUPPORT )pr_err ("Can't create socket for ipv6, fallback to ipv4: %d\n" , ret); - ret =sock_create (PF_INET ,SOCK_STREAM ,IPPROTO_TCP , - &ksmbd_socket); + ret =sock_create_kern (current->nsproxy->net_ns,PF_INET , +SOCK_STREAM ,IPPROTO_TCP , &ksmbd_socket);if (ret) {pr_err ("Can't create socket for ipv4: %d\n" , ret); goto out_clear;
Signature · 1 line
2.34.1
Quoted 4 lines · On Mon, 24 Mar 2025 06:51:55 +0000 [email protected] wrote:
From: ChenXiaoSong <[email protected]>
The socket resides in kernel space, so use
sock_create_kern()instead ofsock_create().
As in the other patches you need to worry about whether the socket holds a reference to the network namespace.
David
Quoted 27 lines
Signed-off-by ChenXiaoSong <[email protected]>--- fs/smb/server/transport_tcp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/smb/server/transport_tcp.c +4
-3@@ -429,12 +429,13 @@ static int create_socket(struct interface *iface)struct socket *ksmbd_socket;bool ipv4 = false; - ret =sock_create (PF_INET6 ,SOCK_STREAM ,IPPROTO_TCP , &ksmbd_socket); + ret =sock_create_kern (current->nsproxy->net_ns,PF_INET6 ,SOCK_STREAM , +IPPROTO_TCP , &ksmbd_socket);if (ret) {if (ret != -EAFNOSUPPORT )pr_err ("Can't create socket for ipv6, fallback to ipv4: %d\n" , ret); - ret =sock_create (PF_INET ,SOCK_STREAM ,IPPROTO_TCP , - &ksmbd_socket); + ret =sock_create_kern (current->nsproxy->net_ns,PF_INET , +SOCK_STREAM ,IPPROTO_TCP , &ksmbd_socket);if (ret) {pr_err ("Can't create socket for ipv4: %d\n" , ret); goto out_clear;
From: David Laight <[email protected]>
Date: Mon, 24 Mar 2025 21:07:47 +0000
Quoted 10 lines
Quoted 4 lines · On Mon, 24 Mar 2025 06:51:55 +0000 [email protected] wrote:
From: ChenXiaoSong <[email protected]>
The socket resides in kernel space, so use
sock_create_kern()instead ofsock_create().As in the other patches you need to worry about whether the socket holds a reference to the network namespace.
Right, and if you don't see any real issue, I recommend leaving it as is for now because we have seen many refcount issues for kernel TCP sockets.
And I totally forgot to respin my series after holiday to clean up such callers.
https://lore.kernel.org/netdev/[email protected]/
I'll repost v4 after the merge window with some modification
1. be less invasive as suggested by Paolo
2. use sk_net_refcnt_upgrade()