Skip to content

Commit 49bd49f

Browse files
sprasad-microsoftsmfrench
authored andcommitted
cifs: send workstation name during ntlmssp session setup
During the ntlmssp session setup (authenticate phases) send the client workstation info. This can make debugging easier on servers. Signed-off-by: Shyam Prasad N <[email protected]> Reviewed-by: Paulo Alcantara (SUSE) <[email protected]> Reviewed-by: Enzo Matsumiya <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent c9f1c19 commit 49bd49f

File tree

8 files changed

+170
-85
lines changed

8 files changed

+170
-85
lines changed

fs/cifs/cifsglob.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/slab.h>
1616
#include <linux/mempool.h>
1717
#include <linux/workqueue.h>
18+
#include <linux/utsname.h>
1819
#include "cifs_fs_sb.h"
1920
#include "cifsacl.h"
2021
#include <crypto/internal/hash.h>
@@ -99,6 +100,8 @@
99100
#define XATTR_DOS_ATTRIB "user.DOSATTRIB"
100101
#endif
101102

103+
#define CIFS_MAX_WORKSTATION_LEN (__NEW_UTS_LEN + 1) /* reasonable max for client */
104+
102105
/*
103106
* CIFS vfs client Status information (based on what we know.)
104107
*/
@@ -909,6 +912,7 @@ struct cifs_ses {
909912
and after mount option parsing we fill it */
910913
char *domainName;
911914
char *password;
915+
char *workstation_name;
912916
struct session_key auth_key;
913917
struct ntlmssp_auth *ntlmssp; /* ciphertext, flags, server challenge */
914918
enum securityEnum sectype; /* what security flavor was specified? */

fs/cifs/connect.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,12 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)
19481948
if (!ses->domainName)
19491949
goto get_ses_fail;
19501950
}
1951+
if (ctx->workstation_name) {
1952+
ses->workstation_name = kstrdup(ctx->workstation_name,
1953+
GFP_KERNEL);
1954+
if (!ses->workstation_name)
1955+
goto get_ses_fail;
1956+
}
19511957
if (ctx->domainauto)
19521958
ses->domainAuto = ctx->domainauto;
19531959
ses->cred_uid = ctx->cred_uid;

fs/cifs/fs_context.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx
309309
new_ctx->username = NULL;
310310
new_ctx->password = NULL;
311311
new_ctx->domainname = NULL;
312+
new_ctx->workstation_name = NULL;
312313
new_ctx->UNC = NULL;
313314
new_ctx->source = NULL;
314315
new_ctx->iocharset = NULL;
@@ -323,6 +324,7 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx
323324
DUP_CTX_STR(UNC);
324325
DUP_CTX_STR(source);
325326
DUP_CTX_STR(domainname);
327+
DUP_CTX_STR(workstation_name);
326328
DUP_CTX_STR(nodename);
327329
DUP_CTX_STR(iocharset);
328330

