Blob Blame History Raw
From 1bb4c6d5573cdebfa2667226a73a3ea054bcb946 Mon Sep 17 00:00:00 2001
From: "Lee, Chun-Yi" <jlee@suse.com>
Date: Thu, 13 Oct 2016 17:41:00 +0800
Subject: [PATCH] PM / hibernate: Fix 2G size issue of snapshot image
 verification

Patch-mainline: Not yet, will send to upstream
References: bsc#1004252

The max size of kmalloc on x86 is 4M, it causes that the verification code
can not allocate enough h_buf buffer to handle the snapshot image that
its size more than 2G. So, using vmalloc instead of kmalloc to fix this
issue.

On the other hand, kernel should not restore snapshot image when secure boot
is enabled and h_buf allocation failed. So changing the codes in verify
function to return -ENOMEM.

Signed-off-by: Lee, Chun-Yi <jlee@suse.com>
---
 kernel/power/snapshot.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -30,6 +30,7 @@
 #include <linux/compiler.h>
 #include <linux/ktime.h>
 #include <linux/efi.h>
+#include <linux/vmalloc.h>
 
 #include <linux/uaccess.h>
 #include <asm/mmu_context.h>
@@ -1411,8 +1412,10 @@ int snapshot_image_verify(void)
 	size_t digest_size, desc_size;
 	int i, ret = 0;
 
-	if (!h_buf)
-		return 0;
+	if (!h_buf) {
+		ret = -ENOMEM;
+		goto forward_ret;
+	}
 
 	ret = get_hibernation_key(&key);
 	if (ret)
@@ -1462,7 +1465,7 @@ int snapshot_image_verify(void)
 		ret = -EKEYREJECTED;
 
 error_shash:
-	kfree(h_buf);
+	vfree(h_buf);
 	kfree(digest);
 error_setkey:
 error_digest:
@@ -1483,7 +1486,7 @@ forward_ret:
 
 static void alloc_h_buf(void)
 {
-	h_buf = kmalloc(sizeof(void *) * nr_copy_pages, GFP_KERNEL);
+	h_buf = vmalloc(sizeof(void *) * nr_copy_pages);
 	if (!h_buf)
 		pr_err("PM: Allocate buffer point array failed\n");
 }