Skip to content

Commit 1a67a57

Browse files
committed
Merge git://git.samba.org/sfrench/cifs-2.6
* git://git.samba.org/sfrench/cifs-2.6: cifs: Assume passwords are encoded according to iocharset (try raspberrypi#2) CIFS: Fix the VFS brlock cache usage in posix locking case [CIFS] Update cifs version to 1.76 CIFS: Remove extra mutex_unlock in cifs_lock_add_if
2 parents 6dbbd92 + 9ef5992 commit 1a67a57

7 files changed

Lines changed: 32 additions & 64 deletions

File tree

‎fs/cifs/cifsencrypt.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int cifs_verify_signature(struct kvec *iov, unsigned int nr_iov,
204204
}
205205

206206
/* first calculate 24 bytes ntlm response and then 16 byte session key */
207-
int setup_ntlm_response(struct cifs_ses *ses)
207+
int setup_ntlm_response(struct cifs_ses *ses, const struct nls_table *nls_cp)
208208
{
209209
int rc = 0;
210210
unsigned int temp_len = CIFS_SESS_KEY_SIZE + CIFS_AUTH_RESP_SIZE;
@@ -221,14 +221,14 @@ int setup_ntlm_response(struct cifs_ses *ses)
221221
ses->auth_key.len = temp_len;
222222

223223
rc = SMBNTencrypt(ses->password, ses->server->cryptkey,
224-
ses->auth_key.response + CIFS_SESS_KEY_SIZE);
224+
ses->auth_key.response + CIFS_SESS_KEY_SIZE, nls_cp);
225225
if (rc) {
226226
cFYI(1, "%s Can't generate NTLM response, error: %d",
227227
__func__, rc);
228228
return rc;
229229
}
230230

231-
rc = E_md4hash(ses->password, temp_key);
231+
rc = E_md4hash(ses->password, temp_key, nls_cp);
232232
if (rc) {
233233
cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc);
234234
return rc;
@@ -404,7 +404,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
404404
}
405405

406406
/* calculate md4 hash of password */
407-
E_md4hash(ses->password, nt_hash);
407+
E_md4hash(ses->password, nt_hash, nls_cp);
408408

409409
rc = crypto_shash_setkey(ses->server->secmech.hmacmd5, nt_hash,
410410
CIFS_NTHASH_SIZE);

‎fs/cifs/cifsfs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
125125
extern const struct export_operations cifs_export_ops;
126126
#endif /* CONFIG_CIFS_NFSD_EXPORT */
127127

128-
#define CIFS_VERSION "1.75"
128+
#define CIFS_VERSION "1.76"
129129
#endif /* _CIFSFS_H */

‎fs/cifs/cifsproto.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,9 @@ extern int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *,
395395
extern int cifs_verify_signature(struct kvec *iov, unsigned int nr_iov,
396396
struct TCP_Server_Info *server,
397397
__u32 expected_sequence_number);
398-
extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *);
399-
extern int setup_ntlm_response(struct cifs_ses *);
398+
extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *,
399+
const struct nls_table *);
400+
extern int setup_ntlm_response(struct cifs_ses *, const struct nls_table *);
400401
extern int setup_ntlmv2_rsp(struct cifs_ses *, const struct nls_table *);
401402
extern int cifs_crypto_shash_allocate(struct TCP_Server_Info *);
402403
extern void cifs_crypto_shash_release(struct TCP_Server_Info *);
@@ -448,7 +449,8 @@ extern int CIFSCheckMFSymlink(struct cifs_fattr *fattr,
448449
const unsigned char *path,
449450
struct cifs_sb_info *cifs_sb, int xid);
450451
extern int mdfour(unsigned char *, unsigned char *, int);
451-
extern int E_md4hash(const unsigned char *passwd, unsigned char *p16);
452+
extern int E_md4hash(const unsigned char *passwd, unsigned char *p16,
453+
const struct nls_table *codepage);
452454
extern int SMBencrypt(unsigned char *passwd, const unsigned char *c8,
453455
unsigned char *p24);
454456

‎fs/cifs/connect.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3452,7 +3452,7 @@ CIFSTCon(unsigned int xid, struct cifs_ses *ses,
34523452
else
34533453
#endif /* CIFS_WEAK_PW_HASH */
34543454
rc = SMBNTencrypt(tcon->password, ses->server->cryptkey,
3455-
bcc_ptr);
3455+
bcc_ptr, nls_codepage);
34563456

34573457
bcc_ptr += CIFS_AUTH_RESP_SIZE;
34583458
if (ses->capabilities & CAP_UNICODE) {

‎fs/cifs/file.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@ cifs_lock_add_if(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
778778
else {
779779
mutex_lock(&cinode->lock_mutex);
780780
list_del_init(&lock->blist);
781-
mutex_unlock(&cinode->lock_mutex);
782781
}
783782
}
784783

@@ -794,6 +793,9 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock)
794793
struct cifsInodeInfo *cinode = CIFS_I(file->f_path.dentry->d_inode);
795794
unsigned char saved_type = flock->fl_type;
796795