@@ -720,6 +722,11 @@ static int smb3_verify_reconfigure_ctx(struct fs_context *fc,
720722
cifs_errorf(fc, "can not change domainname during remount\n");
721723
return -EINVAL;
722724
}
725+
if (new_ctx->workstation_name &&
726+
(!old_ctx->workstation_name || strcmp(new_ctx->workstation_name, old_ctx->workstation_name))) {
727+
cifs_errorf(fc, "can not change workstation_name during remount\n");
728+
return -EINVAL;
729+
}
723730
if (new_ctx->nodename &&
724731
(!old_ctx->nodename || strcmp(new_ctx->nodename, old_ctx->nodename))) {
725732
cifs_errorf(fc, "can not change nodename during remount\n");
@@ -753,7 +760,8 @@ static int smb3_reconfigure(struct fs_context *fc)
753760
return rc;
754761

755762
/*
756-
* We can not change UNC/username/password/domainname/nodename/iocharset
763+
* We can not change UNC/username/password/domainname/
764+
* workstation_name/nodename/iocharset
757765
* during reconnect so ignore what we have in the new context and
758766
* just use what we already have in cifs_sb->ctx.
759767
*/
@@ -762,6 +770,7 @@ static int smb3_reconfigure(struct fs_context *fc)
762770
STEAL_STRING(cifs_sb, ctx, username);
763771
STEAL_STRING(cifs_sb, ctx, password);
764772
STEAL_STRING(cifs_sb, ctx, domainname);
773+
STEAL_STRING(cifs_sb, ctx, workstation_name);
765774
STEAL_STRING(cifs_sb, ctx, nodename);
766775
STEAL_STRING(cifs_sb, ctx, iocharset);
767776

@@ -1414,13 +1423,22 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
14141423

14151424
int smb3_init_fs_context(struct fs_context *fc)
14161425
{
1426+
int rc;
14171427
struct smb3_fs_context *ctx;
14181428
char *nodename = utsname()->nodename;
14191429
int i;
14201430

14211431
ctx = kzalloc(sizeof(struct smb3_fs_context), GFP_KERNEL);
1422-
if (unlikely(!ctx))
1423-
return -ENOMEM;
1432+
if (unlikely(!ctx)) {
1433+
rc = -ENOMEM;
1434+
goto err_exit;
1435+
}
1436+
1437+
ctx->workstation_name = kstrdup(nodename, GFP_KERNEL);
1438+
if (unlikely(!ctx->workstation_name)) {
1439+
rc = -ENOMEM;
1440+
goto err_exit;
1441+
}
14241442

14251443
/*
14261444
* does not have to be perfect mapping since field is
@@ -1493,6 +1511,14 @@ int smb3_init_fs_context(struct fs_context *fc)
14931511
fc->fs_private = ctx;
14941512
fc->ops = &smb3_fs_context_ops;
14951513
return 0;
1514+
1515+
err_exit:
1516+
if (ctx) {
1517+
kfree(ctx->workstation_name);
1518+
kfree(ctx);
1519+
}
1520+
1521+
return rc;
14961522
}
14971523

14981524
void
@@ -1518,6 +1544,8 @@ smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx)
15181544
ctx->source = NULL;
15191545
kfree(ctx->domainname);
15201546
ctx->domainname = NULL;
1547+
kfree(ctx->workstation_name);
1548+
ctx->workstation_name = NULL;
15211549
kfree(ctx->nodename);
15221550
ctx->nodename = NULL;
15231551
kfree(ctx->iocharset);

fs/cifs/fs_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ struct smb3_fs_context {
170170
char *server_hostname;
171171
char *UNC;
172172
char *nodename;
173+
char *workstation_name;
173174
char *iocharset; /* local code page for mapping to and from Unicode */
174175
char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
175176
char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */

fs/cifs/misc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ sesInfoFree(struct cifs_ses *buf_to_free)
9494
kfree_sensitive(buf_to_free->password);
9595
kfree(buf_to_free->user_name);
9696
kfree(buf_to_free->domainName);
97+
kfree(buf_to_free->workstation_name);
9798
kfree_sensitive(buf_to_free->auth_key.response);
9899
kfree(buf_to_free->iface_list);
99100
kfree_sensitive(buf_to_free);

fs/cifs/ntlmssp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ typedef struct _AUTHENTICATE_MESSAGE {
119119
*/
120120

121121
int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, struct cifs_ses *ses);
122-
void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, struct cifs_ses *ses);
122+
int build_ntlmssp_negotiate_blob(unsigned char **pbuffer, u16 *buflen,
123+
struct cifs_ses *ses,
124+
const struct nls_table *nls_cp);
123125
int build_ntlmssp_auth_blob(unsigned char **pbuffer, u16 *buflen,
124126
struct cifs_ses *ses,
125127
const struct nls_table *nls_cp);

0 commit comments

Comments
 (0)