Skip to contentSkip to conversation

fix workstation_name for multiuser mounts

PATCH In review Ryan Bair 3 participants 4 messages Dec 22, 2021 – Feb 3, 2022

Subsystems (2)
lore
Share & tools
lore

Ryan Bair

author
#0 lore raw

Long time user, first time contributor.
Please let me know if I need to be doing something different.

Thanks,
-Ryan

author
#1 lore raw

PATCH 1/1 cifs: fix workstation_name for multiuser mounts

Set workstation_name from the master_tcon for multiuser mounts.

Just in case, protect size_of_ntlmssp_blob against a NULL workstation_name.

---
 fs/cifs/connect.c | 13 +++++++++++++
 fs/cifs/sess.c    |  6 +++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
fs/cifs/connect.c +13 -0
index 1060164b984a..cefd0e9623ba 100644
@@ -1945,6 +1945,19 @@ cifs_set_cifscreds(struct smb3_fs_context *ctx, struct cifs_ses *ses)
 		}
 	}
 
+	ctx->workstation_name = kstrdup(ses->workstation_name, GFP_KERNEL);
+	if (!ctx->workstation_name) {
+		cifs_dbg(FYI, "Unable to allocate memory for workstation_name\n");
+		rc = -ENOMEM;
+		kfree(ctx->username);
+		ctx->username = NULL;
+		kfree_sensitive(ctx->password);
+		ctx->password = NULL;
+		kfree(ctx->domainname);
+		ctx->domainname = NULL;
+		goto out_key_put;
+	}
+
 out_key_put:
 	up_read(&key->sem);
 	key_put(key);
fs/cifs/sess.c +5 -1
index 035dc3e245dc..42133939f35d 100644
@@ -675,7 +675,11 @@ static int size_of_ntlmssp_blob(struct cifs_ses *ses, int base_size)
 	else
 		sz += sizeof(__le16);
 
-	sz += sizeof(__le16) * strnlen(ses->workstation_name, CIFS_MAX_WORKSTATION_LEN);
+	if (ses->workstation_name)
+		sz += sizeof(__le16) * strnlen(ses->workstation_name,
+			CIFS_MAX_WORKSTATION_LEN);
+	else
+		sz += sizeof(__le16);
 
 	return sz;
 }
Signature · 1 line
2.33.1
Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH] cifs: fix workstation_name for multiuser mounts

fs/cifs/connect.c

Quoted 14 lines · Ryan Bair

Set workstation_name from the master_tcon for multiuser mounts.

Just in case, protect size_of_ntlmssp_blob against a NULL workstation_name.

---
 fs/cifs/connect.c | 13 +++++++++++++
 fs/cifs/sess.c    |  6 +++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
fs/cifs/connect.c +0 -0
index 1060164b984a..cefd0e9623ba 100644

Steve, could you pick this up? Please also add the following tags:

Fixes 49bd49f983b5 ("cifs: send workstation name during ntlmssp session setup")

Thanks.

#3 lore raw

Re: [PATCH] cifs: fix workstation_name for multiuser mounts

In reply to Ryan Bair

Missed this email thread during the holidays - will test it out later this week.

Quoted 55 lines · Ryan Bair

Set workstation_name from the master_tcon for multiuser mounts.

Just in case, protect size_of_ntlmssp_blob against a NULL workstation_name.

---
 fs/cifs/connect.c | 13 +++++++++++++
 fs/cifs/sess.c    |  6 +++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
fs/cifs/connect.c +13 -0
index 1060164b984a..cefd0e9623ba 100644
@@ -1945,6 +1945,19 @@ cifs_set_cifscreds(struct smb3_fs_context *ctx, struct cifs_ses *ses)
                }
        }
 
+       ctx->workstation_name = kstrdup(ses->workstation_name, GFP_KERNEL);
+       if (!ctx->workstation_name) {
+               cifs_dbg(FYI, "Unable to allocate memory for workstation_name\n");
+               rc = -ENOMEM;
+               kfree(ctx->username);
+               ctx->username = NULL;
+               kfree_sensitive(ctx->password);
+               ctx->password = NULL;
+               kfree(ctx->domainname);
+               ctx->domainname = NULL;
+               goto out_key_put;
+       }
+
 out_key_put:
        up_read(&key->sem);
        key_put(key);
fs/cifs/sess.c +5 -2
index 035dc3e245dc..42133939f35d 100644
@@ -675,7 +675,11 @@ static int size_of_ntlmssp_blob(struct cifs_ses *ses, int base_size)
        else
                sz += sizeof(__le16);
 
-       sz += sizeof(__le16) * strnlen(ses->workstation_name, CIFS_MAX_WORKSTATION_LEN);
+       if (ses->workstation_name)
+               sz += sizeof(__le16) * strnlen(ses->workstation_name,
+                       CIFS_MAX_WORKSTATION_LEN);
+       else
+               sz += sizeof(__le16);
 
        return sz;
 }
--

2.33.1

Signature · 3 lines
Thanks,

Steve