History

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

Linus Torvalds committed 9 years ago

Commit e06fdaf2 parents a90c6ac 8acdf5042 files · +97 −66Browse files

Showing the changes to include/linux (30 of 42 files). Show all

Unified · Split

30 files
  1. include/linux/binfmts.h +2 −2
  2. include/linux/cdev.h +1 −1
  3. include/linux/compiler-gcc.h +12 −1
  4. include/linux/compiler.h +5 −0
  5. include/linux/cred.h +2 −2
  6. include/linux/dcache.h +1 −1
  7. include/linux/fs.h +9 −8
  8. include/linux/fs_struct.h +1 −1
  9. include/linux/ipc.h +1 −1
  10. include/linux/ipc_namespace.h +1 −1
  11. include/linux/key-type.h +2 −2
  12. include/linux/kmod.h +1 −1
  13. include/linux/kobject.h +1 −1
  14. include/linux/lsm_hooks.h +2 −2
  15. include/linux/mm_types.h +2 −2
  16. include/linux/module.h +2 −2
  17. include/linux/mount.h +1 −1
  18. include/linux/msg.h +1 −1
  19. include/linux/path.h +1 −1
  20. include/linux/pid_namespace.h +1 −1
  21. include/linux/proc_ns.h +1 −1
  22. include/linux/sched.h +15 −1
  23. include/linux/sched/signal.h +1 −1
  24. include/linux/sem.h +1 −1
  25. include/linux/shm.h +1 −1
  26. include/linux/sysctl.h +1 −1
  27. include/linux/tty.h +1 −1
  28. include/linux/tty_driver.h +2 −2
  29. include/linux/user_namespace.h +1 −1
  30. include/linux/utsname.h +1 −1
