All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] efi: fix memory calculation overflow on 32-bit systems
@ 2019-04-09 20:58 Patrick Wildt
  2019-04-10  0:36 ` [U-Boot] [PATCH 1/1] " Heinrich Schuchardt
  2019-04-11  8:38 ` [U-Boot] " Patrick DELAUNAY
  0 siblings, 2 replies; 3+ messages in thread
From: Patrick Wildt @ 2019-04-09 20:58 UTC (permalink / raw)
  To: u-boot

Hi,

There are Cubox-i machines out there with nearly 4 GiB of RAM.  The
RAM starts at 0x10000000 with a size of 0xf0000000.  Thus the end
of RAM is at 0x100000000.  This overflows a 32-bit integer, which
should be fine since in the EFI memory code the variables used are
all 64-bit with a fixed size.  Unfortunately EFI_PAGE_MASK, which is
used in the EFI memory code to remove the lower bits, is based on
the EFI_PAGE_SIZE macro which, uses 1UL with a shift.  This means
the resulting mask is UL, which is only 32-bit on ARMv7.  Use ULL to
make sure that even on 32-bit platforms we use a 64-bit long mask.
Without this there will be no memory available in the EFI memory map
and bootefi will fail allocating pages.

Best regards,
Patrick

diff --git a/include/efi.h b/include/efi.h
index d98441ab19d..3c9d20f8c0b 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -190,7 +190,7 @@ enum efi_mem_type {
 #define EFI_MEM_DESC_VERSION	1
 
 #define EFI_PAGE_SHIFT		12
-#define EFI_PAGE_SIZE		(1UL << EFI_PAGE_SHIFT)
+#define EFI_PAGE_SIZE		(1ULL << EFI_PAGE_SHIFT)
 #define EFI_PAGE_MASK		(EFI_PAGE_SIZE - 1)
 
 struct efi_mem_desc {

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH 1/1] efi: fix memory calculation overflow on 32-bit systems
  2019-04-09 20:58 [U-Boot] efi: fix memory calculation overflow on 32-bit systems Patrick Wildt
@ 2019-04-10  0:36 ` Heinrich Schuchardt
  2019-04-11  8:38 ` [U-Boot] " Patrick DELAUNAY
  1 sibling, 0 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2019-04-10  0:36 UTC (permalink / raw)
  To: u-boot

On 4/9/19 10:58 PM, Patrick Wildt wrote:
> Hi,
>
> There are Cubox-i machines out there with nearly 4 GiB of RAM.  The
> RAM starts at 0x10000000 with a size of 0xf0000000.  Thus the end
> of RAM is at 0x100000000.  This overflows a 32-bit integer, which
> should be fine since in the EFI memory code the variables used are
> all 64-bit with a fixed size.  Unfortunately EFI_PAGE_MASK, which is
> used in the EFI memory code to remove the lower bits, is based on
> the EFI_PAGE_SIZE macro which, uses 1UL with a shift.  This means
> the resulting mask is UL, which is only 32-bit on ARMv7.  Use ULL to
> make sure that even on 32-bit platforms we use a 64-bit long mask.
> Without this there will be no memory available in the EFI memory map
> and bootefi will fail allocating pages.
>
> Best regards,
> Patrick

We are using `& ~EFI_PAGE_MASK` in multiplaces for 64bit operations. So
it makes sense to use a 64bit value.

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

>
> diff --git a/include/efi.h b/include/efi.h
> index d98441ab19d..3c9d20f8c0b 100644
> --- a/include/efi.h
> +++ b/include/efi.h
> @@ -190,7 +190,7 @@ enum efi_mem_type {
>  #define EFI_MEM_DESC_VERSION	1
>
>  #define EFI_PAGE_SHIFT		12
> -#define EFI_PAGE_SIZE		(1UL << EFI_PAGE_SHIFT)
> +#define EFI_PAGE_SIZE		(1ULL << EFI_PAGE_SHIFT)
>  #define EFI_PAGE_MASK		(EFI_PAGE_SIZE - 1)
>
>  struct efi_mem_desc {
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] efi: fix memory calculation overflow on 32-bit systems
  2019-04-09 20:58 [U-Boot] efi: fix memory calculation overflow on 32-bit systems Patrick Wildt
  2019-04-10  0:36 ` [U-Boot] [PATCH 1/1] " Heinrich Schuchardt
@ 2019-04-11  8:38 ` Patrick DELAUNAY
  1 sibling, 0 replies; 3+ messages in thread
From: Patrick DELAUNAY @ 2019-04-11  8:38 UTC (permalink / raw)
  To: u-boot

Hi Patrick,

> From: U-Boot <u-boot-bounces@lists.denx.de> On Behalf Of Patrick Wildt
> 
> Hi,
> 
> There are Cubox-i machines out there with nearly 4 GiB of RAM.  The RAM starts
> at 0x10000000 with a size of 0xf0000000.  Thus the end of RAM is at
> 0x100000000.  This overflows a 32-bit integer, which should be fine since in the
> EFI memory code the variables used are all 64-bit with a fixed size.  Unfortunately
> EFI_PAGE_MASK, which is used in the EFI memory code to remove the lower
> bits, is based on the EFI_PAGE_SIZE macro which, uses 1UL with a shift.  This
> means the resulting mask is UL, which is only 32-bit on ARMv7.  Use ULL to
> make sure that even on 32-bit platforms we use a 64-bit long mask.
> Without this there will be no memory available in the EFI memory map and bootefi
> will fail allocating pages.
> 
> Best regards,
> Patrick
> 
> diff --git a/include/efi.h b/include/efi.h index d98441ab19d..3c9d20f8c0b 100644
> --- a/include/efi.h
> +++ b/include/efi.h
> @@ -190,7 +190,7 @@ enum efi_mem_type {
>  #define EFI_MEM_DESC_VERSION	1
> 
>  #define EFI_PAGE_SHIFT		12
> -#define EFI_PAGE_SIZE		(1UL << EFI_PAGE_SHIFT)
> +#define EFI_PAGE_SIZE		(1ULL << EFI_PAGE_SHIFT)
>  #define EFI_PAGE_MASK		(EFI_PAGE_SIZE - 1)
> 
>  struct efi_mem_desc {

Same issue for stm32mp157c-ev1 board (32bits platform with 1GB at 0xC0000000).

Patched tested on v2019.04 and my issue is solved and it is a better approach that my patch http://patchwork.ozlabs.org/patch/1083262/

So I will abandon my path and 

Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>


> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot


Regards

Patrick

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-11  8:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-09 20:58 [U-Boot] efi: fix memory calculation overflow on 32-bit systems Patrick Wildt
2019-04-10  0:36 ` [U-Boot] [PATCH 1/1] " Heinrich Schuchardt
2019-04-11  8:38 ` [U-Boot] " Patrick DELAUNAY

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.