Skip to content

Commit e06fdaf

Browse files
committed
Merge tag 'gcc-plugins-v4.13-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull structure randomization updates from Kees Cook: "Now that IPC and other changes have landed, enable manual markings for randstruct plugin, including the task_struct. This is the rest of what was staged in -next for the gcc-plugins, and comes in three patches, largest first: - mark "easy" structs with __randomize_layout - mark task_struct with an optional anonymous struct to isolate the __randomize_layout section - mark structs to opt _out_ of automated marking (which will come later) And, FWIW, this continues to pass allmodconfig (normal and patched to enable gcc-plugins) builds of x86_64, i386, arm64, arm, powerpc, and s390 for me" * tag 'gcc-plugins-v4.13-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: randstruct: opt-out externally exposed function pointer structs task_struct: Allow randomized layout randstruct: Mark various structs for randomization
2 parents a90c6ac + 8acdf50 commit e06fdaf

42 files changed

Lines changed: 97 additions & 66 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/arm/include/asm/cacheflush.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct cpu_cache_fns {
116116
void (*dma_unmap_area)(const void *, size_t, int);
117117

118118
void (*dma_flush_range)(const void *, const void *);
119-
};
119+
} __no_randomize_layout;
120120

121121
/*
122122
* Select the calling method

‎arch/x86/include/asm/paravirt_types.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@ struct pv_init_ops {
8484
*/
8585
unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
8686
unsigned long addr, unsigned len);
87-
};
87+
} __no_randomize_layout;
8888

8989

9090
struct pv_lazy_ops {
9191
/* Set deferred update mode, used for batching operations. */
9292
void (*enter)(void);
9393
void (*leave)(void);
9494
void (*flush)(void);
95-
};
95+
} __no_randomize_layout;
9696

9797
struct pv_time_ops {
9898
unsigned long long (*sched_clock)(void);
9999
unsigned long long (*steal_clock)(int cpu);
100-
};
100+
} __no_randomize_layout;
101101

102102
struct pv_cpu_ops {
103103
/* hooks for various privileged instructions */
@@ -176,7 +176,7 @@ struct pv_cpu_ops {
176176

177177
void (*start_context_switch)(struct task_struct *prev);
178178
void (*end_context_switch)(struct task_struct *next);
179-
};
179+
} __no_randomize_layout;
180180

181181
struct pv_irq_ops {
182182
/*
@@ -199,7 +199,7 @@ struct pv_irq_ops {
199199
#ifdef CONFIG_X86_64
200200
void (*adjust_exception_frame)(void);
201201
#endif
202-
};
202+
} __no_randomize_layout;
203203

204204
struct pv_mmu_ops {
205205
unsigned long (*read_cr2)(void);
@@ -305,7 +305,7 @@ struct pv_mmu_ops {
305305
an mfn. We can tell which is which from the index. */
306306
void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
307307
phys_addr_t phys, pgprot_t flags);
308-
};
308+
} __no_randomize_layout;
309309

310310
struct arch_spinlock;
311311
#ifdef CONFIG_SMP
@@ -322,7 +322,7 @@ struct pv_lock_ops {
322322
void (*kick)(int cpu);
323323

324324
struct paravirt_callee_save vcpu_is_preempted;
325-
};
325+
} __no_randomize_layout;
326326

327327
/* This contains all the paravirt structures: we get a convenient
328328
* number for each function using the offset which we use to indicate
@@ -334,7 +334,7 @@ struct paravirt_patch_template {
334334
struct pv_irq_ops pv_irq_ops;
335335
struct pv_mmu_ops pv_mmu_ops;
336336
struct pv_lock_ops pv_lock_ops;
337-
};
337+
} __no_randomize_layout;
338338

339339
extern struct pv_info pv_info;
340340
extern struct pv_init_ops pv_init_ops;

‎arch/x86/include/asm/processor.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ struct cpuinfo_x86 {
129129
/* Index into per_cpu list: */
130130
u16 cpu_index;
131131
u32 microcode;
132-
};
132+
} __randomize_layout;
133133

