Skip to content

Commit 220d83b

Browse files
ematsumiyaSteve French
authored andcommitted
smb: client: make SHA-512 TFM ephemeral
The SHA-512 shash TFM is used only briefly during Session Setup stage, when computing SMB 3.1.1 preauth hash. There's no need to keep it allocated in servers' secmech the whole time, so keep its lifetime inside smb311_update_preauth_hash(). This also makes smb311_crypto_shash_allocate() redundant, so expose smb3_crypto_shash_allocate() and use that. Signed-off-by: Enzo Matsumiya <ematsumiya@suse.de> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent db44ca9 commit 220d83b

File tree

6 files changed

+17
-47
lines changed

6 files changed

+17
-47
lines changed

fs/smb/client/cifsencrypt.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,6 @@ cifs_crypto_secmech_release(struct TCP_Server_Info *server)
700700
cifs_free_hash(&server->secmech.aes_cmac);
701701
cifs_free_hash(&server->secmech.hmacsha256);
702702
cifs_free_hash(&server->secmech.md5);
703-
cifs_free_hash(&server->secmech.sha512);
704703

705704
if (!SERVER_IS_CHAN(server)) {
706705
if (server->secmech.enc) {

fs/smb/client/cifsglob.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ struct session_key {
180180
struct cifs_secmech {
181181
struct shash_desc *md5; /* md5 hash function, for CIFS/SMB1 signatures */
182182
struct shash_desc *hmacsha256; /* hmac-sha256 hash function, for SMB2 signatures */
183-
struct shash_desc *sha512; /* sha512 hash function, for SMB3.1.1 preauth hash */
184183
struct shash_desc *aes_cmac; /* block-cipher based MAC function, for SMB3 signatures */
185184

186185
struct crypto_aead *enc; /* smb3 encryption AEAD TFM (AES-CCM and AES-GCM) */

fs/smb/client/sess.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ cifs_ses_add_channel(struct cifs_ses *ses,
624624
* to sign packets before we generate the channel signing key
625625
* (we sign with the session key)
626626
*/
627-
rc = smb311_crypto_shash_allocate(chan->server);
627+
rc = smb3_crypto_shash_allocate(chan->server);
628628
if (rc) {
629629
cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
630630
mutex_unlock(&ses->session_mutex);

fs/smb/client/smb2misc.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -906,41 +906,41 @@ smb311_update_preauth_hash(struct cifs_ses *ses, struct TCP_Server_Info *server,
906906
|| (hdr->Status !=
907907
cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))))
908908
return 0;
909-
910909
ok:
911-
rc = smb311_crypto_shash_allocate(server);
912-
if (rc)
910+
rc = cifs_alloc_hash("sha512", &sha512);
911+
if (rc) {
912+
cifs_dbg(VFS, "%s: Could not allocate SHA512 shash, rc=%d\n", __func__, rc);
913913
return rc;
914+
}
914915

915-
sha512 = server->secmech.sha512;
916916
rc = crypto_shash_init(sha512);
917917
if (rc) {
918-
cifs_dbg(VFS, "%s: Could not init sha512 shash\n", __func__);
919-
return rc;
918+
cifs_dbg(VFS, "%s: Could not init SHA512 shash, rc=%d\n", __func__, rc);
919+
goto err_free;
920920
}
921921

922922
rc = crypto_shash_update(sha512, ses->preauth_sha_hash,
923923
SMB2_PREAUTH_HASH_SIZE);
924924
if (rc) {
925-
cifs_dbg(VFS, "%s: Could not update sha512 shash\n", __func__);
926-
return rc;
925+
cifs_dbg(VFS, "%s: Could not update SHA512 shash, rc=%d\n", __func__, rc);
926+
goto err_free;
927927
}
928928

929929
for (i = 0; i < nvec; i++) {
930930
rc = crypto_shash_update(sha512, iov[i].iov_base, iov[i].iov_len);
931931
if (rc) {
932-
cifs_dbg(VFS, "%s: Could not update sha512 shash\n",
933-
__func__);
934-
return rc;
932+
cifs_dbg(VFS, "%s: Could not update SHA512 shash, rc=%d\n", __func__, rc);
933+
goto err_free;
935934
}
936935
}
937936

938937
rc = crypto_shash_final(sha512, ses->preauth_sha_hash);
939938
if (rc) {
940-
cifs_dbg(VFS, "%s: Could not finalize sha512 shash\n",
941-
__func__);
942-
return rc;
939+
cifs_dbg(VFS, "%s: Could not finalize SHA12 shash, rc=%d\n", __func__, rc);
940+
goto err_free;
943941
}
942+
err_free:
943+
cifs_free_hash(&sha512);
944944

945945
return 0;
946946
}

fs/smb/client/smb2proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ extern int smb2_validate_and_copy_iov(unsigned int offset,
291291
extern void smb2_copy_fs_info_to_kstatfs(
292292
struct smb2_fs_full_size_info *pfs_inf,
293293
struct kstatfs *kst);
294-
extern int smb311_crypto_shash_allocate(struct TCP_Server_Info *server);
294+
extern int smb3_crypto_shash_allocate(struct TCP_Server_Info *server);
295295
extern int smb311_update_preauth_hash(struct cifs_ses *ses,
296296
struct TCP_Server_Info *server,
297297
struct kvec *iov, int nvec);

fs/smb/client/smb2transport.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
#include "../common/smb2status.h"
2727
#include "smb2glob.h"
2828

29-
static int
30-
smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
29+
int smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
3130
{
3231
struct cifs_secmech *p = &server->secmech;
3332
int rc;
@@ -46,33 +45,6 @@ smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
4645
return rc;
4746
}
4847

49-
int
50-
smb311_crypto_shash_allocate(struct TCP_Server_Info *server)
51-
{
52-
struct cifs_secmech *p = &server->secmech;
53-
int rc = 0;
54-
55-
rc = cifs_alloc_hash("hmac(sha256)", &p->hmacsha256);
56-
if (rc)
57-
return rc;
58-
59-
rc = cifs_alloc_hash("cmac(aes)", &p->aes_cmac);
60-
if (rc)
61-
goto err;
62-
63-
rc = cifs_alloc_hash("sha512", &p->sha512);
64-
if (rc)
65-
goto err;
66-
67-
return 0;
68-
69-
err:
70-
cifs_free_hash(&p->aes_cmac);
71-
cifs_free_hash(&p->hmacsha256);
72-
return rc;
73-
}
74-
75-
7648
static
7749
int smb2_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key)
7850
{

0 commit comments

Comments
 (0)