Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1713239 > unrolled thread
| Started by | Alexander Potapenko <glider@google.com> |
|---|---|
| First post | 2017-08-16 21:10 +0200 |
| Last post | 2017-08-17 12:30 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] x86/boot/64: clang: use fixup_pointer() to access next_early_pgt Alexander Potapenko <glider@google.com> - 2017-08-16 21:10 +0200
Re: [PATCH] x86/boot/64: clang: use fixup_pointer() to access next_early_pgt Alexander Potapenko <glider@google.com> - 2017-08-16 21:20 +0200
Re: [PATCH] x86/boot/64: clang: use fixup_pointer() to access next_early_pgt "Kirill A. Shutemov" <kirill@shutemov.name> - 2017-08-17 00:20 +0200
[tip:x86/urgent] x86/boot/64/clang: Use fixup_pointer() to access 'next_early_pgt' tip-bot for Alexander Potapenko <tipbot@zytor.com> - 2017-08-17 12:30 +0200
| From | Alexander Potapenko <glider@google.com> |
|---|---|
| Date | 2017-08-16 21:10 +0200 |
| Subject | [PATCH] x86/boot/64: clang: use fixup_pointer() to access next_early_pgt |
| Message-ID | <ufbRw-2wV-11@gated-at.bofh.it> |
__startup_64() is normally using fixup_pointer() to access globals in a
position-independent fashion. However |next_early_pgt| was accessed
directly, which wasn't guaranteed to work.
Luckily GCC was generating a R_X86_64_PC32 PC-relative relocation for
|next_early_pgt|, but Clang emitted a R_X86_64_32S, which led to
accessing invalid memory and rebooting the kernel.
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Michael Davidson <md@google.com>
Fixes: c88d71508e36 ("x86/boot/64: Rewrite startup_64() in C")
Signed-off-by: Alexander Potapenko <glider@google.com>
---
arch/x86/kernel/head64.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 46c3c73e7f43..9ba79543d9ee 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -53,6 +53,7 @@ void __head __startup_64(unsigned long physaddr)
pudval_t *pud;
pmdval_t *pmd, pmd_entry;
int i;
+ unsigned int *next_pgt_ptr;
/* Is the address too large? */
if (physaddr >> MAX_PHYSMEM_BITS)
@@ -91,9 +92,9 @@ void __head __startup_64(unsigned long physaddr)
* creates a bunch of nonsense entries but that is fine --
* it avoids problems around wraparound.
*/
-
- pud = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr);
- pmd = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr);
+ next_pgt_ptr = fixup_pointer(&next_early_pgt, physaddr);
+ pud = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr);
+ pmd = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr);
if (IS_ENABLED(CONFIG_X86_5LEVEL)) {
p4d = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr);
--
2.14.1.480.gb18f417b89-goog
[toc] | [next] | [standalone]
| From | Alexander Potapenko <glider@google.com> |
|---|---|
| Date | 2017-08-16 21:20 +0200 |
| Message-ID | <ufc1c-2Al-15@gated-at.bofh.it> |
| In reply to | #1713239 |
On Wed, Aug 16, 2017 at 9:08 PM, Alexander Potapenko <glider@google.com> wrote:
> __startup_64() is normally using fixup_pointer() to access globals in a
> position-independent fashion. However |next_early_pgt| was accessed
> directly, which wasn't guaranteed to work.
>
> Luckily GCC was generating a R_X86_64_PC32 PC-relative relocation for
> |next_early_pgt|, but Clang emitted a R_X86_64_32S, which led to
> accessing invalid memory and rebooting the kernel.
>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: Michael Davidson <md@google.com>
> Fixes: c88d71508e36 ("x86/boot/64: Rewrite startup_64() in C")
> Signed-off-by: Alexander Potapenko <glider@google.com>
> ---
> arch/x86/kernel/head64.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
> index 46c3c73e7f43..9ba79543d9ee 100644
> --- a/arch/x86/kernel/head64.c
> +++ b/arch/x86/kernel/head64.c
> @@ -53,6 +53,7 @@ void __head __startup_64(unsigned long physaddr)
> pudval_t *pud;
> pmdval_t *pmd, pmd_entry;
> int i;
> + unsigned int *next_pgt_ptr;
>
> /* Is the address too large? */
> if (physaddr >> MAX_PHYSMEM_BITS)
> @@ -91,9 +92,9 @@ void __head __startup_64(unsigned long physaddr)
> * creates a bunch of nonsense entries but that is fine --
> * it avoids problems around wraparound.
> */
> -
> - pud = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr);
> - pmd = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr);
> + next_pgt_ptr = fixup_pointer(&next_early_pgt, physaddr);
> + pud = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr);
> + pmd = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr);
>
> if (IS_ENABLED(CONFIG_X86_5LEVEL)) {
> p4d = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr);
> --
> 2.14.1.480.gb18f417b89-goog
>
--
Alexander Potapenko
Software Engineer
Google Germany GmbH
Erika-Mann-Straße, 33
80636 München
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
[toc] | [prev] | [next] | [standalone]
| From | "Kirill A. Shutemov" <kirill@shutemov.name> |
|---|---|
| Date | 2017-08-17 00:20 +0200 |
| Subject | Re: [PATCH] x86/boot/64: clang: use fixup_pointer() to access next_early_pgt |
| Message-ID | <ufePo-4ml-7@gated-at.bofh.it> |
| In reply to | #1713239 |
On Wed, Aug 16, 2017 at 09:08:08PM +0200, Alexander Potapenko wrote:
> __startup_64() is normally using fixup_pointer() to access globals in a
> position-independent fashion. However |next_early_pgt| was accessed
> directly, which wasn't guaranteed to work.
>
> Luckily GCC was generating a R_X86_64_PC32 PC-relative relocation for
> |next_early_pgt|, but Clang emitted a R_X86_64_32S, which led to
> accessing invalid memory and rebooting the kernel.
Thanks for tracking this down.
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: Michael Davidson <md@google.com>
> Fixes: c88d71508e36 ("x86/boot/64: Rewrite startup_64() in C")
Cc: <stable@vger.kernel.org> # 4.12
--
Kirill A. Shutemov
[toc] | [prev] | [next] | [standalone]
| From | tip-bot for Alexander Potapenko <tipbot@zytor.com> |
|---|---|
| Date | 2017-08-17 12:30 +0200 |
| Subject | [tip:x86/urgent] x86/boot/64/clang: Use fixup_pointer() to access 'next_early_pgt' |
| Message-ID | <ufqdR-3w2-33@gated-at.bofh.it> |
| In reply to | #1713239 |
Commit-ID: 187e91fe5e915f4b7f39b824aa422493463e443d
Gitweb: http://git.kernel.org/tip/187e91fe5e915f4b7f39b824aa422493463e443d
Author: Alexander Potapenko <glider@google.com>
AuthorDate: Wed, 16 Aug 2017 21:08:08 +0200
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 17 Aug 2017 09:53:00 +0200
x86/boot/64/clang: Use fixup_pointer() to access 'next_early_pgt'
__startup_64() is normally using fixup_pointer() to access globals in a
position-independent fashion. However 'next_early_pgt' was accessed
directly, which wasn't guaranteed to work.
Luckily GCC was generating a R_X86_64_PC32 PC-relative relocation for
'next_early_pgt', but Clang emitted a R_X86_64_32S, which led to
accessing invalid memory and rebooting the kernel.
Signed-off-by: Alexander Potapenko <glider@google.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michael Davidson <md@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: c88d71508e36 ("x86/boot/64: Rewrite startup_64() in C")
Link: http://lkml.kernel.org/r/20170816190808.131748-1-glider@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/kernel/head64.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 46c3c73..9ba7954 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -53,6 +53,7 @@ void __head __startup_64(unsigned long physaddr)
pudval_t *pud;
pmdval_t *pmd, pmd_entry;
int i;
+ unsigned int *next_pgt_ptr;
/* Is the address too large? */
if (physaddr >> MAX_PHYSMEM_BITS)
@@ -91,9 +92,9 @@ void __head __startup_64(unsigned long physaddr)
* creates a bunch of nonsense entries but that is fine --
* it avoids problems around wraparound.
*/
-
- pud = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr);
- pmd = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr);
+ next_pgt_ptr = fixup_pointer(&next_early_pgt, physaddr);
+ pud = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr);
+ pmd = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr);
if (IS_ENABLED(CONFIG_X86_5LEVEL)) {
p4d = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr);
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web