]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
smb: client: Remove obsolete cmac(aes) allocation
authorEric Biggers <ebiggers@kernel.org>
Sat, 18 Apr 2026 22:13:09 +0000 (15:13 -0700)
committerSteve French <stfrench@microsoft.com>
Wed, 22 Apr 2026 14:56:10 +0000 (09:56 -0500)
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>
fs/smb/client/Kconfig
fs/smb/client/cifs_unicode.c
fs/smb/client/cifsencrypt.c
fs/smb/client/cifsfs.c
fs/smb/client/cifsglob.h
fs/smb/client/cifsproto.h
fs/smb/client/misc.c
fs/smb/client/sess.c
fs/smb/client/smb2proto.h
fs/smb/client/smb2transport.c

index 029bbe595d5fa997ae3a03ee4b6de11e01b06cb9..a1c6ad4d574a0e3fa79dee8e5362f5e28a099d36 100644 (file)
@@ -5,7 +5,6 @@ config CIFS
        select NLS
        select NLS_UCS2_UTILS
        select CRYPTO
-       select CRYPTO_CMAC
        select CRYPTO_AEAD2
        select CRYPTO_CCM
        select CRYPTO_GCM
index e2edc207cef25ae8ac1ce60a6cb8ba3e0b4fede7..4a8a591f4bcac72c930e39daca3ab54b16943127 100644 (file)
@@ -6,6 +6,7 @@
  */
 #include <linux/fs.h>
 #include <linux/slab.h>
+#include <linux/unaligned.h>
 #include "cifs_fs_sb.h"
 #include "cifs_unicode.h"
 #include "cifsglob.h"
index d092bca2df62dd66256139d51a6964126df3260e..34804e9842a8070ea006ea54c0a69c7a9b01d247 100644 (file)
@@ -503,8 +503,6 @@ calc_seckey(struct cifs_ses *ses)
 void
 cifs_crypto_secmech_release(struct TCP_Server_Info *server)
 {
-       cifs_free_hash(&server->secmech.aes_cmac);
-
        if (server->secmech.enc) {
                crypto_free_aead(server->secmech.enc);
                server->secmech.enc = NULL;
index 2e92c7fa2c5dd6f3da49c81e6a6a714ae4a08250..9f76b0347fa9d71df496eb2584b92f0759931069 100644 (file)
@@ -2123,7 +2123,6 @@ MODULE_DESCRIPTION
 MODULE_VERSION(CIFS_VERSION);
 MODULE_SOFTDEP("nls");
 MODULE_SOFTDEP("aes");
-MODULE_SOFTDEP("cmac");
 MODULE_SOFTDEP("aead2");
 MODULE_SOFTDEP("ccm");
 MODULE_SOFTDEP("gcm");
index 74265d055c265ec7029babb22d1b7c16bbf351e4..82e0adc1dabd05c0062948bf7af54dbf34b91b11 100644 (file)
@@ -23,7 +23,6 @@
 #include <linux/fcntl.h>
 #include "cifs_fs_sb.h"
 #include "cifsacl.h"
-#include <crypto/internal/hash.h>
 #include <uapi/linux/cifs/cifs_mount.h>
 #include "../common/smbglob.h"
 #include "../common/smb2pdu.h"
@@ -221,10 +220,8 @@ struct session_key {
        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 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 *dec; /* smb3 decryption AEAD TFM (AES-CCM and AES-GCM) */
 };
index c24c50d732e64858a8b628f09bb2392acdec8f43..4a25afda9448a4e089df601586180473ae9fdb5d 100644 (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 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 smb3_update_ses_channels(struct cifs_ses *ses,
                             struct TCP_Server_Info *server,
index 2aff1cab6c31e3f8deb5d4e50958532e14460eff..0c54b9b79a2ce5b40b2543277f0b299bed3b1251 100644 (file)
@@ -785,63 +785,6 @@ parse_DFS_referrals_exit:
        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)
 {
        const char *end;
index 698bd27119ae080695cd15cd83858d7f26339e0b..de2012cc9cf3ede57c80e148530c95b2e394ad70 100644 (file)
@@ -595,17 +595,6 @@ cifs_ses_add_channel(struct cifs_ses *ses,
        spin_unlock(&ses->chan_lock);
 
        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);
        if (!rc)
index 5f74475ba9d1970cf0741accc194f30713305fdb..1ceb95b907e6b2bf9163db8b6f8d372e259b3692 100644 (file)
@@ -257,7 +257,6 @@ int smb2_validate_and_copy_iov(unsigned int offset, unsigned int buffer_length,
                               char *data);
 void smb2_copy_fs_info_to_kstatfs(struct smb2_fs_full_size_info *pfs_inf,
                                  struct kstatfs *kst);
-int smb3_crypto_shash_allocate(struct TCP_Server_Info *server);
 void smb311_update_preauth_hash(struct cifs_ses *ses,
                                struct TCP_Server_Info *server,
                                struct kvec *iov, int nvec);
index b233e0cd9152949d273b5c02779bf0a06975e9c0..716e58d1b1c92d2c049a702cb61c01dcf4052b49 100644 (file)
 #include "../common/smb2status.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
 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 L128[4] = {0, 0, 0, 128};
        __u8 L256[4] = {0, 0, 1, 0};
-       int rc = 0;
        unsigned char prfhash[SMB2_HMACSHA256_SIZE];
        struct TCP_Server_Info *server = ses->server;
        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(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,
                                     SMB2_NTLMV2_SESSKEY_SIZE);
        hmac_sha256_update(&hmac_ctx, i, 4);