Skip to content

Commit f6a6bf7

Browse files
aaptelsmfrench
authored andcommitted
cifs: switch servers depending on binding state
Currently a lot of the code to initialize a connection & session uses the cifs_ses as input. But depending on if we are opening a new session or a new channel we need to use different server pointers. Add a "binding" flag in cifs_ses and a helper function that returns the server ptr a session should use (only in the sess establishment code path). Signed-off-by: Aurelien Aptel <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent f780bd3 commit f6a6bf7

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

fs/cifs/cifs_spnego.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct key_type cifs_spnego_key_type = {
9898
struct key *
9999
cifs_get_spnego_key(struct cifs_ses *sesInfo)
100100
{
101-
struct TCP_Server_Info *server = sesInfo->server;
101+
struct TCP_Server_Info *server = cifs_ses_server(sesInfo);
102102
struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
103103
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
104104
char *description, *dp;

fs/cifs/cifsglob.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ struct cifs_ses {
994994
bool sign; /* is signing required? */
995995
bool need_reconnect:1; /* connection reset, uid now invalid */
996996
bool domainAuto:1;
997+
bool binding:1; /* are we binding the session? */
997998
__u16 session_flags;
998999
__u8 smb3signingkey[SMB3_SIGN_KEY_SIZE];
9991000
__u8 smb3encryptionkey[SMB3_SIGN_KEY_SIZE];
@@ -1021,6 +1022,15 @@ struct cifs_ses {
10211022
atomic_t chan_seq; /* round robin state */
10221023
};
10231024

1025+
static inline
1026+
struct TCP_Server_Info *cifs_ses_server(struct cifs_ses *ses)
1027+
{
1028+
if (ses->binding)
1029+
return ses->chans[ses->chan_count].server;
1030+
else
1031+
return ses->server;
1032+
}
1033+
10241034
static inline bool
10251035
cap_unix(struct cifs_ses *ses)
10261036
{

fs/cifs/connect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5185,7 +5185,7 @@ int
51855185
cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses)
51865186
{
51875187
int rc = 0;
5188-
struct TCP_Server_Info *server = ses->server;
5188+
struct TCP_Server_Info *server = cifs_ses_server(ses);
51895189

51905190
if (!server->ops->need_neg || !server->ops->negotiate)
51915191
return -ENOSYS;
@@ -5212,7 +5212,7 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
52125212
struct nls_table *nls_info)
52135213
{
52145214
int rc = -ENOSYS;
5215-
struct TCP_Server_Info *server = ses->server;
5215+
struct TCP_Server_Info *server = cifs_ses_server(ses);
52165216

52175217
ses->capabilities = server->capabilities;
52185218
if (linuxExtEnabled == 0)

fs/cifs/sess.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
342342
void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
343343
struct cifs_ses *ses)
344344
{
345+
struct TCP_Server_Info *server = cifs_ses_server(ses);
345346
NEGOTIATE_MESSAGE *sec_blob = (NEGOTIATE_MESSAGE *)pbuffer;
346347
__u32 flags;
347348

@@ -354,9 +355,9 @@ void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
354355
NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
355356
NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC |
356357
NTLMSSP_NEGOTIATE_SEAL;
357-
if (ses->server->sign)
358+
if (server->sign)
358359
flags |= NTLMSSP_NEGOTIATE_SIGN;
359-
if (!ses->server->session_estab || ses->ntlmssp->sesskey_per_smbsess)
360+
if (!server->session_estab || ses->ntlmssp->sesskey_per_smbsess)
360361
flags |= NTLMSSP_NEGOTIATE_KEY_XCH;
361362

362363
sec_blob->NegotiateFlags = cpu_to_le32(flags);

fs/cifs/smb2ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
310310
{
311311
int rc;
312312

313-
ses->server->CurrentMid = 0;
313+
cifs_ses_server(ses)->CurrentMid = 0;
314314
rc = SMB2_negotiate(xid, ses);
315315
/* BB we probably don't need to retry with modern servers */
316316
if (rc == -EAGAIN)

fs/cifs/smb2pdu.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
791791
struct kvec rsp_iov;
792792
int rc = 0;
793793
int resp_buftype;
794-
struct TCP_Server_Info *server = ses->server;
794+
struct TCP_Server_Info *server = cifs_ses_server(ses);
795795
int blob_offset, blob_length;
796796
char *security_blob;
797797
int flags = CIFS_NEG_OP;
@@ -813,7 +813,7 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
813813
memset(server->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE);
814814
memset(ses->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE);
815815

816-
if (strcmp(ses->server->vals->version_string,
816+
if (strcmp(server->vals->version_string,
817817
SMB3ANY_VERSION_STRING) == 0) {
818818
req->Dialects[0] = cpu_to_le16(SMB30_PROT_ID);
819819
req->Dialects[1] = cpu_to_le16(SMB302_PROT_ID);
@@ -829,7 +829,7 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
829829
total_len += 8;
830830
} else {
831831
/* otherwise send specific dialect */
832-
req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id);
832+
req->Dialects[0] = cpu_to_le16(server->vals->protocol_id);
833833
req->DialectCount = cpu_to_le16(1);
834834
total_len += 2;
835835
}
@@ -1171,7 +1171,7 @@ SMB2_sess_alloc_buffer(struct SMB2_sess_data *sess_data)
11711171
int rc;
11721172
struct cifs_ses *ses = sess_data->ses;
11731173
struct smb2_sess_setup_req *req;
1174-
struct TCP_Server_Info *server = ses->server;
1174+
struct TCP_Server_Info *server = cifs_ses_server(ses);
11751175
unsigned int total_len;
11761176

11771177
rc = smb2_plain_req_init(SMB2_SESSION_SETUP, NULL, (void **) &req,
@@ -1258,22 +1258,23 @@ SMB2_sess_establish_session(struct SMB2_sess_data *sess_data)
12581258
{
12591259
int rc = 0;
12601260
struct cifs_ses *ses = sess_data->ses;
1261+
struct TCP_Server_Info *server = cifs_ses_server(ses);
12611262

1262-
mutex_lock(&ses->server->srv_mutex);
1263-
if (ses->server->ops->generate_signingkey) {
1264-
rc = ses->server->ops->generate_signingkey(ses);
1263+
mutex_lock(&server->srv_mutex);
1264+
if (server->ops->generate_signingkey) {
1265+
rc = server->ops->generate_signingkey(ses);
12651266
if (rc) {
12661267
cifs_dbg(FYI,
12671268
"SMB3 session key generation failed\n");
1268-
mutex_unlock(&ses->server->srv_mutex);
1269+
mutex_unlock(&server->srv_mutex);
12691270
return rc;
12701271
}
12711272
}
1272-
if (!ses->server->session_estab) {
1273-
ses->server->sequence_number = 0x2;
1274-
ses->server->session_estab = true;
1273+
if (!server->session_estab) {
1274+
server->sequence_number = 0x2;
1275+
server->session_estab = true;
12751276
}
1276-
mutex_unlock(&ses->server->srv_mutex);
1277+
mutex_unlock(&server->srv_mutex);
12771278

12781279
cifs_dbg(FYI, "SMB2/3 session established successfully\n");
12791280
spin_lock(&GlobalMid_Lock);
@@ -1509,7 +1510,7 @@ SMB2_select_sec(struct cifs_ses *ses, struct SMB2_sess_data *sess_data)
15091510
{
15101511
int type;
15111512

1512-
type = smb2_select_sectype(ses->server, ses->sectype);
1513+
type = smb2_select_sectype(cifs_ses_server(ses), ses->sectype);
15131514
cifs_dbg(FYI, "sess setup type %d\n", type);
15141515
if (type == Unspecified) {
15151516
cifs_dbg(VFS,
@@ -1537,7 +1538,7 @@ SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
15371538
const struct nls_table *nls_cp)
15381539
{
15391540
int rc = 0;
1540-
struct TCP_Server_Info *server = ses->server;
1541+
struct TCP_Server_Info *server = cifs_ses_server(ses);
15411542
struct SMB2_sess_data *sess_data;
15421543

15431544
cifs_dbg(FYI, "Session Setup\n");
@@ -1563,7 +1564,7 @@ SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
15631564
/*
15641565
* Initialize the session hash with the server one.
15651566
*/
1566-
memcpy(ses->preauth_sha_hash, ses->server->preauth_sha_hash,
1567+
memcpy(ses->preauth_sha_hash, server->preauth_sha_hash,
15671568
SMB2_PREAUTH_HASH_SIZE);
15681569

15691570
while (sess_data->func)

0 commit comments

Comments
 (0)