Skip to content

Commit ae04b1b

Browse files
Eric Biggerssmfrench
authored andcommitted
smb: client: Use MD5 library for M-F symlink hashing
Convert parse_mf_symlink() and format_mf_symlink() 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. This also fixes an issue where these functions did not work on kernels booted in FIPS mode. The use of MD5 here is for data integrity rather than a security purpose, so it can use a non-FIPS-approved algorithm. 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 e05b311 commit ae04b1b

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

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_MD5
1920
select CRYPTO_LIB_SHA256
2021
select CRYPTO_LIB_SHA512
2122
select KEYS

fs/smb/client/link.c

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Author(s): Steve French (sfrench@us.ibm.com)
66
*
77
*/
8+
#include <crypto/md5.h>
89
#include <linux/fs.h>
910
#include <linux/stat.h>
1011
#include <linux/slab.h>
@@ -36,23 +37,6 @@
3637
#define CIFS_MF_SYMLINK_MD5_FORMAT "%16phN\n"
3738
#define CIFS_MF_SYMLINK_MD5_ARGS(md5_hash) md5_hash
3839

39-
static int
40-
symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
41-
{
42-
int rc;
43-
struct shash_desc *md5 = NULL;
44-
45-
rc = cifs_alloc_hash("md5", &md5);
46-
if (rc)
47-
return rc;
48-
49-
rc = crypto_shash_digest(md5, link_str, link_len, md5_hash);
50-
if (rc)
51-
cifs_dbg(VFS, "%s: Could not generate md5 hash\n", __func__);
52-
cifs_free_hash(&md5);
53-
return rc;
54-
}
55-
5640
static int
5741
parse_mf_symlink(const u8 *buf, unsigned int buf_len, unsigned int *_link_len,
5842
char **_link_str)
@@ -77,11 +61,7 @@ parse_mf_symlink(const u8 *buf, unsigned int buf_len, unsigned int *_link_len,
7761
if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN)
7862
return -EINVAL;
7963

80-
rc = symlink_hash(link_len, link_str, md5_hash);
81-
if (rc) {
82-
cifs_dbg(FYI, "%s: MD5 hash failure: %d\n", __func__, rc);
83-
return rc;
84-
}
64+
md5(link_str, link_len, md5_hash);
8565

8666
scnprintf(md5_str2, sizeof(md5_str2),
8767
CIFS_MF_SYMLINK_MD5_FORMAT,
@@ -103,7 +83,6 @@ parse_mf_symlink(const u8 *buf, unsigned int buf_len, unsigned int *_link_len,
10383
static int
10484
format_mf_symlink(u8 *buf, unsigned int buf_len, const char *link_str)
10585
{
106-
int rc;
10786
unsigned int link_len;
10887
unsigned int ofs;
10988
u8 md5_hash[16];
@@ -116,11 +95,7 @@ format_mf_symlink(u8 *buf, unsigned int buf_len, const char *link_str)
11695
if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN)
11796
return -ENAMETOOLONG;
11897

119-
rc = symlink_hash(link_len, link_str, md5_hash);
120-
if (rc) {
121-
cifs_dbg(FYI, "%s: MD5 hash failure: %d\n", __func__, rc);
122-
return rc;
123-
}
98+
md5(link_str, link_len, md5_hash);
12499

125100
scnprintf(buf, buf_len,
126101
CIFS_MF_SYMLINK_LEN_FORMAT CIFS_MF_SYMLINK_MD5_FORMAT,

0 commit comments

Comments
 (0)