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

Some content is hidden

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

42 files changed

+97
-66
lines changed

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.

include/linux/cred.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct group_info {
3131
atomic_t usage;
3232
int ngroups;
3333
kgid_t gid[0];
34-
};
34+
} __randomize_layout;
3535

3636
/**
3737
* get_group_info - Get a reference to a group info structure
@@ -145,7 +145,7 @@ struct cred {
145145
struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
146146
struct group_info *group_info; /* supplementary groups for euid/fsgid */
147147
struct rcu_head rcu; /* RCU deletion hook */
148-
};
148+
} __randomize_layout;
149149

150150
extern void __put_cred(struct cred *);
151151
extern void exit_creds(struct task_struct *);

include/linux/dcache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct dentry {
118118
struct hlist_bl_node d_in_lookup_hash; /* only for in-lookup ones */
119119
struct rcu_head d_rcu;
120120
} d_u;
121-
};
121+
} __randomize_layout;
122122

123123
/*
124124
* dentry->d_lock spinlock nesting subclasses:

include/linux/fs.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ struct kiocb {
296296
void *private;
297297
int ki_flags;
298298
enum rw_hint ki_hint;
299-
};
299+
} __randomize_layout;
300300

301301
static inline bool is_sync_kiocb(struct kiocb *kiocb)
302302
{
@@ -404,7 +404,7 @@ struct address_space {
404404
struct list_head private_list; /* ditto */
405405
void *private_data; /* ditto */
406406
errseq_t wb_err;
407-
} __attribute__((aligned(sizeof(long))));
407+
} __attribute__((aligned(sizeof(long)))) __randomize_layout;
408408
/*
409409
* On most architectures that alignment is already the case; but
410410
* must be enforced here for CRIS, to let the least significant bit
@@ -447,7 +447,7 @@ struct block_device {
447447
int bd_fsfreeze_count;
448448
/* Mutex for freeze */
449449
struct mutex bd_fsfreeze_mutex;
450-
};
450+
} __randomize_layout;
451451

452452
/*
453453
* Radix-tree tags, for tagging dirty and writeback pages within the pagecache
@@ -666,7 +666,7 @@ struct inode {
666666
#endif
667667

668668
void *i_private; /* fs or device private pointer */
669-
};
669+
} __randomize_layout;
670670

671671
static inline unsigned int i_blocksize(const struct inode *node)
672672
{
@@ -883,7 +883,8 @@ struct file {
883883
#endif /* #ifdef CONFIG_EPOLL */
884884
struct address_space *f_mapping;
885885
errseq_t f_wb_err;
886-
} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
886+
} __randomize_layout
887+
__attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
887888

888889
struct file_handle {
889890
__u32 handle_bytes;
@@ -1020,7 +1021,7 @@ struct file_lock {
10201021
int state; /* state of grant or error if -ve */
10211022
} afs;
10221023
} fl_u;
1023-
};
1024+
} __randomize_layout;
10241025

10251026
struct file_lock_context {
10261027
spinlock_t flc_lock;
@@ -1412,7 +1413,7 @@ struct super_block {
14121413

14131414
spinlock_t s_inode_wblist_lock;
14141415
struct list_head s_inodes_wb; /* writeback inodes */
1415-
};
1416+
} __randomize_layout;
14161417

14171418
/* Helper functions so that in most cases filesystems will
14181419
* not need to deal directly with kuid_t and kgid_t and can
@@ -1698,7 +1699,7 @@ struct file_operations {
16981699
u64);
16991700
ssize_t (*dedupe_file_range)(struct file *, u64, u64, struct file *,
17001701
u64);
1701-
};
1702+
} __randomize_layout;
17021703

17031704
struct inode_operations {
17041705
struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);

include/linux/fs_struct.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct fs_struct {
1212
int umask;
1313
int in_exec;
1414
struct path root, pwd;
15-
};
15+
} __randomize_layout;
1616

1717
extern struct kmem_cache *fs_cachep;
1818

include/linux/ipc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ struct kern_ipc_perm {
2323

2424
struct rcu_head rcu;
2525
atomic_t refcount;
26-
} ____cacheline_aligned_in_smp;
26+
} ____cacheline_aligned_in_smp __randomize_layout;
2727

2828
#endif /* _LINUX_IPC_H */

include/linux/ipc_namespace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct ipc_namespace {
6161
struct ucounts *ucounts;
6262

6363
struct ns_common ns;
64-
};
64+
} __randomize_layout;
6565

6666
extern struct ipc_namespace init_ipc_ns;
6767
extern spinlock_t mq_lock;

include/linux/key-type.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct key_preparsed_payload {
4545
size_t datalen; /* Raw datalen */
4646
size_t quotalen; /* Quota length for proposed payload */
4747
time_t expiry; /* Expiry time of key */
48-
};
48+
} __randomize_layout;
4949

5050
typedef int (*request_key_actor_t)(struct key_construction *key,
5151
const char *op, void *aux);
@@ -158,7 +158,7 @@ struct key_type {
158158
/* internal fields */
159159
struct list_head link; /* link in types list */
160160
struct lock_class_key lock_class; /* key->sem lock class */
161-
};
161+
} __randomize_layout;
162162

163163
extern struct key_type key_type_keyring;
164164

include/linux/kmod.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct subprocess_info {
6464
int (*init)(struct subprocess_info *info, struct cred *new);
6565
void (*cleanup)(struct subprocess_info *info);
6666
void *data;
67-
};
67+
} __randomize_layout;
6868

6969
extern int
7070
call_usermodehelper(const char *path, char **argv, char **envp, int wait);

include/linux/kobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ struct kset {
172172
spinlock_t list_lock;
173173
struct kobject kobj;
174174
const struct kset_uevent_ops *uevent_ops;
175-
};
175+
} __randomize_layout;
176176

177177
extern void kset_init(struct kset *kset);
178178
extern int __must_check kset_register(struct kset *kset);

include/linux/lsm_hooks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ struct security_hook_heads {
19121912
struct list_head audit_rule_match;
19131913
struct list_head audit_rule_free;
19141914
#endif /* CONFIG_AUDIT */
1915-
};
1915+
} __randomize_layout;
19161916

19171917
/*
19181918
* Security module hook list structure.
@@ -1923,7 +1923,7 @@ struct security_hook_list {
19231923
struct list_head *head;
19241924
union security_list_options hook;
19251925
char *lsm;
1926-
};
1926+
} __randomize_layout;
19271927

19281928
/*
19291929
* Initializing a security_hook_list structure takes

0 commit comments

Comments
 (0)