diff mbox series

[1/2] efi: runtime: Fix potential overflow of soft-reserved region size

Message ID 20240202163433.786581-2-abrestic@rivosinc.com (mailing list archive)
State Superseded
Headers show
Series efi: Fixes for EFI_MEMORY_SP memory on RISC-V and ARM64 | expand

Commit Message

Andrew Bresticker Feb. 2, 2024, 4:34 p.m. UTC
md_size will have been narrowed if we have >= 4GB worth of pages in a
soft-reserved region.

Signed-off-by: Andrew Bresticker <abrestic@rivosinc.com>
---
 drivers/firmware/efi/arm-runtime.c   | 2 +-
 drivers/firmware/efi/riscv-runtime.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Ard Biesheuvel Feb. 2, 2024, 4:37 p.m. UTC | #1
Hi Andrew,

On Fri, 2 Feb 2024 at 17:34, Andrew Bresticker <abrestic@rivosinc.com> wrote:
>
> md_size will have been narrowed if we have >= 4GB worth of pages in a
> soft-reserved region.
>
> Signed-off-by: Andrew Bresticker <abrestic@rivosinc.com>
> ---
>  drivers/firmware/efi/arm-runtime.c   | 2 +-
>  drivers/firmware/efi/riscv-runtime.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c
> index 83f5bb57fa4c..f369256c7003 100644
> --- a/drivers/firmware/efi/arm-runtime.c
> +++ b/drivers/firmware/efi/arm-runtime.c
> @@ -107,7 +107,7 @@ static int __init arm_enable_runtime_services(void)
>                 efi_memory_desc_t *md;
>
>                 for_each_efi_memory_desc(md) {
> -                       int md_size = md->num_pages << EFI_PAGE_SHIFT;
> +                       unsigned long md_size = md->num_pages << EFI_PAGE_SHIFT;

Better use u64 here, and below as well.


>                         struct resource *res;
>
>                         if (!(md->attribute & EFI_MEMORY_SP))
> diff --git a/drivers/firmware/efi/riscv-runtime.c b/drivers/firmware/efi/riscv-runtime.c
> index 09525fb5c240..9da79b8169d2 100644
> --- a/drivers/firmware/efi/riscv-runtime.c
> +++ b/drivers/firmware/efi/riscv-runtime.c
> @@ -85,7 +85,7 @@ static int __init riscv_enable_runtime_services(void)
>                 efi_memory_desc_t *md;
>
>                 for_each_efi_memory_desc(md) {
> -                       int md_size = md->num_pages << EFI_PAGE_SHIFT;
> +                       unsigned long md_size = md->num_pages << EFI_PAGE_SHIFT;
>                         struct resource *res;
>
>                         if (!(md->attribute & EFI_MEMORY_SP))
> --
> 2.34.1
>
>
diff mbox series

Patch

diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c
index 83f5bb57fa4c..f369256c7003 100644
--- a/drivers/firmware/efi/arm-runtime.c
+++ b/drivers/firmware/efi/arm-runtime.c
@@ -107,7 +107,7 @@  static int __init arm_enable_runtime_services(void)
 		efi_memory_desc_t *md;
 
 		for_each_efi_memory_desc(md) {
-			int md_size = md->num_pages << EFI_PAGE_SHIFT;
+			unsigned long md_size = md->num_pages << EFI_PAGE_SHIFT;
 			struct resource *res;
 
 			if (!(md->attribute & EFI_MEMORY_SP))
diff --git a/drivers/firmware/efi/riscv-runtime.c b/drivers/firmware/efi/riscv-runtime.c
index 09525fb5c240..9da79b8169d2 100644
--- a/drivers/firmware/efi/riscv-runtime.c
+++ b/drivers/firmware/efi/riscv-runtime.c
@@ -85,7 +85,7 @@  static int __init riscv_enable_runtime_services(void)
 		efi_memory_desc_t *md;
 
 		for_each_efi_memory_desc(md) {
-			int md_size = md->num_pages << EFI_PAGE_SHIFT;
+			unsigned long md_size = md->num_pages << EFI_PAGE_SHIFT;
 			struct resource *res;
 
 			if (!(md->attribute & EFI_MEMORY_SP))