The patch titled Subject: random,stackprotect: introduce get_random_canary function has been added to the -mm tree. Its filename is randomstackprotect-introduce-get_random_canary-function.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/randomstackprotect-introduce-get_random_canary-function.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/randomstackprotect-introduce-get_random_canary-function.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Rik van Riel <riel@xxxxxxxxxx> Subject: random,stackprotect: introduce get_random_canary function Patch series "stackprotector: ascii armor the stack canary", v2. Zero out the first byte of the stack canary value on 64 bit systems, in order to mitigate unterminated C string overflows. The null byte both prevents C string functions from reading the canary, and from writing it if the canary value were guessed or obtained through some other means. Reducing the entropy by 8 bits is acceptable on 64-bit systems, which will still have 56 bits of entropy left, but not on 32 bit systems, so the "ascii armor" canary is only implemented on 64-bit systems. Inspired by the "ascii armor" code in execshield and Daniel Micay's linux-hardened tree. Also see https://github.com/thestinger/linux-hardened/ This patch (of 5): Introduce get_random_canary(), which provides a random unsigned long canary value with the first byte zeroed out on 64 bit architectures, in order to mitigate non-terminated C string overflows. The null byte both prevents C string functions from reading the canary, and from writing it if the canary value were guessed or obtained through some other means. Reducing the entropy by 8 bits is acceptable on 64-bit systems, which will still have 56 bits of entropy left, but not on 32 bit systems, so the "ascii armor" canary is only implemented on 64-bit systems. Inspired by the "ascii armor" code in the old execshield patches, and Daniel Micay's linux-hardened tree. Link: http://lkml.kernel.org/r/20170524155751.424-2-riel@xxxxxxxxxx Signed-off-by: Rik van Riel <riel@xxxxxxxxxx> Acked-by: Kees Cook <keescook@xxxxxxxxxxxx> Cc: Daniel Micay <danielmicay@xxxxxxxxx> Cc: "Theodore Ts'o" <tytso@xxxxxxx> Cc: H. Peter Anvin <hpa@xxxxxxxxx> Cc: Andy Lutomirski <luto@xxxxxxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxxxxx> Cc: Catalin Marinas <catalin.marinas@xxxxxxx> Cc: Yoshinori Sato <ysato@xxxxxxxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/random.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff -puN include/linux/random.h~randomstackprotect-introduce-get_random_canary-function include/linux/random.h --- a/include/linux/random.h~randomstackprotect-introduce-get_random_canary-function +++ a/include/linux/random.h @@ -57,6 +57,27 @@ static inline unsigned long get_random_l #endif } +/* + * On 64-bit architectures, protect against non-terminated C string overflows + * by zeroing out the first byte of the canary; this leaves 56 bits of entropy. + */ +#ifdef CONFIG_64BIT +# ifdef __LITTLE_ENDIAN +# define CANARY_MASK 0xffffffffffffff00UL +# else /* big endian, 64 bits: */ +# define CANARY_MASK 0x00ffffffffffffffUL +# endif +#else /* 32 bits: */ +# define CANARY_MASK 0xffffffffUL +#endif + +static inline unsigned long get_random_canary(void) +{ + unsigned long val = get_random_long(); + + return val & CANARY_MASK; +} + unsigned long randomize_page(unsigned long start, unsigned long range); u32 prandom_u32(void); _ Patches currently in -mm which might be from riel@xxxxxxxxxx are randomstackprotect-introduce-get_random_canary-function.patch forkrandom-use-get_random_canary-to-set-tsk-stack_canary.patch x86-ascii-armor-the-x86_64-boot-init-stack-canary.patch arm64-ascii-armor-the-arm64-boot-init-stack-canary.patch sh64-ascii-armor-the-sh64-boot-init-stack-canary.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html