Skip to contentSkip to conversation

xen/arm: kernel: Propagate the error if we fail to decompress the kernel

PATCH In review Julien Grall 2 participants 4 messages Apr 6, 2021 – May 10, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen/arm: kernel: Propagate the error if we fail to decompress the kernel

From: Julien Grall <[email protected]>

Currently, we are ignoring any error from perform_gunzip() and replacing the compressed kernel with the "uncompressed" kernel.

If there is a gzip failure, then it means that the output buffer may contain garbagge. So it can result to various sort of behavior that may be difficult to root cause.

In case of failure, free the output buffer and propagate the error. We also need to adjust the return check for kernel_compress() as perform_gunzip() may return a positive value.

Take the opportunity to adjust the code style for the check.

---
Changes in v2:
- Fix build

---
 xen/arch/arm/kernel.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
xen/arch/arm/kernel.c +7 -1
index ab78689ed2a6..8f43caa1866d 100644
@@ -292,6 +292,12 @@ static __init int kernel_decompress(struct bootmodule *mod)
     iounmap(input);
     vunmap(output);
 
+    if ( rc )
+    {
+        free_domheap_pages(pages, kernel_order_out);
+        return rc;
+    }
+
     mod->start = page_to_maddr(pages);
     mod->size = output_size;
 
@@ -503,7 +509,7 @@ int __init kernel_probe(struct kernel_info *info,
 
     /* if it is a gzip'ed image, 32bit or 64bit, uncompress it */
     rc = kernel_decompress(mod);
-    if (rc < 0 && rc != -EINVAL)
+    if ( rc && rc != -EINVAL )
         return rc;
 
 #ifdef CONFIG_ARM_64
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 13 lines · Julien Grall

From: Julien Grall <[email protected]>

Currently, we are ignoring any error from perform_gunzip() and replacing the compressed kernel with the "uncompressed" kernel.

If there is a gzip failure, then it means that the output buffer may contain garbagge. So it can result to various sort of behavior that may be difficult to root cause.

In case of failure, free the output buffer and propagate the error. We also need to adjust the return check for kernel_compress() as perform_gunzip() may return a positive value.

Quoted 8 lines

Take the opportunity to adjust the code style for the check.

---
Changes in v2:
- Fix build
---

#2 lore raw

Hi Michal,

Quoted 16 lines · Michal Orzel
Quoted 15 lines · Julien Grall

From: Julien Grall <[email protected]>

Currently, we are ignoring any error from perform_gunzip() and replacing the compressed kernel with the "uncompressed" kernel.

If there is a gzip failure, then it means that the output buffer may contain garbagge. So it can result to various sort of behavior that may be difficult to root cause.

In case of failure, free the output buffer and propagate the error. We also need to adjust the return check for kernel_compress() as perform_gunzip() may return a positive value.

Take the opportunity to adjust the code style for the check.

Quoted 8 lines
Quoted 6 lines

---
Changes in v2:
- Fix build
---

Thanks! @Stefano, can I get your acked-by?

Cheers,

Signature · 1 line
Julien Grall
#3 lore raw

PING Re: [PATCH v2] xen/arm: kernel: Propagate the error if we fail to decompress the kernel

Quoted 19 lines · Julien Grall
Quoted 18 lines · Michal Orzel
Quoted 17 lines · Julien Grall

From: Julien Grall <[email protected]>

Currently, we are ignoring any error from perform_gunzip() and replacing the compressed kernel with the "uncompressed" kernel.

If there is a gzip failure, then it means that the output buffer may contain garbagge. So it can result to various sort of behavior that may be difficult to root cause.

In case of failure, free the output buffer and propagate the error. We also need to adjust the return check for kernel_compress() as perform_gunzip() may return a positive value.

Take the opportunity to adjust the code style for the check.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

---
     Changes in v2:
         - Fix build
---

Thanks! @Stefano, can I get your acked-by?

Ping? I intend to commit it on Wednesday unless I hear otherwise.

Cheers,

Signature · 1 line
Julien Grall