Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

security: Refactor declaration of LSM hooks

The information about the different types of LSM hooks is scattered
in two locations i.e. union security_list_options and
struct security_hook_heads. Rather than duplicating this information
even further for BPF_PROG_TYPE_LSM, define all the hooks with the
LSM_HOOK macro in lsm_hook_defs.h which is then used to generate all
the data structures required by the LSM framework.

The LSM hooks are defined as:

LSM_HOOK(<return_type>, <default_value>, <hook_name>, args...)

with <default_value> acccessible in security.c as:

LSM_RET_DEFAULT(<hook_name>)

Signed-off-by: KP Singh <kpsingh@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Brendan Jackman <jackmanb@google.com>
Reviewed-by: Florent Revest <revest@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Acked-by: James Morris <jamorris@linux.microsoft.com>
Link: https://lore.kernel.org/bpf/20200329004356.27286-3-kpsingh@chromium.org

authored by

KP Singh and committed by
Daniel Borkmann
98e828a0 fc611f47

+423 -627
+381
include/linux/lsm_hook_defs.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /* 4 + * Linux Security Module Hook declarations. 5 + * 6 + * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com> 7 + * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com> 8 + * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com> 9 + * Copyright (C) 2001 James Morris <jmorris@intercode.com.au> 10 + * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group) 11 + * Copyright (C) 2015 Intel Corporation. 12 + * Copyright (C) 2015 Casey Schaufler <casey@schaufler-ca.com> 13 + * Copyright (C) 2016 Mellanox Techonologies 14 + * Copyright (C) 2020 Google LLC. 15 + */ 16 + 17 + /* 18 + * The macro LSM_HOOK is used to define the data structures required by the 19 + * the LSM framework using the pattern: 20 + * 21 + * LSM_HOOK(<return_type>, <default_value>, <hook_name>, args...) 22 + * 23 + * struct security_hook_heads { 24 + * #define LSM_HOOK(RET, DEFAULT, NAME, ...) struct hlist_head NAME; 25 + * #include <linux/lsm_hook_defs.h> 26 + * #undef LSM_HOOK 27 + * }; 28 + */ 29 + LSM_HOOK(int, 0, binder_set_context_mgr, struct task_struct *mgr) 30 + LSM_HOOK(int, 0, binder_transaction, struct task_struct *from, 31 + struct task_struct *to) 32 + LSM_HOOK(int, 0, binder_transfer_binder, struct task_struct *from, 33 + struct task_struct *to) 34 + LSM_HOOK(int, 0, binder_transfer_file, struct task_struct *from, 35 + struct task_struct *to, struct file *file) 36 + LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child, 37 + unsigned int mode) 38 + LSM_HOOK(int, 0, ptrace_traceme, struct task_struct *parent) 39 + LSM_HOOK(int, 0, capget, struct task_struct *target, kernel_cap_t *effective, 40 + kernel_cap_t *inheritable, kernel_cap_t *permitted) 41 + LSM_HOOK(int, 0, capset, struct cred *new, const struct cred *old, 42 + const kernel_cap_t *effective, const kernel_cap_t *inheritable, 43 + const kernel_cap_t *permitted) 44 + LSM_HOOK(int, 0, capable, const struct cred *cred, struct user_namespace *ns, 45 + int cap, unsigned int opts) 46 + LSM_HOOK(int, 0, quotactl, int cmds, int type, int id, struct super_block *sb) 47 + LSM_HOOK(int, 0, quota_on, struct dentry *dentry) 48 + LSM_HOOK(int, 0, syslog, int type) 49 + LSM_HOOK(int, 0, settime, const struct timespec64 *ts, 50 + const struct timezone *tz) 51 + LSM_HOOK(int, 0, vm_enough_memory, struct mm_struct *mm, long pages) 52 + LSM_HOOK(int, 0, bprm_set_creds, struct linux_binprm *bprm) 53 + LSM_HOOK(int, 0, bprm_check_security, struct linux_binprm *bprm) 54 + LSM_HOOK(void, LSM_RET_VOID, bprm_committing_creds, struct linux_binprm *bprm) 55 + LSM_HOOK(void, LSM_RET_VOID, bprm_committed_creds, struct linux_binprm *bprm) 56 + LSM_HOOK(int, 0, fs_context_dup, struct fs_context *fc, 57 + struct fs_context *src_sc) 58 + LSM_HOOK(int, 0, fs_context_parse_param, struct fs_context *fc, 59 + struct fs_parameter *param) 60 + LSM_HOOK(int, 0, sb_alloc_security, struct super_block *sb) 61 + LSM_HOOK(void, LSM_RET_VOID, sb_free_security, struct super_block *sb) 62 + LSM_HOOK(void, LSM_RET_VOID, sb_free_mnt_opts, void *mnt_opts) 63 + LSM_HOOK(int, 0, sb_eat_lsm_opts, char *orig, void **mnt_opts) 64 + LSM_HOOK(int, 0, sb_remount, struct super_block *sb, void *mnt_opts) 65 + LSM_HOOK(int, 0, sb_kern_mount, struct super_block *sb) 66 + LSM_HOOK(int, 0, sb_show_options, struct seq_file *m, struct super_block *sb) 67 + LSM_HOOK(int, 0, sb_statfs, struct dentry *dentry) 68 + LSM_HOOK(int, 0, sb_mount, const char *dev_name, const struct path *path, 69 + const char *type, unsigned long flags, void *data) 70 + LSM_HOOK(int, 0, sb_umount, struct vfsmount *mnt, int flags) 71 + LSM_HOOK(int, 0, sb_pivotroot, const struct path *old_path, 72 + const struct path *new_path) 73 + LSM_HOOK(int, 0, sb_set_mnt_opts, struct super_block *sb, void *mnt_opts, 74 + unsigned long kern_flags, unsigned long *set_kern_flags) 75 + LSM_HOOK(int, 0, sb_clone_mnt_opts, const struct super_block *oldsb, 76 + struct super_block *newsb, unsigned long kern_flags, 77 + unsigned long *set_kern_flags) 78 + LSM_HOOK(int, 0, sb_add_mnt_opt, const char *option, const char *val, 79 + int len, void **mnt_opts) 80 + LSM_HOOK(int, 0, move_mount, const struct path *from_path, 81 + const struct path *to_path) 82 + LSM_HOOK(int, 0, dentry_init_security, struct dentry *dentry, 83 + int mode, const struct qstr *name, void **ctx, u32 *ctxlen) 84 + LSM_HOOK(int, 0, dentry_create_files_as, struct dentry *dentry, int mode, 85 + struct qstr *name, const struct cred *old, struct cred *new) 86 + 87 + #ifdef CONFIG_SECURITY_PATH 88 + LSM_HOOK(int, 0, path_unlink, const struct path *dir, struct dentry *dentry) 89 + LSM_HOOK(int, 0, path_mkdir, const struct path *dir, struct dentry *dentry, 90 + umode_t mode) 91 + LSM_HOOK(int, 0, path_rmdir, const struct path *dir, struct dentry *dentry) 92 + LSM_HOOK(int, 0, path_mknod, const struct path *dir, struct dentry *dentry, 93 + umode_t mode, unsigned int dev) 94 + LSM_HOOK(int, 0, path_truncate, const struct path *path) 95 + LSM_HOOK(int, 0, path_symlink, const struct path *dir, struct dentry *dentry, 96 + const char *old_name) 97 + LSM_HOOK(int, 0, path_link, struct dentry *old_dentry, 98 + const struct path *new_dir, struct dentry *new_dentry) 99 + LSM_HOOK(int, 0, path_rename, const struct path *old_dir, 100 + struct dentry *old_dentry, const struct path *new_dir, 101 + struct dentry *new_dentry) 102 + LSM_HOOK(int, 0, path_chmod, const struct path *path, umode_t mode) 103 + LSM_HOOK(int, 0, path_chown, const struct path *path, kuid_t uid, kgid_t gid) 104 + LSM_HOOK(int, 0, path_chroot, const struct path *path) 105 + #endif /* CONFIG_SECURITY_PATH */ 106 + 107 + /* Needed for inode based security check */ 108 + LSM_HOOK(int, 0, path_notify, const struct path *path, u64 mask, 109 + unsigned int obj_type) 110 + LSM_HOOK(int, 0, inode_alloc_security, struct inode *inode) 111 + LSM_HOOK(void, LSM_RET_VOID, inode_free_security, struct inode *inode) 112 + LSM_HOOK(int, 0, inode_init_security, struct inode *inode, 113 + struct inode *dir, const struct qstr *qstr, const char **name, 114 + void **value, size_t *len) 115 + LSM_HOOK(int, 0, inode_create, struct inode *dir, struct dentry *dentry, 116 + umode_t mode) 117 + LSM_HOOK(int, 0, inode_link, struct dentry *old_dentry, struct inode *dir, 118 + struct dentry *new_dentry) 119 + LSM_HOOK(int, 0, inode_unlink, struct inode *dir, struct dentry *dentry) 120 + LSM_HOOK(int, 0, inode_symlink, struct inode *dir, struct dentry *dentry, 121 + const char *old_name) 122 + LSM_HOOK(int, 0, inode_mkdir, struct inode *dir, struct dentry *dentry, 123 + umode_t mode) 124 + LSM_HOOK(int, 0, inode_rmdir, struct inode *dir, struct dentry *dentry) 125 + LSM_HOOK(int, 0, inode_mknod, struct inode *dir, struct dentry *dentry, 126 + umode_t mode, dev_t dev) 127 + LSM_HOOK(int, 0, inode_rename, struct inode *old_dir, struct dentry *old_dentry, 128 + struct inode *new_dir, struct dentry *new_dentry) 129 + LSM_HOOK(int, 0, inode_readlink, struct dentry *dentry) 130 + LSM_HOOK(int, 0, inode_follow_link, struct dentry *dentry, struct inode *inode, 131 + bool rcu) 132 + LSM_HOOK(int, 0, inode_permission, struct inode *inode, int mask) 133 + LSM_HOOK(int, 0, inode_setattr, struct dentry *dentry, struct iattr *attr) 134 + LSM_HOOK(int, 0, inode_getattr, const struct path *path) 135 + LSM_HOOK(int, 0, inode_setxattr, struct dentry *dentry, const char *name, 136 + const void *value, size_t size, int flags) 137 + LSM_HOOK(void, LSM_RET_VOID, inode_post_setxattr, struct dentry *dentry, 138 + const char *name, const void *value, size_t size, int flags) 139 + LSM_HOOK(int, 0, inode_getxattr, struct dentry *dentry, const char *name) 140 + LSM_HOOK(int, 0, inode_listxattr, struct dentry *dentry) 141 + LSM_HOOK(int, 0, inode_removexattr, struct dentry *dentry, const char *name) 142 + LSM_HOOK(int, 0, inode_need_killpriv, struct dentry *dentry) 143 + LSM_HOOK(int, 0, inode_killpriv, struct dentry *dentry) 144 + LSM_HOOK(int, -EOPNOTSUPP, inode_getsecurity, struct inode *inode, 145 + const char *name, void **buffer, bool alloc) 146 + LSM_HOOK(int, -EOPNOTSUPP, inode_setsecurity, struct inode *inode, 147 + const char *name, const void *value, size_t size, int flags) 148 + LSM_HOOK(int, 0, inode_listsecurity, struct inode *inode, char *buffer, 149 + size_t buffer_size) 150 + LSM_HOOK(void, LSM_RET_VOID, inode_getsecid, struct inode *inode, u32 *secid) 151 + LSM_HOOK(int, 0, inode_copy_up, struct dentry *src, struct cred **new) 152 + LSM_HOOK(int, 0, inode_copy_up_xattr, const char *name) 153 + LSM_HOOK(int, 0, kernfs_init_security, struct kernfs_node *kn_dir, 154 + struct kernfs_node *kn) 155 + LSM_HOOK(int, 0, file_permission, struct file *file, int mask) 156 + LSM_HOOK(int, 0, file_alloc_security, struct file *file) 157 + LSM_HOOK(void, LSM_RET_VOID, file_free_security, struct file *file) 158 + LSM_HOOK(int, 0, file_ioctl, struct file *file, unsigned int cmd, 159 + unsigned long arg) 160 + LSM_HOOK(int, 0, mmap_addr, unsigned long addr) 161 + LSM_HOOK(int, 0, mmap_file, struct file *file, unsigned long reqprot, 162 + unsigned long prot, unsigned long flags) 163 + LSM_HOOK(int, 0, file_mprotect, struct vm_area_struct *vma, 164 + unsigned long reqprot, unsigned long prot) 165 + LSM_HOOK(int, 0, file_lock, struct file *file, unsigned int cmd) 166 + LSM_HOOK(int, 0, file_fcntl, struct file *file, unsigned int cmd, 167 + unsigned long arg) 168 + LSM_HOOK(void, LSM_RET_VOID, file_set_fowner, struct file *file) 169 + LSM_HOOK(int, 0, file_send_sigiotask, struct task_struct *tsk, 170 + struct fown_struct *fown, int sig) 171 + LSM_HOOK(int, 0, file_receive, struct file *file) 172 + LSM_HOOK(int, 0, file_open, struct file *file) 173 + LSM_HOOK(int, 0, task_alloc, struct task_struct *task, 174 + unsigned long clone_flags) 175 + LSM_HOOK(void, LSM_RET_VOID, task_free, struct task_struct *task) 176 + LSM_HOOK(int, 0, cred_alloc_blank, struct cred *cred, gfp_t gfp) 177 + LSM_HOOK(void, LSM_RET_VOID, cred_free, struct cred *cred) 178 + LSM_HOOK(int, 0, cred_prepare, struct cred *new, const struct cred *old, 179 + gfp_t gfp) 180 + LSM_HOOK(void, LSM_RET_VOID, cred_transfer, struct cred *new, 181 + const struct cred *old) 182 + LSM_HOOK(void, LSM_RET_VOID, cred_getsecid, const struct cred *c, u32 *secid) 183 + LSM_HOOK(int, 0, kernel_act_as, struct cred *new, u32 secid) 184 + LSM_HOOK(int, 0, kernel_create_files_as, struct cred *new, struct inode *inode) 185 + LSM_HOOK(int, 0, kernel_module_request, char *kmod_name) 186 + LSM_HOOK(int, 0, kernel_load_data, enum kernel_load_data_id id) 187 + LSM_HOOK(int, 0, kernel_read_file, struct file *file, 188 + enum kernel_read_file_id id) 189 + LSM_HOOK(int, 0, kernel_post_read_file, struct file *file, char *buf, 190 + loff_t size, enum kernel_read_file_id id) 191 + LSM_HOOK(int, 0, task_fix_setuid, struct cred *new, const struct cred *old, 192 + int flags) 193 + LSM_HOOK(int, 0, task_setpgid, struct task_struct *p, pid_t pgid) 194 + LSM_HOOK(int, 0, task_getpgid, struct task_struct *p) 195 + LSM_HOOK(int, 0, task_getsid, struct task_struct *p) 196 + LSM_HOOK(void, LSM_RET_VOID, task_getsecid, struct task_struct *p, u32 *secid) 197 + LSM_HOOK(int, 0, task_setnice, struct task_struct *p, int nice) 198 + LSM_HOOK(int, 0, task_setioprio, struct task_struct *p, int ioprio) 199 + LSM_HOOK(int, 0, task_getioprio, struct task_struct *p) 200 + LSM_HOOK(int, 0, task_prlimit, const struct cred *cred, 201 + const struct cred *tcred, unsigned int flags) 202 + LSM_HOOK(int, 0, task_setrlimit, struct task_struct *p, unsigned int resource, 203 + struct rlimit *new_rlim) 204 + LSM_HOOK(int, 0, task_setscheduler, struct task_struct *p) 205 + LSM_HOOK(int, 0, task_getscheduler, struct task_struct *p) 206 + LSM_HOOK(int, 0, task_movememory, struct task_struct *p) 207 + LSM_HOOK(int, 0, task_kill, struct task_struct *p, struct kernel_siginfo *info, 208 + int sig, const struct cred *cred) 209 + LSM_HOOK(int, -ENOSYS, task_prctl, int option, unsigned long arg2, 210 + unsigned long arg3, unsigned long arg4, unsigned long arg5) 211 + LSM_HOOK(void, LSM_RET_VOID, task_to_inode, struct task_struct *p, 212 + struct inode *inode) 213 + LSM_HOOK(int, 0, ipc_permission, struct kern_ipc_perm *ipcp, short flag) 214 + LSM_HOOK(void, LSM_RET_VOID, ipc_getsecid, struct kern_ipc_perm *ipcp, 215 + u32 *secid) 216 + LSM_HOOK(int, 0, msg_msg_alloc_security, struct msg_msg *msg) 217 + LSM_HOOK(void, LSM_RET_VOID, msg_msg_free_security, struct msg_msg *msg) 218 + LSM_HOOK(int, 0, msg_queue_alloc_security, struct kern_ipc_perm *perm) 219 + LSM_HOOK(void, LSM_RET_VOID, msg_queue_free_security, 220 + struct kern_ipc_perm *perm) 221 + LSM_HOOK(int, 0, msg_queue_associate, struct kern_ipc_perm *perm, int msqflg) 222 + LSM_HOOK(int, 0, msg_queue_msgctl, struct kern_ipc_perm *perm, int cmd) 223 + LSM_HOOK(int, 0, msg_queue_msgsnd, struct kern_ipc_perm *perm, 224 + struct msg_msg *msg, int msqflg) 225 + LSM_HOOK(int, 0, msg_queue_msgrcv, struct kern_ipc_perm *perm, 226 + struct msg_msg *msg, struct task_struct *target, long type, int mode) 227 + LSM_HOOK(int, 0, shm_alloc_security, struct kern_ipc_perm *perm) 228 + LSM_HOOK(void, LSM_RET_VOID, shm_free_security, struct kern_ipc_perm *perm) 229 + LSM_HOOK(int, 0, shm_associate, struct kern_ipc_perm *perm, int shmflg) 230 + LSM_HOOK(int, 0, shm_shmctl, struct kern_ipc_perm *perm, int cmd) 231 + LSM_HOOK(int, 0, shm_shmat, struct kern_ipc_perm *perm, char __user *shmaddr, 232 + int shmflg) 233 + LSM_HOOK(int, 0, sem_alloc_security, struct kern_ipc_perm *perm) 234 + LSM_HOOK(void, LSM_RET_VOID, sem_free_security, struct kern_ipc_perm *perm) 235 + LSM_HOOK(int, 0, sem_associate, struct kern_ipc_perm *perm, int semflg) 236 + LSM_HOOK(int, 0, sem_semctl, struct kern_ipc_perm *perm, int cmd) 237 + LSM_HOOK(int, 0, sem_semop, struct kern_ipc_perm *perm, struct sembuf *sops, 238 + unsigned nsops, int alter) 239 + LSM_HOOK(int, 0, netlink_send, struct sock *sk, struct sk_buff *skb) 240 + LSM_HOOK(void, LSM_RET_VOID, d_instantiate, struct dentry *dentry, 241 + struct inode *inode) 242 + LSM_HOOK(int, -EINVAL, getprocattr, struct task_struct *p, char *name, 243 + char **value) 244 + LSM_HOOK(int, -EINVAL, setprocattr, const char *name, void *value, size_t size) 245 + LSM_HOOK(int, 0, ismaclabel, const char *name) 246 + LSM_HOOK(int, 0, secid_to_secctx, u32 secid, char **secdata, 247 + u32 *seclen) 248 + LSM_HOOK(int, 0, secctx_to_secid, const char *secdata, u32 seclen, u32 *secid) 249 + LSM_HOOK(void, LSM_RET_VOID, release_secctx, char *secdata, u32 seclen) 250 + LSM_HOOK(void, LSM_RET_VOID, inode_invalidate_secctx, struct inode *inode) 251 + LSM_HOOK(int, 0, inode_notifysecctx, struct inode *inode, void *ctx, u32 ctxlen) 252 + LSM_HOOK(int, 0, inode_setsecctx, struct dentry *dentry, void *ctx, u32 ctxlen) 253 + LSM_HOOK(int, 0, inode_getsecctx, struct inode *inode, void **ctx, 254 + u32 *ctxlen) 255 + 256 + #ifdef CONFIG_SECURITY_NETWORK 257 + LSM_HOOK(int, 0, unix_stream_connect, struct sock *sock, struct sock *other, 258 + struct sock *newsk) 259 + LSM_HOOK(int, 0, unix_may_send, struct socket *sock, struct socket *other) 260 + LSM_HOOK(int, 0, socket_create, int family, int type, int protocol, int kern) 261 + LSM_HOOK(int, 0, socket_post_create, struct socket *sock, int family, int type, 262 + int protocol, int kern) 263 + LSM_HOOK(int, 0, socket_socketpair, struct socket *socka, struct socket *sockb) 264 + LSM_HOOK(int, 0, socket_bind, struct socket *sock, struct sockaddr *address, 265 + int addrlen) 266 + LSM_HOOK(int, 0, socket_connect, struct socket *sock, struct sockaddr *address, 267 + int addrlen) 268 + LSM_HOOK(int, 0, socket_listen, struct socket *sock, int backlog) 269 + LSM_HOOK(int, 0, socket_accept, struct socket *sock, struct socket *newsock) 270 + LSM_HOOK(int, 0, socket_sendmsg, struct socket *sock, struct msghdr *msg, 271 + int size) 272 + LSM_HOOK(int, 0, socket_recvmsg, struct socket *sock, struct msghdr *msg, 273 + int size, int flags) 274 + LSM_HOOK(int, 0, socket_getsockname, struct socket *sock) 275 + LSM_HOOK(int, 0, socket_getpeername, struct socket *sock) 276 + LSM_HOOK(int, 0, socket_getsockopt, struct socket *sock, int level, int optname) 277 + LSM_HOOK(int, 0, socket_setsockopt, struct socket *sock, int level, int optname) 278 + LSM_HOOK(int, 0, socket_shutdown, struct socket *sock, int how) 279 + LSM_HOOK(int, 0, socket_sock_rcv_skb, struct sock *sk, struct sk_buff *skb) 280 + LSM_HOOK(int, 0, socket_getpeersec_stream, struct socket *sock, 281 + char __user *optval, int __user *optlen, unsigned len) 282 + LSM_HOOK(int, 0, socket_getpeersec_dgram, struct socket *sock, 283 + struct sk_buff *skb, u32 *secid) 284 + LSM_HOOK(int, 0, sk_alloc_security, struct sock *sk, int family, gfp_t priority) 285 + LSM_HOOK(void, LSM_RET_VOID, sk_free_security, struct sock *sk) 286 + LSM_HOOK(void, LSM_RET_VOID, sk_clone_security, const struct sock *sk, 287 + struct sock *newsk) 288 + LSM_HOOK(void, LSM_RET_VOID, sk_getsecid, struct sock *sk, u32 *secid) 289 + LSM_HOOK(void, LSM_RET_VOID, sock_graft, struct sock *sk, struct socket *parent) 290 + LSM_HOOK(int, 0, inet_conn_request, struct sock *sk, struct sk_buff *skb, 291 + struct request_sock *req) 292 + LSM_HOOK(void, LSM_RET_VOID, inet_csk_clone, struct sock *newsk, 293 + const struct request_sock *req) 294 + LSM_HOOK(void, LSM_RET_VOID, inet_conn_established, struct sock *sk, 295 + struct sk_buff *skb) 296 + LSM_HOOK(int, 0, secmark_relabel_packet, u32 secid) 297 + LSM_HOOK(void, LSM_RET_VOID, secmark_refcount_inc, void) 298 + LSM_HOOK(void, LSM_RET_VOID, secmark_refcount_dec, void) 299 + LSM_HOOK(void, LSM_RET_VOID, req_classify_flow, const struct request_sock *req, 300 + struct flowi *fl) 301 + LSM_HOOK(int, 0, tun_dev_alloc_security, void **security) 302 + LSM_HOOK(void, LSM_RET_VOID, tun_dev_free_security, void *security) 303 + LSM_HOOK(int, 0, tun_dev_create, void) 304 + LSM_HOOK(int, 0, tun_dev_attach_queue, void *security) 305 + LSM_HOOK(int, 0, tun_dev_attach, struct sock *sk, void *security) 306 + LSM_HOOK(int, 0, tun_dev_open, void *security) 307 + LSM_HOOK(int, 0, sctp_assoc_request, struct sctp_endpoint *ep, 308 + struct sk_buff *skb) 309 + LSM_HOOK(int, 0, sctp_bind_connect, struct sock *sk, int optname, 310 + struct sockaddr *address, int addrlen) 311 + LSM_HOOK(void, LSM_RET_VOID, sctp_sk_clone, struct sctp_endpoint *ep, 312 + struct sock *sk, struct sock *newsk) 313 + #endif /* CONFIG_SECURITY_NETWORK */ 314 + 315 + #ifdef CONFIG_SECURITY_INFINIBAND 316 + LSM_HOOK(int, 0, ib_pkey_access, void *sec, u64 subnet_prefix, u16 pkey) 317 + LSM_HOOK(int, 0, ib_endport_manage_subnet, void *sec, const char *dev_name, 318 + u8 port_num) 319 + LSM_HOOK(int, 0, ib_alloc_security, void **sec) 320 + LSM_HOOK(void, LSM_RET_VOID, ib_free_security, void *sec) 321 + #endif /* CONFIG_SECURITY_INFINIBAND */ 322 + 323 + #ifdef CONFIG_SECURITY_NETWORK_XFRM 324 + LSM_HOOK(int, 0, xfrm_policy_alloc_security, struct xfrm_sec_ctx **ctxp, 325 + struct xfrm_user_sec_ctx *sec_ctx, gfp_t gfp) 326 + LSM_HOOK(int, 0, xfrm_policy_clone_security, struct xfrm_sec_ctx *old_ctx, 327 + struct xfrm_sec_ctx **new_ctx) 328 + LSM_HOOK(void, LSM_RET_VOID, xfrm_policy_free_security, 329 + struct xfrm_sec_ctx *ctx) 330 + LSM_HOOK(int, 0, xfrm_policy_delete_security, struct xfrm_sec_ctx *ctx) 331 + LSM_HOOK(int, 0, xfrm_state_alloc, struct xfrm_state *x, 332 + struct xfrm_user_sec_ctx *sec_ctx) 333 + LSM_HOOK(int, 0, xfrm_state_alloc_acquire, struct xfrm_state *x, 334 + struct xfrm_sec_ctx *polsec, u32 secid) 335 + LSM_HOOK(void, LSM_RET_VOID, xfrm_state_free_security, struct xfrm_state *x) 336 + LSM_HOOK(int, 0, xfrm_state_delete_security, struct xfrm_state *x) 337 + LSM_HOOK(int, 0, xfrm_policy_lookup, struct xfrm_sec_ctx *ctx, u32 fl_secid, 338 + u8 dir) 339 + LSM_HOOK(int, 1, xfrm_state_pol_flow_match, struct xfrm_state *x, 340 + struct xfrm_policy *xp, const struct flowi *fl) 341 + LSM_HOOK(int, 0, xfrm_decode_session, struct sk_buff *skb, u32 *secid, 342 + int ckall) 343 + #endif /* CONFIG_SECURITY_NETWORK_XFRM */ 344 + 345 + /* key management security hooks */ 346 + #ifdef CONFIG_KEYS 347 + LSM_HOOK(int, 0, key_alloc, struct key *key, const struct cred *cred, 348 + unsigned long flags) 349 + LSM_HOOK(void, LSM_RET_VOID, key_free, struct key *key) 350 + LSM_HOOK(int, 0, key_permission, key_ref_t key_ref, const struct cred *cred, 351 + unsigned perm) 352 + LSM_HOOK(int, 0, key_getsecurity, struct key *key, char **_buffer) 353 + #endif /* CONFIG_KEYS */ 354 + 355 + #ifdef CONFIG_AUDIT 356 + LSM_HOOK(int, 0, audit_rule_init, u32 field, u32 op, char *rulestr, 357 + void **lsmrule) 358 + LSM_HOOK(int, 0, audit_rule_known, struct audit_krule *krule) 359 + LSM_HOOK(int, 0, audit_rule_match, u32 secid, u32 field, u32 op, void *lsmrule) 360 + LSM_HOOK(void, LSM_RET_VOID, audit_rule_free, void *lsmrule) 361 + #endif /* CONFIG_AUDIT */ 362 + 363 + #ifdef CONFIG_BPF_SYSCALL 364 + LSM_HOOK(int, 0, bpf, int cmd, union bpf_attr *attr, unsigned int size) 365 + LSM_HOOK(int, 0, bpf_map, struct bpf_map *map, fmode_t fmode) 366 + LSM_HOOK(int, 0, bpf_prog, struct bpf_prog *prog) 367 + LSM_HOOK(int, 0, bpf_map_alloc_security, struct bpf_map *map) 368 + LSM_HOOK(void, LSM_RET_VOID, bpf_map_free_security, struct bpf_map *map) 369 + LSM_HOOK(int, 0, bpf_prog_alloc_security, struct bpf_prog_aux *aux) 370 + LSM_HOOK(void, LSM_RET_VOID, bpf_prog_free_security, struct bpf_prog_aux *aux) 371 + #endif /* CONFIG_BPF_SYSCALL */ 372 + 373 + LSM_HOOK(int, 0, locked_down, enum lockdown_reason what) 374 + 375 + #ifdef CONFIG_PERF_EVENTS 376 + LSM_HOOK(int, 0, perf_event_open, struct perf_event_attr *attr, int type) 377 + LSM_HOOK(int, 0, perf_event_alloc, struct perf_event *event) 378 + LSM_HOOK(void, LSM_RET_VOID, perf_event_free, struct perf_event *event) 379 + LSM_HOOK(int, 0, perf_event_read, struct perf_event *event) 380 + LSM_HOOK(int, 0, perf_event_write, struct perf_event *event) 381 + #endif /* CONFIG_PERF_EVENTS */
+12 -616
include/linux/lsm_hooks.h
··· 1456 1456 * @what: kernel feature being accessed 1457 1457 */ 1458 1458 union security_list_options { 1459 - int (*binder_set_context_mgr)(struct task_struct *mgr); 1460 - int (*binder_transaction)(struct task_struct *from, 1461 - struct task_struct *to); 1462 - int (*binder_transfer_binder)(struct task_struct *from, 1463 - struct task_struct *to); 1464 - int (*binder_transfer_file)(struct task_struct *from, 1465 - struct task_struct *to, 1466 - struct file *file); 1467 - 1468 - int (*ptrace_access_check)(struct task_struct *child, 1469 - unsigned int mode); 1470 - int (*ptrace_traceme)(struct task_struct *parent); 1471 - int (*capget)(struct task_struct *target, kernel_cap_t *effective, 1472 - kernel_cap_t *inheritable, kernel_cap_t *permitted); 1473 - int (*capset)(struct cred *new, const struct cred *old, 1474 - const kernel_cap_t *effective, 1475 - const kernel_cap_t *inheritable, 1476 - const kernel_cap_t *permitted); 1477 - int (*capable)(const struct cred *cred, 1478 - struct user_namespace *ns, 1479 - int cap, 1480 - unsigned int opts); 1481 - int (*quotactl)(int cmds, int type, int id, struct super_block *sb); 1482 - int (*quota_on)(struct dentry *dentry); 1483 - int (*syslog)(int type); 1484 - int (*settime)(const struct timespec64 *ts, const struct timezone *tz); 1485 - int (*vm_enough_memory)(struct mm_struct *mm, long pages); 1486 - 1487 - int (*bprm_set_creds)(struct linux_binprm *bprm); 1488 - int (*bprm_check_security)(struct linux_binprm *bprm); 1489 - void (*bprm_committing_creds)(struct linux_binprm *bprm); 1490 - void (*bprm_committed_creds)(struct linux_binprm *bprm); 1491 - 1492 - int (*fs_context_dup)(struct fs_context *fc, struct fs_context *src_sc); 1493 - int (*fs_context_parse_param)(struct fs_context *fc, struct fs_parameter *param); 1494 - 1495 - int (*sb_alloc_security)(struct super_block *sb); 1496 - void (*sb_free_security)(struct super_block *sb); 1497 - void (*sb_free_mnt_opts)(void *mnt_opts); 1498 - int (*sb_eat_lsm_opts)(char *orig, void **mnt_opts); 1499 - int (*sb_remount)(struct super_block *sb, void *mnt_opts); 1500 - int (*sb_kern_mount)(struct super_block *sb); 1501 - int (*sb_show_options)(struct seq_file *m, struct super_block *sb); 1502 - int (*sb_statfs)(struct dentry *dentry); 1503 - int (*sb_mount)(const char *dev_name, const struct path *path, 1504 - const char *type, unsigned long flags, void *data); 1505 - int (*sb_umount)(struct vfsmount *mnt, int flags); 1506 - int (*sb_pivotroot)(const struct path *old_path, const struct path *new_path); 1507 - int (*sb_set_mnt_opts)(struct super_block *sb, 1508 - void *mnt_opts, 1509 - unsigned long kern_flags, 1510 - unsigned long *set_kern_flags); 1511 - int (*sb_clone_mnt_opts)(const struct super_block *oldsb, 1512 - struct super_block *newsb, 1513 - unsigned long kern_flags, 1514 - unsigned long *set_kern_flags); 1515 - int (*sb_add_mnt_opt)(const char *option, const char *val, int len, 1516 - void **mnt_opts); 1517 - int (*move_mount)(const struct path *from_path, const struct path *to_path); 1518 - int (*dentry_init_security)(struct dentry *dentry, int mode, 1519 - const struct qstr *name, void **ctx, 1520 - u32 *ctxlen); 1521 - int (*dentry_create_files_as)(struct dentry *dentry, int mode, 1522 - struct qstr *name, 1523 - const struct cred *old, 1524 - struct cred *new); 1525 - 1526 - 1527 - #ifdef CONFIG_SECURITY_PATH 1528 - int (*path_unlink)(const struct path *dir, struct dentry *dentry); 1529 - int (*path_mkdir)(const struct path *dir, struct dentry *dentry, 1530 - umode_t mode); 1531 - int (*path_rmdir)(const struct path *dir, struct dentry *dentry); 1532 - int (*path_mknod)(const struct path *dir, struct dentry *dentry, 1533 - umode_t mode, unsigned int dev); 1534 - int (*path_truncate)(const struct path *path); 1535 - int (*path_symlink)(const struct path *dir, struct dentry *dentry, 1536 - const char *old_name); 1537 - int (*path_link)(struct dentry *old_dentry, const struct path *new_dir, 1538 - struct dentry *new_dentry); 1539 - int (*path_rename)(const struct path *old_dir, struct dentry *old_dentry, 1540 - const struct path *new_dir, 1541 - struct dentry *new_dentry); 1542 - int (*path_chmod)(const struct path *path, umode_t mode); 1543 - int (*path_chown)(const struct path *path, kuid_t uid, kgid_t gid); 1544 - int (*path_chroot)(const struct path *path); 1545 - #endif 1546 - /* Needed for inode based security check */ 1547 - int (*path_notify)(const struct path *path, u64 mask, 1548 - unsigned int obj_type); 1549 - int (*inode_alloc_security)(struct inode *inode); 1550 - void (*inode_free_security)(struct inode *inode); 1551 - int (*inode_init_security)(struct inode *inode, struct inode *dir, 1552 - const struct qstr *qstr, 1553 - const char **name, void **value, 1554 - size_t *len); 1555 - int (*inode_create)(struct inode *dir, struct dentry *dentry, 1556 - umode_t mode); 1557 - int (*inode_link)(struct dentry *old_dentry, struct inode *dir, 1558 - struct dentry *new_dentry); 1559 - int (*inode_unlink)(struct inode *dir, struct dentry *dentry); 1560 - int (*inode_symlink)(struct inode *dir, struct dentry *dentry, 1561 - const char *old_name); 1562 - int (*inode_mkdir)(struct inode *dir, struct dentry *dentry, 1563 - umode_t mode); 1564 - int (*inode_rmdir)(struct inode *dir, struct dentry *dentry); 1565 - int (*inode_mknod)(struct inode *dir, struct dentry *dentry, 1566 - umode_t mode, dev_t dev); 1567 - int (*inode_rename)(struct inode *old_dir, struct dentry *old_dentry, 1568 - struct inode *new_dir, 1569 - struct dentry *new_dentry); 1570 - int (*inode_readlink)(struct dentry *dentry); 1571 - int (*inode_follow_link)(struct dentry *dentry, struct inode *inode, 1572 - bool rcu); 1573 - int (*inode_permission)(struct inode *inode, int mask); 1574 - int (*inode_setattr)(struct dentry *dentry, struct iattr *attr); 1575 - int (*inode_getattr)(const struct path *path); 1576 - int (*inode_setxattr)(struct dentry *dentry, const char *name, 1577 - const void *value, size_t size, int flags); 1578 - void (*inode_post_setxattr)(struct dentry *dentry, const char *name, 1579 - const void *value, size_t size, 1580 - int flags); 1581 - int (*inode_getxattr)(struct dentry *dentry, const char *name); 1582 - int (*inode_listxattr)(struct dentry *dentry); 1583 - int (*inode_removexattr)(struct dentry *dentry, const char *name); 1584 - int (*inode_need_killpriv)(struct dentry *dentry); 1585 - int (*inode_killpriv)(struct dentry *dentry); 1586 - int (*inode_getsecurity)(struct inode *inode, const char *name, 1587 - void **buffer, bool alloc); 1588 - int (*inode_setsecurity)(struct inode *inode, const char *name, 1589 - const void *value, size_t size, 1590 - int flags); 1591 - int (*inode_listsecurity)(struct inode *inode, char *buffer, 1592 - size_t buffer_size); 1593 - void (*inode_getsecid)(struct inode *inode, u32 *secid); 1594 - int (*inode_copy_up)(struct dentry *src, struct cred **new); 1595 - int (*inode_copy_up_xattr)(const char *name); 1596 - 1597 - int (*kernfs_init_security)(struct kernfs_node *kn_dir, 1598 - struct kernfs_node *kn); 1599 - 1600 - int (*file_permission)(struct file *file, int mask); 1601 - int (*file_alloc_security)(struct file *file); 1602 - void (*file_free_security)(struct file *file); 1603 - int (*file_ioctl)(struct file *file, unsigned int cmd, 1604 - unsigned long arg); 1605 - int (*mmap_addr)(unsigned long addr); 1606 - int (*mmap_file)(struct file *file, unsigned long reqprot, 1607 - unsigned long prot, unsigned long flags); 1608 - int (*file_mprotect)(struct vm_area_struct *vma, unsigned long reqprot, 1609 - unsigned long prot); 1610 - int (*file_lock)(struct file *file, unsigned int cmd); 1611 - int (*file_fcntl)(struct file *file, unsigned int cmd, 1612 - unsigned long arg); 1613 - void (*file_set_fowner)(struct file *file); 1614 - int (*file_send_sigiotask)(struct task_struct *tsk, 1615 - struct fown_struct *fown, int sig); 1616 - int (*file_receive)(struct file *file); 1617 - int (*file_open)(struct file *file); 1618 - 1619 - int (*task_alloc)(struct task_struct *task, unsigned long clone_flags); 1620 - void (*task_free)(struct task_struct *task); 1621 - int (*cred_alloc_blank)(struct cred *cred, gfp_t gfp); 1622 - void (*cred_free)(struct cred *cred); 1623 - int (*cred_prepare)(struct cred *new, const struct cred *old, 1624 - gfp_t gfp); 1625 - void (*cred_transfer)(struct cred *new, const struct cred *old); 1626 - void (*cred_getsecid)(const struct cred *c, u32 *secid); 1627 - int (*kernel_act_as)(struct cred *new, u32 secid); 1628 - int (*kernel_create_files_as)(struct cred *new, struct inode *inode); 1629 - int (*kernel_module_request)(char *kmod_name); 1630 - int (*kernel_load_data)(enum kernel_load_data_id id); 1631 - int (*kernel_read_file)(struct file *file, enum kernel_read_file_id id); 1632 - int (*kernel_post_read_file)(struct file *file, char *buf, loff_t size, 1633 - enum kernel_read_file_id id); 1634 - int (*task_fix_setuid)(struct cred *new, const struct cred *old, 1635 - int flags); 1636 - int (*task_setpgid)(struct task_struct *p, pid_t pgid); 1637 - int (*task_getpgid)(struct task_struct *p); 1638 - int (*task_getsid)(struct task_struct *p); 1639 - void (*task_getsecid)(struct task_struct *p, u32 *secid); 1640 - int (*task_setnice)(struct task_struct *p, int nice); 1641 - int (*task_setioprio)(struct task_struct *p, int ioprio); 1642 - int (*task_getioprio)(struct task_struct *p); 1643 - int (*task_prlimit)(const struct cred *cred, const struct cred *tcred, 1644 - unsigned int flags); 1645 - int (*task_setrlimit)(struct task_struct *p, unsigned int resource, 1646 - struct rlimit *new_rlim); 1647 - int (*task_setscheduler)(struct task_struct *p); 1648 - int (*task_getscheduler)(struct task_struct *p); 1649 - int (*task_movememory)(struct task_struct *p); 1650 - int (*task_kill)(struct task_struct *p, struct kernel_siginfo *info, 1651 - int sig, const struct cred *cred); 1652 - int (*task_prctl)(int option, unsigned long arg2, unsigned long arg3, 1653 - unsigned long arg4, unsigned long arg5); 1654 - void (*task_to_inode)(struct task_struct *p, struct inode *inode); 1655 - 1656 - int (*ipc_permission)(struct kern_ipc_perm *ipcp, short flag); 1657 - void (*ipc_getsecid)(struct kern_ipc_perm *ipcp, u32 *secid); 1658 - 1659 - int (*msg_msg_alloc_security)(struct msg_msg *msg); 1660 - void (*msg_msg_free_security)(struct msg_msg *msg); 1661 - 1662 - int (*msg_queue_alloc_security)(struct kern_ipc_perm *perm); 1663 - void (*msg_queue_free_security)(struct kern_ipc_perm *perm); 1664 - int (*msg_queue_associate)(struct kern_ipc_perm *perm, int msqflg); 1665 - int (*msg_queue_msgctl)(struct kern_ipc_perm *perm, int cmd); 1666 - int (*msg_queue_msgsnd)(struct kern_ipc_perm *perm, struct msg_msg *msg, 1667 - int msqflg); 1668 - int (*msg_queue_msgrcv)(struct kern_ipc_perm *perm, struct msg_msg *msg, 1669 - struct task_struct *target, long type, 1670 - int mode); 1671 - 1672 - int (*shm_alloc_security)(struct kern_ipc_perm *perm); 1673 - void (*shm_free_security)(struct kern_ipc_perm *perm); 1674 - int (*shm_associate)(struct kern_ipc_perm *perm, int shmflg); 1675 - int (*shm_shmctl)(struct kern_ipc_perm *perm, int cmd); 1676 - int (*shm_shmat)(struct kern_ipc_perm *perm, char __user *shmaddr, 1677 - int shmflg); 1678 - 1679 - int (*sem_alloc_security)(struct kern_ipc_perm *perm); 1680 - void (*sem_free_security)(struct kern_ipc_perm *perm); 1681 - int (*sem_associate)(struct kern_ipc_perm *perm, int semflg); 1682 - int (*sem_semctl)(struct kern_ipc_perm *perm, int cmd); 1683 - int (*sem_semop)(struct kern_ipc_perm *perm, struct sembuf *sops, 1684 - unsigned nsops, int alter); 1685 - 1686 - int (*netlink_send)(struct sock *sk, struct sk_buff *skb); 1687 - 1688 - void (*d_instantiate)(struct dentry *dentry, struct inode *inode); 1689 - 1690 - int (*getprocattr)(struct task_struct *p, char *name, char **value); 1691 - int (*setprocattr)(const char *name, void *value, size_t size); 1692 - int (*ismaclabel)(const char *name); 1693 - int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen); 1694 - int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid); 1695 - void (*release_secctx)(char *secdata, u32 seclen); 1696 - 1697 - void (*inode_invalidate_secctx)(struct inode *inode); 1698 - int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen); 1699 - int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen); 1700 - int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen); 1701 - 1702 - #ifdef CONFIG_SECURITY_NETWORK 1703 - int (*unix_stream_connect)(struct sock *sock, struct sock *other, 1704 - struct sock *newsk); 1705 - int (*unix_may_send)(struct socket *sock, struct socket *other); 1706 - 1707 - int (*socket_create)(int family, int type, int protocol, int kern); 1708 - int (*socket_post_create)(struct socket *sock, int family, int type, 1709 - int protocol, int kern); 1710 - int (*socket_socketpair)(struct socket *socka, struct socket *sockb); 1711 - int (*socket_bind)(struct socket *sock, struct sockaddr *address, 1712 - int addrlen); 1713 - int (*socket_connect)(struct socket *sock, struct sockaddr *address, 1714 - int addrlen); 1715 - int (*socket_listen)(struct socket *sock, int backlog); 1716 - int (*socket_accept)(struct socket *sock, struct socket *newsock); 1717 - int (*socket_sendmsg)(struct socket *sock, struct msghdr *msg, 1718 - int size); 1719 - int (*socket_recvmsg)(struct socket *sock, struct msghdr *msg, 1720 - int size, int flags); 1721 - int (*socket_getsockname)(struct socket *sock); 1722 - int (*socket_getpeername)(struct socket *sock); 1723 - int (*socket_getsockopt)(struct socket *sock, int level, int optname); 1724 - int (*socket_setsockopt)(struct socket *sock, int level, int optname); 1725 - int (*socket_shutdown)(struct socket *sock, int how); 1726 - int (*socket_sock_rcv_skb)(struct sock *sk, struct sk_buff *skb); 1727 - int (*socket_getpeersec_stream)(struct socket *sock, 1728 - char __user *optval, 1729 - int __user *optlen, unsigned len); 1730 - int (*socket_getpeersec_dgram)(struct socket *sock, 1731 - struct sk_buff *skb, u32 *secid); 1732 - int (*sk_alloc_security)(struct sock *sk, int family, gfp_t priority); 1733 - void (*sk_free_security)(struct sock *sk); 1734 - void (*sk_clone_security)(const struct sock *sk, struct sock *newsk); 1735 - void (*sk_getsecid)(struct sock *sk, u32 *secid); 1736 - void (*sock_graft)(struct sock *sk, struct socket *parent); 1737 - int (*inet_conn_request)(struct sock *sk, struct sk_buff *skb, 1738 - struct request_sock *req); 1739 - void (*inet_csk_clone)(struct sock *newsk, 1740 - const struct request_sock *req); 1741 - void (*inet_conn_established)(struct sock *sk, struct sk_buff *skb); 1742 - int (*secmark_relabel_packet)(u32 secid); 1743 - void (*secmark_refcount_inc)(void); 1744 - void (*secmark_refcount_dec)(void); 1745 - void (*req_classify_flow)(const struct request_sock *req, 1746 - struct flowi *fl); 1747 - int (*tun_dev_alloc_security)(void **security); 1748 - void (*tun_dev_free_security)(void *security); 1749 - int (*tun_dev_create)(void); 1750 - int (*tun_dev_attach_queue)(void *security); 1751 - int (*tun_dev_attach)(struct sock *sk, void *security); 1752 - int (*tun_dev_open)(void *security); 1753 - int (*sctp_assoc_request)(struct sctp_endpoint *ep, 1754 - struct sk_buff *skb); 1755 - int (*sctp_bind_connect)(struct sock *sk, int optname, 1756 - struct sockaddr *address, int addrlen); 1757 - void (*sctp_sk_clone)(struct sctp_endpoint *ep, struct sock *sk, 1758 - struct sock *newsk); 1759 - #endif /* CONFIG_SECURITY_NETWORK */ 1760 - 1761 - #ifdef CONFIG_SECURITY_INFINIBAND 1762 - int (*ib_pkey_access)(void *sec, u64 subnet_prefix, u16 pkey); 1763 - int (*ib_endport_manage_subnet)(void *sec, const char *dev_name, 1764 - u8 port_num); 1765 - int (*ib_alloc_security)(void **sec); 1766 - void (*ib_free_security)(void *sec); 1767 - #endif /* CONFIG_SECURITY_INFINIBAND */ 1768 - 1769 - #ifdef CONFIG_SECURITY_NETWORK_XFRM 1770 - int (*xfrm_policy_alloc_security)(struct xfrm_sec_ctx **ctxp, 1771 - struct xfrm_user_sec_ctx *sec_ctx, 1772 - gfp_t gfp); 1773 - int (*xfrm_policy_clone_security)(struct xfrm_sec_ctx *old_ctx, 1774 - struct xfrm_sec_ctx **new_ctx); 1775 - void (*xfrm_policy_free_security)(struct xfrm_sec_ctx *ctx); 1776 - int (*xfrm_policy_delete_security)(struct xfrm_sec_ctx *ctx); 1777 - int (*xfrm_state_alloc)(struct xfrm_state *x, 1778 - struct xfrm_user_sec_ctx *sec_ctx); 1779 - int (*xfrm_state_alloc_acquire)(struct xfrm_state *x, 1780 - struct xfrm_sec_ctx *polsec, 1781 - u32 secid); 1782 - void (*xfrm_state_free_security)(struct xfrm_state *x); 1783 - int (*xfrm_state_delete_security)(struct xfrm_state *x); 1784 - int (*xfrm_policy_lookup)(struct xfrm_sec_ctx *ctx, u32 fl_secid, 1785 - u8 dir); 1786 - int (*xfrm_state_pol_flow_match)(struct xfrm_state *x, 1787 - struct xfrm_policy *xp, 1788 - const struct flowi *fl); 1789 - int (*xfrm_decode_session)(struct sk_buff *skb, u32 *secid, int ckall); 1790 - #endif /* CONFIG_SECURITY_NETWORK_XFRM */ 1791 - 1792 - /* key management security hooks */ 1793 - #ifdef CONFIG_KEYS 1794 - int (*key_alloc)(struct key *key, const struct cred *cred, 1795 - unsigned long flags); 1796 - void (*key_free)(struct key *key); 1797 - int (*key_permission)(key_ref_t key_ref, const struct cred *cred, 1798 - unsigned perm); 1799 - int (*key_getsecurity)(struct key *key, char **_buffer); 1800 - #endif /* CONFIG_KEYS */ 1801 - 1802 - #ifdef CONFIG_AUDIT 1803 - int (*audit_rule_init)(u32 field, u32 op, char *rulestr, 1804 - void **lsmrule); 1805 - int (*audit_rule_known)(struct audit_krule *krule); 1806 - int (*audit_rule_match)(u32 secid, u32 field, u32 op, void *lsmrule); 1807 - void (*audit_rule_free)(void *lsmrule); 1808 - #endif /* CONFIG_AUDIT */ 1809 - 1810 - #ifdef CONFIG_BPF_SYSCALL 1811 - int (*bpf)(int cmd, union bpf_attr *attr, 1812 - unsigned int size); 1813 - int (*bpf_map)(struct bpf_map *map, fmode_t fmode); 1814 - int (*bpf_prog)(struct bpf_prog *prog); 1815 - int (*bpf_map_alloc_security)(struct bpf_map *map); 1816 - void (*bpf_map_free_security)(struct bpf_map *map); 1817 - int (*bpf_prog_alloc_security)(struct bpf_prog_aux *aux); 1818 - void (*bpf_prog_free_security)(struct bpf_prog_aux *aux); 1819 - #endif /* CONFIG_BPF_SYSCALL */ 1820 - int (*locked_down)(enum lockdown_reason what); 1821 - #ifdef CONFIG_PERF_EVENTS 1822 - int (*perf_event_open)(struct perf_event_attr *attr, int type); 1823 - int (*perf_event_alloc)(struct perf_event *event); 1824 - void (*perf_event_free)(struct perf_event *event); 1825 - int (*perf_event_read)(struct perf_event *event); 1826 - int (*perf_event_write)(struct perf_event *event); 1827 - 1828 - #endif 1459 + #define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__); 1460 + #include "lsm_hook_defs.h" 1461 + #undef LSM_HOOK 1829 1462 }; 1830 1463 1831 1464 struct security_hook_heads { 1832 - struct hlist_head binder_set_context_mgr; 1833 - struct hlist_head binder_transaction; 1834 - struct hlist_head binder_transfer_binder; 1835 - struct hlist_head binder_transfer_file; 1836 - struct hlist_head ptrace_access_check; 1837 - struct hlist_head ptrace_traceme; 1838 - struct hlist_head capget; 1839 - struct hlist_head capset; 1840 - struct hlist_head capable; 1841 - struct hlist_head quotactl; 1842 - struct hlist_head quota_on; 1843 - struct hlist_head syslog; 1844 - struct hlist_head settime; 1845 - struct hlist_head vm_enough_memory; 1846 - struct hlist_head bprm_set_creds; 1847 - struct hlist_head bprm_check_security; 1848 - struct hlist_head bprm_committing_creds; 1849 - struct hlist_head bprm_committed_creds; 1850 - struct hlist_head fs_context_dup; 1851 - struct hlist_head fs_context_parse_param; 1852 - struct hlist_head sb_alloc_security; 1853 - struct hlist_head sb_free_security; 1854 - struct hlist_head sb_free_mnt_opts; 1855 - struct hlist_head sb_eat_lsm_opts; 1856 - struct hlist_head sb_remount; 1857 - struct hlist_head sb_kern_mount; 1858 - struct hlist_head sb_show_options; 1859 - struct hlist_head sb_statfs; 1860 - struct hlist_head sb_mount; 1861 - struct hlist_head sb_umount; 1862 - struct hlist_head sb_pivotroot; 1863 - struct hlist_head sb_set_mnt_opts; 1864 - struct hlist_head sb_clone_mnt_opts; 1865 - struct hlist_head sb_add_mnt_opt; 1866 - struct hlist_head move_mount; 1867 - struct hlist_head dentry_init_security; 1868 - struct hlist_head dentry_create_files_as; 1869 - #ifdef CONFIG_SECURITY_PATH 1870 - struct hlist_head path_unlink; 1871 - struct hlist_head path_mkdir; 1872 - struct hlist_head path_rmdir; 1873 - struct hlist_head path_mknod; 1874 - struct hlist_head path_truncate; 1875 - struct hlist_head path_symlink; 1876 - struct hlist_head path_link; 1877 - struct hlist_head path_rename; 1878 - struct hlist_head path_chmod; 1879 - struct hlist_head path_chown; 1880 - struct hlist_head path_chroot; 1881 - #endif 1882 - /* Needed for inode based modules as well */ 1883 - struct hlist_head path_notify; 1884 - struct hlist_head inode_alloc_security; 1885 - struct hlist_head inode_free_security; 1886 - struct hlist_head inode_init_security; 1887 - struct hlist_head inode_create; 1888 - struct hlist_head inode_link; 1889 - struct hlist_head inode_unlink; 1890 - struct hlist_head inode_symlink; 1891 - struct hlist_head inode_mkdir; 1892 - struct hlist_head inode_rmdir; 1893 - struct hlist_head inode_mknod; 1894 - struct hlist_head inode_rename; 1895 - struct hlist_head inode_readlink; 1896 - struct hlist_head inode_follow_link; 1897 - struct hlist_head inode_permission; 1898 - struct hlist_head inode_setattr; 1899 - struct hlist_head inode_getattr; 1900 - struct hlist_head inode_setxattr; 1901 - struct hlist_head inode_post_setxattr; 1902 - struct hlist_head inode_getxattr; 1903 - struct hlist_head inode_listxattr; 1904 - struct hlist_head inode_removexattr; 1905 - struct hlist_head inode_need_killpriv; 1906 - struct hlist_head inode_killpriv; 1907 - struct hlist_head inode_getsecurity; 1908 - struct hlist_head inode_setsecurity; 1909 - struct hlist_head inode_listsecurity; 1910 - struct hlist_head inode_getsecid; 1911 - struct hlist_head inode_copy_up; 1912 - struct hlist_head inode_copy_up_xattr; 1913 - struct hlist_head kernfs_init_security; 1914 - struct hlist_head file_permission; 1915 - struct hlist_head file_alloc_security; 1916 - struct hlist_head file_free_security; 1917 - struct hlist_head file_ioctl; 1918 - struct hlist_head mmap_addr; 1919 - struct hlist_head mmap_file; 1920 - struct hlist_head file_mprotect; 1921 - struct hlist_head file_lock; 1922 - struct hlist_head file_fcntl; 1923 - struct hlist_head file_set_fowner; 1924 - struct hlist_head file_send_sigiotask; 1925 - struct hlist_head file_receive; 1926 - struct hlist_head file_open; 1927 - struct hlist_head task_alloc; 1928 - struct hlist_head task_free; 1929 - struct hlist_head cred_alloc_blank; 1930 - struct hlist_head cred_free; 1931 - struct hlist_head cred_prepare; 1932 - struct hlist_head cred_transfer; 1933 - struct hlist_head cred_getsecid; 1934 - struct hlist_head kernel_act_as; 1935 - struct hlist_head kernel_create_files_as; 1936 - struct hlist_head kernel_load_data; 1937 - struct hlist_head kernel_read_file; 1938 - struct hlist_head kernel_post_read_file; 1939 - struct hlist_head kernel_module_request; 1940 - struct hlist_head task_fix_setuid; 1941 - struct hlist_head task_setpgid; 1942 - struct hlist_head task_getpgid; 1943 - struct hlist_head task_getsid; 1944 - struct hlist_head task_getsecid; 1945 - struct hlist_head task_setnice; 1946 - struct hlist_head task_setioprio; 1947 - struct hlist_head task_getioprio; 1948 - struct hlist_head task_prlimit; 1949 - struct hlist_head task_setrlimit; 1950 - struct hlist_head task_setscheduler; 1951 - struct hlist_head task_getscheduler; 1952 - struct hlist_head task_movememory; 1953 - struct hlist_head task_kill; 1954 - struct hlist_head task_prctl; 1955 - struct hlist_head task_to_inode; 1956 - struct hlist_head ipc_permission; 1957 - struct hlist_head ipc_getsecid; 1958 - struct hlist_head msg_msg_alloc_security; 1959 - struct hlist_head msg_msg_free_security; 1960 - struct hlist_head msg_queue_alloc_security; 1961 - struct hlist_head msg_queue_free_security; 1962 - struct hlist_head msg_queue_associate; 1963 - struct hlist_head msg_queue_msgctl; 1964 - struct hlist_head msg_queue_msgsnd; 1965 - struct hlist_head msg_queue_msgrcv; 1966 - struct hlist_head shm_alloc_security; 1967 - struct hlist_head shm_free_security; 1968 - struct hlist_head shm_associate; 1969 - struct hlist_head shm_shmctl; 1970 - struct hlist_head shm_shmat; 1971 - struct hlist_head sem_alloc_security; 1972 - struct hlist_head sem_free_security; 1973 - struct hlist_head sem_associate; 1974 - struct hlist_head sem_semctl; 1975 - struct hlist_head sem_semop; 1976 - struct hlist_head netlink_send; 1977 - struct hlist_head d_instantiate; 1978 - struct hlist_head getprocattr; 1979 - struct hlist_head setprocattr; 1980 - struct hlist_head ismaclabel; 1981 - struct hlist_head secid_to_secctx; 1982 - struct hlist_head secctx_to_secid; 1983 - struct hlist_head release_secctx; 1984 - struct hlist_head inode_invalidate_secctx; 1985 - struct hlist_head inode_notifysecctx; 1986 - struct hlist_head inode_setsecctx; 1987 - struct hlist_head inode_getsecctx; 1988 - #ifdef CONFIG_SECURITY_NETWORK 1989 - struct hlist_head unix_stream_connect; 1990 - struct hlist_head unix_may_send; 1991 - struct hlist_head socket_create; 1992 - struct hlist_head socket_post_create; 1993 - struct hlist_head socket_socketpair; 1994 - struct hlist_head socket_bind; 1995 - struct hlist_head socket_connect; 1996 - struct hlist_head socket_listen; 1997 - struct hlist_head socket_accept; 1998 - struct hlist_head socket_sendmsg; 1999 - struct hlist_head socket_recvmsg; 2000 - struct hlist_head socket_getsockname; 2001 - struct hlist_head socket_getpeername; 2002 - struct hlist_head socket_getsockopt; 2003 - struct hlist_head socket_setsockopt; 2004 - struct hlist_head socket_shutdown; 2005 - struct hlist_head socket_sock_rcv_skb; 2006 - struct hlist_head socket_getpeersec_stream; 2007 - struct hlist_head socket_getpeersec_dgram; 2008 - struct hlist_head sk_alloc_security; 2009 - struct hlist_head sk_free_security; 2010 - struct hlist_head sk_clone_security; 2011 - struct hlist_head sk_getsecid; 2012 - struct hlist_head sock_graft; 2013 - struct hlist_head inet_conn_request; 2014 - struct hlist_head inet_csk_clone; 2015 - struct hlist_head inet_conn_established; 2016 - struct hlist_head secmark_relabel_packet; 2017 - struct hlist_head secmark_refcount_inc; 2018 - struct hlist_head secmark_refcount_dec; 2019 - struct hlist_head req_classify_flow; 2020 - struct hlist_head tun_dev_alloc_security; 2021 - struct hlist_head tun_dev_free_security; 2022 - struct hlist_head tun_dev_create; 2023 - struct hlist_head tun_dev_attach_queue; 2024 - struct hlist_head tun_dev_attach; 2025 - struct hlist_head tun_dev_open; 2026 - struct hlist_head sctp_assoc_request; 2027 - struct hlist_head sctp_bind_connect; 2028 - struct hlist_head sctp_sk_clone; 2029 - #endif /* CONFIG_SECURITY_NETWORK */ 2030 - #ifdef CONFIG_SECURITY_INFINIBAND 2031 - struct hlist_head ib_pkey_access; 2032 - struct hlist_head ib_endport_manage_subnet; 2033 - struct hlist_head ib_alloc_security; 2034 - struct hlist_head ib_free_security; 2035 - #endif /* CONFIG_SECURITY_INFINIBAND */ 2036 - #ifdef CONFIG_SECURITY_NETWORK_XFRM 2037 - struct hlist_head xfrm_policy_alloc_security; 2038 - struct hlist_head xfrm_policy_clone_security; 2039 - struct hlist_head xfrm_policy_free_security; 2040 - struct hlist_head xfrm_policy_delete_security; 2041 - struct hlist_head xfrm_state_alloc; 2042 - struct hlist_head xfrm_state_alloc_acquire; 2043 - struct hlist_head xfrm_state_free_security; 2044 - struct hlist_head xfrm_state_delete_security; 2045 - struct hlist_head xfrm_policy_lookup; 2046 - struct hlist_head xfrm_state_pol_flow_match; 2047 - struct hlist_head xfrm_decode_session; 2048 - #endif /* CONFIG_SECURITY_NETWORK_XFRM */ 2049 - #ifdef CONFIG_KEYS 2050 - struct hlist_head key_alloc; 2051 - struct hlist_head key_free; 2052 - struct hlist_head key_permission; 2053 - struct hlist_head key_getsecurity; 2054 - #endif /* CONFIG_KEYS */ 2055 - #ifdef CONFIG_AUDIT 2056 - struct hlist_head audit_rule_init; 2057 - struct hlist_head audit_rule_known; 2058 - struct hlist_head audit_rule_match; 2059 - struct hlist_head audit_rule_free; 2060 - #endif /* CONFIG_AUDIT */ 2061 - #ifdef CONFIG_BPF_SYSCALL 2062 - struct hlist_head bpf; 2063 - struct hlist_head bpf_map; 2064 - struct hlist_head bpf_prog; 2065 - struct hlist_head bpf_map_alloc_security; 2066 - struct hlist_head bpf_map_free_security; 2067 - struct hlist_head bpf_prog_alloc_security; 2068 - struct hlist_head bpf_prog_free_security; 2069 - #endif /* CONFIG_BPF_SYSCALL */ 2070 - struct hlist_head locked_down; 2071 - #ifdef CONFIG_PERF_EVENTS 2072 - struct hlist_head perf_event_open; 2073 - struct hlist_head perf_event_alloc; 2074 - struct hlist_head perf_event_free; 2075 - struct hlist_head perf_event_read; 2076 - struct hlist_head perf_event_write; 2077 - #endif 1465 + #define LSM_HOOK(RET, DEFAULT, NAME, ...) struct hlist_head NAME; 1466 + #include "lsm_hook_defs.h" 1467 + #undef LSM_HOOK 2078 1468 } __randomize_layout; 2079 1469 2080 1470 /* ··· 1489 2099 int lbs_msg_msg; 1490 2100 int lbs_task; 1491 2101 }; 2102 + 2103 + /* 2104 + * LSM_RET_VOID is used as the default value in LSM_HOOK definitions for void 2105 + * LSM hooks (in include/linux/lsm_hook_defs.h). 2106 + */ 2107 + #define LSM_RET_VOID ((void) 0) 1492 2108 1493 2109 /* 1494 2110 * Initializing a security_hook_list structure takes
+30 -11
security/security.c
··· 669 669 } 670 670 671 671 /* 672 + * The default value of the LSM hook is defined in linux/lsm_hook_defs.h and 673 + * can be accessed with: 674 + * 675 + * LSM_RET_DEFAULT(<hook_name>) 676 + * 677 + * The macros below define static constants for the default value of each 678 + * LSM hook. 679 + */ 680 + #define LSM_RET_DEFAULT(NAME) (NAME##_default) 681 + #define DECLARE_LSM_RET_DEFAULT_void(DEFAULT, NAME) 682 + #define DECLARE_LSM_RET_DEFAULT_int(DEFAULT, NAME) \ 683 + static const int LSM_RET_DEFAULT(NAME) = (DEFAULT); 684 + #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ 685 + DECLARE_LSM_RET_DEFAULT_##RET(DEFAULT, NAME) 686 + 687 + #include <linux/lsm_hook_defs.h> 688 + #undef LSM_HOOK 689 + 690 + /* 672 691 * Hook list operation macros. 673 692 * 674 693 * call_void_hook: ··· 1357 1338 int rc; 1358 1339 1359 1340 if (unlikely(IS_PRIVATE(inode))) 1360 - return -EOPNOTSUPP; 1341 + return LSM_RET_DEFAULT(inode_getsecurity); 1361 1342 /* 1362 1343 * Only one module will provide an attribute with a given name. 1363 1344 */ 1364 1345 hlist_for_each_entry(hp, &security_hook_heads.inode_getsecurity, list) { 1365 1346 rc = hp->hook.inode_getsecurity(inode, name, buffer, alloc); 1366 - if (rc != -EOPNOTSUPP) 1347 + if (rc != LSM_RET_DEFAULT(inode_getsecurity)) 1367 1348 return rc; 1368 1349 } 1369 - return -EOPNOTSUPP; 1350 + return LSM_RET_DEFAULT(inode_getsecurity); 1370 1351 } 1371 1352 1372 1353 int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags) ··· 1375 1356 int rc; 1376 1357 1377 1358 if (unlikely(IS_PRIVATE(inode))) 1378 - return -EOPNOTSUPP; 1359 + return LSM_RET_DEFAULT(inode_setsecurity); 1379 1360 /* 1380 1361 * Only one module will provide an attribute with a given name. 1381 1362 */ 1382 1363 hlist_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) { 1383 1364 rc = hp->hook.inode_setsecurity(inode, name, value, size, 1384 1365 flags); 1385 - if (rc != -EOPNOTSUPP) 1366 + if (rc != LSM_RET_DEFAULT(inode_setsecurity)) 1386 1367 return rc; 1387 1368 } 1388 - return -EOPNOTSUPP; 1369 + return LSM_RET_DEFAULT(inode_setsecurity); 1389 1370 } 1390 1371 1391 1372 int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size) ··· 1759 1740 unsigned long arg4, unsigned long arg5) 1760 1741 { 1761 1742 int thisrc; 1762 - int rc = -ENOSYS; 1743 + int rc = LSM_RET_DEFAULT(task_prctl); 1763 1744 struct security_hook_list *hp; 1764 1745 1765 1746 hlist_for_each_entry(hp, &security_hook_heads.task_prctl, list) { 1766 1747 thisrc = hp->hook.task_prctl(option, arg2, arg3, arg4, arg5); 1767 - if (thisrc != -ENOSYS) { 1748 + if (thisrc != LSM_RET_DEFAULT(task_prctl)) { 1768 1749 rc = thisrc; 1769 1750 if (thisrc != 0) 1770 1751 break; ··· 1936 1917 continue; 1937 1918 return hp->hook.getprocattr(p, name, value); 1938 1919 } 1939 - return -EINVAL; 1920 + return LSM_RET_DEFAULT(getprocattr); 1940 1921 } 1941 1922 1942 1923 int security_setprocattr(const char *lsm, const char *name, void *value, ··· 1949 1930 continue; 1950 1931 return hp->hook.setprocattr(name, value, size); 1951 1932 } 1952 - return -EINVAL; 1933 + return LSM_RET_DEFAULT(setprocattr); 1953 1934 } 1954 1935 1955 1936 int security_netlink_send(struct sock *sk, struct sk_buff *skb) ··· 2334 2315 const struct flowi *fl) 2335 2316 { 2336 2317 struct security_hook_list *hp; 2337 - int rc = 1; 2318 + int rc = LSM_RET_DEFAULT(xfrm_state_pol_flow_match); 2338 2319 2339 2320 /* 2340 2321 * Since this function is expected to return 0 or 1, the judgment