134134
struct cpuid_regs {
135135
u32 eax, ebx, ecx, edx;

‎fs/mount.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct mnt_namespace {
1616
u64 event;
1717
unsigned int mounts; /* # of mounts in the namespace */
1818
unsigned int pending_mounts;
19-
};
19+
} __randomize_layout;
2020

2121
struct mnt_pcp {
2222
int mnt_count;
@@ -69,7 +69,7 @@ struct mount {
6969
struct hlist_head mnt_pins;
7070
struct fs_pin mnt_umount;
7171
struct dentry *mnt_ex_mountpoint;
72-
};
72+
} __randomize_layout;
7373

7474
#define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
7575

‎fs/namei.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ struct nameidata {
524524
struct inode *link_inode;
525525
unsigned root_seq;
526526
int dfd;
527-
};
527+
} __randomize_layout;
528528

529529
static void set_nameidata(struct nameidata *p, int dfd, struct filename *name)
530530
{

‎fs/proc/internal.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct proc_dir_entry {
5151
spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
5252
u8 namelen;
5353
char name[];
54-
};
54+
} __randomize_layout;
5555

5656
union proc_op {
5757
int (*proc_get_link)(struct dentry *, struct path *);
@@ -70,7 +70,7 @@ struct proc_inode {
7070
struct hlist_node sysctl_inodes;
7171
const struct proc_ns_operations *ns_ops;
7272
struct inode vfs_inode;
73-
};
73+
} __randomize_layout;
7474

7575
/*
7676
* General functions
@@ -279,7 +279,7 @@ struct proc_maps_private {
279279
#ifdef CONFIG_NUMA
280280
struct mempolicy *task_mempolicy;
281281
#endif
282-
};
282+
} __randomize_layout;
283283

284284
struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode);
285285

‎include/linux/binfmts.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct linux_binprm {
4646
unsigned interp_flags;
4747
unsigned interp_data;
4848
unsigned long loader, exec;
49-
};
49+
} __randomize_layout;
5050

5151
#define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
5252
#define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
@@ -81,7 +81,7 @@ struct linux_binfmt {
8181
int (*load_shlib)(struct file *);
8282
int (*core_dump)(struct coredump_params *cprm);
8383
unsigned long min_coredump; /* minimal dump size */
84-
};
84+
} __randomize_layout;
8585

8686
extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
8787

‎include/linux/cdev.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct cdev {
1717
struct list_head list;
1818
dev_t dev;
1919
unsigned int count;
20-
};
20+
} __randomize_layout;
2121

2222
void cdev_init(struct cdev *, const struct file_operations *);
2323

‎include/linux/compiler-gcc.h‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,25 @@
235235
#endif /* GCC_VERSION >= 40500 */
236236

237237
#if GCC_VERSION >= 40600
238+
238239
/*
239240
* When used with Link Time Optimization, gcc can optimize away C functions or
240241
* variables which are referenced only from assembly code. __visible tells the
241242
* optimizer that something else uses this function or variable, thus preventing
242243
* this.
243244
*/
244245
#define __visible __attribute__((externally_visible))
245-
#endif
246+
247+
/*
248+
* RANDSTRUCT_PLUGIN wants to use an anonymous struct, but it is only
249+
* possible since GCC 4.6. To provide as much build testing coverage
250+
* as possible, this is used for all GCC 4.6+ builds, and not just on
251+
* RANDSTRUCT_PLUGIN builds.
252+
*/
253+
#define randomized_struct_fields_start struct {
254+
#define randomized_struct_fields_end } __randomize_layout;
255+
256+
#endif /* GCC_VERSION >= 40600 */
246257

247258

248259
#if GCC_VERSION >= 40900 && !defined(__CHECKER__)

‎include/linux/compiler.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
452452
# define __no_randomize_layout
453453
#endif
454454

455+
#ifndef randomized_struct_fields_start
456+
# define randomized_struct_fields_start
457+
# define randomized_struct_fields_end
458+
#endif
459+
455460
/*
456461
* Tell gcc if a function is cold. The compiler will assume any path
457462
* directly leading to the call is unlikely.

0 commit comments

Comments
 (0)