[PATCH 1/2] ARM: mm: DEBUG_RODATA makes no sense with XIP_KERNEL

Subsystems: arm port, the rest

STALE3818d

9 messages, 3 authors, 2016-02-16 · open the first message on its own page

[PATCH 1/2] ARM: mm: DEBUG_RODATA makes no sense with XIP_KERNEL

From: Arnd Bergmann <arnd@arndb.de>
Date: 2016-02-16 16:04:30

When CONFIG_DEBUG_ALIGN_RODATA is set, we get a link error:

arch/arm/mm/built-in.o:(.data+0x4bc): undefined reference to `__start_rodata_section_aligned'

However, this combination is useless, as XIP_KERNEL implies that all the
RODATA is already marked readonly, so both CONFIG_DEBUG_RODATA and
CONFIG_DEBUG_ALIGN_RODATA (which depends on the other) are not
needed with XIP_KERNEL, and this patches enforces that using a Kconfig
dependency.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 25362dc496ed ("ARM: 8501/1: mm: flip priority of CONFIG_DEBUG_RODATA")
---
 arch/arm/mm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
index fbf2296388ce..8894045caba9 100644
--- a/arch/arm/mm/Kconfig
+++ b/arch/arm/mm/Kconfig
@@ -1039,7 +1039,7 @@ config ARCH_SUPPORTS_BIG_ENDIAN
 
 config DEBUG_RODATA
 	bool "Make kernel text and rodata read-only"
-	depends on MMU
+	depends on MMU && !XIP_KERNEL
 	default y if CPU_V7
 	help
 	  If this is set, kernel text and rodata memory will be made
-- 
2.7.0

[PATCH 2/2] ARM: mm: hide __start_rodata_section_aligned for non-debug builds

From: Arnd Bergmann <arnd@arndb.de>
Date: 2016-02-16 16:04:52

The __start_rodata_section_aligned is only referenced by the
DEBUG_RODATA code, which is only used when the MMU is enabled,
but the definition fails on !MMU builds:

arch/arm/kernel/vmlinux.lds:702: undefined symbol `SECTION_SHIFT' referenced in expression

This hides the symbol whenever DEBUG_RODATA is disabled.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 64ac2e74f0b2 ("ARM: 8502/1: mm: mark section-aligned portion of rodata NX")
---
 arch/arm/kernel/vmlinux.lds.S | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index 2d7085ae1c2f..bb12933aee22 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -322,12 +322,14 @@ SECTIONS
 	STABS_DEBUG
 }
 
+#ifdef CONFIG_DEBUG_RODATA
 /*
  * Without CONFIG_DEBUG_ALIGN_RODATA, __start_rodata_section_aligned will
  * be the first section-aligned location after __start_rodata. Otherwise,
  * it will be equal to __start_rodata.
  */
 __start_rodata_section_aligned = ALIGN(__start_rodata, 1 << SECTION_SHIFT);
+#endif
 
 /*
  * These must never be empty
-- 
2.7.0

Re: [PATCH 2/2] ARM: mm: hide __start_rodata_section_aligned for non-debug builds

From: Ard Biesheuvel <hidden>
Date: 2016-02-16 16:12:56

On 16 February 2016 at 17:03, Arnd Bergmann [off-list ref] wrote:
quoted hunk
The __start_rodata_section_aligned is only referenced by the
DEBUG_RODATA code, which is only used when the MMU is enabled,
but the definition fails on !MMU builds:

arch/arm/kernel/vmlinux.lds:702: undefined symbol `SECTION_SHIFT' referenced in expression

This hides the symbol whenever DEBUG_RODATA is disabled.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 64ac2e74f0b2 ("ARM: 8502/1: mm: mark section-aligned portion of rodata NX")
---
 arch/arm/kernel/vmlinux.lds.S | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index 2d7085ae1c2f..bb12933aee22 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -322,12 +322,14 @@ SECTIONS
        STABS_DEBUG
 }

+#ifdef CONFIG_DEBUG_RODATA
 /*
  * Without CONFIG_DEBUG_ALIGN_RODATA, __start_rodata_section_aligned will
  * be the first section-aligned location after __start_rodata. Otherwise,
  * it will be equal to __start_rodata.
  */
 __start_rodata_section_aligned = ALIGN(__start_rodata, 1 << SECTION_SHIFT);
+#endif
Does

PROVIDE(__start_rodata_section_aligned = xxx);

do the trick as well? If it does, it's a bit cleaner.

Re: [PATCH 2/2] ARM: mm: hide __start_rodata_section_aligned for non-debug builds

From: Arnd Bergmann <arnd@arndb.de>
Date: 2016-02-16 16:35:11

On Tuesday 16 February 2016 17:12:52 Ard Biesheuvel wrote:
quoted
+#ifdef CONFIG_DEBUG_RODATA
 /*
  * Without CONFIG_DEBUG_ALIGN_RODATA, __start_rodata_section_aligned will
  * be the first section-aligned location after __start_rodata. Otherwise,
  * it will be equal to __start_rodata.
  */
 __start_rodata_section_aligned = ALIGN(__start_rodata, 1 << SECTION_SHIFT);
+#endif
Does

PROVIDE(__start_rodata_section_aligned = xxx);

do the trick as well? If it does, it's a bit cleaner.
I would assume not, as the problem is that SECTION_SHIFT is a macro that
is not defined when the MMU is disabled.

	Arnd

Re: [PATCH 2/2] ARM: mm: hide __start_rodata_section_aligned for non-debug builds

From: Ard Biesheuvel <hidden>
Date: 2016-02-16 16:36:35

On 16 February 2016 at 17:34, Arnd Bergmann [off-list ref] wrote:
On Tuesday 16 February 2016 17:12:52 Ard Biesheuvel wrote:
quoted
quoted
+#ifdef CONFIG_DEBUG_RODATA
 /*
  * Without CONFIG_DEBUG_ALIGN_RODATA, __start_rodata_section_aligned will
  * be the first section-aligned location after __start_rodata. Otherwise,
  * it will be equal to __start_rodata.
  */
 __start_rodata_section_aligned = ALIGN(__start_rodata, 1 << SECTION_SHIFT);
+#endif
Does

PROVIDE(__start_rodata_section_aligned = xxx);

do the trick as well? If it does, it's a bit cleaner.
I would assume not, as the problem is that SECTION_SHIFT is a macro that
is not defined when the MMU is disabled.
I just tested it myself, and it in fact does work.

PROVIDE() means the expression is evaluated lazily, and SECTION_SHIFT
is just an undefined identifier in the linker script scope if the
preprocessor does not define it.

Anyway, I don't have a strong preference, so ack either way.

Re: [PATCH 1/2] ARM: mm: DEBUG_RODATA makes no sense with XIP_KERNEL

From: Ard Biesheuvel <hidden>
Date: 2016-02-16 16:05:46

On 16 February 2016 at 17:03, Arnd Bergmann [off-list ref] wrote:
When CONFIG_DEBUG_ALIGN_RODATA is set, we get a link error:

arch/arm/mm/built-in.o:(.data+0x4bc): undefined reference to `__start_rodata_section_aligned'

However, this combination is useless, as XIP_KERNEL implies that all the
RODATA is already marked readonly, so both CONFIG_DEBUG_RODATA and
CONFIG_DEBUG_ALIGN_RODATA (which depends on the other) are not
needed with XIP_KERNEL, and this patches enforces that using a Kconfig
s/patches/patch/
dependency.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Ard Biesheuvel <redacted>
quoted hunk
Fixes: 25362dc496ed ("ARM: 8501/1: mm: flip priority of CONFIG_DEBUG_RODATA")
---
 arch/arm/mm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
index fbf2296388ce..8894045caba9 100644
--- a/arch/arm/mm/Kconfig
+++ b/arch/arm/mm/Kconfig
@@ -1039,7 +1039,7 @@ config ARCH_SUPPORTS_BIG_ENDIAN

 config DEBUG_RODATA
        bool "Make kernel text and rodata read-only"
-       depends on MMU
+       depends on MMU && !XIP_KERNEL
        default y if CPU_V7
        help
          If this is set, kernel text and rodata memory will be made
--
2.7.0

Re: [PATCH 1/2] ARM: mm: DEBUG_RODATA makes no sense with XIP_KERNEL

From: Kees Cook <hidden>
Date: 2016-02-16 18:41:14

On Tue, Feb 16, 2016 at 8:03 AM, Arnd Bergmann [off-list ref] wrote:
When CONFIG_DEBUG_ALIGN_RODATA is set, we get a link error:

arch/arm/mm/built-in.o:(.data+0x4bc): undefined reference to `__start_rodata_section_aligned'

