Skip to contentSkip to conversation

kernel: kexec_file: fix error return code of kexec_calculate_store_digests()

PATCH Applied Jia-Ju Bai 2 participants 2 messages Mar 9, 2021 – Mar 11, 2021

Subsystems (3)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 kernel: kexec_file: fix error return code of kexec_calculate_store_digests()

When vzalloc() returns NULL to sha_regions, no error return code of kexec_calculate_store_digests() is assigned.
To fix this bug, ret is assigned with -ENOMEM in this case.

Fixes a43cac0d9dc2 ("kexec: split kexec_file syscall code to kexec_file.c")
---
 kernel/kexec_file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/kexec_file.c +3 -1
index 5c3447cf7ad5..33400ff051a8 100644
@@ -740,8 +740,10 @@ static int kexec_calculate_store_digests(struct kimage *image)
 
 	sha_region_sz = KEXEC_SEGMENT_MAX * sizeof(struct kexec_sha_region);
 	sha_regions = vzalloc(sha_region_sz);
-	if (!sha_regions)
+	if (!sha_regions) {
+		ret = -ENOMEM;
 		goto out_free_desc;
+	}
 
 	desc->tfm   = tfm;
 
Signature · 7 lines
2.17.1


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · Jia-Ju Bai

When vzalloc() returns NULL to sha_regions, no error return code of kexec_calculate_store_digests() is assigned.
To fix this bug, ret is assigned with -ENOMEM in this case.

Fixes a43cac0d9dc2 ("kexec: split kexec_file syscall code to kexec_file.c")
---
 kernel/kexec_file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/kexec_file.c +0 -0
index 5c3447cf7ad5..33400ff051a8 100644

kernel/kexec_file.c static int kexec_calculate_store_digests(struct kimage *image) · line 745

Quoted 7 lines
kernel/kexec_file.c +2 -1
@@ -740,8 +740,10 @@ static int kexec_calculate_store_digests(struct kimage *image)
 
 	sha_region_sz = KEXEC_SEGMENT_MAX * sizeof(struct kexec_sha_region);
 	sha_regions = vzalloc(sha_region_sz);
-	if (!sha_regions)
+	if (!sha_regions) {
+		ret = -ENOMEM;
 		goto out_free_desc;

A good catch. Even though the chance of failure is very small, it does cause issue if happened.

Thanks
Baoquan

Quoted 13 lines
kernel/kexec_file.c +1 -0
+	}
 
 	desc->tfm   = tfm;
 
Signature · 7 lines
2.17.1


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec