Skip to content

Commit ee2c925

Browse files
shirishpargaonkarSteve French
authored andcommitted
cifs: More crypto cleanup (try raspberrypi#2)
Replaced md4 hashing function local to cifs module with kernel crypto APIs. As a result, md4 hashing function and its supporting functions in file md4.c are not needed anymore. Cleaned up function declarations, removed forward function declarations, and removed a header file that is being deleted from being included. Verified that sec=ntlm/i, sec=ntlmv2/i, and sec=ntlmssp/i work correctly. Signed-off-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com> Reviewed-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve French <sfrench@us.ibm.com>
1 parent d39454f commit ee2c925

9 files changed

Lines changed: 97 additions & 286 deletions

File tree

‎fs/cifs/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ obj-$(CONFIG_CIFS) += cifs.o
55

66
cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \
77
link.o misc.o netmisc.o smbdes.o smbencrypt.o transport.o asn1.o \
8-
md4.o cifs_unicode.o nterr.o xattr.o cifsencrypt.o \
8+
cifs_unicode.o nterr.o xattr.o cifsencrypt.o \
99
readdir.o ioctl.o sess.o export.o
1010

1111
cifs-$(CONFIG_CIFS_ACL) += cifsacl.o

‎fs/cifs/cifsencrypt.c‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636
/* Note that the smb header signature field on input contains the
3737
sequence number before this function is called */
3838

39-
extern void mdfour(unsigned char *out, unsigned char *in, int n);
40-
extern void E_md4hash(const unsigned char *passwd, unsigned char *p16);
41-
extern void SMBencrypt(unsigned char *passwd, const unsigned char *c8,
42-
unsigned char *p24);
43-
4439
static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu,
4540
struct TCP_Server_Info *server, char *signature)
4641
{
@@ -233,6 +228,7 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu,
233228
/* first calculate 24 bytes ntlm response and then 16 byte session key */
234229
int setup_ntlm_response(struct cifsSesInfo *ses)
235230
{
231+
int rc = 0;
236232
unsigned int temp_len = CIFS_SESS_KEY_SIZE + CIFS_AUTH_RESP_SIZE;
237233
char temp_key[CIFS_SESS_KEY_SIZE];
238234

@@ -246,13 +242,26 @@ int setup_ntlm_response(struct cifsSesInfo *ses)
246242
}
247243
ses->auth_key.len = temp_len;
248244

249-
SMBNTencrypt(ses->password, ses->server->cryptkey,
245+
rc = SMBNTencrypt(ses->password, ses->server->cryptkey,
250246
ses->auth_key.response + CIFS_SESS_KEY_SIZE);
247+
if (rc) {
248+
cFYI(1, "%s Can't generate NTLM response, error: %d",
249+
__func__, rc);
250+
return rc;
251+
}
252+
253+
rc = E_md4hash(ses->password, temp_key);
254+
if (rc) {
255+
cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc);
256+
return rc;
257+
}
251258

252-
E_md4hash(ses->password, temp_key);
253-
mdfour(ses->auth_key.response, temp_key, CIFS_SESS_KEY_SIZE);
259+
rc = mdfour(ses->auth_key.response, temp_key, CIFS_SESS_KEY_SIZE);
260+
if (rc)
261+
cFYI(1, "%s Can't generate NTLM session key, error: %d",
262+
__func__, rc);
254263

255-
return 0;
264+
return rc;
256265
}
257266

258267
#ifdef CONFIG_CIFS_WEAK_PW_HASH
@@ -699,14 +708,13 @@ cifs_crypto_shash_allocate(struct TCP_Server_Info *server)
699708
unsigned int size;
700709

