2019-08-30 21:50:42

by Masayoshi Mizuma

[permalink] [raw]
Subject: [PATCH v3 0/5] Adjust the padding size for KASLR

From: Masayoshi Mizuma <[email protected]>

The system sometimes crashes while memory hot-adding on KASLR
enabled system. The crash happens because the regions pointed by
kaslr_regions[].base are overwritten by the hot-added memory.

It happens because of the padding size for kaslr_regions[].base isn't
enough for the system whose physical memory layout has huge space for
memory hotplug. kaslr_regions[].base points "actual installed
memory size + padding" or higher address. So, if the "actual + padding"
is lower address than the maximum memory address, which means the memory
address reachable by memory hot-add, kaslr_regions[].base is destroyed by
the overwritten.

address
^
|------- maximum memory address (Hotplug)
| ^
|------- kaslr_regions[0].base | Hotadd-able region
| ^ |
| | padding |
| V V
|------- actual memory address (Installed on boot)
|

Fix it by getting the maximum memory address from SRAT and store
the value in boot_param, then set the padding size while KASLR
initializing if the default padding size isn't enough.

Masayoshi Mizuma (5):
x86/boot: Wrap up the SRAT traversing code into subtable_parse()
x86/boot: Add max_addr field in struct boot_params
x86/boot: Get the max address from SRAT
x86/mm/KASLR: Cleanup calculation for direct mapping size
x86/mm/KASLR: Adjust the padding size for the direct mapping.

Documentation/x86/zero-page.rst | 4 ++
arch/x86/boot/compressed/acpi.c | 33 +++++++++---
arch/x86/include/uapi/asm/bootparam.h | 2 +-
arch/x86/mm/kaslr.c | 77 +++++++++++++++++++++------
4 files changed, 93 insertions(+), 23 deletions(-)

--
2.18.1


2019-08-30 21:50:41

by Masayoshi Mizuma

[permalink] [raw]
Subject: [PATCH v3 2/5] x86/boot: Add max_addr field in struct boot_params

From: Masayoshi Mizuma <[email protected]>

Add max_addr field in struct boot_params. max_addr shows the
maximum memory address to be reachable by memory hot-add.
max_addr is set by parsing ACPI SRAT.

