Skip to content

Commit

Permalink
cifs: send workstation name during ntlmssp session setup
Browse files Browse the repository at this point in the history
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 <sprasad@microsoft.com>
Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Reviewed-by: Enzo Matsumiya <ematsumiya@suse.de>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
Shyam Prasad N authored and Steve French committed Nov 8, 2021
1 parent c9f1c19 commit 49bd49f
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 85 deletions.
4 changes: 4 additions & 0 deletions fs/cifs/cifsglob.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/slab.h>
#include <linux/mempool.h>
#include <linux/workqueue.h>
#include <linux/utsname.h>
#include "cifs_fs_sb.h"
#include "cifsacl.h"
#include <crypto/internal/hash.h>
Expand Down Expand Up @@ -99,6 +100,8 @@
#define XATTR_DOS_ATTRIB "user.DOSATTRIB"
#endif

#define CIFS_MAX_WORKSTATION_LEN (__NEW_UTS_LEN + 1) /* reasonable max for client */

/*
* CIFS vfs client Status information (based on what we know.)
*/
Expand Down Expand Up @@ -909,6 +912,7 @@ struct cifs_ses {
and after mount option parsing we fill it */
char *domainName;
char *password;
char *workstation_name;
struct session_key auth_key;
struct ntlmssp_auth *ntlmssp; /* ciphertext, flags, server challenge */
enum securityEnum sectype; /* what security flavor was specified? */
Expand Down
6 changes: 6 additions & 0 deletions fs/cifs/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,12 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)
if (!ses->domainName)
goto get_ses_fail;
}
if (ctx->workstation_name) {
ses->workstation_name = kstrdup(ctx->workstation_name,
GFP_KERNEL);
if (!ses->workstation_name)
goto get_ses_fail;
}
if (ctx->domainauto)
ses->domainAuto = ctx->domainauto;
ses->cred_uid = ctx->cred_uid;
Expand Down
34 changes: 31 additions & 3 deletions fs/cifs/fs_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx
new_ctx->username = NULL;
new_ctx->password = NULL;
new_ctx->domainname = NULL;
new_ctx->workstation_name = NULL;
new_ctx->UNC = NULL;
new_ctx->source = NULL;
new_ctx->iocharset = NULL;
Expand All @@ -323,6 +324,7 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx
DUP_CTX_STR(UNC);
DUP_CTX_STR(source);
DUP_CTX_STR(domainname);
DUP_CTX_STR(workstation_name);
DUP_CTX_STR(nodename);
DUP_CTX_STR(iocharset);

Expand Down Expand Up @@ -720,6 +722,11 @@ static int smb3_verify_reconfigure_ctx(struct fs_context *fc,
cifs_errorf(fc, "can not change domainname during remount\n");
return -EINVAL;
}
if (new_ctx->workstation_name &&
(!old_ctx->workstation_name || strcmp(new_ctx->workstation_name, old_ctx->workstation_name))) {
cifs_errorf(fc, "can not change workstation_name during remount\n");
return -EINVAL;
}
if (new_ctx->nodename &&
(!old_ctx->nodename || strcmp(new_ctx->nodename, old_ctx->nodename))) {
cifs_errorf(fc, "can not change nodename during remount\n");
Expand Down Expand Up @@ -753,7 +760,8 @@ static int smb3_reconfigure(struct fs_context *fc)
return rc;

/*
* We can not change UNC/username/password/domainname/nodename/iocharset
* We can not change UNC/username/password/domainname/
* workstation_name/nodename/iocharset
* during reconnect so ignore what we have in the new context and
* just use what we already have in cifs_sb->ctx.
*/
Expand All @@ -762,6 +770,7 @@ static int smb3_reconfigure(struct fs_context *fc)
STEAL_STRING(cifs_sb, ctx, username);
STEAL_STRING(cifs_sb, ctx, password);
STEAL_STRING(cifs_sb, ctx, domainname);
STEAL_STRING(cifs_sb, ctx, workstation_name);
STEAL_STRING(cifs_sb, ctx, nodename);
STEAL_STRING(cifs_sb, ctx, iocharset);

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

int smb3_init_fs_context(struct fs_context *fc)
{
int rc;
struct smb3_fs_context *ctx;
char *nodename = utsname()->nodename;
int i;

ctx = kzalloc(sizeof(struct smb3_fs_context), GFP_KERNEL);
if (unlikely(!ctx))
return -ENOMEM;
if (unlikely(!ctx)) {
rc = -ENOMEM;
goto err_exit;
}

ctx->workstation_name = kstrdup(nodename, GFP_KERNEL);
if (unlikely(!ctx->workstation_name)) {
rc = -ENOMEM;
goto err_exit;
}

/*
* does not have to be perfect mapping since field is
Expand Down Expand Up @@ -1493,6 +1511,14 @@ int smb3_init_fs_context(struct fs_context *fc)
fc->fs_private = ctx;
fc->ops = &smb3_fs_context_ops;
return 0;

err_exit:
if (ctx) {
kfree(ctx->workstation_name);
kfree(ctx);
}

return rc;
}

void
Expand All @@ -1518,6 +1544,8 @@ smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx)
ctx->source = NULL;
kfree(ctx->domainname);
ctx->domainname = NULL;
kfree(ctx->workstation_name);
ctx->workstation_name = NULL;
kfree(ctx->nodename);
ctx->nodename = NULL;
kfree(ctx->iocharset);
Expand Down
1 change: 1 addition & 0 deletions fs/cifs/fs_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ struct smb3_fs_context {
char *server_hostname;
char *UNC;
char *nodename;
char *workstation_name;
char *iocharset; /* local code page for mapping to and from Unicode */
char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
Expand Down
1 change: 1 addition & 0 deletions fs/cifs/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ sesInfoFree(struct cifs_ses *buf_to_free)
kfree_sensitive(buf_to_free->password);
kfree(buf_to_free->user_name);
kfree(buf_to_free->domainName);
kfree(buf_to_free->workstation_name);
kfree_sensitive(buf_to_free->auth_key.response);
kfree(buf_to_free->iface_list);
kfree_sensitive(buf_to_free);
Expand Down
4 changes: 3 additions & 1 deletion fs/cifs/ntlmssp.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ typedef struct _AUTHENTICATE_MESSAGE {
*/

int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, struct cifs_ses *ses);
void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, struct cifs_ses *ses);
int build_ntlmssp_negotiate_blob(unsigned char **pbuffer, u16 *buflen,
struct cifs_ses *ses,
const struct nls_table *nls_cp);
int build_ntlmssp_auth_blob(unsigned char **pbuffer, u16 *buflen,
struct cifs_ses *ses,
const struct nls_table *nls_cp);
Loading

0 comments on commit 49bd49f

Please sign in to comment.