Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

stackprotector: move get_random_canary() into stackprotector.h

This has nothing to do with random.c and everything to do with stack
protectors. Yes, it uses randomness. But many things use randomness.
random.h and random.c are concerned with the generation of randomness,
not with each and every use. So move this function into the more
specific stackprotector.h file where it belongs.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

+24 -23
+1 -1
arch/x86/kernel/cpu/common.c
··· 22 22 #include <linux/io.h> 23 23 #include <linux/syscore_ops.h> 24 24 #include <linux/pgtable.h> 25 + #include <linux/stackprotector.h> 25 26 26 27 #include <asm/cmdline.h> 27 - #include <asm/stackprotector.h> 28 28 #include <asm/perf_event.h> 29 29 #include <asm/mmu_context.h> 30 30 #include <asm/doublefault.h>
+1 -1
arch/x86/kernel/setup_percpu.c
··· 11 11 #include <linux/smp.h> 12 12 #include <linux/topology.h> 13 13 #include <linux/pfn.h> 14 + #include <linux/stackprotector.h> 14 15 #include <asm/sections.h> 15 16 #include <asm/processor.h> 16 17 #include <asm/desc.h> ··· 22 21 #include <asm/proto.h> 23 22 #include <asm/cpumask.h> 24 23 #include <asm/cpu.h> 25 - #include <asm/stackprotector.h> 26 24 27 25 DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number); 28 26 EXPORT_PER_CPU_SYMBOL(cpu_number);
+1
arch/x86/kernel/smpboot.c
··· 56 56 #include <linux/numa.h> 57 57 #include <linux/pgtable.h> 58 58 #include <linux/overflow.h> 59 + #include <linux/stackprotector.h> 59 60 60 61 #include <asm/acpi.h> 61 62 #include <asm/desc.h>
+1 -1
arch/x86/xen/enlighten_pv.c
··· 32 32 #include <linux/edd.h> 33 33 #include <linux/reboot.h> 34 34 #include <linux/virtio_anchor.h> 35 + #include <linux/stackprotector.h> 35 36 36 37 #include <xen/xen.h> 37 38 #include <xen/events.h> ··· 65 64 #include <asm/pgalloc.h> 66 65 #include <asm/tlbflush.h> 67 66 #include <asm/reboot.h> 68 - #include <asm/stackprotector.h> 69 67 #include <asm/hypervisor.h> 70 68 #include <asm/mach_traps.h> 71 69 #include <asm/mwait.h>
-19
include/linux/random.h
··· 116 116 return floor + get_random_u32_below(ceil - floor + 1); 117 117 } 118 118 119 - /* 120 - * On 64-bit architectures, protect against non-terminated C string overflows 121 - * by zeroing out the first byte of the canary; this leaves 56 bits of entropy. 122 - */ 123 - #ifdef CONFIG_64BIT 124 - # ifdef __LITTLE_ENDIAN 125 - # define CANARY_MASK 0xffffffffffffff00UL 126 - # else /* big endian, 64 bits: */ 127 - # define CANARY_MASK 0x00ffffffffffffffUL 128 - # endif 129 - #else /* 32 bits: */ 130 - # define CANARY_MASK 0xffffffffUL 131 - #endif 132 - 133 - static inline unsigned long get_random_canary(void) 134 - { 135 - return get_random_long() & CANARY_MASK; 136 - } 137 - 138 119 void __init random_init_early(const char *command_line); 139 120 void __init random_init(void); 140 121 bool rng_is_initialized(void);
+19
include/linux/stackprotector.h
··· 6 6 #include <linux/sched.h> 7 7 #include <linux/random.h> 8 8 9 + /* 10 + * On 64-bit architectures, protect against non-terminated C string overflows 11 + * by zeroing out the first byte of the canary; this leaves 56 bits of entropy. 12 + */ 13 + #ifdef CONFIG_64BIT 14 + # ifdef __LITTLE_ENDIAN 15 + # define CANARY_MASK 0xffffffffffffff00UL 16 + # else /* big endian, 64 bits: */ 17 + # define CANARY_MASK 0x00ffffffffffffffUL 18 + # endif 19 + #else /* 32 bits: */ 20 + # define CANARY_MASK 0xffffffffUL 21 + #endif 22 + 23 + static inline unsigned long get_random_canary(void) 24 + { 25 + return get_random_long() & CANARY_MASK; 26 + } 27 + 9 28 #if defined(CONFIG_STACKPROTECTOR) || defined(CONFIG_ARM64_PTR_AUTH) 10 29 # include <asm/stackprotector.h> 11 30 #else
+1 -1
kernel/fork.c
··· 75 75 #include <linux/freezer.h> 76 76 #include <linux/delayacct.h> 77 77 #include <linux/taskstats_kern.h> 78 - #include <linux/random.h> 79 78 #include <linux/tty.h> 80 79 #include <linux/fs_struct.h> 81 80 #include <linux/magic.h> ··· 96 97 #include <linux/scs.h> 97 98 #include <linux/io_uring.h> 98 99 #include <linux/bpf.h> 100 + #include <linux/stackprotector.h> 99 101 100 102 #include <asm/pgalloc.h> 101 103 #include <linux/uaccess.h>