Skip to content

Commit 9ffc669

Browse files
committed
Merge tag 'gcc-plugins-v4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull gcc plugins update from Kees Cook: "This adds a new gcc plugin named "latent_entropy". It is designed to extract as much possible uncertainty from a running system at boot time as possible, hoping to capitalize on any possible variation in CPU operation (due to runtime data differences, hardware differences, SMP ordering, thermal timing variation, cache behavior, etc). At the very least, this plugin is a much more comprehensive example for how to manipulate kernel code using the gcc plugin internals" * tag 'gcc-plugins-v4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: latent_entropy: Mark functions with __latent_entropy gcc-plugins: Add latent_entropy plugin
2 parents 133d970 + 0766f78 commit 9ffc669

File tree

24 files changed

+725
-22
lines changed

24 files changed

+725
-22
lines changed

arch/Kconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,24 @@ config GCC_PLUGIN_SANCOV
383383
gcc-4.5 on). It is based on the commit "Add fuzzing coverage support"
384384
by Dmitry Vyukov <[email protected]>.
385385

386+
config GCC_PLUGIN_LATENT_ENTROPY
387+
bool "Generate some entropy during boot and runtime"
388+
depends on GCC_PLUGINS
389+
help
390+
By saying Y here the kernel will instrument some kernel code to
391+
extract some entropy from both original and artificially created
392+
program state. This will help especially embedded systems where
393+
there is little 'natural' source of entropy normally. The cost
394+
is some slowdown of the boot process (about 0.5%) and fork and
395+
irq processing.
396+
397+
Note that entropy extracted this way is not cryptographically
398+
secure!
399+
400+
This plugin was ported from grsecurity/PaX. More information at:
401+
* https://grsecurity.net/
402+
* https://pax.grsecurity.net/
403+
386404
config HAVE_CC_STACKPROTECTOR
387405
bool
388406
help

arch/powerpc/kernel/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ CFLAGS_prom_init.o += -fPIC
1414
CFLAGS_btext.o += -fPIC
1515
endif
1616

17+
CFLAGS_cputable.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
18+
CFLAGS_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
19+
CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
20+
CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
21+
1722
ifdef CONFIG_FUNCTION_TRACER
1823
# Do not trace early boot code
1924
CFLAGS_REMOVE_cputable.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)

block/blk-softirq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
1818
* Softirq action handler - move entries to local list and loop over them
1919
* while passing them to the queue registered handler.
2020
*/
21-
static void blk_done_softirq(struct softirq_action *h)
21+
static __latent_entropy void blk_done_softirq(struct softirq_action *h)
2222
{
2323
struct list_head *cpu_list, local_list;
2424

drivers/char/random.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ static ssize_t _extract_entropy(struct entropy_store *r, void *buf,
479479

480480
static void crng_reseed(struct crng_state *crng, struct entropy_store *r);
481481
static void push_to_pool(struct work_struct *work);
482-
static __u32 input_pool_data[INPUT_POOL_WORDS];
483-
static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
482+
static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
483+
static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
484484

485485
static struct entropy_store input_pool = {
486486
.poolinfo = &poolinfo_table[0],

fs/namespace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
28242824
return new_ns;
28252825
}
28262826

2827+
__latent_entropy
28272828
struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
28282829
struct user_namespace *user_ns, struct fs_struct *new_fs)
28292830
{

include/linux/compiler-gcc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@
188188
#endif /* GCC_VERSION >= 40300 */
189189

190190
#if GCC_VERSION >= 40500
191+
192+
#ifndef __CHECKER__
193+
#ifdef LATENT_ENTROPY_PLUGIN
194+
#define __latent_entropy __attribute__((latent_entropy))
195+
#endif
196+
#endif
197+
191198
/*
192199
* Mark a position in code as unreachable. This can be used to
193200
* suppress control flow warnings after asm blocks that transfer

include/linux/compiler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
429429
# define __attribute_const__ /* unimplemented */
430430
#endif
431431

432+
#ifndef __latent_entropy
433+
# define __latent_entropy
434+
#endif
435+
432436
/*
433437
* Tell gcc if a function is cold. The compiler will assume any path
434438
* directly leading to the call is unlikely.

include/linux/fdtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ struct files_struct *get_files_struct(struct task_struct *);
105105
void put_files_struct(struct files_struct *fs);
106106
void reset_files_struct(struct files_struct *);
107107
int unshare_files(struct files_struct **);
108-
struct files_struct *dup_fd(struct files_struct *, int *);
108+
struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
109109
void do_close_on_exec(struct files_struct *);
110110
int iterate_fd(struct files_struct *, unsigned,
111111
int (*)(const void *, struct file *, unsigned),

include/linux/genhd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
437437
extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
438438

439439
/* drivers/char/random.c */
440-
extern void add_disk_randomness(struct gendisk *disk);
440+
extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
441441
extern void rand_initialize_disk(struct gendisk *disk);
442442

443443
static inline sector_t get_start_sect(struct block_device *bdev)

include/linux/init.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
/* These are for everybody (although not all archs will actually
4141
discard it in modules) */
42-
#define __init __section(.init.text) __cold notrace
42+
#define __init __section(.init.text) __cold notrace __latent_entropy
4343
#define __initdata __section(.init.data)
4444
#define __initconst __section(.init.rodata)
4545
#define __exitdata __section(.exit.data)
@@ -75,7 +75,8 @@
7575
#define __exit __section(.exit.text) __exitused __cold notrace
7676

7777
/* Used for MEMORY_HOTPLUG */
78-
#define __meminit __section(.meminit.text) __cold notrace
78+
#define __meminit __section(.meminit.text) __cold notrace \
79+
__latent_entropy
7980
#define __meminitdata __section(.meminit.data)
8081
#define __meminitconst __section(.meminit.rodata)
8182
#define __memexit __section(.memexit.text) __exitused __cold notrace

0 commit comments

Comments
 (0)