linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: page-align sections for DEBUG_RODATA
@ 2015-10-26 21:42 Mark Rutland
  2015-10-27  2:37 ` Ard Biesheuvel
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Rutland @ 2015-10-26 21:42 UTC (permalink / raw)
  To: linux-arm-kernel

A kernel built with DEBUG_RO_DATA && !CONFIG_DEBUG_ALIGN_RODATA doesn't
have .text aligned to a page boundary, though fixup_executable works at
page-granularity thanks to its use of create_mapping. If .text is not
page-aligned, the first page it exists in may be marked non-executable,
leading to failures when an attempt is made to execute code in said
page.

This patch upgrades ALIGN_DEBUG_RO and ALIGN_DEBUG_RO_MIN to force page
alignment for DEBUG_RO_DATA && !CONFIG_DEBUG_ALIGN_RODATA kernels,
ensuring that all sections with specific RWX permission requirements are
mapped with the correct permissions.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reported-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Laura Abbott <laura@labbott.name>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Suzuki Poulose <suzuki.poulose@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
---
 arch/arm64/kernel/vmlinux.lds.S | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Note: this is intended to supercede [1,2].

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/380486.html
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/380999.html

diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 9807333..4d77757 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -60,9 +60,12 @@ PECOFF_FILE_ALIGNMENT = 0x200;
 #define PECOFF_EDATA_PADDING
 #endif
 
-#ifdef CONFIG_DEBUG_ALIGN_RODATA
+#if defined(CONFIG_DEBUG_ALIGN_RODATA)
 #define ALIGN_DEBUG_RO			. = ALIGN(1<<SECTION_SHIFT);
 #define ALIGN_DEBUG_RO_MIN(min)		ALIGN_DEBUG_RO
+#elif defined(CONFIG_DEBUG_RODATA)
+#define ALIGN_DEBUG_RO			. = ALIGN(1<<PAGE_SHIFT);
+#define ALIGN_DEBUG_RO_MIN(min)		ALIGN_DEBUG_RO
 #else
 #define ALIGN_DEBUG_RO
 #define ALIGN_DEBUG_RO_MIN(min)		. = ALIGN(min);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] arm64: page-align sections for DEBUG_RODATA
  2015-10-26 21:42 [PATCH] arm64: page-align sections for DEBUG_RODATA Mark Rutland
@ 2015-10-27  2:37 ` Ard Biesheuvel
  2015-10-27 10:56   ` Mark Rutland
  0 siblings, 1 reply; 4+ messages in thread
From: Ard Biesheuvel @ 2015-10-27  2:37 UTC (permalink / raw)
  To: linux-arm-kernel

On 27 October 2015 at 06:42, Mark Rutland <mark.rutland@arm.com> wrote:
> A kernel built with DEBUG_RO_DATA && !CONFIG_DEBUG_ALIGN_RODATA doesn't
> have .text aligned to a page boundary, though fixup_executable works at
> page-granularity thanks to its use of create_mapping. If .text is not
> page-aligned, the first page it exists in may be marked non-executable,
> leading to failures when an attempt is made to execute code in said
> page.
>
> This patch upgrades ALIGN_DEBUG_RO and ALIGN_DEBUG_RO_MIN to force page
> alignment for DEBUG_RO_DATA && !CONFIG_DEBUG_ALIGN_RODATA kernels,
> ensuring that all sections with specific RWX permission requirements are
> mapped with the correct permissions.
>
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Reported-by: Jeremy Linton <jeremy.linton@arm.com>
> Reviewed-by: Laura Abbott <laura@labbott.name>
> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Suzuki Poulose <suzuki.poulose@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> ---
>  arch/arm64/kernel/vmlinux.lds.S | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> Note: this is intended to supercede [1,2].
>
> [1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/380486.html
> [2] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/380999.html
>
> diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
> index 9807333..4d77757 100644
> --- a/arch/arm64/kernel/vmlinux.lds.S
> +++ b/arch/arm64/kernel/vmlinux.lds.S
> @@ -60,9 +60,12 @@ PECOFF_FILE_ALIGNMENT = 0x200;
>  #define PECOFF_EDATA_PADDING
>  #endif
>
> -#ifdef CONFIG_DEBUG_ALIGN_RODATA
> +#if defined(CONFIG_DEBUG_ALIGN_RODATA)
>  #define ALIGN_DEBUG_RO                 . = ALIGN(1<<SECTION_SHIFT);
>  #define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
> +#elif defined(CONFIG_DEBUG_RODATA)
> +#define ALIGN_DEBUG_RO                 . = ALIGN(1<<PAGE_SHIFT);
> +#define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
>  #else
>  #define ALIGN_DEBUG_RO
>  #define ALIGN_DEBUG_RO_MIN(min)                . = ALIGN(min);

Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] arm64: page-align sections for DEBUG_RODATA
  2015-10-27  2:37 ` Ard Biesheuvel
