Skip to contentSkip to conversation

arm64:Mark __stack_chk_guard as __ro_after_init

RFC PATCH Applied Dan Li 4 participants 7 messages Sep 14, 2021 – Sep 16, 2021 arm64

lore
Share & tools
lore

Dan Li

author
#0 lore raw

RFC PATCH 1/1 arm64:Mark __stack_chk_guard as __ro_after_init

__stack_chk_guard is setup once while init stage and never changed after that.

Although the modification of this variable at runtime will usually cause the kernel to crash (so dose the attacker), it should be marked as _ro_after_init, and it should not affect performance if it is placed in the ro_after_init section.

This should also be the case on the ARM platform, or am I missing something?

---
 arch/arm64/kernel/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/process.c +1 -1
index c8989b9..c858b85 100644
@@ -60,7 +60,7 @@
 
 #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_STACKPROTECTOR_PER_TASK)
 #include <linux/stackprotector.h>
-unsigned long __stack_chk_guard __read_mostly;
+unsigned long __stack_chk_guard __ro_after_init;
 EXPORT_SYMBOL(__stack_chk_guard);
 #endif
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 10 lines · Dan Li

__stack_chk_guard is setup once while init stage and never changed after that.

Although the modification of this variable at runtime will usually cause the kernel to crash (so dose the attacker), it should be marked as _ro_after_init, and it should not affect performance if it is placed in the ro_after_init section.

This should also be the case on the ARM platform, or am I missing something?

I don't see why it can't be - we only write to it in boot_init_stack_canary(), same as ARM64.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
reviewer Acked-by on v1 1/1
#2 lore raw
In reply to Dan Li
Quoted 8 lines · Dan Li

__stack_chk_guard is setup once while init stage and never changed after that.

Although the modification of this variable at runtime will usually cause the kernel to crash (so dose the attacker), it should be marked as _ro_after_init, and it should not affect performance if it is placed in the ro_after_init section.

Quoted 4 lines

This should also be the case on the ARM platform, or am I missing something?

FWIW, this makes sense to me:

Looking at the history, this was added to arm64 in commit:

c0c264ae5112d1cd ("arm64: Add CONFIG_CC_STACKPROTECTOR")

... whereas __ro_after_init was introduced around 2 years later in commit:

c74ba8b3480da6dd ("arch: Introduce post-init read-only memory")

... so we weren't deliberately avoiding __ro_after_init, and there are probably a significant number of other variables we could apply it to.

Mark.

Quoted 20 lines
---
 arch/arm64/kernel/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/process.c +1 -1
index c8989b9..c858b85 100644
@@ -60,7 +60,7 @@
 
 #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_STACKPROTECTOR_PER_TASK)
 #include <linux/stackprotector.h>
-unsigned long __stack_chk_guard __read_mostly;
+unsigned long __stack_chk_guard __ro_after_init;
 EXPORT_SYMBOL(__stack_chk_guard);
 #endif
 
Signature · 1 line
2.7.4
author
#3 lore raw

Hi King, Rutland:

Thanks for the reply and let me understand the reason here.

Then may I first submit a patch to modify the attributes of __stack_chk_guard of the arm/aarch64 platform?

Quoted 52 lines · Mark Rutland
Quoted 8 lines · Dan Li

__stack_chk_guard is setup once while init stage and never changed after that.

Although the modification of this variable at runtime will usually cause the kernel to crash (so dose the attacker), it should be marked as _ro_after_init, and it should not affect performance if it is placed in the ro_after_init section.

Quoted 4 lines

This should also be the case on the ARM platform, or am I missing something?

FWIW, this makes sense to me:

Looking at the history, this was added to arm64 in commit:

   c0c264ae5112d1cd ("arm64: Add CONFIG_CC_STACKPROTECTOR")

... whereas __ro_after_init was introduced around 2 years later in commit:

c74ba8b3480da6dd ("arch: Introduce post-init read-only memory")

... so we weren't deliberately avoiding __ro_after_init, and there are probably a significant number of other variables we could apply it to.

Mark.

Quoted 20 lines
---
  arch/arm64/kernel/process.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/process.c +1 -1
index c8989b9..c858b85 100644
@@ -60,7 +60,7 @@
 
  #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_STACKPROTECTOR_PER_TASK)
  #include <linux/stackprotector.h>
-unsigned long __stack_chk_guard __read_mostly;
+unsigned long __stack_chk_guard __ro_after_init;
  EXPORT_SYMBOL(__stack_chk_guard);
  #endif
 
Signature · 1 line
2.7.4
reviewer
#4 lore raw
Quoted 6 lines · ashimida

Hi King, Rutland:

Thanks for the reply and let me understand the reason here.

Then may I first submit a patch to modify the attributes of __stack_chk_guard of the arm/aarch64 platform?

This patch looks fine as-is (hence the Acked-by). Doing the same for arch/arm makes sense, but that should be a separate patch.

I was suggesting that in future we should probably do the same in more places, not that you need to do so now.

Thanks,
Mark.

Quoted 52 lines · Mark Rutland
Quoted 50 lines · Dan Li
Quoted 8 lines

__stack_chk_guard is setup once while init stage and never changed after that.

Although the modification of this variable at runtime will usually cause the kernel to crash (so dose the attacker), it should be marked as _ro_after_init, and it should not affect performance if it is placed in the ro_after_init section.

Quoted 4 lines

This should also be the case on the ARM platform, or am I missing something?

FWIW, this makes sense to me:

Looking at the history, this was added to arm64 in commit:

   c0c264ae5112d1cd ("arm64: Add CONFIG_CC_STACKPROTECTOR")

... whereas __ro_after_init was introduced around 2 years later in commit:

c74ba8b3480da6dd ("arch: Introduce post-init read-only memory")

... so we weren't deliberately avoiding __ro_after_init, and there are probably a significant number of other variables we could apply it to.

Mark.

Quoted 18 lines
---
  arch/arm64/kernel/process.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/process.c +1 -1
index c8989b9..c858b85 100644
@@ -60,7 +60,7 @@
  #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_STACKPROTECTOR_PER_TASK)
  #include <linux/stackprotector.h>
-unsigned long __stack_chk_guard __read_mostly;
+unsigned long __stack_chk_guard __ro_after_init;
  EXPORT_SYMBOL(__stack_chk_guard);
  #endif
Signature · 1 line
2.7.4
author
#5 lore raw

Fine, I got it, thanks for reply.

Quoted 17 lines · Mark Rutland
Quoted 6 lines · ashimida

Hi King, Rutland:

Thanks for the reply and let me understand the reason here.

Then may I first submit a patch to modify the attributes of __stack_chk_guard of the arm/aarch64 platform?

This patch looks fine as-is (hence the Acked-by). Doing the same for arch/arm makes sense, but that should be a separate patch.

I was suggesting that in future we should probably do the same in more places, not that you need to do so now.

Thanks,
Mark.

maintainer Applied
#6 lore raw
In reply to Dan Li
Quoted 9 lines · Dan Li

__stack_chk_guard is setup once while init stage and never changed after that.

Although the modification of this variable at runtime will usually cause the kernel to crash (so dose the attacker), it should be marked as _ro_after_init, and it should not affect performance if it is placed in the ro_after_init section.

[...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64:Mark __stack_chk_guard as __ro_after_init

      https://git.kernel.org/arm64/c/9fcb2e93f41c
Signature · 7 lines
Catalin


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel