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


Groups > linux.kernel > #1274013

Re: [PATCH v2 1/5] x86/mm/pageattr: Ensure cpa->pfn only contains page frame numbers

From Matt Fleming <matt@codeblueprint.co.uk>
Newsgroups linux.kernel
Subject Re: [PATCH v2 1/5] x86/mm/pageattr: Ensure cpa->pfn only contains page frame numbers
Date 2015-11-20 13:10 +0100
Message-ID <qwSFQ-71A-21@gated-at.bofh.it> (permalink)
References <quRbc-1jj-11@gated-at.bofh.it> <quRbc-1jj-31@gated-at.bofh.it> <qvyzw-3C8-13@gated-at.bofh.it> <qvL3I-3gw-15@gated-at.bofh.it> <qw68a-jO-31@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, 18 Nov, at 09:14:23AM, Ingo Molnar wrote:
> 
> * Matt Fleming <matt@codeblueprint.co.uk> wrote:
> 
> > > > +	npages = (_end - _text) >> PAGE_SHIFT;
> > > 
> > > You really need to PFN_ALIGN _end and _text. Has been wrong in the
> > > existing code as well.
> >  
> > Hmm... very good point.
> 
> So I think we should instead guarantee that _end and _text are page aligned.
> 
> _text is already page aligned:
> 
> SECTIONS
> {
> #ifdef CONFIG_X86_32
>         . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
>         phys_startup_32 = startup_32 - LOAD_OFFSET;
> #else
>         . = __START_KERNEL;
>         phys_startup_64 = startup_64 - LOAD_OFFSET;
> #endif
> 
>         /* Text and read-only data */
>         .text :  AT(ADDR(.text) - LOAD_OFFSET) {
>                 _text = .;
> 
> The reason for aligning _end as well is that we already page-align the BSS and BRK 
> sections of the kernel and its various section boundary symbols:
> 
>         /* BSS */
>         . = ALIGN(PAGE_SIZE);
>         .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
>                 __bss_start = .;
>                 *(.bss..page_aligned)
>                 *(.bss)
>                 . = ALIGN(PAGE_SIZE);
>                 __bss_stop = .;
>         }
> 
>         . = ALIGN(PAGE_SIZE);
>         .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
>                 __brk_base = .;
>                 . += 64 * 1024;         /* 64k alignment slop space */
>                 *(.brk_reservation)     /* areas brk users have reserved */
>                 __brk_limit = .;
>         }
> 
>         _end = .;
> 
>         STABS_DEBUG
>         DWARF_DEBUG
> 
> _end is the only odd one out, so we should align it as well - because it's easy to 
> make such pfn conversion bugs.

FWIW, I saw no changes in either 32-bit or 64-bit vmlinux size when
building with the following patch, so it seems like a pretty easy win,

---

From 25ad518fa52e589f110376ae06e42fb20b3e4188 Mon Sep 17 00:00:00 2001
From: Matt Fleming <matt@codeblueprint.co.uk>
Date: Fri, 20 Nov 2015 11:46:11 +0000
Subject: [PATCH] x86: Page align _end to avoid pfn conversion bugs

Ingo noted that if we can guarantee _end is aligned to PAGE_SIZE we
can automatically avoid bugs along the lines of,

	size = _end - _text >> PAGE_SHIFT

which is missing a call to PFN_ALIGN(). The EFI mixed mode contains
this bug, for example.

_text is already aligned to PAGE_SIZE through the use of
LOAD_PHYSICAL_ADDR, and the BSS and BRK sections are explicitly
aligned in the linker script, so it makes sense to align _end to
match.

Reported-by: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H . Peter Anvin" <hpa@zytor.com>
Cc: Toshi Kani <toshi.kani@hp.com>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
---
 arch/x86/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 74e4bf11f562..4f1994257a18 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -325,6 +325,7 @@ SECTIONS
 		__brk_limit = .;
 	}
 
+	. = ALIGN(PAGE_SIZE);
 	_end = .;
 
         STABS_DEBUG
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: [PATCH v2 1/5] x86/mm/pageattr: Ensure cpa->pfn only contains  page frame numbers Thomas Gleixner <tglx@linutronix.de> - 2015-11-16 21:30 +0100
  Re: [PATCH v2 1/5] x86/mm/pageattr: Ensure cpa->pfn only contains  page frame numbers Borislav Petkov <bp@suse.de> - 2015-11-16 22:30 +0100
    Re: [PATCH v2 1/5] x86/mm/pageattr: Ensure cpa->pfn only contains  page frame numbers Thomas Gleixner <tglx@linutronix.de> - 2015-11-16 22:50 +0100
      Re: [PATCH v2 1/5] x86/mm/pageattr: Ensure cpa->pfn only contains  page frame numbers Thomas Gleixner <tglx@linutronix.de> - 2015-11-17 10:00 +0100
  Re: [PATCH v2 1/5] x86/mm/pageattr: Ensure cpa->pfn only contains  page frame numbers Matt Fleming <matt@codeblueprint.co.uk> - 2015-11-17 10:50 +0100
    Re: [PATCH v2 1/5] x86/mm/pageattr: Ensure cpa->pfn only contains  page frame numbers Ingo Molnar <mingo@kernel.org> - 2015-11-18 09:20 +0100
      Re: [PATCH v2 1/5] x86/mm/pageattr: Ensure cpa->pfn only contains  page frame numbers Matt Fleming <matt@codeblueprint.co.uk> - 2015-11-20 13:10 +0100

csiph-web