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 <ardb@kernel.org>
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
This commit is contained in:
Eric Biggers 2026-04-18 15:13:09 -07:00 committed by Steve French
parent 3a4580e713
commit 4c1c07820a
10 changed files with 2 additions and 95 deletions

View File

@ -5,7 +5,6 @@ config CIFS
select NLS select NLS
select NLS_UCS2_UTILS select NLS_UCS2_UTILS
select CRYPTO select CRYPTO
select CRYPTO_CMAC
select CRYPTO_AEAD2 select CRYPTO_AEAD2
select CRYPTO_CCM select CRYPTO_CCM
select CRYPTO_GCM select CRYPTO_GCM

View File

@ -6,6 +6,7 @@
*/ */
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/unaligned.h>
#include "cifs_fs_sb.h" #include "cifs_fs_sb.h"
#include "cifs_unicode.h" #include "cifs_unicode.h"
#include "cifsglob.h" #include "cifsglob.h"

View File

@ -503,8 +503,6 @@ calc_seckey(struct cifs_ses *ses)
void void
cifs_crypto_secmech_release(struct TCP_Server_Info *server) cifs_crypto_secmech_release(struct TCP_Server_Info *server)
{ {
cifs_free_hash(&server->secmech.aes_cmac);
if (server->secmech.enc) { if (server->secmech.enc) {
crypto_free_aead(server->secmech.enc); crypto_free_aead(server->secmech.enc);
server->secmech.enc = NULL; server->secmech.enc = NULL;

View File

@ -2123,7 +2123,6 @@ MODULE_DESCRIPTION
MODULE_VERSION(CIFS_VERSION); MODULE_VERSION(CIFS_VERSION);
MODULE_SOFTDEP("nls"); MODULE_SOFTDEP("nls");
MODULE_SOFTDEP("aes"); MODULE_SOFTDEP("aes");
MODULE_SOFTDEP("cmac");
MODULE_SOFTDEP("aead2"); MODULE_SOFTDEP("aead2");
MODULE_SOFTDEP("ccm"); MODULE_SOFTDEP("ccm");
MODULE_SOFTDEP("gcm"); MODULE_SOFTDEP("gcm");

View File

@ -23,7 +23,6 @@
#include <linux/fcntl.h> #include <linux/fcntl.h>
#include "cifs_fs_sb.h" #include "cifs_fs_sb.h"
#include "cifsacl.h" #include "cifsacl.h"
#include <crypto/internal/hash.h>
#include <uapi/linux/cifs/cifs_mount.h> #include <uapi/linux/cifs/cifs_mount.h>
#include "../common/smbglob.h" #include "../common/smbglob.h"
#include "../common/smb2pdu.h" #include "../common/smb2pdu.h"
@ -221,10 +220,8 @@ struct session_key {
char *response; char *response;
}; };
/* crypto hashing related structure/fields, not specific to a sec mech */ /* encryption related structure/fields, not specific to a sec mech */
struct cifs_secmech { struct cifs_secmech {
struct shash_desc *aes_cmac; /* block-cipher based MAC function, for SMB3 signatures */
struct crypto_aead *enc; /* smb3 encryption AEAD TFM (AES-CCM and AES-GCM) */ struct crypto_aead *enc; /* smb3 encryption AEAD TFM (AES-CCM and AES-GCM) */
struct crypto_aead *dec; /* smb3 decryption AEAD TFM (AES-CCM and AES-GCM) */ struct crypto_aead *dec; /* smb3 decryption AEAD TFM (AES-CCM and AES-GCM) */
}; };

View File

@ -351,9 +351,6 @@ int __cifs_calc_signature(struct smb_rqst *rqst,
enum securityEnum cifs_select_sectype(struct TCP_Server_Info *server, enum securityEnum cifs_select_sectype(struct TCP_Server_Info *server,
enum securityEnum requested); enum securityEnum requested);
int cifs_alloc_hash(const char *name, struct shash_desc **sdesc);
void cifs_free_hash(struct shash_desc **sdesc);
int cifs_try_adding_channels(struct cifs_ses *ses); int cifs_try_adding_channels(struct cifs_ses *ses);
int smb3_update_ses_channels(struct cifs_ses *ses, int smb3_update_ses_channels(struct cifs_ses *ses,
struct TCP_Server_Info *server, struct TCP_Server_Info *server,

View File

@ -785,63 +785,6 @@ parse_dfs_referrals(struct get_dfs_referral_rsp *rsp, u32 rsp_size,
return rc; return rc;
} }
/**
* cifs_alloc_hash - allocate hash and hash context together
* @name: The name of the crypto hash algo
* @sdesc: SHASH descriptor where to put the pointer to the hash TFM
*
* The caller has to make sure @sdesc is initialized to either NULL or
* a valid context. It can be freed via cifs_free_hash().
*/
int
cifs_alloc_hash(const char *name, struct shash_desc **sdesc)
{
int rc = 0;
struct crypto_shash *alg = NULL;
if (*sdesc)
return 0;
alg = crypto_alloc_shash(name, 0, 0);
if (IS_ERR(alg)) {
cifs_dbg(VFS, "Could not allocate shash TFM '%s'\n", name);
rc = PTR_ERR(alg);
*sdesc = NULL;
return rc;
}
*sdesc = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(alg), GFP_KERNEL);
if (*sdesc == NULL) {
cifs_dbg(VFS, "no memory left to allocate shash TFM '%s'\n", name);
crypto_free_shash(alg);
return -ENOMEM;
}
(*sdesc)->tfm = alg;
return 0;
}
/**
* cifs_free_hash - free hash and hash context together
* @sdesc: Where to find the pointer to the hash TFM
*
* Freeing a NULL descriptor is safe.
*/
void
cifs_free_hash(struct shash_desc **sdesc)
{
if (unlikely(!sdesc) || !*sdesc)
return;
if ((*sdesc)->tfm) {
crypto_free_shash((*sdesc)->tfm);
(*sdesc)->tfm = NULL;
}
kfree_sensitive(*sdesc);
*sdesc = NULL;
}
void extract_unc_hostname(const char *unc, const char **h, size_t *len) void extract_unc_hostname(const char *unc, const char **h, size_t *len)
{ {
const char *end; const char *end;

View File

@ -595,17 +595,6 @@ cifs_ses_add_channel(struct cifs_ses *ses,
spin_unlock(&ses->chan_lock); spin_unlock(&ses->chan_lock);
mutex_lock(&ses->session_mutex); mutex_lock(&ses->session_mutex);
/*
* We need to allocate the server crypto now as we will need
* to sign packets before we generate the channel signing key
* (we sign with the session key)
*/
rc = smb3_crypto_shash_allocate(chan->server);
if (rc) {
cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
mutex_unlock(&ses->session_mutex);
goto out;
}
rc = cifs_negotiate_protocol(xid, ses, chan->server); rc = cifs_negotiate_protocol(xid, ses, chan->server);
if (!rc) if (!rc)

View File

@ -257,7 +257,6 @@ int smb2_validate_and_copy_iov(unsigned int offset, unsigned int buffer_length,
char *data); char *data);
void smb2_copy_fs_info_to_kstatfs(struct smb2_fs_full_size_info *pfs_inf, void smb2_copy_fs_info_to_kstatfs(struct smb2_fs_full_size_info *pfs_inf,
struct kstatfs *kst); struct kstatfs *kst);
int smb3_crypto_shash_allocate(struct TCP_Server_Info *server);
void smb311_update_preauth_hash(struct cifs_ses *ses, void smb311_update_preauth_hash(struct cifs_ses *ses,
struct TCP_Server_Info *server, struct TCP_Server_Info *server,
struct kvec *iov, int nvec); struct kvec *iov, int nvec);

View File

@ -29,14 +29,6 @@
#include "../common/smb2status.h" #include "../common/smb2status.h"
#include "smb2glob.h" #include "smb2glob.h"
int
smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
{
struct cifs_secmech *p = &server->secmech;
return cifs_alloc_hash("cmac(aes)", &p->aes_cmac);
}
static static
int smb3_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key) int smb3_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key)
{ {
@ -266,7 +258,6 @@ static int generate_key(struct cifs_ses *ses, struct kvec label,
__u8 i[4] = {0, 0, 0, 1}; __u8 i[4] = {0, 0, 0, 1};
__u8 L128[4] = {0, 0, 0, 128}; __u8 L128[4] = {0, 0, 0, 128};
__u8 L256[4] = {0, 0, 1, 0}; __u8 L256[4] = {0, 0, 1, 0};
int rc = 0;
unsigned char prfhash[SMB2_HMACSHA256_SIZE]; unsigned char prfhash[SMB2_HMACSHA256_SIZE];
struct TCP_Server_Info *server = ses->server; struct TCP_Server_Info *server = ses->server;
struct hmac_sha256_ctx hmac_ctx; struct hmac_sha256_ctx hmac_ctx;
@ -274,12 +265,6 @@ static int generate_key(struct cifs_ses *ses, struct kvec label,
memset(prfhash, 0x0, SMB2_HMACSHA256_SIZE); memset(prfhash, 0x0, SMB2_HMACSHA256_SIZE);
memset(key, 0x0, key_size); memset(key, 0x0, key_size);
rc = smb3_crypto_shash_allocate(server);
if (rc) {
cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
return rc;
}
hmac_sha256_init_usingrawkey(&hmac_ctx, ses->auth_key.response, hmac_sha256_init_usingrawkey(&hmac_ctx, ses->auth_key.response,
SMB2_NTLMV2_SESSKEY_SIZE); SMB2_NTLMV2_SESSKEY_SIZE);
hmac_sha256_update(&hmac_ctx, i, 4); hmac_sha256_update(&hmac_ctx, i, 4);