Signed-off-by: Masayoshi Mizuma <[email protected]>
---
Documentation/x86/zero-page.rst | 4 ++++
arch/x86/include/uapi/asm/bootparam.h | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/x86/zero-page.rst b/Documentation/x86/zero-page.rst
index f088f5881..cc3938d68 100644
--- a/Documentation/x86/zero-page.rst
+++ b/Documentation/x86/zero-page.rst
@@ -19,6 +19,7 @@ Offset/Size Proto Name Meaning
058/008 ALL tboot_addr Physical address of tboot shared page
060/010 ALL ist_info Intel SpeedStep (IST) BIOS support information
(struct ist_info)
+078/010 ALL max_addr The possible maximum physical memory address [1]_
080/010 ALL hd0_info hd0 disk parameter, OBSOLETE!!
090/010 ALL hd1_info hd1 disk parameter, OBSOLETE!!
0A0/010 ALL sys_desc_table System description table (struct sys_desc_table),
@@ -43,3 +44,6 @@ Offset/Size Proto Name Meaning
(array of struct e820_entry)
D00/1EC ALL eddbuf EDD data (array of struct edd_info)
=========== ===== ======================= =================================================
+
+.. [1] max_addr shows the maximum memory address to be reachable by memory
+ hot-add. max_addr is set by parsing ACPI SRAT.
diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
index c895df548..6efad338b 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -158,7 +158,7 @@ struct boot_params {
__u64 tboot_addr; /* 0x058 */
struct ist_info ist_info; /* 0x060 */
__u64 acpi_rsdp_addr; /* 0x070 */
- __u8 _pad3[8]; /* 0x078 */
+ __u64 max_addr; /* 0x078 */
__u8 hd0_info[16]; /* obsolete! */ /* 0x080 */
__u8 hd1_info[16]; /* obsolete! */ /* 0x090 */
struct sys_desc_table sys_desc_table; /* obsolete! */ /* 0x0a0 */
--
2.18.1

2019-09-05 16:20:02

by Baoquan He

[permalink] [raw]
Subject: Re: [PATCH v3 2/5] x86/boot: Add max_addr field in struct boot_params

On 08/30/19 at 05:47pm, Masayoshi Mizuma wrote:
> From: Masayoshi Mizuma <[email protected]>
>
> Add max_addr field in struct boot_params. max_addr shows the
> maximum memory address to be reachable by memory hot-add.
> max_addr is set by parsing ACPI SRAT.
>
> Signed-off-by: Masayoshi Mizuma <[email protected]>
> ---
> Documentation/x86/zero-page.rst | 4 ++++
> arch/x86/include/uapi/asm/bootparam.h | 2 +-
> 2 files changed, 5 insertions(+), 1 deletion(-)

Reviewed-by: Baoquan He <[email protected]>

Thanks
Baoquan

>
> diff --git a/Documentation/x86/zero-page.rst b/Documentation/x86/zero-page.rst
> index f088f5881..cc3938d68 100644
> --- a/Documentation/x86/zero-page.rst
> +++ b/Documentation/x86/zero-page.rst
> @@ -19,6 +19,7 @@ Offset/Size Proto Name Meaning
> 058/008 ALL tboot_addr Physical address of tboot shared page
> 060/010 ALL ist_info Intel SpeedStep (IST) BIOS support information
> (struct ist_info)
> +078/010 ALL max_addr The possible maximum physical memory address [1]_
> 080/010 ALL hd0_info hd0 disk parameter, OBSOLETE!!
> 090/010 ALL hd1_info hd1 disk parameter, OBSOLETE!!
> 0A0/010 ALL sys_desc_table System description table (struct sys_desc_table),
> @@ -43,3 +44,6 @@ Offset/Size Proto Name Meaning
> (array of struct e820_entry)
> D00/1EC ALL eddbuf EDD data (array of struct edd_info)
> =========== ===== ======================= =================================================
> +
> +.. [1] max_addr shows the maximum memory address to be reachable by memory
> + hot-add. max_addr is set by parsing ACPI SRAT.
> diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
> index c895df548..6efad338b 100644
> --- a/arch/x86/include/uapi/asm/bootparam.h
> +++ b/arch/x86/include/uapi/asm/bootparam.h
> @@ -158,7 +158,7 @@ struct boot_params {
> __u64 tboot_addr; /* 0x058 */
> struct ist_info ist_info; /* 0x060 */
> __u64 acpi_rsdp_addr; /* 0x070 */
> - __u8 _pad3[8]; /* 0x078 */
> + __u64 max_addr; /* 0x078 */
> __u8 hd0_info[16]; /* obsolete! */ /* 0x080 */
> __u8 hd1_info[16]; /* obsolete! */ /* 0x090 */
> struct sys_desc_table sys_desc_table; /* obsolete! */ /* 0x0a0 */
> --
> 2.18.1
>

2019-10-29 07:26:07

by Baoquan He

[permalink] [raw]
Subject: Re: [PATCH v3 0/5] Adjust the padding size for KASLR

Hi Masa,

On 08/30/19 at 05:47pm, Masayoshi Mizuma wrote:
> From: Masayoshi Mizuma <[email protected]>

Any plan about this patchset?

Thanks
Baoquan

>
> The system sometimes crashes while memory hot-adding on KASLR
> enabled system. The crash happens because the regions pointed by
> kaslr_regions[].base are overwritten by the hot-added memory.
>
> It happens because of the padding size for kaslr_regions[].base isn't
> enough for the system whose physical memory layout has huge space for
> memory hotplug. kaslr_regions[].base points "actual installed
> memory size + padding" or higher address. So, if the "actual + padding"
> is lower address than the maximum memory address, which means the memory
> address reachable by memory hot-add, kaslr_regions[].base is destroyed by
> the overwritten.
>
> address
> ^
> |------- maximum memory address (Hotplug)
> | ^
> |------- kaslr_regions[0].base | Hotadd-able region
> | ^ |
> | | padding |
> | V V
> |------- actual memory address (Installed on boot)
> |
>
> Fix it by getting the maximum memory address from SRAT and store
> the value in boot_param, then set the padding size while KASLR
> initializing if the default padding size isn't enough.
>
> Masayoshi Mizuma (5):
> x86/boot: Wrap up the SRAT traversing code into subtable_parse()
> x86/boot: Add max_addr field in struct boot_params
> x86/boot: Get the max address from SRAT
> x86/mm/KASLR: Cleanup calculation for direct mapping size
> x86/mm/KASLR: Adjust the padding size for the direct mapping.
>
> Documentation/x86/zero-page.rst | 4 ++
> arch/x86/boot/compressed/acpi.c | 33 +++++++++---
> arch/x86/include/uapi/asm/bootparam.h | 2 +-
> arch/x86/mm/kaslr.c | 77 +++++++++++++++++++++------
> 4 files changed, 93 insertions(+), 23 deletions(-)
>
> --
> 2.18.1
>

2019-10-29 15:59:29

by Masayoshi Mizuma

[permalink] [raw]
Subject: Re: [PATCH v3 0/5] Adjust the padding size for KASLR

Hi Baoquan,

On Tue, Oct 29, 2019 at 10:59:20AM +0800, Baoquan He wrote:
> Hi Masa,
>
> On 08/30/19 at 05:47pm, Masayoshi Mizuma wrote:
> > From: Masayoshi Mizuma <[email protected]>
>
> Any plan about this patchset?

Thank you for pinging me and so sorry for the delay.
I'll post the v4 in this week.

Thanks,
Masa

>
> Thanks
> Baoquan
>
> >
> > The system sometimes crashes while memory hot-adding on KASLR
> > enabled system. The crash happens because the regions pointed by
> > kaslr_regions[].base are overwritten by the hot-added memory.
> >
> > It happens because of the padding size for kaslr_regions[].base isn't
> > enough for the system whose physical memory layout has huge space for
> > memory hotplug. kaslr_regions[].base points "actual installed
> > memory size + padding" or higher address. So, if the "actual + padding"
> > is lower address than the maximum memory address, which means the memory
> > address reachable by memory hot-add, kaslr_regions[].base is destroyed by
> > the overwritten.
> >
> > address
> > ^
> > |------- maximum memory address (Hotplug)
> > | ^
> > |------- kaslr_regions[0].base | Hotadd-able region
> > | ^ |
> > | | padding |
> > | V V
> > |------- actual memory address (Installed on boot)
> > |
> >
> > Fix it by getting the maximum memory address from SRAT and store
> > the value in boot_param, then set the padding size while KASLR
> > initializing if the default padding size isn't enough.
> >
> > Masayoshi Mizuma (5):
> > x86/boot: Wrap up the SRAT traversing code into subtable_parse()
> > x86/boot: Add max_addr field in struct boot_params
> > x86/boot: Get the max address from SRAT
> > x86/mm/KASLR: Cleanup calculation for direct mapping size
> > x86/mm/KASLR: Adjust the padding size for the direct mapping.
> >
> > Documentation/x86/zero-page.rst | 4 ++
> > arch/x86/boot/compressed/acpi.c | 33 +++++++++---
> > arch/x86/include/uapi/asm/bootparam.h | 2 +-
> > arch/x86/mm/kaslr.c | 77 +++++++++++++++++++++------
> > 4 files changed, 93 insertions(+), 23 deletions(-)
> >
> > --
> > 2.18.1
> >
>