Skip to content

Commit

Permalink
Merge tag 'gcc-plugins-v4.13-rc2' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/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
  • Loading branch information
torvalds committed Jul 19, 2017
2 parents a90c6ac + 8acdf50 commit e06fdaf
Show file tree
Hide file tree
Showing 42 changed files with 97 additions and 66 deletions.
2 changes: 1 addition & 1 deletion arch/arm/include/asm/cacheflush.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct cpu_cache_fns {
void (*dma_unmap_area)(const void *, size_t, int);

void (*dma_flush_range)(const void *, const void *);
};
} __no_randomize_layout;

/*
* Select the calling method
Expand Down
16 changes: 8 additions & 8 deletions arch/x86/include/asm/paravirt_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,20 @@ struct pv_init_ops {
*/
unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
unsigned long addr, unsigned len);
};
} __no_randomize_layout;


struct pv_lazy_ops {
/* Set deferred update mode, used for batching operations. */
void (*enter)(void);
void (*leave)(void);
void (*flush)(void);
};
} __no_randomize_layout;

struct pv_time_ops {
unsigned long long (*sched_clock)(void);
unsigned long long (*steal_clock)(int cpu);
};
} __no_randomize_layout;

struct pv_cpu_ops {
/* hooks for various privileged instructions */
Expand Down Expand Up @@ -176,7 +176,7 @@ struct pv_cpu_ops {

void (*start_context_switch)(struct task_struct *prev);
void (*end_context_switch)(struct task_struct *next);
};
} __no_randomize_layout;

struct pv_irq_ops {
/*
Expand All @@ -199,7 +199,7 @@ struct pv_irq_ops {
#ifdef CONFIG_X86_64
void (*adjust_exception_frame)(void);
#endif
};
} __no_randomize_layout;

struct pv_mmu_ops {
unsigned long (*read_cr2)(void);
Expand Down Expand Up @@ -305,7 +305,7 @@ struct pv_mmu_ops {
an mfn. We can tell which is which from the index. */
void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
phys_addr_t phys, pgprot_t flags);
};
} __no_randomize_layout;

struct arch_spinlock;
#ifdef CONFIG_SMP
Expand All @@ -322,7 +322,7 @@ struct pv_lock_ops {
void (*kick)(int cpu);

struct paravirt_callee_save vcpu_is_preempted;
};
} __no_randomize_layout;

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

extern struct pv_info pv_info;
extern struct pv_init_ops pv_init_ops;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ struct cpuinfo_x86 {
/* Index into per_cpu list: */
u16 cpu_index;
u32 microcode;
};
} __randomize_layout;

struct cpuid_regs {
u32 eax, ebx, ecx, edx;
Expand Down
4 changes: 2 additions & 2 deletions fs/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct mnt_namespace {
u64 event;
unsigned int mounts; /* # of mounts in the namespace */
unsigned int pending_mounts;
};
} __randomize_layout;

struct mnt_pcp {
int mnt_count;
Expand Down Expand Up @@ -69,7 +69,7 @@ struct mount {
struct hlist_head mnt_pins;
struct fs_pin mnt_umount;
struct dentry *mnt_ex_mountpoint;
};
} __randomize_layout;

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

Expand Down
2 changes: 1 addition & 1 deletion fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ struct nameidata {
struct inode *link_inode;
unsigned root_seq;
int dfd;
};
} __randomize_layout;

static void set_nameidata(struct nameidata *p, int dfd, struct filename *name)
{
Expand Down
6 changes: 3 additions & 3 deletions fs/proc/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct proc_dir_entry {
spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
u8 namelen;
char name[];
};
} __randomize_layout;

union proc_op {
int (*proc_get_link)(struct dentry *, struct path *);
Expand All @@ -70,7 +70,7 @@ struct proc_inode {
struct hlist_node sysctl_inodes;
const struct proc_ns_operations *ns_ops;
struct inode vfs_inode;
};
} __randomize_layout;

/*
* General functions
Expand Down Expand Up @@ -279,7 +279,7 @@ struct proc_maps_private {
#ifdef CONFIG_NUMA
struct mempolicy *task_mempolicy;
#endif
};
} __randomize_layout;

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

Expand Down
4 changes: 2 additions & 2 deletions include/linux/binfmts.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct linux_binprm {
unsigned interp_flags;
unsigned interp_data;
unsigned long loader, exec;
};
} __randomize_layout;

#define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
#define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
Expand Down Expand Up @@ -81,7 +81,7 @@ struct linux_binfmt {
int (*load_shlib)(struct file *);
int (*core_dump)(struct coredump_params *cprm);
unsigned long min_coredump; /* minimal dump size */
};
} __randomize_layout;

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

Expand Down
2 changes: 1 addition & 1 deletion include/linux/cdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct cdev {
struct list_head list;
dev_t dev;
unsigned int count;
};
} __randomize_layout;

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

Expand Down
13 changes: 12 additions & 1 deletion include/linux/compiler-gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,25 @@
#endif /* GCC_VERSION >= 40500 */

#if GCC_VERSION >= 40600

/*
* When used with Link Time Optimization, gcc can optimize away C functions or
* variables which are referenced only from assembly code. __visible tells the
* optimizer that something else uses this function or variable, thus preventing
* this.
*/
#define __visible __attribute__((externally_visible))
#endif

/*
* RANDSTRUCT_PLUGIN wants to use an anonymous struct, but it is only
* possible since GCC 4.6. To provide as much build testing coverage
* as possible, this is used for all GCC 4.6+ builds, and not just on
* RANDSTRUCT_PLUGIN builds.
*/
#define randomized_struct_fields_start struct {
#define randomized_struct_fields_end } __randomize_layout;

#endif /* GCC_VERSION >= 40600 */


