diff options
author | Aurelien Aptel <aaptel@suse.com> | 2018-02-16 13:19:27 -0500 |
---|---|---|
committer | Steve French <stfrench@microsoft.com> | 2018-04-01 21:24:39 -0400 |
commit | 82fb82be05585426405667dd5f0510aa953ba439 (patch) | |
tree | 48f5f72f33aa3c2c29e53cd4fee906db96f1f2ce /fs/cifs/cifsencrypt.c | |
parent | f30e4148b19d38790e68ec277dea3ad1d6c66db6 (diff) |
CIFS: refactor crypto shash/sdesc allocation&free
shash and sdesc and always allocated and freed together.
* abstract this in new functions cifs_alloc_hash() and cifs_free_hash().
* make smb2/3 crypto allocation independent from each other.
Signed-off-by: Aurelien Aptel <aaptel@suse.com>
Signed-off-by: Steve French <smfrench@gmail.com>
Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com>
CC: Stable <stable@vger.kernel.org>
Diffstat (limited to 'fs/cifs/cifsencrypt.c')
-rw-r--r-- | fs/cifs/cifsencrypt.c | 78 |
1 files changed, 7 insertions, 71 deletions
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c index f2b0a7f124da..478a145aa4d0 100644 --- a/fs/cifs/cifsencrypt.c +++ b/fs/cifs/cifsencrypt.c | |||
@@ -36,37 +36,6 @@ | |||
36 | #include <crypto/skcipher.h> | 36 | #include <crypto/skcipher.h> |
37 | #include <crypto/aead.h> | 37 | #include <crypto/aead.h> |
38 | 38 | ||
39 | static int | ||
40 | cifs_crypto_shash_md5_allocate(struct TCP_Server_Info *server) | ||
41 | { | ||
42 | int rc; | ||
43 | unsigned int size; | ||
44 | |||
45 | if (server->secmech.sdescmd5 != NULL) | ||
46 | return 0; /* already allocated */ | ||
47 | |||
48 | server->secmech.md5 = crypto_alloc_shash("md5", 0, 0); | ||
49 | if (IS_ERR(server->secmech.md5)) { | ||
50 | cifs_dbg(VFS, "could not allocate crypto md5\n"); | ||
51 | rc = PTR_ERR(server->secmech.md5); | ||
52 | server->secmech.md5 = NULL; | ||
53 | return rc; | ||
54 | } | ||
55 | |||
56 | size = sizeof(struct shash_desc) + | ||
57 | crypto_shash_descsize(server->secmech.md5); | ||
58 | server->secmech.sdescmd5 = kmalloc(size, GFP_KERNEL); | ||
59 | if (!server->secmech.sdescmd5) { | ||
60 | crypto_free_shash(server->secmech.md5); | ||
61 | server->secmech.md5 = NULL; | ||
62 | return -ENOMEM; | ||
63 | } | ||
64 | server->secmech.sdescmd5->shash.tfm = server->secmech.md5; | ||
65 | server->secmech.sdescmd5->shash.flags = 0x0; | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | int __cifs_calc_signature(struct smb_rqst *rqst, | 39 | int __cifs_calc_signature(struct smb_rqst *rqst, |
71 | struct TCP_Server_Info *server, char *signature, | 40 | struct TCP_Server_Info *server, char *signature, |
72 | struct shash_desc *shash) | 41 | struct shash_desc *shash) |
@@ -132,13 +101,10 @@ static int cifs_calc_signature(struct smb_rqst *rqst, | |||
132 | if (!rqst->rq_iov || !signature || !server) | 101 | if (!rqst->rq_iov || !signature || !server) |
133 | return -EINVAL; | 102 | return -EINVAL; |
134 | 103 | ||
135 | if (!server->secmech.sdescmd5) { | 104 | rc = cifs_alloc_hash("md5", &server->secmech.md5, |
136 | rc = cifs_crypto_shash_md5_allocate(server); | 105 | &server->secmech.sdescmd5); |
137 | if (rc) { | 106 | if (rc) |
138 | cifs_dbg(VFS, "%s: Can't alloc md5 crypto\n", __func__); | 107 | return -1; |
139 | return -1; | ||
140 | } | ||
141 | } | ||
142 | 108 | ||
143 | rc = crypto_shash_init(&server->secmech.sdescmd5->shash); | 109 | rc = crypto_shash_init(&server->secmech.sdescmd5->shash); |
144 | if (rc) { | 110 | if (rc) { |
@@ -663,37 +629,6 @@ CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash) | |||
663 | return rc; | 629 | return rc; |
664 | } | 630 | } |
665 | 631 | ||
666 | static int crypto_hmacmd5_alloc(struct TCP_Server_Info *server) | ||
667 | { | ||
668 | int rc; | ||
669 | unsigned int size; | ||
670 | |||
671 | /* check if already allocated */ | ||
672 | if (server->secmech.sdeschmacmd5) | ||
673 | return 0; | ||
674 | |||
675 | server->secmech.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0); | ||
676 | if (IS_ERR(server->secmech.hmacmd5)) { | ||
677 | cifs_dbg(VFS, "could not allocate crypto hmacmd5\n"); | ||
678 | rc = PTR_ERR(server->secmech.hmacmd5); | ||
679 | server->secmech.hmacmd5 = NULL; | ||
680 | return rc; | ||
681 | } | ||
682 | |||
683 | size = sizeof(struct shash_desc) + | ||
684 | crypto_shash_descsize(server->secmech.hmacmd5); | ||
685 | server->secmech.sdeschmacmd5 = kmalloc(size, GFP_KERNEL); | ||
686 | if (!server->secmech.sdeschmacmd5) { | ||
687 | crypto_free_shash(server->secmech.hmacmd5); | ||
688 | server->secmech.hmacmd5 = NULL; | ||
689 | return -ENOMEM; | ||
690 | } | ||
691 | server->secmech.sdeschmacmd5->shash.tfm = server->secmech.hmacmd5; | ||
692 | server->secmech.sdeschmacmd5->shash.flags = 0x0; | ||
693 | |||
694 | return 0; | ||
695 | } | ||
696 | |||
697 | int | 632 | int |
698 | setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp) | 633 | setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp) |
699 | { | 634 | { |
@@ -757,9 +692,10 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp) | |||
757 | 692 | ||
758 | mutex_lock(&ses->server->srv_mutex); | 693 | mutex_lock(&ses->server->srv_mutex); |
759 | 694 | ||
760 | rc = crypto_hmacmd5_alloc(ses->server); | 695 | rc = cifs_alloc_hash("hmac(md5)", |
696 | &ses->server->secmech.hmacmd5, | ||
697 | &ses->server->secmech.sdeschmacmd5); | ||
761 | if (rc) { | 698 | if (rc) { |
762 | cifs_dbg(VFS, "could not crypto alloc hmacmd5 rc %d\n", rc); | ||
763 | goto unlock; | 699 | goto unlock; |
764 | } | 700 | } |
765 | 701 | ||