include/linux/binfmts.h+2−2
@@ -46,7 +46,7 @@ struct linux_binprm { · 45 unmodified lines
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 { · 28 unmodified lines
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+1−1
@@ -17,7 +17,7 @@ struct cdev { · 16 unmodified lines
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+12−1
@@ -235,6 +235,7 @@ · 234 unmodified lines
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
@@ -242,7 +243,17 @@ · 1 unmodified line
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+5−0
@@ -452,6 +452,11 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s · 451 unmodified lines
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+2−2
@@ -31,7 +31,7 @@ struct group_info { · 30 unmodified lines
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 { · 107 unmodified lines
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+1−1
@@ -118,7 +118,7 @@ struct dentry { · 117 unmodified lines
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+9−8
@@ -296,7 +296,7 @@ struct kiocb { · 295 unmodified lines
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 { · 101 unmodified lines
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 { · 36 unmodified lines
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 { · 212 unmodified lines
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 { · 210 unmodified lines
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 { · 130 unmodified lines
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 { · 385 unmodified lines
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 { · 279 unmodified lines
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+1−1
@@ -12,7 +12,7 @@ struct fs_struct { · 11 unmodified lines
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+1−1
@@ -23,6 +23,6 @@ struct kern_ipc_perm { · 22 unmodified lines
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+1−1
@@ -61,7 +61,7 @@ struct ipc_namespace { · 60 unmodified lines
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+2−2
@@ -45,7 +45,7 @@ struct key_preparsed_payload { · 44 unmodified lines
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 { · 106 unmodified lines
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+1−1
@@ -64,7 +64,7 @@ struct subprocess_info { · 63 unmodified lines
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+1−1
@@ -172,7 +172,7 @@ struct kset { · 171 unmodified lines
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+2−2
@@ -1912,7 +1912,7 @@ struct security_hook_heads { · 1911 unmodified lines
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 { · 4 unmodified lines
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
include/linux/mm_types.h+2−2
@@ -342,7 +342,7 @@ struct vm_area_struct { · 341 unmodified lines
342342 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
343343 #endif
344344 struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
345−};
345+} __randomize_layout;
346346
347347 struct core_thread {
348348 struct task_struct *task;
@@ -500,7 +500,7 @@ struct mm_struct { · 151 unmodified lines
500500 atomic_long_t hugetlb_usage;
501501 #endif
502502 struct work_struct async_put_work;
503−};
503+} __randomize_layout;
504504
505505 extern struct mm_struct init_mm;
506506
include/linux/module.h+2−2
@@ -45,7 +45,7 @@ struct module_kobject { · 44 unmodified lines
4545 struct kobject *drivers_dir;
4646 struct module_param_attrs *mp;
4747 struct completion *kobj_completion;
48−};
48+} __randomize_layout;
4949
5050 struct module_attribute {
5151 struct attribute attr;
@@ -475,7 +475,7 @@ struct module { · 423 unmodified lines
475475 ctor_fn_t *ctors;
476476 unsigned int num_ctors;
477477 #endif
478−} ____cacheline_aligned;
478+} ____cacheline_aligned __randomize_layout;
479479 #ifndef MODULE_ARCH_INIT
480480 #define MODULE_ARCH_INIT {}
481481 #endif
include/linux/mount.h+1−1
@@ -67,7 +67,7 @@ struct vfsmount { · 66 unmodified lines
6767 struct dentry *mnt_root; /* root of the mounted tree */
6868 struct super_block *mnt_sb; /* pointer to superblock */
6969 int mnt_flags;
70−};
70+} __randomize_layout;
7171
7272 struct file; /* forward dec */
7373 struct path;
include/linux/msg.h+1−1
@@ -29,7 +29,7 @@ struct msg_queue { · 28 unmodified lines
2929 struct list_head q_messages;
3030 struct list_head q_receivers;
3131 struct list_head q_senders;
32−};
32+} __randomize_layout;
3333
3434 /* Helper routines for sys_msgsnd and sys_msgrcv */
3535 extern long do_msgsnd(int msqid, long mtype, void __user *mtext,
include/linux/path.h+1−1
@@ -7,7 +7,7 @@ struct vfsmount; · 6 unmodified lines
77 struct path {
88 struct vfsmount *mnt;
99 struct dentry *dentry;
10−};
10+} __randomize_layout;
1111
1212 extern void path_get(const struct path *);
1313 extern void path_put(const struct path *);
include/linux/pid_namespace.h+1−1
@@ -52,7 +52,7 @@ struct pid_namespace { · 51 unmodified lines
5252 int hide_pid;
5353 int reboot; /* group exit code if this pidns was rebooted */
5454 struct ns_common ns;
55−};
55+} __randomize_layout;
5656
5757 extern struct pid_namespace init_pid_ns;
5858
include/linux/proc_ns.h+1−1
@@ -21,7 +21,7 @@ struct proc_ns_operations { · 20 unmodified lines
2121 int (*install)(struct nsproxy *nsproxy, struct ns_common *ns);
2222 struct user_namespace *(*owner)(struct ns_common *ns);
2323 struct ns_common *(*get_parent)(struct ns_common *ns);
24−};
24+} __randomize_layout;
2525
2626 extern const struct proc_ns_operations netns_operations;
2727 extern const struct proc_ns_operations utsns_operations;
include/linux/sched.h+15−1
@@ -426,7 +426,7 @@ struct sched_rt_entity { · 425 unmodified lines
426426 /* rq "owned" by this entity/group: */
427427 struct rt_rq *my_q;
428428 #endif
429−};
429+} __randomize_layout;
430430
431431 struct sched_dl_entity {
432432 struct rb_node rb_node;
@@ -526,6 +526,13 @@ struct task_struct { · 93 unmodified lines
526526 #endif
527527 /* -1 unrunnable, 0 runnable, >0 stopped: */
528528 volatile long state;
529+
530+ /*
531+ * This begins the randomizable portion of task_struct. Only
532+ * scheduling-critical items should be added above here.
533+ */
534+ randomized_struct_fields_start
535+
529536 void *stack;
530537 atomic_t usage;
531538 /* Per task flags (PF_*), defined further below: */
@@ -1079,6 +1086,13 @@ struct task_struct { · 547 unmodified lines
10791086 /* Used by LSM modules for access restriction: */
10801087 void *security;
10811088 #endif
1089+
1090+ /*
1091+ * New fields for task_struct should be added above here, so that
1092+ * they are included in the randomized portion of task_struct.
1093+ */
1094+ randomized_struct_fields_end
1095+
10821096 /* CPU-specific state of this task: */
10831097 struct thread_struct thread;
10841098
include/linux/sched/signal.h+1−1
@@ -222,7 +222,7 @@ struct signal_struct { · 221 unmodified lines
222222 struct mutex cred_guard_mutex; /* guard against foreign influences on
223223 * credential calculations
224224 * (notably. ptrace) */
225−};
225+} __randomize_layout;
226226
227227 /*
228228 * Bits in flags field of signal_struct.
include/linux/sem.h+1−1
@@ -41,7 +41,7 @@ struct sem_array { · 40 unmodified lines
4141 unsigned int use_global_lock;/* >0: global lock required */
4242
4343 struct sem sems[];
44−};
44+} __randomize_layout;
4545
4646 #ifdef CONFIG_SYSVIPC
4747
include/linux/shm.h+1−1
@@ -22,7 +22,7 @@ struct shmid_kernel /* private to the kernel */ · 21 unmodified lines
2222 /* The task created the shm object. NULL if the task is dead. */
2323 struct task_struct *shm_creator;
2424 struct list_head shm_clist; /* list by creator */
25−};
25+} __randomize_layout;
2626
2727 /* shm_mode upper byte flags */
2828 #define SHM_DEST 01000 /* segment will be destroyed on last detach */
include/linux/sysctl.h+1−1
@@ -120,7 +120,7 @@ struct ctl_table · 119 unmodified lines
120120 struct ctl_table_poll *poll;
121121 void *extra1;
122122 void *extra2;
123−};
123+} __randomize_layout;
124124
125125 struct ctl_node {
126126 struct rb_node node;
include/linux/tty.h+1−1
@@ -332,7 +332,7 @@ struct tty_struct { · 331 unmodified lines
332332 /* If the tty has a pending do_SAK, queue it here - akpm */
333333 struct work_struct SAK_work;
334334 struct tty_port *port;
335−};
335+} __randomize_layout;
336336
337337 /* Each of a tty's open files has private_data pointing to tty_file_private */
338338 struct tty_file_private {
include/linux/tty_driver.h+2−2
@@ -291,7 +291,7 @@ struct tty_operations { · 290 unmodified lines
291291 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
292292 #endif
293293 const struct file_operations *proc_fops;
294−};
294+} __randomize_layout;
295295
296296 struct tty_driver {
297297 int magic; /* magic number for this structure */
@@ -325,7 +325,7 @@ struct tty_driver { · 27 unmodified lines
325325
326326 const struct tty_operations *ops;
327327 struct list_head tty_drivers;
328−};
328+} __randomize_layout;
329329
330330 extern struct list_head tty_drivers;
331331
include/linux/user_namespace.h+1−1
@@ -66,7 +66,7 @@ struct user_namespace { · 65 unmodified lines
6666 #endif
6767 struct ucounts *ucounts;
6868 int ucount_max[UCOUNT_COUNTS];
69−};
69+} __randomize_layout;
7070
7171 struct ucounts {
7272 struct hlist_node node;
include/linux/utsname.h+1−1
@@ -26,7 +26,7 @@ struct uts_namespace { · 25 unmodified lines
2626 struct user_namespace *user_ns;
2727 struct ucounts *ucounts;
2828 struct ns_common ns;
29−};
29+} __randomize_layout;
3030 extern struct uts_namespace init_uts_ns;
3131
3232 #ifdef CONFIG_UTS_NS