Introduce the latent_entropy gcc plugin
Subsystems (17)
cover Introduce the latent_entropy gcc plugin
I would like to introduce the latent_entropy gcc plugin. This plugin mitigates the problem of the kernel having too little entropy during and after boot for generating crypto keys.
This plugin mixes random values into the latent_entropy global variable in functions marked by the __latent_entropy attribute.
The value of this global variable is added to the kernel entropy pool to increase the entropy.
It is a CII project supported by the Linux Foundation.
The latent_entropy plugin was ported from grsecurity/PaX originally written by the PaX Team. You can find more about the plugin here:
https://grsecurity.net/pipermail/grsecurity/2012-July/001093.html
The plugin supports all gcc version from 4.5 to 6.0.
I do some changes above the PaX version. The important one is mixing the stack pointer into the global variable too.
You can find more about the changes here:
https://github.com/ephox-gcc-plugins/latent_entropy
This patch set is based on the "Introduce GCC plugin infrastructure" patch set (v9).
Emese Revfy (3):
Add the latent_entropy gcc plugin
Mark functions with the latent_entropy attribute
Add the extra_latent_entropy kernel parameter
--- Documentation/kernel-parameters.txt | 5 + arch/Kconfig | 22 ++ arch/powerpc/kernel/Makefile | 8 +- block/blk-softirq.c | 2 +- drivers/char/random.c | 6 +- fs/namespace.c | 2 +- include/linux/compiler-gcc.h | 5 + include/linux/compiler.h | 4 + include/linux/fdtable.h | 2 +- include/linux/genhd.h | 2 +- include/linux/init.h | 10 +- include/linux/random.h | 12 +- init/main.c | 1 + kernel/fork.c | 5 +- kernel/rcu/tiny.c | 2 +- kernel/rcu/tree.c | 2 +- kernel/sched/fair.c | 2 +- kernel/softirq.c | 4 +- kernel/time/timer.c | 2 +- lib/irq_poll.c | 2 +- lib/random32.c | 2 +- mm/page_alloc.c | 28 ++ net/core/dev.c | 4 +- scripts/Makefile.gcc-plugins | 10 +- scripts/gcc-plugins/Makefile | 1 + scripts/gcc-plugins/latent_entropy_plugin.c | 446 ++++++++++++++++++++++++++++ 26 files changed, 562 insertions(+), 29 deletions(-)
PATCH 1/3 Add the latent_entropy gcc plugin
This plugin mitigates the problem of the kernel having too little entropy during and after boot for generating crypto keys.
It creates a local variable in every marked function. The value of this variable is modified by randomly chosen operations (add, xor and rol) and
random values (gcc generates them at compile time and the stack pointer at runtime). It depends on the control flow (e.g., loops, conditions).
Before the function returns the plugin writes this local variable into the latent_entropy global variable. The value of this global variable is added to the kernel entropy pool in do_one_initcall() and _do_fork().
Based on work created by the PaX Team.
--- arch/Kconfig | 17 ++ arch/powerpc/kernel/Makefile | 8 +- include/linux/random.h | 8 + init/main.c | 1 + kernel/fork.c | 1 + mm/page_alloc.c | 5 + scripts/Makefile.gcc-plugins | 10 +- scripts/gcc-plugins/Makefile | 1 + scripts/gcc-plugins/latent_entropy_plugin.c | 446 ++++++++++++++++++++++++++++ 9 files changed, 491 insertions(+), 6 deletions(-) create mode 100644 scripts/gcc-plugins/latent_entropy_plugin.c
arch/Kconfig +17 -0
@@ -393,6 +393,23 @@ config GCC_PLUGIN_SANCOV gcc-4.5 on). It is based on the commit "Add fuzzing coverage support" by Dmitry Vyukov <[email protected]>. +config GCC_PLUGIN_LATENT_ENTROPY + bool "latent entropy" + depends on GCC_PLUGINS + help + By saying Y here the kernel will instrument some kernel code to + extract some entropy from both original and artificially created + program state. This will help especially embedded systems where + there is little 'natural' source of entropy normally. The cost + is some slowdown of the boot process and fork and irq processing. + + Note that entropy extracted this way is not known to be cryptographically + secure! + + This plugin was ported from grsecurity/PaX. More information at: + * https://grsecurity.net/ + * https://pax.grsecurity.net/ + config HAVE_CC_STACKPROTECTOR bool help
arch/powerpc/kernel/Makefile +4 -4
@@ -16,10 +16,10 @@ endif ifdef CONFIG_FUNCTION_TRACER # Do not trace early boot code -CFLAGS_REMOVE_cputable.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_prom_init.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_btext.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_prom.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_cputable.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) $(DISABLE_LATENT_ENTROPY_PLUGIN) +CFLAGS_REMOVE_prom_init.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) $(DISABLE_LATENT_ENTROPY_PLUGIN) +CFLAGS_REMOVE_btext.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) $(DISABLE_LATENT_ENTROPY_PLUGIN) +CFLAGS_REMOVE_prom.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) $(DISABLE_LATENT_ENTROPY_PLUGIN) # do not trace tracer code CFLAGS_REMOVE_ftrace.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) # timers used by tracing
include/linux/random.h +8 -0
@@ -18,6 +18,14 @@ struct random_ready_callback { };extern void add_device_randomness (const void *,unsigned int ); + +static inline void add_latent_entropy (void ) +{ +#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY +add_device_randomness ((const void *)&latent_entropy,sizeof (latent_entropy)); +#endif +} +extern void add_input_randomness (unsigned int type,unsigned int code,unsigned int value);extern void add_interrupt_randomness (int irq,int irq_flags);
init/main.c +1 -0
@@ -781,6 +781,7 @@ int __init_or_module do_one_initcall(initcall_t fn) }WARN (msgbuf[0 ],"initcall %pF returned with %s\n" , fn, msgbuf); +add_latent_entropy ();return ret; }
kernel/fork.c +1 -0
@@ -1766,6 +1766,7 @@ long _do_fork(unsigned long clone_flags, p =copy_process (clone_flags, stack_start, stack_size, child_tidptr,NULL , trace, tls,NUMA_NO_NODE ); +add_latent_entropy ();/* * Do this prior waking up the new thread - the thread pointer * might get invalid after that point, if the thread exits quickly.
mm/page_alloc.c +5 -0
@@ -1234,6 +1234,11 @@ static void __free_pages_ok(struct page *page, unsigned int order)local_irq_restore (flags); } +#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY +volatile u64 latent_entropy; +EXPORT_SYMBOL (latent_entropy); +#endif +static void __init __free_pages_boot_core (struct page *page,unsigned int order) {unsigned int nr_pages =1 << order;
scripts/Makefile.gcc-plugins +8 -2
@@ -6,6 +6,12 @@ ifdef CONFIG_GCC_PLUGINS gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so + gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so + gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += -DLATENT_ENTROPY_PLUGIN + ifdef CONFIG_PAX_LATENT_ENTROPY + DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable + endif + ifdef CONFIG_GCC_PLUGIN_SANCOV ifeq ($(CFLAGS_KCOV),) # It is needed because of the gcc-plugin.sh and gcc version checks.
@@ -19,9 +25,9 @@ ifdef CONFIG_GCC_PLUGINS endif endif - GCC_PLUGINS_CFLAGS := $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) + GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) - export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN SANCOV_PLUGIN + export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN SANCOV_PLUGIN DISABLE_LATENT_ENTROPY_PLUGIN ifeq ($(PLUGINCC),) ifneq ($(GCC_PLUGINS_CFLAGS),)
scripts/gcc-plugins/Makefile +1 -0
@@ -23,5 +23,6 @@ always := $($(HOSTLIBS)-y) cyc_complexity_plugin-objs := cyc_complexity_plugin.o sancov_plugin-objs := sancov_plugin.o +latent_entropy_plugin-objs := latent_entropy_plugin.o clean-files += *.so
scripts/gcc-plugins/latent_entropy_plugin.c new file +446 -0
446 lines not on this page · raw message
Signature · 1 line
2.8.1
PATCH 2/3 Mark functions with the latent_entropy attribute
In reply to Emese RevfyThese functions have been selected because they are init functions or are called at random times or they have variable loops.
Based on work created by the PaX Team.
--- block/blk-softirq.c | 2 +- drivers/char/random.c | 6 +++--- fs/namespace.c | 2 +- include/linux/compiler-gcc.h | 5 +++++ include/linux/compiler.h | 4 ++++ include/linux/fdtable.h | 2 +- include/linux/genhd.h | 2 +- include/linux/init.h | 10 ++++++++-- include/linux/random.h | 4 ++-- kernel/fork.c | 4 ++-- kernel/rcu/tiny.c | 2 +- kernel/rcu/tree.c | 2 +- kernel/sched/fair.c | 2 +- kernel/softirq.c | 4 ++-- kernel/time/timer.c | 2 +- lib/irq_poll.c | 2 +- lib/random32.c | 2 +- mm/page_alloc.c | 2 +- net/core/dev.c | 4 ++-- 19 files changed, 39 insertions(+), 24 deletions(-)
block/blk-softirq.c +1 -1
@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);* Softirq action handler - move entries to local list and loop over them * while passing them to the queue registered handler. */ -static void blk_done_softirq (struct softirq_action *h) +static __latent_entropy void blk_done_softirq(struct softirq_action *h) {struct list_head *cpu_list, local_list;
drivers/char/random.c +3 -3
@@ -443,9 +443,9 @@ struct entropy_store { };static void push_to_pool (struct work_struct *work); -static __u32 input_pool_data[INPUT_POOL_WORDS ]; -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS ]; -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS ]; +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy; +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy; +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;static struct entropy_store input_pool = { .poolinfo = &poolinfo_table[0 ],
fs/namespace.c +1 -1
@@ -2778,7 +2778,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)return new_ns; } -struct mnt_namespace *copy_mnt_ns (unsigned long flags,struct mnt_namespace *ns, +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,struct user_namespace *user_ns,struct fs_struct *new_fs) {struct mnt_namespace *new_ns;
include/linux/compiler-gcc.h +5 -0
@@ -188,6 +188,11 @@#endif /* GCC_VERSION >= 40300 */ #if GCC_VERSION >=40500 + +#ifdef LATENT_ENTROPY_PLUGIN +#define __latent_entropy __attribute__((latent_entropy)) +#endif +/* * Mark a position in code as unreachable. This can be used to * suppress control flow warnings after asm blocks that transfer
include/linux/compiler.h +4 -0
@@ -425,6 +425,10 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s# define __attribute_const__/* unimplemented */ #endif +#ifndef __latent_entropy +# define __latent_entropy +#endif +/* * Tell gcc if a function is cold. The compiler will assume any path * directly leading to the call is unlikely.
include/linux/fdtable.h +1 -1
@@ -105,7 +105,7 @@ struct files_struct *get_files_struct(struct task_struct *);void put_files_struct (struct files_struct *fs);void reset_files_struct (struct files_struct *);int unshare_files (struct files_struct **); -struct files_struct *dup_fd (struct files_struct *,int *); +struct files_struct *dup_fd (struct files_struct *,int *) __latent_entropy;void do_close_on_exec (struct files_struct *); int iterate_fd(struct files_struct *, unsigned, int (*)(const void *, struct file *, unsigned),
include/linux/genhd.h +1 -1
@@ -433,7 +433,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);extern unsigned int disk_clear_events (struct gendisk *disk,unsigned int mask);/* drivers/char/random.c */ -extern void add_disk_randomness (struct gendisk *disk); +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;extern void rand_initialize_disk (struct gendisk *disk);static inline sector_t get_start_sect (struct block_device *bdev)
include/linux/init.h +8 -2
@@ -37,9 +37,15 @@* section. */ +#ifdef CONFIG_MEMORY_HOTPLUG +#define add_meminit_latent_entropy +#else +#define add_meminit_latent_entropy __latent_entropy +#endif +/* These are for everybody (although not all archs will actually discard it in modules) */ -#define __init __section(.init.text) __cold notrace +#define __init __section(.init.text) __cold notrace __latent_entropy#define __initdata __section(.init.data)#define __initconst __constsection(.init.rodata)#define __exitdata __section(.exit.data)
@@ -92,7 +98,7 @@#define __exit __section(.exit.text) __exitused __cold notrace/* Used for MEMORY_HOTPLUG */ -#define __meminit __section(.meminit.text) __cold notrace +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy#define __meminitdata __section(.meminit.data)#define __meminitconst __constsection(.meminit.rodata)#define __memexit __section(.memexit.text) __exitused __cold notrace
include/linux/random.h +2 -2
@@ -27,8 +27,8 @@ static inline void add_latent_entropy(void) } extern void add_input_randomness(unsigned int type, unsigned int code, -unsigned int value); -extern void add_interrupt_randomness (int irq,int irq_flags); + unsigned int value) __latent_entropy; +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;extern void get_random_bytes (void *buf,int nbytes);extern int add_random_ready_callback (struct random_ready_callback *rdy);
kernel/fork.c +2 -2
@@ -406,7 +406,7 @@ free_tsk: }#ifdef CONFIG_MMU -static int dup_mmap (struct mm_struct *mm,struct mm_struct *oldmm) +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) {struct vm_area_struct *mpnt, *tmp, *prev, **pprev;struct rb_node **rb_link, *rb_parent;
@@ -1281,7 +1281,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)* parts of the process environment (as per the clone * flags). The actual kick-off is left to the caller. */ -static struct task_struct *copy_process(unsigned long clone_flags, +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags, unsigned long stack_start, unsigned long stack_size, int __user *child_tidptr,
kernel/rcu/tiny.c +1 -1
@@ -170,7 +170,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp) false)); } -static void rcu_process_callbacks (struct softirq_action *unused) +static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused) {__rcu_process_callbacks (&rcu_sched_ctrlblk);__rcu_process_callbacks (&rcu_bh_ctrlblk);
kernel/rcu/tree.c +1 -1
@@ -3004,7 +3004,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)/* * Do RCU core processing for the current CPU. */ -static void rcu_process_callbacks (struct softirq_action *unused) +static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused) {struct rcu_state *rsp;
kernel/sched/fair.c +1 -1
@@ -8205,7 +8205,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }* run_rebalance_domains is triggered when needed from the scheduler tick. * Also triggered for nohz idle balancing (with nohz_balancing_kick set). */ -static void run_rebalance_domains (struct softirq_action *h) +static __latent_entropy void run_rebalance_domains(struct softirq_action *h) {struct rq *this_rq =this_rq (); enum cpu_idle_type idle = this_rq->idle_balance ?
kernel/softirq.c +2 -2
@@ -482,7 +482,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t) }EXPORT_SYMBOL (__tasklet_hi_schedule_first); -static void tasklet_action (struct softirq_action *a) +static __latent_entropy void tasklet_action(struct softirq_action *a) {struct tasklet_struct *list;
@@ -518,7 +518,7 @@ static void tasklet_action(struct softirq_action *a) } } -static void tasklet_hi_action (struct softirq_action *a) +static __latent_entropy void tasklet_hi_action(struct softirq_action *a) {struct tasklet_struct *list;
kernel/time/timer.c +1 -1
@@ -1414,7 +1414,7 @@ void update_process_times(int user_tick)/* * This function runs timers and the timer-tq in bottom half context. */ -static void run_timer_softirq (struct softirq_action *h) +static __latent_entropy void run_timer_softirq(struct softirq_action *h) {struct tvec_base *base =this_cpu_ptr (&tvec_bases);
lib/irq_poll.c +1 -1
@@ -74,7 +74,7 @@ void irq_poll_complete(struct irq_poll *iop) }EXPORT_SYMBOL (irq_poll_complete); -static void irq_poll_softirq (struct softirq_action *h) +static void __latent_entropy irq_poll_softirq(struct softirq_action *h) {struct list_head *list =this_cpu_ptr (&blk_cpu_iopoll);int rearm =0 , budget = irq_poll_budget;
lib/random32.c +1 -1
@@ -47,7 +47,7 @@ static inline void prandom_state_selftest(void) }#endif -static DEFINE_PER_CPU(struct rnd_state, net_rand_state); +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;/** * prandom_u32_state - seeded pseudo-random number generator.
mm/page_alloc.c +1 -1
@@ -1235,7 +1235,7 @@ static void __free_pages_ok(struct page *page, unsigned int order) }#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY -volatile u64 latent_entropy; +volatile u64 latent_entropy __latent_entropy;EXPORT_SYMBOL (latent_entropy);#endif
net/core/dev.c +2 -2
@@ -3851,7 +3851,7 @@ int netif_rx_ni(struct sk_buff *skb) }EXPORT_SYMBOL (netif_rx_ni); -static void net_tx_action (struct softirq_action *h) +static __latent_entropy void net_tx_action(struct softirq_action *h) {struct softnet_data *sd =this_cpu_ptr (&softnet_data);
@@ -5175,7 +5175,7 @@ out_unlock:return work; } -static void net_rx_action (struct softirq_action *h) +static __latent_entropy void net_rx_action(struct softirq_action *h) {struct softnet_data *sd =this_cpu_ptr (&softnet_data);unsigned long time_limit = jiffies +2 ;
Signature · 1 line
2.8.1
PATCH 3/3 Add the extra_latent_entropy kernel parameter
In reply to Emese RevfyWhen extra_latent_entropy is passed on the kernel command line, entropy will be extracted from up to the first 4GB of RAM while the runtime memory allocator is being initialized.
Based on work created by the PaX Team.
--- Documentation/kernel-parameters.txt | 5 +++++ arch/Kconfig | 5 +++++ mm/page_alloc.c | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+)
Documentation/kernel-parameters.txt +5 -0
@@ -2862,6 +2862,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted. the specified number of seconds. This is to be used if your oopses keep scrolling off the screen. + extra_latent_entropy + Enable a very simple form of latent entropy extraction + from the first 4GB of memory as the bootmem allocator + passes the memory pages to the buddy allocator. + pcbit= [HW,ISDN] pcd. [PARIDE]
arch/Kconfig +5 -0
@@ -403,6 +403,11 @@ config GCC_PLUGIN_LATENT_ENTROPY there is little 'natural' source of entropy normally. The cost is some slowdown of the boot process and fork and irq processing. + When extra_latent_entropy is passed on the kernel command line, + entropy will be extracted from up to the first 4GB of RAM while the + runtime memory allocator is being initialized. This costs even more + slowdown of the boot process. + Note that entropy extracted this way is not known to be cryptographically secure!
mm/page_alloc.c +23 -0
@@ -63,6 +63,7 @@#include <linux/sched/rt.h> #include <linux/page_owner.h> #include <linux/kthread.h> +#include <linux/random.h> #include <asm/sections.h> #include <asm/tlbflush.h>
@@ -1235,6 +1236,15 @@ static void __free_pages_ok(struct page *page, unsigned int order) }#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY +bool __meminitdata extra_latent_entropy; + +static int __init setup_extra_latent_entropy (char *str) +{ + extra_latent_entropy = true; +return 0 ; +} +early_param ("extra_latent_entropy" , setup_extra_latent_entropy); + volatile u64 latent_entropy __latent_entropy;EXPORT_SYMBOL (latent_entropy);#endif
@@ -1254,6 +1264,19 @@ static void __init __free_pages_boot_core(struct page *page, unsigned int order)__ClearPageReserved (p);set_page_count (p,0 ); +#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY +if (extra_latent_entropy && !PageHighMem (page) &&page_to_pfn (page) <0x100000 ) { +u64 hash =0 ; +size_t index, end =PAGE_SIZE * nr_pages /sizeof hash; +const u64 *data =lowmem_page_address (page); + +for (index =0 ; index < end; index++) + hash ^= hash + data[index]; + latent_entropy ^= hash; +add_device_randomness ((const void *)&latent_entropy,sizeof (latent_entropy)); + } +#endif +page_zone (page)->managed_pages += nr_pages;set_page_refcounted (page);__free_pages (page, order);
Signature · 7 lines
2.8.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v1 3/3] Add the extra_latent_entropy kernel parameter
Quoted 80 lines · Emese Revfy
When
extra_latent_entropyis passed on the kernel command line, entropy will be extracted from up to the first 4GB of RAM while the runtime memory allocator is being initialized.Based on work created by the PaX Team.
Signed-off-by Emese Revfy <[email protected]>--- Documentation/kernel-parameters.txt | 5 +++++ arch/Kconfig | 5 +++++ mm/page_alloc.c | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+)Documentation/kernel-parameters.txt +5
-0@@ -2862,6 +2862,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted. the specified number of seconds. This is to be used if your oopses keep scrolling off the screen. + extra_latent_entropy + Enable a very simple form of latent entropy extraction + from the first 4GB of memory as the bootmem allocator + passes the memory pages to the buddy allocator. + pcbit= [HW,ISDN] pcd. [PARIDE]arch/Kconfig +5
-0@@ -403,6 +403,11 @@ config GCC_PLUGIN_LATENT_ENTROPY there is little 'natural' source of entropy normally. The cost is some slowdown of the boot process and fork and irq processing. + When extra_latent_entropy is passed on the kernel command line, + entropy will be extracted from up to the first 4GB of RAM while the + runtime memory allocator is being initialized. This costs even more + slowdown of the boot process. + Note that entropy extracted this way is not known to be cryptographically secure!mm/page_alloc.c +13
-0@@ -63,6 +63,7 @@#include <linux/sched/rt.h> #include <linux/page_owner.h> #include <linux/kthread.h> +#include <linux/random.h> #include <asm/sections.h> #include <asm/tlbflush.h> @@ -1235,6 +1236,15 @@ static void __free_pages_ok(struct page *page, unsigned int order) }#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY +bool __meminitdata extra_latent_entropy; + +static int __init setup_extra_latent_entropy (char *str) +{ + extra_latent_entropy = true; +return 0 ; +} +early_param ("extra_latent_entropy" , setup_extra_latent_entropy); + volatile u64 latent_entropy __latent_entropy;EXPORT_SYMBOL (latent_entropy);#endif @@ -1254,6 +1264,19 @@ static void __init __free_pages_boot_core(struct page *page, unsigned int order)__ClearPageReserved (p);set_page_count (p,0 ); +#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY +if (extra_latent_entropy && !PageHighMem (page) &&page_to_pfn (page) <0x100000 ) { +u64 hash =0 ;
mm/page_alloc.c static void __init __free_pages_boot_core(struct page *page, unsigned int order) · line 1279
Quoted 10 lines
mm/page_alloc.c +10
-0+size_t index, end =PAGE_SIZE * nr_pages /sizeof hash; +const u64 *data =lowmem_page_address (page); + +for (index =0 ; index < end; index++) + hash ^= hash + data[index]; + latent_entropy ^= hash; + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy)); + } +#endif +
We try to minimize #ifdefs in the .c code, so in this case, I think I would define "extra_latent_entropy" during an #else above so this "if" can be culled by the compiler automatically:
#else
# define extra_latent_entropy false #endif
Others may have better suggestions to avoid the second #ifdef, but this seems the cleanest way to me to tie this to the earlier #ifdef.
-Kees
Quoted 6 lines
mm/page_alloc.c +0
-1page_zone (page)->managed_pages += nr_pages;set_page_refcounted (page);__free_pages (page, order); --2.8.1
Signature · 2 lines
Kees Cook Chrome OS & Brillo Security
Re: [PATCH v1 2/3] Mark functions with the latent_entropy attribute
In reply to Emese RevfyQuoted 10 lines · Emese Revfy
These functions have been selected because they are init functions or are called at random times or they have variable loops.
Based on work created by the PaX Team.
Signed-off-by Emese Revfy <[email protected]>[...]
include/linux/compiler-gcc.h line 194
Quoted 7 lines
include/linux/compiler-gcc.h +4
-0@@ -188,6 +188,11 @@#endif /* GCC_VERSION >= 40300 */ #if GCC_VERSION >=40500 + +#ifdef LATENT_ENTROPY_PLUGIN +#define __latent_entropy __attribute__((latent_entropy)) +#endif
This deserves a full comment above it to describe its purpose and use for when people go trying to figure out what it is and where to use it. The commit message is a bit terse, so I'd try to expand both to describe what function characteristics a developer should look for to mark something with __latent_entropy.
Quoted 27 lines
include/linux/compiler-gcc.h +1
-0+/* * Mark a position in code as unreachable. This can be used to * suppress control flow warnings after asm blocks that transfer include/linux/init.h +7
-1@@ -37,9 +37,15 @@* section. */ +#ifdef CONFIG_MEMORY_HOTPLUG +#define add_meminit_latent_entropy +#else +#define add_meminit_latent_entropy __latent_entropy +#endif +/* These are for everybody (although not all archs will actually discard it in modules) */ -#define __init __section(.init.text) __cold notrace +#define __init __section(.init.text) __cold notrace __latent_entropy#define __initdata __section(.init.data)#define __initconst __constsection(.init.rodata)#define __exitdata __section(.exit.data)
include/linux/init.h line 104
Quoted 8 lines
include/linux/init.h +1
-1@@ -92,7 +98,7 @@#define __exit __section(.exit.text) __exitused __cold notrace/* Used for MEMORY_HOTPLUG */ -#define __meminit __section(.meminit.text) __cold notrace +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy#define __meminitdata __section(.meminit.data)#define __meminitconst __constsection(.meminit.rodata)#define __memexit __section(.memexit.text) __exitused __cold notrace
I was confused by these defines. :) Maybe "add_meminit_latent_entropy" should be named "__memory_hotplug_only_latent_entropy" or something like that?
-Kees
Signature · 2 lines
Kees Cook Chrome OS & Brillo Security
Re: [PATCH v1 1/3] Add the latent_entropy gcc plugin
In reply to Emese RevfyQuoted 11 lines · Emese Revfy
This plugin mitigates the problem of the kernel having too little entropy during and after boot for generating crypto keys.
It creates a local variable in every marked function. The value of this variable is modified by randomly chosen operations (add, xor and rol) and
random values (gcc generates them at compile time and the stack pointer at runtime). It depends on the control flow (e.g., loops, conditions).Before the function returns the plugin writes this local variable into the
latent_entropyglobal variable. The value of this global variable is added to the kernel entropy pool indo_one_initcall()and_do_fork().
I'm excited to see this! This looks like it'll help a lot with early entropy, which is something that'll be a problem for some architectures that are trying to do early randomish things (e.g. the heap layout randomization, various canaries, etc).
Do you have any good examples of a before/after case of early randomness being fixed by this?
Quoted 23 lines
Based on work created by the PaX Team.
Signed-off-by Emese Revfy <[email protected]>--- arch/Kconfig | 17 ++ arch/powerpc/kernel/Makefile | 8 +- include/linux/random.h | 8 + init/main.c | 1 + kernel/fork.c | 1 + mm/page_alloc.c | 5 + scripts/Makefile.gcc-plugins | 10 +- scripts/gcc-plugins/Makefile | 1 + scripts/gcc-plugins/latent_entropy_plugin.c | 446 ++++++++++++++++++++++++++++ 9 files changed, 491 insertions(+), 6 deletions(-) create mode 100644 scripts/gcc-plugins/latent_entropy_plugin.carch/Kconfig +0
-0@@ -393,6 +393,23 @@ config GCC_PLUGIN_SANCOV gcc-4.5 on). It is based on the commit "Add fuzzing coverage support" by Dmitry Vyukov <[email protected]>.
arch/Kconfig config GCC_PLUGIN_SANCOV · line 404
Quoted 10 lines
arch/Kconfig +9
-0+config GCC_PLUGIN_LATENT_ENTROPY + bool "latent entropy" + depends on GCC_PLUGINS + help + By saying Y here the kernel will instrument some kernel code to + extract some entropy from both original and artificially created + program state. This will help especially embedded systems where + there is little 'natural' source of entropy normally. The cost + is some slowdown of the boot process and fork and irq processing.
Can "some" be more well quantified?
arch/Kconfig config GCC_PLUGIN_SANCOV · line 407
Quoted 3 lines
arch/Kconfig +3
-0+ + Note that entropy extracted this way is not known to be cryptographically + secure!
maybe add ", but should be good enough for canaries and other secrets." ?
Quoted 33 lines
arch/Kconfig +5
-0+ + This plugin was ported from grsecurity/PaX. More information at: + * https://grsecurity.net/ + * https://pax.grsecurity.net/ + config HAVE_CC_STACKPROTECTOR bool helparch/powerpc/kernel/Makefile +4
-4@@ -16,10 +16,10 @@ endif ifdef CONFIG_FUNCTION_TRACER # Do not trace early boot code -CFLAGS_REMOVE_cputable.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_prom_init.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_btext.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_prom.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_cputable.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) $(DISABLE_LATENT_ENTROPY_PLUGIN) +CFLAGS_REMOVE_prom_init.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) $(DISABLE_LATENT_ENTROPY_PLUGIN) +CFLAGS_REMOVE_btext.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) $(DISABLE_LATENT_ENTROPY_PLUGIN) +CFLAGS_REMOVE_prom.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) $(DISABLE_LATENT_ENTROPY_PLUGIN) # do not trace tracer code CFLAGS_REMOVE_ftrace.o = -mno-sched-epilog $(CC_FLAGS_FTRACE) # timers used by tracinginclude/linux/random.h +0
-0@@ -18,6 +18,14 @@ struct random_ready_callback { };
include/linux/random.h struct random_ready_callback { · line 28
Quoted 10 lines
include/linux/random.h +8
-0extern void add_device_randomness (const void *,unsigned int ); + +static inline void add_latent_entropy (void ) +{ +#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY +add_device_randomness ((const void *)&latent_entropy,sizeof (latent_entropy)); +#endif +} +
Traditionally the code style of #ifdef arrangement in header files uses an "#else" since there's usually other code to wrap in it, and it results in small future diffs:
#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
static inline void add_latent_entropy(void)
{
add_device_randomness((const void *)&latent_entropy,sizeof(latent_entropy));
}
#else
static inline void add_latent_entropy(void) { } #endif
Also, does this matter that it's non-atomic? It seems like the u64 below is being written to by multiple threads and even read by multiple threads. Am I misunderstanding something?
scripts/gcc-plugins/latent_entropy_plugin.c
Quoted 5 lines
[...]
new file mode 100644
index 0000000..7295c39scripts/gcc-plugins/latent_entropy_plugin.c new file +0
-0
I feel like most of the functions in this plugin could use some more comments about what each one does.
-Kees
Signature · 2 lines
Kees Cook Chrome OS & Brillo Security
Re: [PATCH v1 3/3] Add the extra_latent_entropy kernel parameter
In reply to Kees CookQuoted 39 lines · On Tue, 24 May 2016 10:09:16 -0700 Kees Cook <[email protected]> wrote:
Quoted 23 lines · Emese Revfy
mm/page_alloc.c +12
-0@@ -1235,6 +1236,15 @@ static void __free_pages_ok(struct page *page, unsigned int order) }#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY +bool __meminitdata extra_latent_entropy; + +static int __init setup_extra_latent_entropy (char *str) +{ + extra_latent_entropy = true; +return 0 ; +} +early_param ("extra_latent_entropy" , setup_extra_latent_entropy); + volatile u64 latent_entropy __latent_entropy;EXPORT_SYMBOL (latent_entropy);#endif @@ -1254,6 +1264,19 @@ static void __init __free_pages_boot_core(struct page *page, unsigned int order)__ClearPageReserved (p);set_page_count (p,0 ); +#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY +if (extra_latent_entropy && !PageHighMem (page) &&page_to_pfn (page) <0x100000 ) { +u64 hash =0 ;mm/page_alloc.c static void __init __free_pages_boot_core(struct page *page, unsigned int order) · line 1279
Quoted 10 lines
mm/page_alloc.c +10
-0+size_t index, end =PAGE_SIZE * nr_pages /sizeof hash; +const u64 *data =lowmem_page_address (page); + +for (index =0 ; index < end; index++) + hash ^= hash + data[index]; + latent_entropy ^= hash; + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy)); + } +#endif +We try to minimize #ifdefs in the .c code, so in this case, I think I would define "
extra_latent_entropy" during an #else above so this "if" can be culled by the compiler automatically:
Quoted 6 lines
#else
# define extra_latent_entropy false #endifOthers may have better suggestions to avoid the second #ifdef, but this seems the cleanest way to me to tie this to the earlier #ifdef.
Hi,
I think the best way would be if I removed all #ifdefs because this is useful without the latent_entropy plugin.
I don't know wether the default value of extra_latent_entropy should be true or false. I'll do some performance measurements.
Signature · 1 line
Emese
Re: [PATCH v1 2/3] Mark functions with the latent_entropy attribute
In reply to Kees CookQuoted 17 lines · On Tue, 24 May 2016 10:16:09 -0700 Kees Cook <[email protected]> wrote:
Quoted 16 lines · Emese Revfy
include/linux/init.h +7
-1+#ifdef CONFIG_MEMORY_HOTPLUG +#define add_meminit_latent_entropy +#else +#define add_meminit_latent_entropy __latent_entropy +#endif +/* These are for everybody (although not all archs will actually discard it in modules) */ -#define __init __section(.init.text) __cold notrace +#define __init __section(.init.text) __cold notrace __latent_entropy#define __initdata __section(.init.data)#define __initconst __constsection(.init.rodata)#define __exitdata __section(.exit.data)@@ -92,7 +98,7 @@#define __exit __section(.exit.text) __exitused __cold notrace
Quoted 10 lines
include/linux/init.h line 104
Quoted 6 lines
include/linux/init.h +1
-1/* Used for MEMORY_HOTPLUG */ -#define __meminit __section(.meminit.text) __cold notrace +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy#define __meminitdata __section(.meminit.data)#define __meminitconst __constsection(.meminit.rodata)#define __memexit __section(.memexit.text) __exitused __cold notraceI was confused by these defines. :) Maybe "
add_meminit_latent_entropy" should be named "__memory_hotplug_only_latent_entropy" or something like that?
I think the plugin doesn't cause a significant slowdown when CONFIG_MEMORY_HOTPLUG is enabled so I would rather always add the __latent_entropy attribute to __meminit.
Signature · 7 lines
Emese -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v1 2/3] Mark functions with the latent_entropy attribute
Quoted 31 lines · Emese Revfy
Quoted 17 lines · On Tue, 24 May 2016 10:16:09 -0700 Kees Cook <[email protected]> wrote:
Quoted 16 lines · Emese Revfy
include/linux/init.h +7
-1+#ifdef CONFIG_MEMORY_HOTPLUG +#define add_meminit_latent_entropy +#else +#define add_meminit_latent_entropy __latent_entropy +#endif +/* These are for everybody (although not all archs will actually discard it in modules) */ -#define __init __section(.init.text) __cold notrace +#define __init __section(.init.text) __cold notrace __latent_entropy#define __initdata __section(.init.data)#define __initconst __constsection(.init.rodata)#define __exitdata __section(.exit.data)@@ -92,7 +98,7 @@#define __exit __section(.exit.text) __exitused __cold notraceQuoted 10 lines
include/linux/init.h line 104
Quoted 6 lines
include/linux/init.h +1
-1/* Used for MEMORY_HOTPLUG */ -#define __meminit __section(.meminit.text) __cold notrace +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy#define __meminitdata __section(.meminit.data)#define __meminitconst __constsection(.meminit.rodata)#define __memexit __section(.memexit.text) __exitused __cold notraceI was confused by these defines. :) Maybe "
add_meminit_latent_entropy" should be named "__memory_hotplug_only_latent_entropy" or something like that?
Quoted 1 line
I think the plugin doesn't cause a significant slowdown when
CONFIG_MEMORY_HOTPLUGis enabled so I would rather always add the__latent_entropyattribute to__meminit.
That seems fine to me. :)
-Kees
Signature · 2 lines
Kees Cook Chrome OS & Brillo Security
Re: [PATCH v1 1/3] Add the latent_entropy gcc plugin
In reply to Kees CookQuoted 3 lines · On Tue, 24 May 2016 10:32:15 -0700 Kees Cook <[email protected]> wrote:
Also, does this matter that it's non-atomic? It seems like the u64 below is being written to by multiple threads and even read by multiple threads. Am I misunderstanding something?
The non-atomic accesses are intentional because they can extract more latent entropy from these data races.
Quoted 8 lines
scripts/gcc-plugins/latent_entropy_plugin.c
Quoted 5 lines
[...]
new file mode 100644
index 0000000..7295c39scripts/gcc-plugins/latent_entropy_plugin.c new file +0
-0I feel like most of the functions in this plugin could use some more comments about what each one does.
I think the important parts are commented (most parts just use the gcc API). Where would you like more comments?
Signature · 1 line
Emese
Re: [PATCH v1 1/3] Add the latent_entropy gcc plugin
In reply to Kees CookQuoted 11 lines · Kees Cook
Quoted 3 lines · Emese Revfy
This plugin mitigates the problem of the kernel having too little entropy during and after boot for generating crypto keys.
I'm excited to see this! This looks like it'll help a lot with early entropy, which is something that'll be a problem for some architectures that are trying to do early randomish things (e.g. the heap layout randomization, various canaries, etc).
Do you have any good examples of a before/after case of early randomness being fixed by this?
unfortunately, i don't know of a way to quantify this kind of PRNG as the effective algorithm is not something simple and well-structured for which we have theories and tools to analyze already. of course this cuts both ways, an attacker faces the same barrier of non-analyzability.
what can at most be observed is the state of the latent_entropy global variable after init across many boots but that'd provide a rather low and useless lower estimate only (e.g., up to 20 bits for a million reboots, or 30 bits for a billion reboots, etc).
to answer your question, i'd like to believe that there's enough latent entropy in program state that can be harnessed to (re)seed the entropy pool but we'll probably never know just how well we are doing it so accounting for it and claiming 'fixed' will stay in the realm of wishful thinking i'm afraid.
cheers,
PaX Team
Re: [PATCH v1 1/3] Add the latent_entropy gcc plugin
Quoted 19 lines · PaX Team
Quoted 11 lines · Kees Cook
Quoted 3 lines · Emese Revfy
This plugin mitigates the problem of the kernel having too little entropy during and after boot for generating crypto keys.
I'm excited to see this! This looks like it'll help a lot with early entropy, which is something that'll be a problem for some architectures that are trying to do early randomish things (e.g. the heap layout randomization, various canaries, etc).
Do you have any good examples of a before/after case of early randomness being fixed by this?
unfortunately, i don't know of a way to quantify this kind of PRNG as the effective algorithm is not something simple and well-structured for which we have theories and tools to analyze already. of course this cuts both ways, an attacker faces the same barrier of non-analyzability.
Quoted 8 lines
what can at most be observed is the state of the
latent_entropyglobal variable after init across many boots but that'd provide a rather low and useless lower estimate only (e.g., up to 20 bits for a million reboots, or 30 bits for a billion reboots, etc).to answer your question, i'd like to believe that there's enough latent entropy in program state that can be harnessed to (re)seed the entropy pool but we'll probably never know just how well we are doing it so accounting for it and claiming 'fixed' will stay in the realm of wishful thinking i'm afraid.
Yeah, answering "how random is this?" is not easy, but that's not what I meant. I'm more curious about specific build configs or hardware where calling get_random_int() early enough would always produce the same value (or the same value across all threads, etc), and in these cases, the new entropy should be visible when using the latent entropy plugin.
-Kees
Signature · 2 lines
Kees Cook Chrome OS & Brillo Security
Re: [PATCH v1 1/3] Add the latent_entropy gcc plugin
In reply to Emese RevfyQuoted 6 lines · Emese Revfy
+/*
+ * Copyright 2012-2016 by the PaX Team <[email protected]>
+ * Copyright 2016 by Emese Revfy <[email protected]>
+ * Licensed under the GPL v2
+ *
+ * Note: the choice of the license means that the compilation process is
Quoted 6 lines
+ * NOT 'eligible' as defined by gcc's library exception to the GPL v3, + * but for the kernel it doesn't matter since it doesn't link against + * any of the gcc libraries+ *
+ * gcc plugin to help generate a little bit of entropy from program state,
+ * used throughout the uptime of the kernel
The "Note" seems misleading. Since this is a GCC plugin, and directly uses GCC's internal interfaces, doesn't that make it a derived work of GCC, and thus, require that it be licensed under GPLv3 instead of GPLv2 (which is incompatible)?
AFAIK this is how the GPLv3 works in this context, and the GCC exception doesn't change that because it only applies to libgcc and friends (and does not weaken the default effects of the GPL over the rest of GCC). My understanding is that the whole "eligible compilation" licensing hack was designed to hinder non-linking proprietary compilation passes that operate over data files containing an internal GCC representation, but plain old loaded plugins still need to be GPLv3 regardless of whether you link the end result to libgcc or not.
(Also, don't some arches link against libgcc, further complicating this? Trying to use this compiler plugin with those arches would wind up with non-redistributable kernels, this time due to the exception.)
Signature · 2 lines
Hector Martin ([email protected]) Public Key: https://marcan.st/marcan.asc
Re: [PATCH v1 1/3] Add the latent_entropy gcc plugin
Quoted 28 lines · Hector Martin
Quoted 6 lines · Emese Revfy
+/*
+ * Copyright 2012-2016 by the PaX Team <[email protected]>
+ * Copyright 2016 by Emese Revfy <[email protected]>
+ * Licensed under the GPL v2
+ *
+ * Note: the choice of the license means that the compilation process isQuoted 6 lines
+ * NOT 'eligible' as defined by gcc's library exception to the GPL v3, + * but for the kernel it doesn't matter since it doesn't link against + * any of the gcc libraries+ *
+ * gcc plugin to help generate a little bit of entropy from program state,
+ * used throughout the uptime of the kernelThe "Note" seems misleading. Since this is a GCC plugin, and directly uses GCC's internal interfaces, doesn't that make it a derived work of GCC, and thus, require that it be licensed under GPLv3 instead of GPLv2 (which is incompatible)?
AFAIK this is how the GPLv3 works in this context, and the GCC exception doesn't change that because it only applies to libgcc and friends (and does not weaken the default effects of the GPL over the rest of GCC). My understanding is that the whole "eligible compilation" licensing hack was designed to hinder non-linking proprietary compilation passes that operate over data files containing an internal GCC representation, but plain old loaded plugins still need to be GPLv3 regardless of whether you link the end result to libgcc or not.
Quoted 3 lines
(Also, don't some arches link against libgcc, further complicating this? Trying to use this compiler plugin with those arches would wind up with non-redistributable kernels, this time due to the exception.)
IANAL. My interpretation is that plugins can be whatever license they want to be, and if they declare that they're GPL-compatible (which GPLv2 is), then the produced output can be under whatever license it wants. Regardless, things are clearly following the intended purposes:
the plugin is free software, used to help gcc compile free software, so no weird proprietary source, steps, or outputs, which is what the gcc folks were trying to make sure continued to happen.
-Kees
Signature · 2 lines
Kees Cook Chrome OS & Brillo Security
Re: [PATCH v1 1/3] Add the latent_entropy gcc plugin
Quoted 33 lines · Kees Cook
Quoted 28 lines · Hector Martin
Quoted 6 lines · Emese Revfy
+/*
+ * Copyright 2012-2016 by the PaX Team <[email protected]>
+ * Copyright 2016 by Emese Revfy <[email protected]>
+ * Licensed under the GPL v2
+ *
+ * Note: the choice of the license means that the compilation process isQuoted 6 lines
+ * NOT 'eligible' as defined by gcc's library exception to the GPL v3, + * but for the kernel it doesn't matter since it doesn't link against + * any of the gcc libraries+ *
+ * gcc plugin to help generate a little bit of entropy from program state,
+ * used throughout the uptime of the kernelThe "Note" seems misleading. Since this is a GCC plugin, and directly uses GCC's internal interfaces, doesn't that make it a derived work of GCC, and thus, require that it be licensed under GPLv3 instead of GPLv2 (which is incompatible)?
AFAIK this is how the GPLv3 works in this context, and the GCC exception doesn't change that because it only applies to libgcc and friends (and does not weaken the default effects of the GPL over the rest of GCC). My understanding is that the whole "eligible compilation" licensing hack was designed to hinder non-linking proprietary compilation passes that operate over data files containing an internal GCC representation, but plain old loaded plugins still need to be GPLv3 regardless of whether you link the end result to libgcc or not.
Quoted 3 lines
(Also, don't some arches link against libgcc, further complicating this? Trying to use this compiler plugin with those arches would wind up with non-redistributable kernels, this time due to the exception.)
Quoted 7 lines
IANAL. My interpretation is that plugins can be whatever license they want to be, and if they declare that they're GPL-compatible (which GPLv2 is), then the produced output can be under whatever license it wants. Regardless, things are clearly following the intended purposes:
the plugin is free software, used to help gcc compile free software, so no weird proprietary source, steps, or outputs, which is what the gcc folks were trying to make sure continued to happen.
The first problem isn't the output, it's the plugin itself. The FSF is clear on their interpretation that plugins need to be licensed under a compatible license under this kind of scenario:
http://www.gnu.org/licenses/gpl-faq.en.html#GPLAndPlugins
Since the FSF is the copyright owner for GCC, I'd say that makes a pretty clear case that the plugin needs to be GPLv3 (they don't specify v2 vs. v3 in that FAQ, but since the licenses are incompatible, GPLv2 is as good as proprietary in the eyes of GPLv3).
As for the output, unfortunately, GPLv2 is not "GPL-compatible". This is defined here:
http://www.gnu.org/licenses/gcc-exception-3.1.en.html
Quoted 3 lines
"GPL-compatible Software" is software whose conditions of propagation, modification and use would permit combination with GCC in accord with the license of GCC.
It's one of those unfortunate cases where a term defined in the legalese doesn't match the obvious interpretation, but in this context, "GPL-compatioble" means "GPLv3-compatible", and GPLv2 isn't - so the plugin combined with GCC does not for an "Eligible Compilation Process", and that means that if it is used to compile software that links with libgcc, that software has to be GPLv3-compatible - which the kernel isn't. AFAICT, that makes any kernels built for arches which link libgcc and which use this plugin non-redistributable. There is no issue with the source code form, as the kernel does not explicitly invoke libgcc interfaces, but the binary would contain a mix of GPLv2-only and GPLv3-only-exception-does-not-apply code.
IANAL, but regardless of whether this is all free software anyway, license compliance is important. If all free software were to be treated equally, we wouldn't have choices like GPLv2 vs GPLv3 vs BSD vs MIT to begin with.
Signature · 2 lines
Hector Martin "marcan" ([email protected]) Public Key: http://www.marcansoft.com/marcan.asc
Re: [PATCH v1 1/3] Add the latent_entropy gcc plugin
Quoted 46 lines · Hector Martin "marcan
Quoted 33 lines · Kees Cook
Quoted 28 lines · Hector Martin
Quoted 6 lines · Emese Revfy
+/*
+ * Copyright 2012-2016 by the PaX Team <[email protected]>
+ * Copyright 2016 by Emese Revfy <[email protected]>
+ * Licensed under the GPL v2
+ *
+ * Note: the choice of the license means that the compilation process isQuoted 6 lines
+ * NOT 'eligible' as defined by gcc's library exception to the GPL v3, + * but for the kernel it doesn't matter since it doesn't link against + * any of the gcc libraries+ *
+ * gcc plugin to help generate a little bit of entropy from program state,
+ * used throughout the uptime of the kernelThe "Note" seems misleading. Since this is a GCC plugin, and directly uses GCC's internal interfaces, doesn't that make it a derived work of GCC, and thus, require that it be licensed under GPLv3 instead of GPLv2 (which is incompatible)?
AFAIK this is how the GPLv3 works in this context, and the GCC exception doesn't change that because it only applies to libgcc and friends (and does not weaken the default effects of the GPL over the rest of GCC). My understanding is that the whole "eligible compilation" licensing hack was designed to hinder non-linking proprietary compilation passes that operate over data files containing an internal GCC representation, but plain old loaded plugins still need to be GPLv3 regardless of whether you link the end result to libgcc or not.
Quoted 3 lines
(Also, don't some arches link against libgcc, further complicating this? Trying to use this compiler plugin with those arches would wind up with non-redistributable kernels, this time due to the exception.)
Quoted 7 lines
IANAL. My interpretation is that plugins can be whatever license they want to be, and if they declare that they're GPL-compatible (which GPLv2 is), then the produced output can be under whatever license it wants. Regardless, things are clearly following the intended purposes:
the plugin is free software, used to help gcc compile free software, so no weird proprietary source, steps, or outputs, which is what the gcc folks were trying to make sure continued to happen.The first problem isn't the output, it's the plugin itself. The FSF is clear on their interpretation that plugins need to be licensed under a compatible license under this kind of scenario:
Quoted 6 lines
http://www.gnu.org/licenses/gpl-faq.en.html#GPLAndPlugins
Since the FSF is the copyright owner for GCC, I'd say that makes a pretty clear case that the plugin needs to be GPLv3 (they don't specify v2 vs. v3 in that FAQ, but since the licenses are incompatible, GPLv2 is as good as proprietary in the eyes of GPLv3).
"If the program dynamically links plug-ins, and they make function calls to each other and share data structures, we believe they form a single program, which must be treated as an extension of both the main program and the plug-ins. This means you must license the plug-in under the GPL or a GPL-compatible free software license and distribute it with source code in a GPL-compliant way."
I would point out "we believe" followed up with "GPL-compatible" (not GPLv3-compatible, and the FAQ does distinguish between them in other places). And in
http://www.gnu.org/licenses/gpl-faq.html#WhatDoesCompatMean they appear to be all-inclusive about GPL versions.
Dynamic linking license requirements are a legal unknown. See "Derivative work: yes or no?" in https://lwn.net/Articles/548216/
In the cases of these unclear interpretations, I always fall back to the spirit or intent of the licensing: GPL wants things to be copyleft. Are these plugins copyleft? Yes, done.
Quoted 9 lines
As for the output, unfortunately, GPLv2 is not "GPL-compatible". This is defined here:
http://www.gnu.org/licenses/gcc-exception-3.1.en.html
Quoted 3 lines
"GPL-compatible Software" is software whose conditions of propagation, modification and use would permit combination with GCC in accord with the license of GCC.
Quoted 8 lines
It's one of those unfortunate cases where a term defined in the legalese doesn't match the obvious interpretation, but in this context, "GPL-compatioble" means "GPLv3-compatible", and GPLv2 isn't - so the plugin combined with GCC does not for an "Eligible Compilation Process", and that means that if it is used to compile software that links with libgcc, that software has to be GPLv3-compatible - which the kernel isn't. AFAICT, that makes any kernels built for arches which link libgcc and which use this plugin non-redistributable.
If this interpretation is true, then you can take it up with the tile arch maintainers once they add the plugin support. :) (This appears to be the only arch that uses libgcc.)
Quoted 9 lines
There is no issue with
the source code form, as the kernel does not explicitly invoke libgcc interfaces, but the binary would contain a mix of GPLv2-only and GPLv3-only-exception-does-not-apply code.IANAL, but regardless of whether this is all free software anyway, license compliance is important. If all free software were to be treated equally, we wouldn't have choices like GPLv2 vs GPLv3 vs BSD vs MIT to begin with.
I don't think we'll convince each other of our respective opinions, but as I said, when there are unknowns or confusions, the best thing to do is to look at the intent. The licensing on gcc plugins appears to me to be about preserving copyleft integrity of the entire stack, which, while "only" GPLv2, is true for this situation.
-Kees
Signature · 2 lines
Kees Cook Chrome OS & Brillo Security
Re: [PATCH v1 1/3] Add the latent_entropy gcc plugin
Quoted 62 lines · Kees Cook
Quoted 46 lines · Hector Martin "marcan
Quoted 33 lines · Kees Cook
Quoted 28 lines · Hector Martin
Quoted 6 lines · Emese Revfy
+/*
+ * Copyright 2012-2016 by the PaX Team <[email protected]>
+ * Copyright 2016 by Emese Revfy <[email protected]>
+ * Licensed under the GPL v2
+ *
+ * Note: the choice of the license means that the compilation process isQuoted 6 lines
+ * NOT 'eligible' as defined by gcc's library exception to the GPL v3, + * but for the kernel it doesn't matter since it doesn't link against + * any of the gcc libraries+ *
+ * gcc plugin to help generate a little bit of entropy from program state,
+ * used throughout the uptime of the kernelThe "Note" seems misleading. Since this is a GCC plugin, and directly uses GCC's internal interfaces, doesn't that make it a derived work of GCC, and thus, require that it be licensed under GPLv3 instead of GPLv2 (which is incompatible)?
AFAIK this is how the GPLv3 works in this context, and the GCC exception doesn't change that because it only applies to libgcc and friends (and does not weaken the default effects of the GPL over the rest of GCC). My understanding is that the whole "eligible compilation" licensing hack was designed to hinder non-linking proprietary compilation passes that operate over data files containing an internal GCC representation, but plain old loaded plugins still need to be GPLv3 regardless of whether you link the end result to libgcc or not.
Quoted 3 lines
(Also, don't some arches link against libgcc, further complicating this? Trying to use this compiler plugin with those arches would wind up with non-redistributable kernels, this time due to the exception.)
Quoted 7 lines
IANAL. My interpretation is that plugins can be whatever license they want to be, and if they declare that they're GPL-compatible (which GPLv2 is), then the produced output can be under whatever license it wants. Regardless, things are clearly following the intended purposes:
the plugin is free software, used to help gcc compile free software, so no weird proprietary source, steps, or outputs, which is what the gcc folks were trying to make sure continued to happen.The first problem isn't the output, it's the plugin itself. The FSF is clear on their interpretation that plugins need to be licensed under a compatible license under this kind of scenario:
Quoted 6 lines
http://www.gnu.org/licenses/gpl-faq.en.html#GPLAndPlugins
Since the FSF is the copyright owner for GCC, I'd say that makes a pretty clear case that the plugin needs to be GPLv3 (they don't specify v2 vs. v3 in that FAQ, but since the licenses are incompatible, GPLv2 is as good as proprietary in the eyes of GPLv3).
"If the program dynamically links plug-ins, and they make function calls to each other and share data structures, we believe they form a single program, which must be treated as an extension of both the main program and the plug-ins. This means you must license the plug-in under the GPL or a GPL-compatible free software license and distribute it with source code in a GPL-compliant way."
Quoted 5 lines
I would point out "we believe" followed up with "GPL-compatible" (not GPLv3-compatible, and the FAQ does distinguish between them in other places). And in
http://www.gnu.org/licenses/gpl-faq.html#WhatDoesCompatMean they appear to be all-inclusive about GPL versions.
That GPLv2 and GPLv3 are not compatible is pretty well established:
http://www.gnu.org/licenses/gpl-faq.en.html#v2v3Compatibility
Ultimately, though, the license is what matters. And the GPLv3 license is pretty clear:
Quoted 2 lines
For example, Corresponding Source includes interface definition files associated with source files for the work
Thus, GCC internal interfaces are covered by the GPLv3.
Quoted 4 lines
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
As the plugin uses those interfaces, it is "based on" GCC.
Quoted 6 lines
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7.
And, thus, it has to be released under GPLv3.
Quoted 2 lines
Dynamic linking license requirements are a legal unknown. See "Derivative work: yes or no?" in https://lwn.net/Articles/548216/
The only thing subject to interpretation here is whether plug-ins sharing internal data structures really count as derivative works; the FAQ that I linked above makes it clear that the FSF thinks they do. Now, some people may think otherwise; that would be something that would have to be tested in court, but either way, not complying with that would be going against the FSF's wishes.
Keep in mind that usage of the GCC plugin interface is one of the strongest cases for being a derivative work; it's not a mere import of a dynamic library without sharing symbols, it's not a standardized interface. In fact it hooks quite deeply into GCC internals, and deals pretty exclusively in concepts that are fundamental to the design and implementation of GCC. This goes beyond "by linking you create a derivative work" - there's a strong argument that the source code for the plugin, itself, is a derivative work already. The FSF has been quite protective about this and vocal about not wanting license-incompatible plugins (and various workarounds for such).
Quoted 3 lines
In the cases of these unclear interpretations, I always fall back to the spirit or intent of the licensing: GPL wants things to be copyleft. Are these plugins copyleft? Yes, done.
If only the GPL were that simple :-)
Quoted 18 lines
Quoted 9 lines
As for the output, unfortunately, GPLv2 is not "GPL-compatible". This is defined here:
http://www.gnu.org/licenses/gcc-exception-3.1.en.html
Quoted 3 lines
"GPL-compatible Software" is software whose conditions of propagation, modification and use would permit combination with GCC in accord with the license of GCC.
Quoted 8 lines
It's one of those unfortunate cases where a term defined in the legalese doesn't match the obvious interpretation, but in this context, "GPL-compatioble" means "GPLv3-compatible", and GPLv2 isn't - so the plugin combined with GCC does not for an "Eligible Compilation Process", and that means that if it is used to compile software that links with libgcc, that software has to be GPLv3-compatible - which the kernel isn't. AFAICT, that makes any kernels built for arches which link libgcc and which use this plugin non-redistributable.
Quoted 3 lines
If this interpretation is true, then you can take it up with the tile arch maintainers once they add the plugin support. :) (This appears to be the only arch that uses libgcc.)
AFAICT all of arch/{arc,cris,hexagon,m32r,nios2,openrisc,parisc,tile,xtensa}/Makefile link against libgcc.
FWIW I don't think there's really anything left to interpretation; that license exception wording is pretty damn explicit.
Quoted 10 lines
Quoted 9 lines
There is no issue with
the source code form, as the kernel does not explicitly invoke libgcc interfaces, but the binary would contain a mix of GPLv2-only and GPLv3-only-exception-does-not-apply code.IANAL, but regardless of whether this is all free software anyway, license compliance is important. If all free software were to be treated equally, we wouldn't have choices like GPLv2 vs GPLv3 vs BSD vs MIT to begin with.
Quoted 5 lines
I don't think we'll convince each other of our respective opinions, but as I said, when there are unknowns or confusions, the best thing to do is to look at the intent. The licensing on gcc plugins appears to me to be about preserving copyleft integrity of the entire stack, which, while "only" GPLv2, is true for this situation.
That's a simple way to look at it, but think about it this way: if GPLv2 were already the ultimate copyleft license (in the FSF's view), there would be no GPLv3. By writing GPLv3 and switching GCC to it, the FSF is clearly making a decision that they would like people to abide by the terms of the GPLv3. Releasing a plugin, which is arguably a derivative work, under the GPLv2 "rolls back" the FSF's decision to switch to GPLv3. Sure, it's all free software, but the details matter.
Then there is the other side: is there are reason not to just make the plugin v2v3? That would certainly remove all doubt and potential issues, and complies with both GCC's license and the kernel's.
Signature · 2 lines
Hector Martin "marcan" ([email protected]) Public Key: http://www.marcansoft.com/marcan.asc
Re: [PATCH v1 1/3] Add the latent_entropy gcc plugin
In reply to Kees CookQuoted 6 lines · On Tue, 24 May 2016 19:55:17 -0700 Kees Cook <[email protected]> wrote:
Yeah, answering "how random is this?" is not easy, but that's not what I meant. I'm more curious about specific build configs or hardware where calling
get_random_int()early enough would always produce the same value (or the same value across all threads, etc), and in these cases, the new entropy should be visible when using the latent entropy plugin.
I booted minimal configs (not allnoconfig because it can't boot in qemu) many times. I couldn't produce same values.
Signature · 7 lines
Emese -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v1 1/3] Add the latent_entropy gcc plugin
In reply to Hector Martin "marcanQuoted 3 lines · Hector Martin "marcan
Then there is the other side: is there are reason not to just make the plugin v2v3? That would certainly remove all doubt and potential issues, and complies with both GCC's license and the kernel's.
If that works, please take it up with the plugin authors. You and I aren't going to convince each other, and I'm satisfied with the licensing as it already is.
-Kees
Signature · 2 lines
Kees Cook Chrome OS & Brillo Security