Skip to content

Commit b872f56

Browse files
herbertxMikulas Patocka
authored andcommitted
dm-crypt: Extend state buffer size in crypt_iv_lmk_one
Add a macro CRYPTO_MD5_STATESIZE for the Crypto API export state size of md5 and use that in dm-crypt instead of relying on the size of struct md5_state (the latter is currently undergoing a transition and may shrink). This commit fixes a crash on 32-bit machines: Oops: Oops: 0000 [#1] SMP CPU: 1 UID: 0 PID: 12 Comm: kworker/u16:0 Not tainted 6.16.0-rc2+ #993 PREEMPT(full) Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020 Workqueue: kcryptd-254:0-1 kcryptd_crypt [dm_crypt] EIP: __crypto_shash_export+0xf/0x90 Code: 4a c1 c7 40 20 a0 b4 4a c1 81 cf 0e 00 04 08 89 78 50 e9 2b ff ff ff 8d 74 26 00 55 89 e5 57 56 53 89 c3 89 d6 8b 00 8b 40 14 <8b> 50 fc f6 40 13 01 74 04 4a 2b 50 14 85 c9 74 10 89 f2 89 d8 ff EAX: 303a3435 EBX: c3007c90 ECX: 00000000 EDX: c3007c38 ESI: c3007c38 EDI: c3007c90 EBP: c3007bfc ESP: c3007bf0 DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068 EFLAGS: 00010216 CR0: 80050033 CR2: 303a3431 CR3: 04fbe000 CR4: 00350e90 Call Trace: crypto_shash_export+0x65/0xc0 crypt_iv_lmk_one+0x106/0x1a0 [dm_crypt] Fixes: efd62c8 ("crypto: md5-generic - Use API partial block handling") Reported-by: Milan Broz <[email protected]> Signed-off-by: Herbert Xu <[email protected]> Tested-by: Milan Broz <[email protected]> Closes: https://lore.kernel.org/linux-crypto/[email protected]/T/ Signed-off-by: Mikulas Patocka <[email protected]>
1 parent 86731a2 commit b872f56

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

drivers/md/dm-crypt.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,10 @@ static int crypt_iv_lmk_one(struct crypt_config *cc, u8 *iv,
517517
{
518518
struct iv_lmk_private *lmk = &cc->iv_gen_private.lmk;
519519
SHASH_DESC_ON_STACK(desc, lmk->hash_tfm);
520-
struct md5_state md5state;
520+
union {
521+
struct md5_state md5state;
522+
u8 state[CRYPTO_MD5_STATESIZE];
523+
} u;
521524
__le32 buf[4];
522525
int i, r;
523526

@@ -548,13 +551,13 @@ static int crypt_iv_lmk_one(struct crypt_config *cc, u8 *iv,
548551
return r;
549552

550553
/* No MD5 padding here */
551-
r = crypto_shash_export(desc, &md5state);
554+
r = crypto_shash_export(desc, &u.md5state);
552555
if (r)
553556
return r;
554557

555558
for (i = 0; i < MD5_HASH_WORDS; i++)
556-
__cpu_to_le32s(&md5state.hash[i]);
557-
memcpy(iv, &md5state.hash, cc->iv_size);
559+
__cpu_to_le32s(&u.md5state.hash[i]);
560+
memcpy(iv, &u.md5state.hash, cc->iv_size);
558561

559562
return 0;
560563
}

include/crypto/hash.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ struct shash_desc {
202202
#define HASH_REQUEST_CLONE(name, gfp) \
203203
hash_request_clone(name, sizeof(__##name##_req), gfp)
204204

205+
#define CRYPTO_HASH_STATESIZE(coresize, blocksize) (coresize + blocksize + 1)
206+
205207
/**
206208
* struct shash_alg - synchronous message digest definition
207209
* @init: see struct ahash_alg

include/crypto/md5.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef _CRYPTO_MD5_H
33
#define _CRYPTO_MD5_H
44

5+
#include <crypto/hash.h>
56
#include <linux/types.h>
67

78
#define MD5_DIGEST_SIZE 16
@@ -15,6 +16,9 @@
1516
#define MD5_H2 0x98badcfeUL
1617
#define MD5_H3 0x10325476UL
1718

19+
#define CRYPTO_MD5_STATESIZE \
20+
CRYPTO_HASH_STATESIZE(MD5_STATE_SIZE, MD5_HMAC_BLOCK_SIZE)
21+
1822
extern const u8 md5_zero_message_hash[MD5_DIGEST_SIZE];
1923

2024
struct md5_state {

0 commit comments

Comments
 (0)