@ 2015-10-27 10:56   ` Mark Rutland
  2015-10-29 17:25     ` Catalin Marinas
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Rutland @ 2015-10-27 10:56 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Oct 27, 2015 at 11:37:04AM +0900, Ard Biesheuvel wrote:
> On 27 October 2015 at 06:42, Mark Rutland <mark.rutland@arm.com> wrote:
> > A kernel built with DEBUG_RO_DATA && !CONFIG_DEBUG_ALIGN_RODATA doesn't
> > have .text aligned to a page boundary, though fixup_executable works at
> > page-granularity thanks to its use of create_mapping. If .text is not
> > page-aligned, the first page it exists in may be marked non-executable,
> > leading to failures when an attempt is made to execute code in said
> > page.
> >
> > This patch upgrades ALIGN_DEBUG_RO and ALIGN_DEBUG_RO_MIN to force page
> > alignment for DEBUG_RO_DATA && !CONFIG_DEBUG_ALIGN_RODATA kernels,
> > ensuring that all sections with specific RWX permission requirements are
> > mapped with the correct permissions.
> >
> > Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> > Reported-by: Jeremy Linton <jeremy.linton@arm.com>
> > Reviewed-by: Laura Abbott <laura@labbott.name>
> > Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > Cc: Suzuki Poulose <suzuki.poulose@arm.com>
> > Cc: Will Deacon <will.deacon@arm.com>
> > ---
> >  arch/arm64/kernel/vmlinux.lds.S | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > Note: this is intended to supercede [1,2].
> >
> > [1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/380486.html
> > [2] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/380999.html
> >
> > diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
> > index 9807333..4d77757 100644
> > --- a/arch/arm64/kernel/vmlinux.lds.S
> > +++ b/arch/arm64/kernel/vmlinux.lds.S
> > @@ -60,9 +60,12 @@ PECOFF_FILE_ALIGNMENT = 0x200;
> >  #define PECOFF_EDATA_PADDING
> >  #endif
> >
> > -#ifdef CONFIG_DEBUG_ALIGN_RODATA
> > +#if defined(CONFIG_DEBUG_ALIGN_RODATA)
> >  #define ALIGN_DEBUG_RO                 . = ALIGN(1<<SECTION_SHIFT);
> >  #define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
> > +#elif defined(CONFIG_DEBUG_RODATA)
> > +#define ALIGN_DEBUG_RO                 . = ALIGN(1<<PAGE_SHIFT);
> > +#define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
> >  #else
> >  #define ALIGN_DEBUG_RO
> >  #define ALIGN_DEBUG_RO_MIN(min)                . = ALIGN(min);
> 
> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Cheers, Ard.

Jeremy, does this work for you?

If so, I expect Catalin will take this for 4.4, with the addition of any
Acks and:

Fixes: da141706aea52c1a ("arm64: add better page protections to arm64")
Cc: <stable@vger.kernel.org>

Thanks,
Mark.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] arm64: page-align sections for DEBUG_RODATA
  2015-10-27 10:56   ` Mark Rutland
@ 2015-10-29 17:25     ` Catalin Marinas
  0 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2015-10-29 17:25 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Oct 27, 2015 at 10:56:33AM +0000, Mark Rutland wrote:
> On Tue, Oct 27, 2015 at 11:37:04AM +0900, Ard Biesheuvel wrote:
> > On 27 October 2015 at 06:42, Mark Rutland <mark.rutland@arm.com> wrote:
> > > A kernel built with DEBUG_RO_DATA && !CONFIG_DEBUG_ALIGN_RODATA doesn't
> > > have .text aligned to a page boundary, though fixup_executable works at
> > > page-granularity thanks to its use of create_mapping. If .text is not
> > > page-aligned, the first page it exists in may be marked non-executable,
> > > leading to failures when an attempt is made to execute code in said
> > > page.
> > >
> > > This patch upgrades ALIGN_DEBUG_RO and ALIGN_DEBUG_RO_MIN to force page
> > > alignment for DEBUG_RO_DATA && !CONFIG_DEBUG_ALIGN_RODATA kernels,
> > > ensuring that all sections with specific RWX permission requirements are
> > > mapped with the correct permissions.
> > >
> > > Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> > > Reported-by: Jeremy Linton <jeremy.linton@arm.com>
> > > Reviewed-by: Laura Abbott <laura@labbott.name>
> > > Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > > Cc: Suzuki Poulose <suzuki.poulose@arm.com>
> > > Cc: Will Deacon <will.deacon@arm.com>
[...]
> Jeremy, does this work for you?
> 
> If so, I expect Catalin will take this for 4.4, with the addition of any
> Acks and:
> 
> Fixes: da141706aea52c1a ("arm64: add better page protections to arm64")
> Cc: <stable@vger.kernel.org>

I applied this patch. I haven't pushed it out yet, in case Jeremy wants
to add any acked/tested-by tags.

Thanks.

-- 
Catalin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-29 17:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-26 21:42 [PATCH] arm64: page-align sections for DEBUG_RODATA Mark Rutland
2015-10-27  2:37 ` Ard Biesheuvel
2015-10-27 10:56   ` Mark Rutland
2015-10-29 17:25     ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).