Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1703741 > unrolled thread

[PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions

Started byBaoquan He <bhe@redhat.com>
First post2017-08-04 09:30 +0200
Last post2017-08-04 12:50 +0200
Articles 7 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions Baoquan He <bhe@redhat.com> - 2017-08-04 09:30 +0200
    [PATCH v8 1/2] efi: Introduce efi_memdesc_ptr to get pointer to memmap descriptor Baoquan He <bhe@redhat.com> - 2017-08-04 09:30 +0200
    Re: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized  in mirror regions Baoquan He <bhe@redhat.com> - 2017-08-04 10:00 +0200
      Re: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized  in mirror regions Baoquan He <bhe@redhat.com> - 2017-08-04 11:30 +0200
        Re: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized  in mirror regions Chao Fan <fanc.fnst@cn.fujitsu.com> - 2017-08-04 11:50 +0200
        Re: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized  in mirror regions Chao Fan <fanc.fnst@cn.fujitsu.com> - 2017-08-04 12:00 +0200
          Re: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized  in mirror regions Baoquan He <bhe@redhat.com> - 2017-08-04 12:50 +0200

#1703741 — [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions

FromBaoquan He <bhe@redhat.com>
Date2017-08-04 09:30 +0200
Subject[PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions
Message-ID<uaFdv-3Yv-7@gated-at.bofh.it>
Patch 1/2 is newly added to add efi_memdesc_ptr helper to wrap the
open code which gets the start of efi memmap descriptor and also
explain why it need be done like that, Ingo suggested it. 

And also replace several places of the open code with efi_memdesc_ptr
helper.

And also use efi_memdesc_ptr in process_efi_entries() which handle efi
mirror issue during KASLR.


Change:
v7->v8:
    Add efi_memdesc_ptr helper to wrap the open code which gets the
    start of map descriptor according to Ingo's suggestion.

v6->v7:
  Ingo pointed out several incorrect line break issues and unclear
  description of patch log. Correct them and rewrite patch log.

  And also rewrite the EFI warning message that if EFI memmap is above
  4G in 32bit system since 32bit system can not handle data above 4G at
  kernel decompression stage. This is suggested by Ingo too.

v5->v6:
  Code style issue fix according to Kees's comment.

  This is based on tip/x86/boot, patch 1,2,3/4 in v5 post has
  been put into tip/x86/boot now.



Baoquan He (2):
  efi: Introduce efi_memdesc_ptr to get pointer to memmap descriptor
  x86/boot/KASLR: Restrict kernel to be randomized in mirror regions

 arch/x86/boot/compressed/eboot.c               |  2 +-
 arch/x86/boot/compressed/kaslr.c               | 68 +++++++++++++++++++++++++-
 drivers/firmware/efi/libstub/efi-stub-helper.c |  4 +-
 include/linux/efi.h                            | 19 +++++++
 4 files changed, 88 insertions(+), 5 deletions(-)

-- 
2.5.5

[toc] | [next] | [standalone]


#1703742 — [PATCH v8 1/2] efi: Introduce efi_memdesc_ptr to get pointer to memmap descriptor

FromBaoquan He <bhe@redhat.com>
Date2017-08-04 09:30 +0200
Subject[PATCH v8 1/2] efi: Introduce efi_memdesc_ptr to get pointer to memmap descriptor
Message-ID<uaFdv-3Yv-15@gated-at.bofh.it>
In reply to#1703741
The existing map iteration helper for_each_efi_memory_desc_in_map can
only be used after OS initializes EFI to fill data of struct efi_memory_map.
Before that we also need iterate map descriptors which are stored in several
intermediate structures, like struct efi_boot_memmap for arch independent
usage and struct efi_info for x86 ARCH only.

Introduce efi_memdesc_ptr to get pointer to a map descriptor, and replace
several places of open code with it.

Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Baoquan He <bhe@redhat.com>
---
 arch/x86/boot/compressed/eboot.c               |  2 +-
 drivers/firmware/efi/libstub/efi-stub-helper.c |  4 ++--
 include/linux/efi.h                            | 19 +++++++++++++++++++
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index c3e869eaef0c..31e12b43be77 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -767,7 +767,7 @@ static efi_status_t setup_e820(struct boot_params *params,
 		m |= (u64)efi->efi_memmap_hi << 32;
 #endif
 
-		d = (efi_memory_desc_t *)(m + (i * efi->efi_memdesc_size));
+		d = efi_memdesc_ptr(m, efi->efi_memdesc_size, i);
 		switch (d->type) {
 		case EFI_RESERVED_TYPE:
 		case EFI_RUNTIME_SERVICES_CODE:
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index b0184360efc6..2db55c32e7ed 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -205,7 +205,7 @@ efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
 		unsigned long m = (unsigned long)map;
 		u64 start, end;
 
-		desc = (efi_memory_desc_t *)(m + (i * desc_size));
+		desc = efi_memdesc_ptr(m, desc_size, i);
 		if (desc->type != EFI_CONVENTIONAL_MEMORY)
 			continue;
 
@@ -298,7 +298,7 @@ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
 		unsigned long m = (unsigned long)map;
 		u64 start, end;
 
-		desc = (efi_memory_desc_t *)(m + (i * desc_size));
+		desc = efi_memdesc_ptr(m, desc_size, i);
 
 		if (desc->type != EFI_CONVENTIONAL_MEMORY)
 			continue;
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 8269bcb8ccf7..9a6ea328705f 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -1020,6 +1020,25 @@ extern int efi_memattr_init(void);
 extern int efi_memattr_apply_permissions(struct mm_struct *mm,
 					 efi_memattr_perm_setter fn);
 
+/*
+ * efi_memdesc_ptr - get the n-th efi memmap descriptor
+ * @map: the start of efi memmap
+ * @desc_size: the size of space for each efi memmap descriptor
+ * @n: the index of efi memmap descriptor
+ *
+ * EFI boot service provides function GetMemoryMap() to get a copy of the
+ * current memory map which is an array of memory descriptors, each of
+ * which describes a contiguous block of memory. And also get the size of
+ * map, and the size of each descriptor, etc. Note that per section 6.2 of
+ * UEFI Spec 2.6 Errata A, the returned size of each descriptor might not
+ * be equal to sizeof(efi_memory_memdesc_t) since efi_memory_memdesc_t may
+ * be extended in the future in response to hardware innovation. Thus OS
+ * MUST use the returned size of descriptor to find the start of each
+ * efi_memory_memdesc_t in the memory map array.
+ */
+#define efi_memdesc_ptr(map, desc_size, n)				\
+	(efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
+
 /* Iterate through an efi_memory_map */
 #define for_each_efi_memory_desc_in_map(m, md)				   \
 	for ((md) = (m)->map;						   \
-- 
2.5.5

[toc] | [prev] | [next] | [standalone]


#1703766 — Re: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions

FromBaoquan He <bhe@redhat.com>
Date2017-08-04 10:00 +0200
SubjectRe: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions
Message-ID<uaFGy-4bb-15@gated-at.bofh.it>
In reply to#1703741
Sorry, NACK this series, there's error to hang system. Before I just
halt system intentionally with error() to check the efi memmap printing,
didn't notice this. Checking the cause.

On 08/04/17 at 03:26pm, Baoquan He wrote:
> Patch 1/2 is newly added to add efi_memdesc_ptr helper to wrap the
> open code which gets the start of efi memmap descriptor and also
> explain why it need be done like that, Ingo suggested it. 
> 
> And also replace several places of the open code with efi_memdesc_ptr
> helper.
> 
> And also use efi_memdesc_ptr in process_efi_entries() which handle efi
> mirror issue during KASLR.
> 
> 
> Change:
> v7->v8:
>     Add efi_memdesc_ptr helper to wrap the open code which gets the
>     start of map descriptor according to Ingo's suggestion.
> 
> v6->v7:
>   Ingo pointed out several incorrect line break issues and unclear
>   description of patch log. Correct them and rewrite patch log.
> 
>   And also rewrite the EFI warning message that if EFI memmap is above
>   4G in 32bit system since 32bit system can not handle data above 4G at
>   kernel decompression stage. This is suggested by Ingo too.
> 
> v5->v6:
>   Code style issue fix according to Kees's comment.
> 
>   This is based on tip/x86/boot, patch 1,2,3/4 in v5 post has
>   been put into tip/x86/boot now.
> 
> 
> 
> Baoquan He (2):
>   efi: Introduce efi_memdesc_ptr to get pointer to memmap descriptor
>   x86/boot/KASLR: Restrict kernel to be randomized in mirror regions
> 
>  arch/x86/boot/compressed/eboot.c               |  2 +-
>  arch/x86/boot/compressed/kaslr.c               | 68 +++++++++++++++++++++++++-
>  drivers/firmware/efi/libstub/efi-stub-helper.c |  4 +-
>  include/linux/efi.h                            | 19 +++++++
>  4 files changed, 88 insertions(+), 5 deletions(-)
> 
> -- 
> 2.5.5
> 

[toc] | [prev] | [next] | [standalone]


#1703819 — Re: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions

FromBaoquan He <bhe@redhat.com>
Date2017-08-04 11:30 +0200
SubjectRe: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions
Message-ID<uaH5D-5ax-13@gated-at.bofh.it>
In reply to#1703766
On 08/04/17 at 03:52pm, Baoquan He wrote:
> Sorry, NACK this series, there's error to hang system. Before I just
> halt system intentionally with error() to check the efi memmap printing,
> didn't notice this. Checking the cause.

I rebuilt the code or change the one of the replacement back, hang never
seen again. Not sure if I copied the wrong kernel or any other mistakes.
Have got a hardware system with efi enabled to try again, see if
anything wrong will happen. It's really weird. And Chao also is helping
to try on his side.

> 
> On 08/04/17 at 03:26pm, Baoquan He wrote:
> > Patch 1/2 is newly added to add efi_memdesc_ptr helper to wrap the
> > open code which gets the start of efi memmap descriptor and also
> > explain why it need be done like that, Ingo suggested it. 
> > 
> > And also replace several places of the open code with efi_memdesc_ptr
> > helper.
> > 
> > And also use efi_memdesc_ptr in process_efi_entries() which handle efi
> > mirror issue during KASLR.
> > 
> > 
> > Change:
> > v7->v8:
> >     Add efi_memdesc_ptr helper to wrap the open code which gets the
> >     start of map descriptor according to Ingo's suggestion.
> > 
> > v6->v7:
> >   Ingo pointed out several incorrect line break issues and unclear
> >   description of patch log. Correct them and rewrite patch log.
> > 
> >   And also rewrite the EFI warning message that if EFI memmap is above
> >   4G in 32bit system since 32bit system can not handle data above 4G at
> >   kernel decompression stage. This is suggested by Ingo too.
> > 
> > v5->v6:
> >   Code style issue fix according to Kees's comment.
> > 
> >   This is based on tip/x86/boot, patch 1,2,3/4 in v5 post has
> >   been put into tip/x86/boot now.
> > 
> > 
> > 
> > Baoquan He (2):
> >   efi: Introduce efi_memdesc_ptr to get pointer to memmap descriptor
> >   x86/boot/KASLR: Restrict kernel to be randomized in mirror regions
> > 
> >  arch/x86/boot/compressed/eboot.c               |  2 +-
> >  arch/x86/boot/compressed/kaslr.c               | 68 +++++++++++++++++++++++++-
> >  drivers/firmware/efi/libstub/efi-stub-helper.c |  4 +-
> >  include/linux/efi.h                            | 19 +++++++
> >  4 files changed, 88 insertions(+), 5 deletions(-)
> > 
> > -- 
> > 2.5.5
> > 

[toc] | [prev] | [next] | [standalone]


#1703832 — Re: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions

FromChao Fan <fanc.fnst@cn.fujitsu.com>
Date2017-08-04 11:50 +0200
SubjectRe: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions
Message-ID<uaHoZ-5ix-3@gated-at.bofh.it>
In reply to#1703819
On Fri, Aug 04, 2017 at 05:22:41PM +0800, Baoquan He wrote:
>On 08/04/17 at 03:52pm, Baoquan He wrote:
>> Sorry, NACK this series, there's error to hang system. Before I just
>> halt system intentionally with error() to check the efi memmap printing,
>> didn't notice this. Checking the cause.
>
>I rebuilt the code or change the one of the replacement back, hang never
>seen again. Not sure if I copied the wrong kernel or any other mistakes.
>Have got a hardware system with efi enabled to try again, see if
>anything wrong will happen. It's really weird. And Chao also is helping

Maybe a little later, cause from tommorow, I will be on vacation for 9
days.

Thanks,
Chao Fan

>to try on his side.
>
>> 
>> On 08/04/17 at 03:26pm, Baoquan He wrote:
>> > Patch 1/2 is newly added to add efi_memdesc_ptr helper to wrap the
>> > open code which gets the start of efi memmap descriptor and also
>> > explain why it need be done like that, Ingo suggested it. 
>> > 
>> > And also replace several places of the open code with efi_memdesc_ptr
>> > helper.
>> > 
>> > And also use efi_memdesc_ptr in process_efi_entries() which handle efi
>> > mirror issue during KASLR.
>> > 
>> > 
>> > Change:
>> > v7->v8:
>> >     Add efi_memdesc_ptr helper to wrap the open code which gets the
>> >     start of map descriptor according to Ingo's suggestion.
>> > 
>> > v6->v7:
>> >   Ingo pointed out several incorrect line break issues and unclear
>> >   description of patch log. Correct them and rewrite patch log.
>> > 
>> >   And also rewrite the EFI warning message that if EFI memmap is above
>> >   4G in 32bit system since 32bit system can not handle data above 4G at
>> >   kernel decompression stage. This is suggested by Ingo too.
>> > 
>> > v5->v6:
>> >   Code style issue fix according to Kees's comment.
>> > 
>> >   This is based on tip/x86/boot, patch 1,2,3/4 in v5 post has
>> >   been put into tip/x86/boot now.
>> > 
>> > 
>> > 
>> > Baoquan He (2):
>> >   efi: Introduce efi_memdesc_ptr to get pointer to memmap descriptor
>> >   x86/boot/KASLR: Restrict kernel to be randomized in mirror regions
>> > 
>> >  arch/x86/boot/compressed/eboot.c               |  2 +-
>> >  arch/x86/boot/compressed/kaslr.c               | 68 +++++++++++++++++++++++++-
>> >  drivers/firmware/efi/libstub/efi-stub-helper.c |  4 +-
>> >  include/linux/efi.h                            | 19 +++++++
>> >  4 files changed, 88 insertions(+), 5 deletions(-)
>> > 
>> > -- 
>> > 2.5.5
>> > 
>
>

[toc] | [prev] | [next] | [standalone]


#1703837 — Re: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions

FromChao Fan <fanc.fnst@cn.fujitsu.com>
Date2017-08-04 12:00 +0200
SubjectRe: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions
Message-ID<uaHyG-5lE-7@gated-at.bofh.it>
In reply to#1703819
On Fri, Aug 04, 2017 at 05:22:41PM +0800, Baoquan He wrote:
>On 08/04/17 at 03:52pm, Baoquan He wrote:
>> Sorry, NACK this series, there's error to hang system. Before I just
>> halt system intentionally with error() to check the efi memmap printing,
>> didn't notice this. Checking the cause.
>
>I rebuilt the code or change the one of the replacement back, hang never
>seen again. Not sure if I copied the wrong kernel or any other mistakes.
>Have got a hardware system with efi enabled to try again, see if
>anything wrong will happen. It's really weird. And Chao also is helping
>to try on his side.

Hi Bao,

After testing for 10 times, no problem happened.
Maybe you did something wrong in the first time.

Thanks,
Chao Fan

>
>> 
>> On 08/04/17 at 03:26pm, Baoquan He wrote:
>> > Patch 1/2 is newly added to add efi_memdesc_ptr helper to wrap the
>> > open code which gets the start of efi memmap descriptor and also
>> > explain why it need be done like that, Ingo suggested it. 
>> > 
>> > And also replace several places of the open code with efi_memdesc_ptr
>> > helper.
>> > 
>> > And also use efi_memdesc_ptr in process_efi_entries() which handle efi
>> > mirror issue during KASLR.
>> > 
>> > 
>> > Change:
>> > v7->v8:
>> >     Add efi_memdesc_ptr helper to wrap the open code which gets the
>> >     start of map descriptor according to Ingo's suggestion.
>> > 
>> > v6->v7:
>> >   Ingo pointed out several incorrect line break issues and unclear
>> >   description of patch log. Correct them and rewrite patch log.
>> > 
>> >   And also rewrite the EFI warning message that if EFI memmap is above
>> >   4G in 32bit system since 32bit system can not handle data above 4G at
>> >   kernel decompression stage. This is suggested by Ingo too.
>> > 
>> > v5->v6:
>> >   Code style issue fix according to Kees's comment.
>> > 
>> >   This is based on tip/x86/boot, patch 1,2,3/4 in v5 post has
>> >   been put into tip/x86/boot now.
>> > 
>> > 
>> > 
>> > Baoquan He (2):
>> >   efi: Introduce efi_memdesc_ptr to get pointer to memmap descriptor
>> >   x86/boot/KASLR: Restrict kernel to be randomized in mirror regions
>> > 
>> >  arch/x86/boot/compressed/eboot.c               |  2 +-
>> >  arch/x86/boot/compressed/kaslr.c               | 68 +++++++++++++++++++++++++-
>> >  drivers/firmware/efi/libstub/efi-stub-helper.c |  4 +-
>> >  include/linux/efi.h                            | 19 +++++++
>> >  4 files changed, 88 insertions(+), 5 deletions(-)
>> > 
>> > -- 
>> > 2.5.5
>> > 
>
>

[toc] | [prev] | [next] | [standalone]


#1703866 — Re: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions

FromBaoquan He <bhe@redhat.com>
Date2017-08-04 12:50 +0200
SubjectRe: [PATCH v8 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions
Message-ID<uaIl4-5QW-17@gated-at.bofh.it>
In reply to#1703837
On 08/04/17 at 05:59pm, Chao Fan wrote:
> On Fri, Aug 04, 2017 at 05:22:41PM +0800, Baoquan He wrote:
> >On 08/04/17 at 03:52pm, Baoquan He wrote:
> >> Sorry, NACK this series, there's error to hang system. Before I just
> >> halt system intentionally with error() to check the efi memmap printing,
> >> didn't notice this. Checking the cause.
> >
> >I rebuilt the code or change the one of the replacement back, hang never
> >seen again. Not sure if I copied the wrong kernel or any other mistakes.
> >Have got a hardware system with efi enabled to try again, see if
> >anything wrong will happen. It's really weird. And Chao also is helping
> >to try on his side.
> 
> Hi Bao,
> 
> After testing for 10 times, no problem happened.
> Maybe you did something wrong in the first time.

Thanks, Chao. I tried several times on a machine with efi enabled, no
problem found.

Sorry, guys, so it's a false alarm.

> >
> >> 
> >> On 08/04/17 at 03:26pm, Baoquan He wrote:
> >> > Patch 1/2 is newly added to add efi_memdesc_ptr helper to wrap the
> >> > open code which gets the start of efi memmap descriptor and also
> >> > explain why it need be done like that, Ingo suggested it. 
> >> > 
> >> > And also replace several places of the open code with efi_memdesc_ptr
> >> > helper.
> >> > 
> >> > And also use efi_memdesc_ptr in process_efi_entries() which handle efi
> >> > mirror issue during KASLR.
> >> > 
> >> > 
> >> > Change:
> >> > v7->v8:
> >> >     Add efi_memdesc_ptr helper to wrap the open code which gets the
> >> >     start of map descriptor according to Ingo's suggestion.
> >> > 
> >> > v6->v7:
> >> >   Ingo pointed out several incorrect line break issues and unclear
> >> >   description of patch log. Correct them and rewrite patch log.
> >> > 
> >> >   And also rewrite the EFI warning message that if EFI memmap is above
> >> >   4G in 32bit system since 32bit system can not handle data above 4G at
> >> >   kernel decompression stage. This is suggested by Ingo too.
> >> > 
> >> > v5->v6:
> >> >   Code style issue fix according to Kees's comment.
> >> > 
> >> >   This is based on tip/x86/boot, patch 1,2,3/4 in v5 post has
> >> >   been put into tip/x86/boot now.
> >> > 
> >> > 
> >> > 
> >> > Baoquan He (2):
> >> >   efi: Introduce efi_memdesc_ptr to get pointer to memmap descriptor
> >> >   x86/boot/KASLR: Restrict kernel to be randomized in mirror regions
> >> > 
> >> >  arch/x86/boot/compressed/eboot.c               |  2 +-
> >> >  arch/x86/boot/compressed/kaslr.c               | 68 +++++++++++++++++++++++++-
> >> >  drivers/firmware/efi/libstub/efi-stub-helper.c |  4 +-
> >> >  include/linux/efi.h                            | 19 +++++++
> >> >  4 files changed, 88 insertions(+), 5 deletions(-)
> >> > 
> >> > -- 
> >> > 2.5.5
> >> > 
> >
> >
> 
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web