#if GCC_VERSION >= 40900 && !defined(__CHECKER__)
Expand Down
5 changes: 5 additions & 0 deletions include/linux/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
# define __no_randomize_layout
#endif

#ifndef randomized_struct_fields_start
# define randomized_struct_fields_start
# define randomized_struct_fields_end
#endif

/*
* Tell gcc if a function is cold. The compiler will assume any path
* directly leading to the call is unlikely.
Expand Down
4 changes: 2 additions & 2 deletions include/linux/cred.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct group_info {
atomic_t usage;
int ngroups;
kgid_t gid[0];
};
} __randomize_layout;

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

extern void __put_cred(struct cred *);
extern void exit_creds(struct task_struct *);
Expand Down
2 changes: 1 addition & 1 deletion include/linux/dcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct dentry {
struct hlist_bl_node d_in_lookup_hash; /* only for in-lookup ones */
struct rcu_head d_rcu;
} d_u;
};
} __randomize_layout;

/*
* dentry->d_lock spinlock nesting subclasses:
Expand Down
17 changes: 9 additions & 8 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ struct kiocb {
void *private;
int ki_flags;
enum rw_hint ki_hint;
};
} __randomize_layout;

static inline bool is_sync_kiocb(struct kiocb *kiocb)
{
Expand Down Expand Up @@ -404,7 +404,7 @@ struct address_space {
struct list_head private_list; /* ditto */
void *private_data; /* ditto */
errseq_t wb_err;
} __attribute__((aligned(sizeof(long))));
} __attribute__((aligned(sizeof(long)))) __randomize_layout;
/*
* On most architectures that alignment is already the case; but
* must be enforced here for CRIS, to let the least significant bit
Expand Down Expand Up @@ -447,7 +447,7 @@ struct block_device {
int bd_fsfreeze_count;
/* Mutex for freeze */
struct mutex bd_fsfreeze_mutex;
};
} __randomize_layout;

/*
* Radix-tree tags, for tagging dirty and writeback pages within the pagecache
Expand Down Expand Up @@ -666,7 +666,7 @@ struct inode {
#endif

void *i_private; /* fs or device private pointer */
};
} __randomize_layout;

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

struct file_handle {
__u32 handle_bytes;
Expand Down Expand Up @@ -1020,7 +1021,7 @@ struct file_lock {
int state; /* state of grant or error if -ve */
} afs;
} fl_u;
};
} __randomize_layout;

struct file_lock_context {
spinlock_t flc_lock;
Expand Down Expand Up @@ -1412,7 +1413,7 @@ struct super_block {

spinlock_t s_inode_wblist_lock;
struct list_head s_inodes_wb; /* writeback inodes */
};
} __randomize_layout;

/* Helper functions so that in most cases filesystems will
* not need to deal directly with kuid_t and kgid_t and can
Expand Down Expand Up @@ -1698,7 +1699,7 @@ struct file_operations {
u64);
ssize_t (*dedupe_file_range)(struct file *, u64, u64, struct file *,
u64);
};
} __randomize_layout;

struct inode_operations {
struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
Expand Down
2 changes: 1 addition & 1 deletion include/linux/fs_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct fs_struct {
int umask;
int in_exec;
struct path root, pwd;
};
} __randomize_layout;

extern struct kmem_cache *fs_cachep;

Expand Down
2 changes: 1 addition & 1 deletion include/linux/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ struct kern_ipc_perm {

struct rcu_head rcu;
atomic_t refcount;
} ____cacheline_aligned_in_smp;
} ____cacheline_aligned_in_smp __randomize_layout;

#endif /* _LINUX_IPC_H */
2 changes: 1 addition & 1 deletion include/linux/ipc_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct ipc_namespace {
struct ucounts *ucounts;

struct ns_common ns;
};
} __randomize_layout;

extern struct ipc_namespace init_ipc_ns;
extern spinlock_t mq_lock;
Expand Down
4 changes: 2 additions & 2 deletions include/linux/key-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct key_preparsed_payload {
size_t datalen; /* Raw datalen */
size_t quotalen; /* Quota length for proposed payload */
time_t expiry; /* Expiry time of key */
};
} __randomize_layout;

typedef int (*request_key_actor_t)(struct key_construction *key,
const char *op, void *aux);
Expand Down Expand Up @@ -158,7 +158,7 @@ struct key_type {
/* internal fields */
struct list_head link; /* link in types list */
struct lock_class_key lock_class; /* key->sem lock class */
};
} __randomize_layout;

extern struct key_type key_type_keyring;

Expand Down
2 changes: 1 addition & 1 deletion include/linux/kmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct subprocess_info {
int (*init)(struct subprocess_info *info, struct cred *new);
void (*cleanup)(struct subprocess_info *info);
void *data;
};
} __randomize_layout;

extern int
call_usermodehelper(const char *path, char **argv, char **envp, int wait);
Expand Down
2 changes: 1 addition & 1 deletion include/linux/kobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ struct kset {
spinlock_t list_lock;
struct kobject kobj;
const struct kset_uevent_ops *uevent_ops;
};
} __randomize_layout;

extern void kset_init(struct kset *kset);
extern int __must_check kset_register(struct kset *kset);
Expand Down
4 changes: 2 additions & 2 deletions include/linux/lsm_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,7 @@ struct security_hook_heads {
struct list_head audit_rule_match;
struct list_head audit_rule_free;
#endif /* CONFIG_AUDIT */
};
} __randomize_layout;

/*
* Security module hook list structure.
Expand All @@ -1923,7 +1923,7 @@ struct security_hook_list {
struct list_head *head;
union security_list_options hook;
char *lsm;
};
} __randomize_layout;

/*
* Initializing a security_hook_list structure takes
Expand Down
Loading

0 comments on commit e06fdaf

Please sign in to comment.