Skip to contentSkip to conversation

x86: ascii armor the x86_64 boot init stack canary

PATCH New [email protected] 1 participant 1 message Jul 12, 2017 x86

lore
Share & tools
lore
#0 lore raw

PATCH 67/96 x86: ascii armor the x86_64 boot init stack canary

From: Rik van Riel <[email protected]>
Subject: x86: ascii armor the x86_64 boot init stack canary

Use the ascii-armor canary to prevent unterminated C string overflows from being able to successfully overwrite the canary, even if they somehow obtain the canary value.

Inspired by execshield ascii-armor and Daniel Micay's linux-hardened tree.

---

 arch/x86/include/asm/stackprotector.h |    1 +
 1 file changed, 1 insertion(+)
arch/x86/include/asm/stackprotector.h renamed from arch/x86/include/asm/stackprotector.h~x86-ascii-armor-the-x86_64-boot-init-stack-canary +1 -0
diff -puN arch/x86/include/asm/stackprotector.h~x86-ascii-armor-the-x86_64-boot-init-stack-canary arch/x86/include/asm/stackprotector.h
@@ -74,6 +74,7 @@ static __always_inline void boot_init_st
 	get_random_bytes(&canary, sizeof(canary));
 	tsc = rdtsc();
 	canary += tsc + (tsc << 32UL);
+	canary &= CANARY_MASK;
 
 	current->stack_canary = canary;
 #ifdef CONFIG_X86_64

_