701710
server->secmech.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0);
702-
if (!server->secmech.hmacmd5 ||
703-
IS_ERR(server->secmech.hmacmd5)) {
711+
if (IS_ERR(server->secmech.hmacmd5)) {
704712
cERROR(1, "could not allocate crypto hmacmd5\n");
705713
return PTR_ERR(server->secmech.hmacmd5);
706714
}
707715

708716
server->secmech.md5 = crypto_alloc_shash("md5", 0, 0);
709-
if (!server->secmech.md5 || IS_ERR(server->secmech.md5)) {
717+
if (IS_ERR(server->secmech.md5)) {
710718
cERROR(1, "could not allocate crypto md5\n");
711719
rc = PTR_ERR(server->secmech.md5);
712720
goto crypto_allocate_md5_fail;

‎fs/cifs/cifsencrypt.h‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎fs/cifs/cifsproto.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ extern int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *,
375375
extern int cifs_verify_signature(struct smb_hdr *,
376376
struct TCP_Server_Info *server,
377377
__u32 expected_sequence_number);
378-
extern void SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *);
378+
extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *);
379379
extern int setup_ntlm_response(struct cifsSesInfo *);
380380
extern int setup_ntlmv2_rsp(struct cifsSesInfo *, const struct nls_table *);
381381
extern int cifs_crypto_shash_allocate(struct TCP_Server_Info *);
@@ -425,4 +425,11 @@ extern bool CIFSCouldBeMFSymlink(const struct cifs_fattr *fattr);
425425
extern int CIFSCheckMFSymlink(struct cifs_fattr *fattr,
426426
const unsigned char *path,
427427
struct cifs_sb_info *cifs_sb, int xid);
428+
extern int mdfour(unsigned char *, unsigned char *, int);
429+
extern int E_md4hash(const unsigned char *passwd, unsigned char *p16);
430+
extern void SMBencrypt(unsigned char *passwd, const unsigned char *c8,
431+
unsigned char *p24);
432+
extern void E_P16(unsigned char *p14, unsigned char *p16);
433+
extern void E_P24(unsigned char *p21, const unsigned char *c8,
434+
unsigned char *p24);
428435
#endif /* _CIFSPROTO_H */

‎fs/cifs/connect.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
/* SMB echo "timeout" -- FIXME: tunable? */
5656
#define SMB_ECHO_INTERVAL (60 * HZ)
5757

58-
extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8,
59-
unsigned char *p24);
60-
6158
extern mempool_t *cifs_req_poolp;
6259

6360
struct smb_vol {
@@ -2990,7 +2987,8 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
29902987
bcc_ptr);
29912988
else
29922989
#endif /* CIFS_WEAK_PW_HASH */
2993-
SMBNTencrypt(tcon->password, ses->server->cryptkey, bcc_ptr);
2990+
rc = SMBNTencrypt(tcon->password, ses->server->cryptkey,
2991+
bcc_ptr);
29942992

29952993
bcc_ptr += CIFS_AUTH_RESP_SIZE;
29962994
if (ses->capabilities & CAP_UNICODE) {

‎fs/cifs/link.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
5454
struct sdesc *sdescmd5;
5555

5656
md5 = crypto_alloc_shash("md5", 0, 0);
57-
if (!md5 || IS_ERR(md5)) {
58-
rc = PTR_ERR(md5);
57+
if (IS_ERR(md5)) {
5958
cERROR(1, "%s: Crypto md5 allocation error %d\n", __func__, rc);
60-
return rc;
59+
return PTR_ERR(md5);
6160
}
6261
size = sizeof(struct shash_desc) + crypto_shash_descsize(md5);
6362
sdescmd5 = kmalloc(size, GFP_KERNEL);

‎fs/cifs/md4.c‎

Lines changed: 0 additions & 205 deletions
This file was deleted.

‎fs/cifs/smbdes.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
up with a different answer to the one above)
4646
*/
4747
#include <linux/slab.h>
48-
#include "cifsencrypt.h"
4948
#define uchar unsigned char
5049

5150
static uchar perm1[56] = { 57, 49, 41, 33, 25, 17, 9,

0 commit comments

Comments
 (0)