Skip to content

Commit 4c1c078

Browse files
Eric Biggerssmfrench
authored andcommitted
smb: client: Remove obsolete cmac(aes) allocation
Since the crypto library API is now being used instead of crypto_shash, the "cmac(aes)" crypto_shash that is being allocated and stored in 'struct cifs_secmech' is no longer used. Remove it. That makes the kconfig selection of CRYPTO_CMAC and the module softdep on "cmac" unnecessary. So remove those too. Finally, since this removes the last use of crypto_shash from the smb client, also remove the remaining crypto_shash-related helper functions. Note: cifs_unicode.c was relying on <linux/unaligned.h> being included transitively via <crypto/internal/hash.h>. Since the latter include is removed, make cifs_unicode.c include <linux/unaligned.h> explicitly. Reviewed-by: Ard Biesheuvel <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 3a4580e commit 4c1c078

10 files changed

Lines changed: 2 additions & 95 deletions

File tree

fs/smb/client/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ config CIFS
55
select NLS
66
select NLS_UCS2_UTILS
77
select CRYPTO
8-
select CRYPTO_CMAC
98
select CRYPTO_AEAD2
109
select CRYPTO_CCM
1110
select CRYPTO_GCM

fs/smb/client/cifs_unicode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
#include <linux/fs.h>
88
#include <linux/slab.h>
9+
#include <linux/unaligned.h>
910
#include "cifs_fs_sb.h"
1011
#include "cifs_unicode.h"
1112
#include "cifsglob.h"

