Skip to content

Commit 0766f78

Browse files
ephox-gcc-pluginskees
authored andcommitted
latent_entropy: Mark functions with __latent_entropy
The __latent_entropy gcc attribute can be used only on functions and variables. If it is on a function then the plugin will instrument it for gathering control-flow entropy. If the attribute is on a variable then the plugin will initialize it with random contents. The variable must be an integer, an integer array type or a structure with integer fields. These specific functions have been selected because they are init functions (to help gather boot-time entropy), are called at unpredictable times, or they have variable loops, each of which provide some level of latent entropy. Signed-off-by: Emese Revfy <[email protected]> [kees: expanded commit message] Signed-off-by: Kees Cook <[email protected]>
1 parent 38addce commit 0766f78

File tree

19 files changed

+37
-22
lines changed

19 files changed

+37
-22
lines changed

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
@@ -2759,6 +2759,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
27592759
return new_ns;
27602760
}
27612761

2762+
__latent_entropy
27622763
struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
27632764
struct user_namespace *user_ns, struct fs_struct *new_fs)
27642765
{

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
@@ -406,6 +406,10 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
406406
# define __attribute_const__ /* unimplemented */
407407
#endif
408408

409+
#ifndef __latent_entropy
410+
# define __latent_entropy
411+
#endif
412+
409413
/*
410414
* Tell gcc if a function is cold. The compiler will assume any path
411415
* 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 __constsection(.init.rodata)
4545
#define __exitdata __section(.exit.data)
@@ -86,7 +86,8 @@
8686
#define __exit __section(.exit.text) __exitused __cold notrace
8787

8888
/* Used for MEMORY_HOTPLUG */
89-
#define __meminit __section(.meminit.text) __cold notrace
89+
#define __meminit __section(.meminit.text) __cold notrace \
90+
__latent_entropy
9091
#define __meminitdata __section(.meminit.data)
9192
#define __meminitconst __constsection(.meminit.rodata)
9293
#define __memexit __section(.memexit.text) __exitused __cold notrace

include/linux/random.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ static inline void add_latent_entropy(void) {}
3030
#endif
3131

3232
extern void add_input_randomness(unsigned int type, unsigned int code,
33-
unsigned int value);
34-
extern void add_interrupt_randomness(int irq, int irq_flags);
33+
unsigned int value) __latent_entropy;
34+
extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
3535

3636
extern void get_random_bytes(void *buf, int nbytes);
3737
extern int add_random_ready_callback(struct random_ready_callback *rdy);

kernel/fork.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
404404
}
405405

406406
#ifdef CONFIG_MMU
407-
static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
407+
static __latent_entropy int dup_mmap(struct mm_struct *mm,
408+
struct mm_struct *oldmm)
408409
{
409410
struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
410411
struct rb_node **rb_link, *rb_parent;
@@ -1296,7 +1297,8 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
12961297
* parts of the process environment (as per the clone
12971298
* flags). The actual kick-off is left to the caller.
12981299
*/
1299-
static struct task_struct *copy_process(unsigned long clone_flags,
1300+
static __latent_entropy struct task_struct *copy_process(
1301+
unsigned long clone_flags,
13001302
unsigned long stack_start,
13011303
unsigned long stack_size,
13021304
int __user *child_tidptr,

0 commit comments

Comments
 (0)