However, this combination is useless, as XIP_KERNEL implies that all the
RODATA is already marked readonly, so both CONFIG_DEBUG_RODATA and
CONFIG_DEBUG_ALIGN_RODATA (which depends on the other) are not
needed with XIP_KERNEL, and this patches enforces that using a Kconfig
dependency.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 25362dc496ed ("ARM: 8501/1: mm: flip priority of CONFIG_DEBUG_RODATA")
Oh, hm, I didn't see this before sending my fix for the rodata start issue.
quoted hunk
---
 arch/arm/mm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
index fbf2296388ce..8894045caba9 100644
--- a/arch/arm/mm/Kconfig
+++ b/arch/arm/mm/Kconfig
@@ -1039,7 +1039,7 @@ config ARCH_SUPPORTS_BIG_ENDIAN

 config DEBUG_RODATA
        bool "Make kernel text and rodata read-only"
-       depends on MMU
+       depends on MMU && !XIP_KERNEL
If we do this, we need to probably clean up the xip linker script to
remove all the references to DEBUG_*RODATA too.

-Kees
        default y if CPU_V7
        help
          If this is set, kernel text and rodata memory will be made
--
2.7.0


-- 
Kees Cook
Chrome OS & Brillo Security

Re: [PATCH 1/2] ARM: mm: DEBUG_RODATA makes no sense with XIP_KERNEL

From: Kees Cook <hidden>
Date: 2016-02-16 20:31:21

On Tue, Feb 16, 2016 at 8:03 AM, Arnd Bergmann [off-list ref] wrote:
When CONFIG_DEBUG_ALIGN_RODATA is set, we get a link error:

arch/arm/mm/built-in.o:(.data+0x4bc): undefined reference to `__start_rodata_section_aligned'

However, this combination is useless, as XIP_KERNEL implies that all the
RODATA is already marked readonly, so both CONFIG_DEBUG_RODATA and
CONFIG_DEBUG_ALIGN_RODATA (which depends on the other) are not
needed with XIP_KERNEL, and this patches enforces that using a Kconfig
dependency.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 25362dc496ed ("ARM: 8501/1: mm: flip priority of CONFIG_DEBUG_RODATA")
For this and the 2/2 patch:

Acked-by: Kees Cook <redacted>

I've sent follow-up to clean up the XIP linker script too, if you want
to take that as the 3rd patch in this series of fixes.

-Kees
quoted hunk
---
 arch/arm/mm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
index fbf2296388ce..8894045caba9 100644
--- a/arch/arm/mm/Kconfig
+++ b/arch/arm/mm/Kconfig
@@ -1039,7 +1039,7 @@ config ARCH_SUPPORTS_BIG_ENDIAN

 config DEBUG_RODATA
        bool "Make kernel text and rodata read-only"
-       depends on MMU
+       depends on MMU && !XIP_KERNEL
        default y if CPU_V7
        help
          If this is set, kernel text and rodata memory will be made
--
2.7.0


-- 
Kees Cook
Chrome OS & Brillo Security

Re: [PATCH 1/2] ARM: mm: DEBUG_RODATA makes no sense with XIP_KERNEL

From: Kees Cook <hidden>
Date: 2016-02-16 23:12:27

On Tue, Feb 16, 2016 at 12:31 PM, Kees Cook [off-list ref] wrote:
On Tue, Feb 16, 2016 at 8:03 AM, Arnd Bergmann [off-list ref] wrote:
quoted
When CONFIG_DEBUG_ALIGN_RODATA is set, we get a link error:

arch/arm/mm/built-in.o:(.data+0x4bc): undefined reference to `__start_rodata_section_aligned'

However, this combination is useless, as XIP_KERNEL implies that all the
RODATA is already marked readonly, so both CONFIG_DEBUG_RODATA and
CONFIG_DEBUG_ALIGN_RODATA (which depends on the other) are not
needed with XIP_KERNEL, and this patches enforces that using a Kconfig
dependency.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 25362dc496ed ("ARM: 8501/1: mm: flip priority of CONFIG_DEBUG_RODATA")
For this and the 2/2 patch:

Acked-by: Kees Cook <redacted>

I've sent follow-up to clean up the XIP linker script too, if you want
to take that as the 3rd patch in this series of fixes.
Arnd, when you send your 2 patches to the tracker, can you also send
mine (so the ordering is correct)?

Thanks!

-Kees

-- 
Kees Cook
Chrome OS & Brillo Security
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help