2015-11-06 13:26:11

by Krzysztof Mazur

[permalink] [raw]
Subject: [PATCH] x86/setup: fix low identity map for >= 2GB kernel range

The commit f5f3497cad8c8416a74b9aaceb127908755d020a (x86/setup: Extend
low identity map to cover whole kernel range) extended the low identity
mapping. However, if the kernel uses more than 2 GB (VMSPLIT_2G_OPT or
VMSPLIT_1G memory split), the normal memory mapping is overwritten by
the low identity mapping causing crash. To avoid overwritting, limit the
low identity map to cover only memory before kernel range (PAGE_OFFSET).

Signed-off-by: Krzysztof Mazur <[email protected]>
---
The bug can be also fixed by copying identity mapping before copying
kernel address range, but this fix is smaller.

It might be also helpful to add a warning, if the low identity mapping
is truncated due to kernel mapping (KERNEL_PGD_BOUNDARY < KERNEL_PGD_PTRS).

arch/x86/kernel/setup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index a3cccbf..37c8ea8 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1180,7 +1180,7 @@ void __init setup_arch(char **cmdline_p)
*/
clone_pgd_range(initial_page_table,
swapper_pg_dir + KERNEL_PGD_BOUNDARY,
- KERNEL_PGD_PTRS);
+ min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
#endif

tboot_probe();
--
2.6.0


2015-11-06 13:27:42

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH] x86/setup: fix low identity map for >= 2GB kernel range

On Fri, Nov 06, 2015 at 02:18:36PM +0100, Krzysztof Mazur wrote:
> The commit f5f3497cad8c8416a74b9aaceb127908755d020a (x86/setup: Extend
> low identity map to cover whole kernel range) extended the low identity
> mapping. However, if the kernel uses more than 2 GB (VMSPLIT_2G_OPT or
> VMSPLIT_1G memory split), the normal memory mapping is overwritten by
> the low identity mapping causing crash. To avoid overwritting, limit the
> low identity map to cover only memory before kernel range (PAGE_OFFSET).
>
> Signed-off-by: Krzysztof Mazur <[email protected]>
> ---
> The bug can be also fixed by copying identity mapping before copying
> kernel address range, but this fix is smaller.
>
> It might be also helpful to add a warning, if the low identity mapping
> is truncated due to kernel mapping (KERNEL_PGD_BOUNDARY < KERNEL_PGD_PTRS).
>
> arch/x86/kernel/setup.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index a3cccbf..37c8ea8 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -1180,7 +1180,7 @@ void __init setup_arch(char **cmdline_p)
> */
> clone_pgd_range(initial_page_table,
> swapper_pg_dir + KERNEL_PGD_BOUNDARY,
> - KERNEL_PGD_PTRS);
> + min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
> #endif
>
> tboot_probe();

http://git.kernel.org/tip/1c5dac914794f0170e1582d8ffdee52d30e0e4dd

--
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.

2015-11-06 14:11:43

by Krzysztof Mazur

[permalink] [raw]
Subject: Re: [PATCH] x86/setup: fix low identity map for >= 2GB kernel range

On Fri, Nov 06, 2015 at 02:27:33PM +0100, Borislav Petkov wrote:
> On Fri, Nov 06, 2015 at 02:18:36PM +0100, Krzysztof Mazur wrote:
> > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> > index a3cccbf..37c8ea8 100644
> > --- a/arch/x86/kernel/setup.c
> > +++ b/arch/x86/kernel/setup.c
> > @@ -1180,7 +1180,7 @@ void __init setup_arch(char **cmdline_p)
> > */
> > clone_pgd_range(initial_page_table,
> > swapper_pg_dir + KERNEL_PGD_BOUNDARY,
> > - KERNEL_PGD_PTRS);
> > + min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
> > #endif
> >
> > tboot_probe();
>
> http://git.kernel.org/tip/1c5dac914794f0170e1582d8ffdee52d30e0e4dd
>

Thanks and sorry. Yes, it has been already fixed. I've rechecked only
mainline.

