From: Henry Martin <bsdhenrymartin@gmail.com>
To: Paulo Alcantara <pc@manguebit.org>,
Namjae Jeon <linkinjeon@kernel.org>,
Ronnie Sahlberg <ronniesahlberg@gmail.com>,
Shyam Prasad N <sprasad@microsoft.com>,
Tom Talpey <tom@talpey.com>, Bharath SM <bharathsm@microsoft.com>
Cc: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
linux-kernel@vger.kernel.org,
Henry Martin <bsdhenrymartin@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] cifs: fix UAF read of server->hostname in cifs_get_spnego_key()
Date: Tue, 27 Oct 2026 23:04:38 +0800 [thread overview]
Message-ID: <20261027150438.943354-1-bsdhenrymartin@gmail.com> (raw)
cifs_get_spnego_key() reads server->hostname without holding
server->srv_lock (fs/smb/client/cifs_spnego.c):
const char *hostname = server->hostname;
...
desc_len = ... + strlen(hostname) + ...
...
dp += sprintf(dp, "ver=0x%x;host=%s;", ..., hostname);
while the DFS failover path frees and replaces the hostname under
srv_lock (__reconnect_target_locked(), fs/smb/client/connect.c):
spin_lock(&server->srv_lock);
kfree(server->hostname);
server->hostname = hostname;
spin_unlock(&server->srv_lock);
The read side runs on the kerberos auth path without the lock, so the
strlen() and the sprintf() can race with the free.
Take a stable copy of the hostname under srv_lock at function entry,
before any use.
This issue was discovered by Tencent CodeBuddy Security.
Fixes: 93d5cb517db3 ("cifs: Add support for failover in cifs_reconnect()")
Cc: stable@vger.kernel.org
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
fs/smb/client/cifs_spnego.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/fs/smb/client/cifs_spnego.c b/fs/smb/client/cifs_spnego.c
index 44c4072756804..488ddf6df138d 100644
--- a/fs/smb/client/cifs_spnego.c
+++ b/fs/smb/client/cifs_spnego.c
@@ -105,7 +105,15 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo,
char *description, *dp;
size_t desc_len;
struct key *spnego_key;
- const char *hostname = server->hostname;
+ char hostname[CIFS_NI_MAXHOST + 1];
+
+ /* hostname is replaced under srv_lock by the DFS failover path
+ * (kfree + new assignment); take a stable copy while holding the
+ * lock so strlen()/sprintf() below cannot race with the free.
+ */
+ spin_lock(&server->srv_lock);
+ strscpy(hostname, server->hostname, sizeof(hostname));
+ spin_unlock(&server->srv_lock);
/* length of fields (with semicolons): ver=0xyz ip4=ipaddress
host=hostname sec=mechanism uid=0xFF user=username */
--
2.43.7
reply other threads:[~2026-10-27 15:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261027150438.943354-1-bsdhenrymartin@gmail.com \
--to=bsdhenrymartin@gmail.com \
--cc=bharathsm@microsoft.com \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pc@manguebit.org \
--cc=ronniesahlberg@gmail.com \
--cc=samba-technical@lists.samba.org \
--cc=sprasad@microsoft.com \
--cc=stable@vger.kernel.org \
--cc=tom@talpey.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
all inboxes | Powered by JetHome®