Skip to content

Commit af5fea5

Browse files
Eric Biggerssmfrench
authored andcommitted
smb: client: Use SHA-512 library for SMB3.1.1 preauth hash
Convert smb311_update_preauth_hash() to use the SHA-512 library instead of a "sha512" crypto_shash. This is simpler and faster. With the library there's no need to allocate memory, no need to handle errors, and the SHA-512 code is accessed directly without inefficient indirect calls and other unnecessary API overhead. Remove the call to smb311_crypto_shash_allocate() from smb311_update_preauth_hash(), since it appears to have been needed only to allocate the "sha512" crypto_shash. (It also had the side effect of allocating the "cmac(aes)" crypto_shash, but that's also done in generate_key() which is where the AES-CMAC key is initialized.) For now the "sha512" crypto_shash is still being allocated elsewhere. It will be removed in a later commit. Reviewed-by: Stefan Metzmacher <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 6447b0e commit af5fea5

3 files changed

Lines changed: 16 additions & 44 deletions

File tree

fs/smb/client/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ config CIFS
1616
select CRYPTO_ECB
1717
select CRYPTO_AES
1818
select CRYPTO_LIB_ARC4
19+
select CRYPTO_LIB_SHA512
1920
select KEYS
2021
select DNS_RESOLVER
2122
select ASN1

fs/smb/client/smb2misc.c

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Pavel Shilovsky ([email protected]) 2012
88
*
99
*/
10+
#include <crypto/sha2.h>
1011
#include <linux/ctype.h>
1112
#include "cifsglob.h"
1213
#include "cifsproto.h"
@@ -888,13 +889,13 @@ smb2_handle_cancelled_mid(struct mid_q_entry *mid, struct TCP_Server_Info *serve
888889
* @iov: array containing the SMB request we will send to the server
889890
* @nvec: number of array entries for the iov
890891
*/
891-
int
892+
void
892893
smb311_update_preauth_hash(struct cifs_ses *ses, struct TCP_Server_Info *server,
893894
struct kvec *iov, int nvec)
894895
{
895-
int i, rc;
896+
int i;
896897
struct smb2_hdr *hdr;
897-
struct shash_desc *sha512 = NULL;
898+
struct sha512_ctx sha_ctx;
898899

899900
hdr = (struct smb2_hdr *)iov[0].iov_base;
900901
/* neg prot are always taken */
@@ -907,52 +908,22 @@ smb311_update_preauth_hash(struct cifs_ses *ses, struct TCP_Server_Info *server,
907908
* and we can test it. Preauth requires 3.1.1 for now.
908909
*/
909910
if (server->dialect != SMB311_PROT_ID)
910-
return 0;
911+
return;
911912

912913
if (hdr->Command != SMB2_SESSION_SETUP)
913-
return 0;
914+
return;
914915

915916
/* skip last sess setup response */
916917
if ((hdr->Flags & SMB2_FLAGS_SERVER_TO_REDIR)
917918
&& (hdr->Status == NT_STATUS_OK
918919
|| (hdr->Status !=
919920
cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))))
920-
return 0;
921+
return;
921922

922923
ok:
923-
rc = smb311_crypto_shash_allocate(server);
924-
if (rc)
925-
return rc;
926-
927-
sha512 = server->secmech.sha512;
928-
rc = crypto_shash_init(sha512);
929-
if (rc) {
930-
cifs_dbg(VFS, "%s: Could not init sha512 shash\n", __func__);
931-
return rc;
932-
}
933-
934-
rc = crypto_shash_update(sha512, ses->preauth_sha_hash,
935-
SMB2_PREAUTH_HASH_SIZE);
936-
if (rc) {
937-
cifs_dbg(VFS, "%s: Could not update sha512 shash\n", __func__);
938-
return rc;
939-
}
940-
941-
for (i = 0; i < nvec; i++) {
942-
rc = crypto_shash_update(sha512, iov[i].iov_base, iov[i].iov_len);
943-
if (rc) {
944-
cifs_dbg(VFS, "%s: Could not update sha512 shash\n",
945-
__func__);
946-
return rc;
947-
}
948-
}
949-
950-
rc = crypto_shash_final(sha512, ses->preauth_sha_hash);
951-
if (rc) {
952-
cifs_dbg(VFS, "%s: Could not finalize sha512 shash\n",
953-
__func__);
954-
return rc;
955-
}
956-
957-
return 0;
924+
sha512_init(&sha_ctx);
925+
sha512_update(&sha_ctx, ses->preauth_sha_hash, SMB2_PREAUTH_HASH_SIZE);
926+
for (i = 0; i < nvec; i++)
927+
sha512_update(&sha_ctx, iov[i].iov_base, iov[i].iov_len);
928+
sha512_final(&sha_ctx, ses->preauth_sha_hash);
958929
}

fs/smb/client/smb2proto.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ extern void smb2_copy_fs_info_to_kstatfs(
296296
struct smb2_fs_full_size_info *pfs_inf,
297297
struct kstatfs *kst);
298298
extern int smb311_crypto_shash_allocate(struct TCP_Server_Info *server);
299-
extern int smb311_update_preauth_hash(struct cifs_ses *ses,
300-
struct TCP_Server_Info *server,
301-
struct kvec *iov, int nvec);
299+
extern void smb311_update_preauth_hash(struct cifs_ses *ses,
300+
struct TCP_Server_Info *server,
301+
struct kvec *iov, int nvec);
302302
extern int smb2_query_info_compound(const unsigned int xid,
303303
struct cifs_tcon *tcon,
304304
const char *path, u32 desired_access,

0 commit comments

Comments
 (0)