However, I think that there should be
min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY), not just KERNEL_PGD_BOUNDARY
(usually 768 for normal 1G/3G split), because swapper_pg_dir has only
1024 entries and 768+768 is 1536.

Krzysiek

2015-11-06 15:00:35

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH] x86/setup: fix low identity map for >= 2GB kernel range



On 06/11/2015 15:11, Krzysztof Mazur wrote:
>> >
>> > http://git.kernel.org/tip/1c5dac914794f0170e1582d8ffdee52d30e0e4dd
>> >
> Thanks and sorry. Yes, it has been already fixed. I've rechecked only
> mainline.
>
> However, I think that there should be
> min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY), not just KERNEL_PGD_BOUNDARY
> (usually 768 for normal 1G/3G split), because swapper_pg_dir has only
> 1024 entries and 768+768 is 1536.

You are right.

Paolo

2015-11-07 09:43:14

by Matt Fleming

[permalink] [raw]
Subject: Re: [PATCH] x86/setup: fix low identity map for >= 2GB kernel range

On Fri, 06 Nov, at 03:11:39PM, Krzysztof Mazur wrote:
> On Fri, Nov 06, 2015 at 02:27:33PM +0100, Borislav Petkov wrote:
> > On Fri, Nov 06, 2015 at 02:18:36PM +0100, Krzysztof Mazur wrote:
> > > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> > > index a3cccbf..37c8ea8 100644
> > > --- a/arch/x86/kernel/setup.c
> > > +++ b/arch/x86/kernel/setup.c
> > > @@ -1180,7 +1180,7 @@ void __init setup_arch(char **cmdline_p)
> > > */
> > > clone_pgd_range(initial_page_table,
> > > swapper_pg_dir + KERNEL_PGD_BOUNDARY,
> > > - KERNEL_PGD_PTRS);
> > > + min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
> > > #endif
> > >
> > > tboot_probe();
> >
> > http://git.kernel.org/tip/1c5dac914794f0170e1582d8ffdee52d30e0e4dd
> >
>
> Thanks and sorry. Yes, it has been already fixed. I've rechecked only
> mainline.
>
> However, I think that there should be
> min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY), not just KERNEL_PGD_BOUNDARY
> (usually 768 for normal 1G/3G split), because swapper_pg_dir has only
> 1024 entries and 768+768 is 1536.

Yeah, this fix is preferable to the one that is currently sitting in
tip/x86/urgent. Curse you VMSPLIT!

Subject: [tip:x86/urgent] x86/setup: Fix low identity map for >= 2GB kernel range

Commit-ID: 68accac392d859d24adcf1be3a90e41f978bd54c
Gitweb: http://git.kernel.org/tip/68accac392d859d24adcf1be3a90e41f978bd54c
Author: Krzysztof Mazur <[email protected]>
AuthorDate: Fri, 6 Nov 2015 14:18:36 +0100
Committer: Thomas Gleixner <[email protected]>
CommitDate: Sat, 7 Nov 2015 10:39:40 +0100

x86/setup: Fix low identity map for >= 2GB kernel range

The commit f5f3497cad8c extended the low identity mapping. However, if
the kernel uses more than 2 GB (VMSPLIT_2G_OPT or VMSPLIT_1G memory
split), the normal memory mapping is overwritten by the low identity
mapping causing a crash. To avoid overwritting, limit the low identity
map to cover only memory before kernel range (PAGE_OFFSET).

Fixes: f5f3497cad8c "x86/setup: Extend low identity map to cover whole kernel range
Signed-off-by: Krzysztof Mazur <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Thomas Gleixner <[email protected]>
---
arch/x86/kernel/setup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index a1e4da9..29db25f 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1188,7 +1188,7 @@ void __init setup_arch(char **cmdline_p)
*/
clone_pgd_range(initial_page_table,
swapper_pg_dir + KERNEL_PGD_BOUNDARY,
- KERNEL_PGD_PTRS);
+ min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
#endif

tboot_probe();