Linux-CIFS Archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Namjae Jeon <linkinjeon@kernel.org>,
	Steve French <stfrench@microsoft.com>,
	Sasha Levin <sashal@kernel.org>,
	smfrench@gmail.com, linux-cifs@vger.kernel.org
Subject: [PATCH AUTOSEL 6.17-6.1] ksmbd: use sock_create_kern interface to create kernel socket
Date: Sat, 25 Oct 2025 11:55:06 -0400	[thread overview]
Message-ID: <20251025160905.3857885-75-sashal@kernel.org> (raw)
In-Reply-To: <20251025160905.3857885-1-sashal@kernel.org>

From: Namjae Jeon <linkinjeon@kernel.org>

[ Upstream commit 3677ca67b9791481af16d86e47c3c7d1f2442f95 ]

we should use sock_create_kern() if the socket resides in kernel space.

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

YES – ksmbd now creates its listening sockets with `sock_create_kern()`,
so the socket is marked as a kernel socket and bypasses LSM policy
checks that would otherwise block the listener.
- `fs/smb/server/transport_tcp.c:474-505` replaces both IPv6 and IPv4
  calls to `sock_create()` with
  `sock_create_kern(current->nsproxy->net_ns, …)`, ensuring
  `__sock_create()` runs with `kern=1` (`net/socket.c:1661-1682`).
- When `kern` stays 0 (old code) LSMs such as SELinux and AppArmor
  enforce their policy hooks, which often deny kernel threads from
  opening INET stream sockets (`security/selinux/hooks.c:4797-4839`,
  `security/apparmor/lsm.c:1261-1301`). That failure bubbles back to
  `create_socket()` and leaves the ksmbd interface unconfigured
  (`fs/smb/server/transport_tcp.c:474-519`), so the server never starts
  listening.
- The change aligns ksmbd with other kernel networking users (e.g., the
  SMB client already calls `sock_create_kern()` in
  `fs/smb/client/connect.c:3366-3374`) and introduces no behavioral or
  API risk beyond correctly flagging the socket as kernel-owned.

Given that this fixes a real service outage on systems with enforcing
LSM policies, is tightly scoped, and carries minimal regression risk, it
is a strong candidate for stable backporting. Suggested verification:
bring up ksmbd under SELinux/AppArmor enforcing and confirm the listener
binds successfully.

 fs/smb/server/transport_tcp.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/smb/server/transport_tcp.c b/fs/smb/server/transport_tcp.c
index 1009cb324fd51..43401d09c9db4 100644
--- a/fs/smb/server/transport_tcp.c
+++ b/fs/smb/server/transport_tcp.c
@@ -473,12 +473,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;
-- 
2.51.0


       reply	other threads:[~2025-10-25 16:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20251025160905.3857885-1-sashal@kernel.org>
2025-10-25 15:55 ` Sasha Levin [this message]
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.1] smb: client: transport: avoid reconnects triggered by pending task work Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] smb: client: update cfid->last_access_time in open_cached_dir_by_dentry() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251025160905.3857885-75-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=smfrench@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=stfrench@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).