]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dm-crypt: Extend state buffer size in crypt_iv_lmk_one
authorHerbert Xu <herbert@gondor.apana.org.au>
Mon, 23 Jun 2025 11:11:50 +0000 (19:11 +0800)
committerMikulas Patocka <mpatocka@redhat.com>
Mon, 23 Jun 2025 11:50:02 +0000 (13:50 +0200)
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: efd62c85525e ("crypto: md5-generic - Use API partial block handling")
Reported-by: Milan Broz <gmazyland@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Tested-by: Milan Broz <gmazyland@gmail.com>
Closes: https://lore.kernel.org/linux-crypto/f1625ddc-e82e-4b77-80c2-dc8e45b54848@gmail.com/T/
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
drivers/md/dm-crypt.c
include/crypto/hash.h
include/crypto/md5.h

index 9dfdb63220d746241d4d490058dc1ef6c374811c..17157c4216a5b553e34118dfc32f0fb2b8563d0a 100644 (file)
@@ -517,7 +517,10 @@ static int crypt_iv_lmk_one(struct crypt_config *cc, u8 *iv,
 {
        struct iv_lmk_private *lmk = &cc->iv_gen_private.lmk;
        SHASH_DESC_ON_STACK(desc, lmk->hash_tfm);
-       struct md5_state md5state;
+       union {
+               struct md5_state md5state;
+               u8 state[CRYPTO_MD5_STATESIZE];
+       } u;
        __le32 buf[4];
        int i, r;
 
@@ -548,13 +551,13 @@ static int crypt_iv_lmk_one(struct crypt_config *cc, u8 *iv,
                return r;
 
        /* No MD5 padding here */
-       r = crypto_shash_export(desc, &md5state);
+       r = crypto_shash_export(desc, &u.md5state);
        if (r)
                return r;
 
        for (i = 0; i < MD5_HASH_WORDS; i++)
-               __cpu_to_le32s(&md5state.hash[i]);
-       memcpy(iv, &md5state.hash, cc->iv_size);
+               __cpu_to_le32s(&u.md5state.hash[i]);
+       memcpy(iv, &u.md5state.hash, cc->iv_size);
 
        return 0;
 }
index 6f6b9de12cd323d61f86808bbf9dd4ae7b4cbb2f..db294d452e8cd9e30f1179c16f483e853816c8df 100644 (file)
@@ -202,6 +202,8 @@ struct shash_desc {
 #define HASH_REQUEST_CLONE(name, gfp) \
        hash_request_clone(name, sizeof(__##name##_req), gfp)
 
+#define CRYPTO_HASH_STATESIZE(coresize, blocksize) (coresize + blocksize + 1)
+
 /**
  * struct shash_alg - synchronous message digest definition
  * @init: see struct ahash_alg
index 198b5d69b92fe60cf6d502f0ca1630bb82d3d6dc..28ee533a0507a7a3c52666e5688ec49adb2f8aac 100644 (file)
@@ -2,6 +2,7 @@
 #ifndef _CRYPTO_MD5_H
 #define _CRYPTO_MD5_H
 
+#include <crypto/hash.h>
 #include <linux/types.h>
 
 #define MD5_DIGEST_SIZE                16
@@ -15,6 +16,9 @@
 #define MD5_H2 0x98badcfeUL
 #define MD5_H3 0x10325476UL
 
+#define CRYPTO_MD5_STATESIZE \
+       CRYPTO_HASH_STATESIZE(MD5_STATE_SIZE, MD5_HMAC_BLOCK_SIZE)
+
 extern const u8 md5_zero_message_hash[MD5_DIGEST_SIZE];
 
 struct md5_state {