Skip to content

Commit c2cd0b0

Browse files
keesrafaeljw
authored andcommitted
x86/power/hibernate_64: Remove VLA usage
In the quest to remove all stack VLA usage from the kernel [1], this removes the discouraged use of AHASH_REQUEST_ON_STACK by switching to shash directly and allocating the descriptor in heap memory (which should be fine: the tfm has already been allocated there too). Link: https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com # [1] Signed-off-by: Kees Cook <[email protected]> Acked-by: Pavel Machek <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent d5641c6 commit c2cd0b0

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

arch/x86/power/hibernate_64.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,29 +233,35 @@ struct restore_data_record {
233233
*/
234234
static int get_e820_md5(struct e820_table *table, void *buf)
235235
{
236-
struct scatterlist sg;
237-
struct crypto_ahash *tfm;
236+
struct crypto_shash *tfm;
237+
struct shash_desc *desc;
238238
int size;
239239
int ret = 0;
240240

241-
tfm = crypto_alloc_ahash("md5", 0, CRYPTO_ALG_ASYNC);
241+
tfm = crypto_alloc_shash("md5", 0, 0);
242242
if (IS_ERR(tfm))
243243
return -ENOMEM;
244244

245-
{
246-
AHASH_REQUEST_ON_STACK(req, tfm);
247-
size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry) * table->nr_entries;
248-
ahash_request_set_tfm(req, tfm);
249-
sg_init_one(&sg, (u8 *)table, size);
250-
ahash_request_set_callback(req, 0, NULL, NULL);
251-
ahash_request_set_crypt(req, &sg, buf, size);
252-
253-
if (crypto_ahash_digest(req))
254-
ret = -EINVAL;
255-
ahash_request_zero(req);
245+
desc = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(tfm),
246+
GFP_KERNEL);
247+
if (!desc) {
248+
ret = -ENOMEM;
249+
goto free_tfm;
256250
}
257-
crypto_free_ahash(tfm);
258251

252+
desc->tfm = tfm;
253+
desc->flags = 0;
254+
255+
size = offsetof(struct e820_table, entries) +
256+
sizeof(struct e820_entry) * table->nr_entries;
257+
258+
if (crypto_shash_digest(desc, (u8 *)table, size, buf))
259+
ret = -EINVAL;
260+
261+
kzfree(desc);
262+
263+
free_tfm:
264+
crypto_free_shash(tfm);
259265
return ret;
260266
}
261267

0 commit comments

Comments
 (0)