796+
if ((flock->fl_flags & FL_POSIX) == 0)
797+
return 1;
798+
797799
mutex_lock(&cinode->lock_mutex);
798800
posix_test_lock(file, flock);
799801

@@ -810,12 +812,15 @@ static int
810812
cifs_posix_lock_set(struct file *file, struct file_lock *flock)
811813
{
812814
struct cifsInodeInfo *cinode = CIFS_I(file->f_path.dentry->d_inode);
813-
int rc;
815+
int rc = 1;
816+
817+
if ((flock->fl_flags & FL_POSIX) == 0)
818+
return rc;
814819

815820
mutex_lock(&cinode->lock_mutex);
816821
if (!cinode->can_cache_brlcks) {
817822
mutex_unlock(&cinode->lock_mutex);
818-
return 1;
823+
return rc;
819824
}
820825
rc = posix_lock_file_wait(file, flock);
821826
mutex_unlock(&cinode->lock_mutex);

‎fs/cifs/sess.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ CIFS_SessSetup(unsigned int xid, struct cifs_ses *ses,
683683
cpu_to_le16(CIFS_AUTH_RESP_SIZE);
684684

685685
/* calculate ntlm response and session key */
686-
rc = setup_ntlm_response(ses);
686+
rc = setup_ntlm_response(ses, nls_cp);
687687
if (rc) {
688688
cERROR(1, "Error %d during NTLM authentication", rc);
689689
goto ssetup_exit;

‎fs/cifs/smbencrypt.c‎

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -199,83 +199,44 @@ SMBencrypt(unsigned char *passwd, const unsigned char *c8, unsigned char *p24)
199199
return rc;
200200
}
201201

202-
/* Routines for Windows NT MD4 Hash functions. */
203-
static int
204-
_my_wcslen(__u16 *str)
205-
{
206-
int len = 0;
207-
while (*str++ != 0)
208-
len++;
209-
return len;
210-
}
211-
212-
/*
213-
* Convert a string into an NT UNICODE string.
214-
* Note that regardless of processor type
215-
* this must be in intel (little-endian)
216-
* format.
217-
*/
218-
219-
static int
220-
_my_mbstowcs(__u16 *dst, const unsigned char *src, int len)
221-
{ /* BB not a very good conversion routine - change/fix */
222-
int i;
223-
__u16 val;
224-
225-
for (i = 0; i < len; i++) {
226-
val = *src;
227-
SSVAL(dst, 0, val);
228-
dst++;
229-
src++;
230-
if (val == 0)
231-
break;
232-
}
233-
return i;
234-
}
235-
236202
/*
237203
* Creates the MD4 Hash of the users password in NT UNICODE.
238204
*/
239205

240206
int
241-
E_md4hash(const unsigned char *passwd, unsigned char *p16)
207+
E_md4hash(const unsigned char *passwd, unsigned char *p16,
208+
const struct nls_table *codepage)
242209
{
243210
int rc;
244211
int len;
245212
__u16 wpwd[129];
246213

247214
/* Password cannot be longer than 128 characters */
248-
if (passwd) {
249-
len = strlen((char *) passwd);
250-
if (len > 128)
251-
len = 128;
252-
253-
/* Password must be converted to NT unicode */
254-
_my_mbstowcs(wpwd, passwd, len);
255-
} else
215+
if (passwd) /* Password must be converted to NT unicode */
216+
len = cifs_strtoUCS(wpwd, passwd, 128, codepage);
217+
else {
256218
len = 0;
219+
*wpwd = 0; /* Ensure string is null terminated */
220+
}
257221

258-
wpwd[len] = 0; /* Ensure string is null terminated */
259-
/* Calculate length in bytes */
260-
len = _my_wcslen(wpwd) * sizeof(__u16);
261-
262-
rc = mdfour(p16, (unsigned char *) wpwd, len);
263-
memset(wpwd, 0, 129 * 2);
222+
rc = mdfour(p16, (unsigned char *) wpwd, len * sizeof(__u16));
223+
memset(wpwd, 0, 129 * sizeof(__u16));
264224

265225
return rc;
266226
}
267227

268228
/* Does the NT MD4 hash then des encryption. */
269229
int
270-
SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24)
230+
SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24,
231+
const struct nls_table *codepage)
271232
{
272233
int rc;
273234
unsigned char p16[16], p21[21];
274235

275236
memset(p16, '\0', 16);
276237
memset(p21, '\0', 21);
277238

278-
rc = E_md4hash(passwd, p16);
239+
rc = E_md4hash(passwd, p16, codepage);
279240
if (rc) {
280241
cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc);
281242
return rc;

0 commit comments

Comments
 (0)