Skip to content

Commit 16cb6b0

Browse files
paliSteve French
authored andcommitted
cifs: Fix encoding of SMB1 Session Setup Kerberos Request in non-UNICODE mode
Like in UNICODE mode, SMB1 Session Setup Kerberos Request contains oslm and domain strings. Extract common code into ascii_oslm_strings() and ascii_domain_string() functions (similar to unicode variants) and use these functions in non-UNICODE code path in sess_auth_kerberos(). Decision if non-UNICODE or UNICODE mode is used is based on the SMBFLG2_UNICODE flag in Flags2 packed field, and not based on the capabilities of server. Fix this check too. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 9502dd5 commit 16cb6b0

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

fs/smb/client/sess.c

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,22 @@ unicode_oslm_strings(char **pbcc_area, const struct nls_table *nls_cp)
680680
*pbcc_area = bcc_ptr;
681681
}
682682

683+
static void
684+
ascii_oslm_strings(char **pbcc_area, const struct nls_table *nls_cp)
685+
{
686+
char *bcc_ptr = *pbcc_area;
687+
688+
strcpy(bcc_ptr, "Linux version ");
689+
bcc_ptr += strlen("Linux version ");
690+
strcpy(bcc_ptr, init_utsname()->release);
691+
bcc_ptr += strlen(init_utsname()->release) + 1;
692+
693+
strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
694+
bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
695+
696+
*pbcc_area = bcc_ptr;
697+
}
698+
683699
static void unicode_domain_string(char **pbcc_area, struct cifs_ses *ses,
684700
const struct nls_table *nls_cp)
685701
{
@@ -704,6 +720,25 @@ static void unicode_domain_string(char **pbcc_area, struct cifs_ses *ses,
704720
*pbcc_area = bcc_ptr;
705721
}
706722

723+
static void ascii_domain_string(char **pbcc_area, struct cifs_ses *ses,
724+
const struct nls_table *nls_cp)
725+
{
726+
char *bcc_ptr = *pbcc_area;
727+
int len;
728+
729+
/* copy domain */
730+
if (ses->domainName != NULL) {
731+
len = strscpy(bcc_ptr, ses->domainName, CIFS_MAX_DOMAINNAME_LEN);
732+
if (WARN_ON_ONCE(len < 0))
733+
len = CIFS_MAX_DOMAINNAME_LEN - 1;
734+
bcc_ptr += len;
735+
} /* else we send a null domain name so server will default to its own domain */
736+
*bcc_ptr = 0;
737+
bcc_ptr++;
738+
739+
*pbcc_area = bcc_ptr;
740+
}
741+
707742
static void unicode_ssetup_strings(char **pbcc_area, struct cifs_ses *ses,
708743
const struct nls_table *nls_cp)
709744
{
@@ -749,25 +784,10 @@ static void ascii_ssetup_strings(char **pbcc_area, struct cifs_ses *ses,
749784
*bcc_ptr = 0;
750785
bcc_ptr++; /* account for null termination */
751786

752-
/* copy domain */
753-
if (ses->domainName != NULL) {
754-
len = strscpy(bcc_ptr, ses->domainName, CIFS_MAX_DOMAINNAME_LEN);
755-
if (WARN_ON_ONCE(len < 0))
756-
len = CIFS_MAX_DOMAINNAME_LEN - 1;
757-
bcc_ptr += len;
758-
} /* else we send a null domain name so server will default to its own domain */
759-
*bcc_ptr = 0;
760-
bcc_ptr++;
761-
762787
/* BB check for overflow here */
763788

764-
strcpy(bcc_ptr, "Linux version ");
765-
bcc_ptr += strlen("Linux version ");
766-
strcpy(bcc_ptr, init_utsname()->release);
767-
bcc_ptr += strlen(init_utsname()->release) + 1;
768-
769-
strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
770-
bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
789+
ascii_domain_string(&bcc_ptr, ses, nls_cp);
790+
ascii_oslm_strings(&bcc_ptr, nls_cp);
771791

772792
*pbcc_area = bcc_ptr;
773793
}
@@ -1570,7 +1590,7 @@ sess_auth_kerberos(struct sess_data *sess_data)
15701590
sess_data->iov[1].iov_len = msg->secblob_len;
15711591
pSMB->req.SecurityBlobLength = cpu_to_le16(sess_data->iov[1].iov_len);
15721592

1573-
if (ses->capabilities & CAP_UNICODE) {
1593+
if (pSMB->req.hdr.Flags2 & SMBFLG2_UNICODE) {
15741594
/* unicode strings must be word aligned */
15751595
if (!IS_ALIGNED(sess_data->iov[0].iov_len + sess_data->iov[1].iov_len, 2)) {
15761596
*bcc_ptr = 0;
@@ -1579,8 +1599,8 @@ sess_auth_kerberos(struct sess_data *sess_data)
15791599
unicode_oslm_strings(&bcc_ptr, sess_data->nls_cp);
15801600
unicode_domain_string(&bcc_ptr, ses, sess_data->nls_cp);
15811601
} else {
1582-
/* BB: is this right? */
1583-
ascii_ssetup_strings(&bcc_ptr, ses, sess_data->nls_cp);
1602+
ascii_oslm_strings(&bcc_ptr, sess_data->nls_cp);
1603+
ascii_domain_string(&bcc_ptr, ses, sess_data->nls_cp);
15841604
}
15851605

15861606
sess_data->iov[2].iov_len = (long) bcc_ptr -

0 commit comments

Comments
 (0)