Skip to content

Commit c04e55b

Browse files
Eric Biggerssmfrench
authored andcommitted
smb: client: Use MD5 library for SMB1 signature calculation
Convert cifs_calc_signature() to use the MD5 library instead of a "md5" crypto_shash. This is simpler and faster. With the library there's no need to allocate memory, no need to handle errors, and the MD5 code is accessed directly without inefficient indirect calls and other unnecessary API overhead. To preserve the existing behavior of MD5 signature support being disabled when the kernel is booted with "fips=1", make cifs_calc_signature() check fips_enabled itself. Previously it relied on the error from cifs_alloc_hash("md5", &server->secmech.md5). Reviewed-by: Stefan Metzmacher <metze@samba.org> Acked-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent ae04b1b commit c04e55b

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

fs/smb/client/cifsencrypt.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@
2424
#include <linux/iov_iter.h>
2525
#include <crypto/aead.h>
2626
#include <crypto/arc4.h>
27+
#include <crypto/md5.h>
2728
#include <crypto/sha2.h>
2829

2930
static int cifs_sig_update(struct cifs_calc_sig_ctx *ctx,
3031
const u8 *data, size_t len)
3132
{
33+
if (ctx->md5) {
34+
md5_update(ctx->md5, data, len);
35+
return 0;
36+
}
3237
if (ctx->hmac) {
3338
hmac_sha256_update(ctx->hmac, data, len);
3439
return 0;
@@ -38,6 +43,10 @@ static int cifs_sig_update(struct cifs_calc_sig_ctx *ctx,
3843

3944
static int cifs_sig_final(struct cifs_calc_sig_ctx *ctx, u8 *out)
4045
{
46+
if (ctx->md5) {
47+
md5_final(ctx->md5, out);
48+
return 0;
49+
}
4150
if (ctx->hmac) {
4251
hmac_sha256_final(ctx->hmac, out);
4352
return 0;
@@ -130,31 +139,22 @@ int __cifs_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
130139
static int cifs_calc_signature(struct smb_rqst *rqst,
131140
struct TCP_Server_Info *server, char *signature)
132141
{
133-
int rc;
142+
struct md5_ctx ctx;
134143

135144
if (!rqst->rq_iov || !signature || !server)
136145
return -EINVAL;
137-
138-
rc = cifs_alloc_hash("md5", &server->secmech.md5);
139-
if (rc)
140-
return -1;
141-
142-
rc = crypto_shash_init(server->secmech.md5);
143-
if (rc) {
144-
cifs_dbg(VFS, "%s: Could not init md5\n", __func__);
145-
return rc;
146+
if (fips_enabled) {
147+
cifs_dbg(VFS,
148+
"MD5 signature support is disabled due to FIPS\n");
149+
return -EOPNOTSUPP;
146150
}
147151

148-
rc = crypto_shash_update(server->secmech.md5,
149-
server->session_key.response, server->session_key.len);
150-
if (rc) {
151-
cifs_dbg(VFS, "%s: Could not update with response\n", __func__);
152-
return rc;
153-
}
152+
md5_init(&ctx);
153+
md5_update(&ctx, server->session_key.response, server->session_key.len);
154154

155155
return __cifs_calc_signature(
156156
rqst, server, signature,
157-
&(struct cifs_calc_sig_ctx){ .shash = server->secmech.md5 });
157+
&(struct cifs_calc_sig_ctx){ .md5 = &ctx });
158158
}
159159

160160
/* must be called with server->srv_mutex held */

fs/smb/client/cifsproto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ int cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
633633
const unsigned char *path, char *pbuf,
634634
unsigned int *pbytes_written);
635635
struct cifs_calc_sig_ctx {
636+
struct md5_ctx *md5;
636637
struct hmac_sha256_ctx *hmac;
637638
struct shash_desc *shash;
638639
};

0 commit comments

Comments
 (0)