diff options
author | Kees Cook <keescook@chromium.org> | 2018-07-24 12:49:28 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2018-07-26 04:26:31 -0400 |
commit | c2cd0b08e1efd9ee58d09049a6c77e5efa0ef627 (patch) | |
tree | b771156d6c486adbbc39d589a880fdfe17df90dc | |
parent | d5641c64c48f4408500a348301bff01fbf2c1ec5 (diff) |
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 <keescook@chromium.org>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r-- | arch/x86/power/hibernate_64.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c index 67ccf64c8bd8..f8e3b668d20b 100644 --- a/arch/x86/power/hibernate_64.c +++ b/arch/x86/power/hibernate_64.c | |||
@@ -233,29 +233,35 @@ struct restore_data_record { | |||
233 | */ | 233 | */ |
234 | static int get_e820_md5(struct e820_table *table, void *buf) | 234 | static int get_e820_md5(struct e820_table *table, void *buf) |
235 | { | 235 | { |
236 | struct scatterlist sg; | 236 | struct crypto_shash *tfm; |
237 | struct crypto_ahash *tfm; | 237 | struct shash_desc *desc; |
238 | int size; | 238 | int size; |
239 | int ret = 0; | 239 | int ret = 0; |
240 | 240 | ||
241 | tfm = crypto_alloc_ahash("md5", 0, CRYPTO_ALG_ASYNC); | 241 | tfm = crypto_alloc_shash("md5", 0, 0); |
242 | if (IS_ERR(tfm)) | 242 | if (IS_ERR(tfm)) |
243 | return -ENOMEM; | 243 | return -ENOMEM; |
244 | 244 | ||
245 | { | 245 | desc = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(tfm), |
246 | AHASH_REQUEST_ON_STACK(req, tfm); | 246 | GFP_KERNEL); |
247 | size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry) * table->nr_entries; | 247 | if (!desc) { |
248 | ahash_request_set_tfm(req, tfm); | 248 | ret = -ENOMEM; |
249 | sg_init_one(&sg, (u8 *)table, size); | 249 | goto free_tfm; |
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); | ||
256 | } | 250 | } |
257 | crypto_free_ahash(tfm); | ||
258 | 251 | ||
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); | ||
259 | return ret; | 265 | return ret; |
260 | } | 266 | } |
261 | 267 | ||