diff mbox series

cifs: fix workstation_name for multiuser mounts

Message ID 20211222160405.3174438-2-ryandbair@gmail.com (mailing list archive)
State New, archived
Headers show
Series cifs: fix workstation_name for multiuser mounts | expand

Commit Message

Ryan Bair Dec. 22, 2021, 4:04 p.m. UTC
Set workstation_name from the master_tcon for multiuser mounts.

Just in case, protect size_of_ntlmssp_blob against a NULL workstation_name.

Signed-off-by: Ryan Bair <ryandbair@gmail.com>
---
 fs/cifs/connect.c | 13 +++++++++++++
 fs/cifs/sess.c    |  6 +++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

Comments

Paulo Alcantara Feb. 1, 2022, 5:22 p.m. UTC | #1
Ryan Bair <ryandbair@gmail.com> writes:

> Set workstation_name from the master_tcon for multiuser mounts.
>
> Just in case, protect size_of_ntlmssp_blob against a NULL workstation_name.
>
> Signed-off-by: Ryan Bair <ryandbair@gmail.com>
> ---
>  fs/cifs/connect.c | 13 +++++++++++++
>  fs/cifs/sess.c    |  6 +++++-
>  2 files changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> index 1060164b984a..cefd0e9623ba 100644
> --- a/fs/cifs/connect.c
> +++ b/fs/cifs/connect.c

Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>

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

        Fixes: 49bd49f983b5 ("cifs: send workstation name during ntlmssp session setup")
        Cc: stable@vger.kernel.org # 5.16

Thanks.
Steve French Feb. 3, 2022, 3:32 a.m. UTC | #2
Missed this email thread during the holidays - will test it out later this week.

On Fri, Dec 24, 2021 at 5:07 AM Ryan Bair <ryandbair@gmail.com> wrote:
>
> Set workstation_name from the master_tcon for multiuser mounts.
>
> Just in case, protect size_of_ntlmssp_blob against a NULL workstation_name.
>
> Signed-off-by: Ryan Bair <ryandbair@gmail.com>
> ---
>  fs/cifs/connect.c | 13 +++++++++++++
>  fs/cifs/sess.c    |  6 +++++-
>  2 files changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> index 1060164b984a..cefd0e9623ba 100644
> --- a/fs/cifs/connect.c
> +++ b/fs/cifs/connect.c
> @@ -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);
> diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
> index 035dc3e245dc..42133939f35d 100644
> --- a/fs/cifs/sess.c
> +++ b/fs/cifs/sess.c
> @@ -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
>
diff mbox series

Patch

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 1060164b984a..cefd0e9623ba 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -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);
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
index 035dc3e245dc..42133939f35d 100644
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -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;
 }