fs/smb/client/cifsencrypt.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,6 @@ calc_seckey(struct cifs_ses *ses)
503503
void
504504
cifs_crypto_secmech_release(struct TCP_Server_Info *server)
505505
{
506-
cifs_free_hash(&server->secmech.aes_cmac);
507-
508506
if (server->secmech.enc) {
509507
crypto_free_aead(server->secmech.enc);
510508
server->secmech.enc = NULL;

fs/smb/client/cifsfs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2123,7 +2123,6 @@ MODULE_DESCRIPTION
21232123
MODULE_VERSION(CIFS_VERSION);
21242124
MODULE_SOFTDEP("nls");
21252125
MODULE_SOFTDEP("aes");
2126-
MODULE_SOFTDEP("cmac");
21272126
MODULE_SOFTDEP("aead2");
21282127
MODULE_SOFTDEP("ccm");
21292128
MODULE_SOFTDEP("gcm");

fs/smb/client/cifsglob.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <linux/fcntl.h>
2424
#include "cifs_fs_sb.h"
2525
#include "cifsacl.h"
26-
#include <crypto/internal/hash.h>
2726
#include <uapi/linux/cifs/cifs_mount.h>
2827
#include "../common/smbglob.h"
2928
#include "../common/smb2pdu.h"
@@ -221,10 +220,8 @@ struct session_key {
221220
char *response;
222221
};
223222

224-
/* crypto hashing related structure/fields, not specific to a sec mech */
223+
/* encryption related structure/fields, not specific to a sec mech */
225224
struct cifs_secmech {
226-
struct shash_desc *aes_cmac; /* block-cipher based MAC function, for SMB3 signatures */
227-
228225
struct crypto_aead *enc; /* smb3 encryption AEAD TFM (AES-CCM and AES-GCM) */
229226
struct crypto_aead *dec; /* smb3 decryption AEAD TFM (AES-CCM and AES-GCM) */
230227
};

fs/smb/client/cifsproto.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,6 @@ int __cifs_calc_signature(struct smb_rqst *rqst,
351351
enum securityEnum cifs_select_sectype(struct TCP_Server_Info *server,
352352
enum securityEnum requested);
353353

354-
int cifs_alloc_hash(const char *name, struct shash_desc **sdesc);
355-
void cifs_free_hash(struct shash_desc **sdesc);
356-
357354
int cifs_try_adding_channels(struct cifs_ses *ses);
358355
int smb3_update_ses_channels(struct cifs_ses *ses,
359356
struct TCP_Server_Info *server,

fs/smb/client/misc.c

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -785,63 +785,6 @@ parse_dfs_referrals(struct get_dfs_referral_rsp *rsp, u32 rsp_size,
785785
return rc;
786786
}
787787

788-
/**
789-
* cifs_alloc_hash - allocate hash and hash context together
790-
* @name: The name of the crypto hash algo
791-
* @sdesc: SHASH descriptor where to put the pointer to the hash TFM
792-
*
793-
* The caller has to make sure @sdesc is initialized to either NULL or
794-
* a valid context. It can be freed via cifs_free_hash().
795-
*/
796-
int
797-
cifs_alloc_hash(const char *name, struct shash_desc **sdesc)
798-
{
799-
int rc = 0;
800-
struct crypto_shash *alg = NULL;
801-
802-
if (*sdesc)
803-
return 0;
804-
805-
alg = crypto_alloc_shash(name, 0, 0);
806-
if (IS_ERR(alg)) {
807-
cifs_dbg(VFS, "Could not allocate shash TFM '%s'\n", name);
808-
rc = PTR_ERR(alg);
809-
*sdesc = NULL;
810-
return rc;
811-
}
812-
813-
*sdesc = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(alg), GFP_KERNEL);
814-
if (*sdesc == NULL) {
815-
cifs_dbg(VFS, "no memory left to allocate shash TFM '%s'\n", name);
816-
crypto_free_shash(alg);
817-
return -ENOMEM;
818-
}
819-
820-
(*sdesc)->tfm = alg;
821-
return 0;
822-
}
823-
824-
/**
825-
* cifs_free_hash - free hash and hash context together
826-
* @sdesc: Where to find the pointer to the hash TFM
827-
*
828-
* Freeing a NULL descriptor is safe.
829-
*/
830-
void
831-
cifs_free_hash(struct shash_desc **sdesc)
832-
{
833-
if (unlikely(!sdesc) || !*sdesc)
834-
return;
835-
836-
if ((*sdesc)->tfm) {
837-
crypto_free_shash((*sdesc)->tfm);
838-
(*sdesc)->tfm = NULL;
839-
}
840-
841-
kfree_sensitive(*sdesc);
842-
*sdesc = NULL;
843-
}
844-
845788
void extract_unc_hostname(const char *unc, const char **h, size_t *len)
846789
{
847790
const char *end;

fs/smb/client/sess.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -595,17 +595,6 @@ cifs_ses_add_channel(struct cifs_ses *ses,
595595
spin_unlock(&ses->chan_lock);
596596

597597
mutex_lock(&ses->session_mutex);
598-
/*
599-
* We need to allocate the server crypto now as we will need
600-
* to sign packets before we generate the channel signing key
601-
* (we sign with the session key)
602-
*/
603-
rc = smb3_crypto_shash_allocate(chan->server);
604-
if (rc) {
605-
cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
606-
mutex_unlock(&ses->session_mutex);
607-
goto out;
608-
}
609598

610599
rc = cifs_negotiate_protocol(xid, ses, chan->server);
611600
if (!rc)

fs/smb/client/smb2proto.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ int smb2_validate_and_copy_iov(unsigned int offset, unsigned int buffer_length,
257257
char *data);
258258
void smb2_copy_fs_info_to_kstatfs(struct smb2_fs_full_size_info *pfs_inf,
259259
struct kstatfs *kst);
260-
int smb3_crypto_shash_allocate(struct TCP_Server_Info *server);
261260
void smb311_update_preauth_hash(struct cifs_ses *ses,
262261
struct TCP_Server_Info *server,
263262
struct kvec *iov, int nvec);

fs/smb/client/smb2transport.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@
2929
#include "../common/smb2status.h"
3030
#include "smb2glob.h"
3131

32-
int
33-
smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
34-
{
35-
struct cifs_secmech *p = &server->secmech;
36-
37-
return cifs_alloc_hash("cmac(aes)", &p->aes_cmac);
38-
}
39-
4032
static
4133
int smb3_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key)
4234
{
@@ -266,20 +258,13 @@ static int generate_key(struct cifs_ses *ses, struct kvec label,
266258
__u8 i[4] = {0, 0, 0, 1};
267259
__u8 L128[4] = {0, 0, 0, 128};
268260
__u8 L256[4] = {0, 0, 1, 0};
269-
int rc = 0;
270261
unsigned char prfhash[SMB2_HMACSHA256_SIZE];
271262
struct TCP_Server_Info *server = ses->server;
272263
struct hmac_sha256_ctx hmac_ctx;
273264

274265
memset(prfhash, 0x0, SMB2_HMACSHA256_SIZE);
275266
memset(key, 0x0, key_size);
276267

277-
rc = smb3_crypto_shash_allocate(server);
278-
if (rc) {
279-
cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
280-
return rc;
281-
}
282-
283268
hmac_sha256_init_usingrawkey(&hmac_ctx, ses->auth_key.response,
284269
SMB2_NTLMV2_SESSKEY_SIZE);
285270
hmac_sha256_update(&hmac_ctx, i, 4);

0 commit comments

Comments
 (0)