Skip to content

Commit

Permalink
Merge tag '6.5-rc3-smb3-client-fixes' of git://git.samba.org/sfrench/…
Browse files Browse the repository at this point in the history
…cifs-2.6

Pull smb client fixes from Steve French:
 "Four small SMB3 client fixes:

   - two reconnect fixes (to address the case where non-default
     iocharset gets incorrectly overridden at reconnect with the
     default charset)

   - fix for NTLMSSP_AUTH request setting a flag incorrectly)

   - Add missing check for invalid tlink (tree connection) in ioctl"

* tag '6.5-rc3-smb3-client-fixes' of git://git.samba.org/sfrench/cifs-2.6:
  cifs: add missing return value check for cifs_sb_tlink
  smb3: do not set NTLMSSP_VERSION flag for negotiate not auth request
  cifs: fix charset issue in reconnection
  fs/nls: make load_nls() take a const parameter
  • Loading branch information
torvalds committed Jul 30, 2023
2 parents b88e123 + a171eb5 commit d31e379
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions fs/nls/nls_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ int unregister_nls(struct nls_table * nls)
return -EINVAL;
}

static struct nls_table *find_nls(char *charset)
static struct nls_table *find_nls(const char *charset)
{
struct nls_table *nls;
spin_lock(&nls_lock);
Expand All @@ -288,7 +288,7 @@ static struct nls_table *find_nls(char *charset)
return nls;
}

struct nls_table *load_nls(char *charset)
struct nls_table *load_nls(const char *charset)
{
return try_then_request_module(find_nls(charset), "nls_%s", charset);
}
Expand Down
1 change: 1 addition & 0 deletions fs/smb/client/cifsglob.h
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ struct cifs_ses {
unsigned long chans_need_reconnect;
/* ========= end: protected by chan_lock ======== */
struct cifs_ses *dfs_root_ses;
struct nls_table *local_nls;
};

static inline bool
Expand Down
3 changes: 1 addition & 2 deletions fs/smb/client/cifssmb.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
}
spin_unlock(&server->srv_lock);

nls_codepage = load_nls_default();
nls_codepage = ses->local_nls;

/*
* need to prevent multiple threads trying to simultaneously
Expand Down Expand Up @@ -200,7 +200,6 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
rc = -EAGAIN;
}

unload_nls(nls_codepage);
return rc;
}

Expand Down
5 changes: 5 additions & 0 deletions fs/smb/client/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,10 @@ static int match_session(struct cifs_ses *ses, struct smb3_fs_context *ctx)
CIFS_MAX_PASSWORD_LEN))
return 0;
}

if (strcmp(ctx->local_nls->charset, ses->local_nls->charset))
return 0;

return 1;
}

Expand Down Expand Up @@ -2286,6 +2290,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)

ses->sectype = ctx->sectype;
ses->sign = ctx->sign;
ses->local_nls = load_nls(ctx->local_nls->charset);

/* add server as first channel */
spin_lock(&ses->chan_lock);
Expand Down
5 changes: 5 additions & 0 deletions fs/smb/client/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
}
cifs_sb = CIFS_SB(inode->i_sb);
tlink = cifs_sb_tlink(cifs_sb);
if (IS_ERR(tlink)) {
rc = PTR_ERR(tlink);
break;
}

tcon = tlink_tcon(tlink);
rc = cifs_dump_full_key(tcon, (void __user *)arg);
cifs_put_tlink(tlink);
Expand Down
1 change: 1 addition & 0 deletions fs/smb/client/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ sesInfoFree(struct cifs_ses *buf_to_free)
return;
}

unload_nls(buf_to_free->local_nls);
atomic_dec(&sesInfoAllocCount);
kfree(buf_to_free->serverOS);
kfree(buf_to_free->serverDomain);
Expand Down
4 changes: 3 additions & 1 deletion fs/smb/client/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ int build_ntlmssp_smb3_negotiate_blob(unsigned char **pbuffer,
}


/* See MS-NLMP 2.2.1.3 */
int build_ntlmssp_auth_blob(unsigned char **pbuffer,
u16 *buflen,
struct cifs_ses *ses,
Expand Down Expand Up @@ -1047,7 +1048,8 @@ int build_ntlmssp_auth_blob(unsigned char **pbuffer,

flags = ses->ntlmssp->server_flags | NTLMSSP_REQUEST_TARGET |
NTLMSSP_NEGOTIATE_TARGET_INFO | NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED;

/* we only send version information in ntlmssp negotiate, so do not set this flag */
flags = flags & ~NTLMSSP_NEGOTIATE_VERSION;
tmp = *pbuffer + sizeof(AUTHENTICATE_MESSAGE);
sec_blob->NegotiateFlags = cpu_to_le32(flags);

Expand Down
3 changes: 1 addition & 2 deletions fs/smb/client/smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
}
spin_unlock(&server->srv_lock);

nls_codepage = load_nls_default();
nls_codepage = ses->local_nls;

/*
* need to prevent multiple threads trying to simultaneously
Expand Down Expand Up @@ -324,7 +324,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
rc = -EAGAIN;
}
failed:
unload_nls(nls_codepage);
return rc;
}

Expand Down
2 changes: 1 addition & 1 deletion include/linux/nls.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum utf16_endian {
/* nls_base.c */
extern int __register_nls(struct nls_table *, struct module *);
extern int unregister_nls(struct nls_table *);
extern struct nls_table *load_nls(char *);
extern struct nls_table *load_nls(const char *charset);
extern void unload_nls(struct nls_table *);
extern struct nls_table *load_nls_default(void);
#define register_nls(nls) __register_nls((nls), THIS_MODULE)
Expand Down

0 comments on commit d31e379

Please sign in to comment.