lsm_hooks.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /*
  2. * Linux Security Module interfaces
  3. *
  4. * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
  5. * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com>
  6. * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
  7. * Copyright (C) 2001 James Morris <jmorris@intercode.com.au>
  8. * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group)
  9. * Copyright (C) 2015 Intel Corporation.
  10. * Copyright (C) 2015 Casey Schaufler <casey@schaufler-ca.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * Due to this file being licensed under the GPL there is controversy over
  18. * whether this permits you to write a module that #includes this file
  19. * without placing your module under the GPL. Please consult a lawyer for
  20. * advice before doing this.
  21. *
  22. */
  23. #ifndef __LINUX_LSM_HOOKS_H
  24. #define __LINUX_LSM_HOOKS_H
  25. #include <linux/security.h>
  26. /* Maximum number of letters for an LSM name string */
  27. #define SECURITY_NAME_MAX 10
  28. #ifdef CONFIG_SECURITY
  29. struct security_operations {
  30. char name[SECURITY_NAME_MAX + 1];
  31. int (*binder_set_context_mgr)(struct task_struct *mgr);
  32. int (*binder_transaction)(struct task_struct *from,
  33. struct task_struct *to);
  34. int (*binder_transfer_binder)(struct task_struct *from,
  35. struct task_struct *to);
  36. int (*binder_transfer_file)(struct task_struct *from,
  37. struct task_struct *to,
  38. struct file *file);
  39. int (*ptrace_access_check)(struct task_struct *child,
  40. unsigned int mode);
  41. int (*ptrace_traceme)(struct task_struct *parent);
  42. int (*capget)(struct task_struct *target, kernel_cap_t *effective,
  43. kernel_cap_t *inheritable, kernel_cap_t *permitted);
  44. int (*capset)(struct cred *new, const struct cred *old,
  45. const kernel_cap_t *effective,
  46. const kernel_cap_t *inheritable,
  47. const kernel_cap_t *permitted);
  48. int (*capable)(const struct cred *cred, struct user_namespace *ns,
  49. int cap, int audit);
  50. int (*quotactl)(int cmds, int type, int id, struct super_block *sb);
  51. int (*quota_on)(struct dentry *dentry);
  52. int (*syslog)(int type);
  53. int (*settime)(const struct timespec *ts, const struct timezone *tz);
  54. int (*vm_enough_memory)(struct mm_struct *mm, long pages);
  55. int (*bprm_set_creds)(struct linux_binprm *bprm);
  56. int (*bprm_check_security)(struct linux_binprm *bprm);
  57. int (*bprm_secureexec)(struct linux_binprm *bprm);
  58. void (*bprm_committing_creds)(struct linux_binprm *bprm);
  59. void (*bprm_committed_creds)(struct linux_binprm *bprm);
  60. int (*sb_alloc_security)(struct super_block *sb);
  61. void (*sb_free_security)(struct super_block *sb);
  62. int (*sb_copy_data)(char *orig, char *copy);
  63. int (*sb_remount)(struct super_block *sb, void *data);
  64. int (*sb_kern_mount)(struct super_block *sb, int flags, void *data);
  65. int (*sb_show_options)(struct seq_file *m, struct super_block *sb);
  66. int (*sb_statfs)(struct dentry *dentry);
  67. int (*sb_mount)(const char *dev_name, struct path *path,
  68. const char *type, unsigned long flags, void *data);
  69. int (*sb_umount)(struct vfsmount *mnt, int flags);
  70. int (*sb_pivotroot)(struct path *old_path, struct path *new_path);
  71. int (*sb_set_mnt_opts)(struct super_block *sb,
  72. struct security_mnt_opts *opts,
  73. unsigned long kern_flags,
  74. unsigned long *set_kern_flags);
  75. int (*sb_clone_mnt_opts)(const struct super_block *oldsb,
  76. struct super_block *newsb);
  77. int (*sb_parse_opts_str)(char *options, struct security_mnt_opts *opts);
  78. int (*dentry_init_security)(struct dentry *dentry, int mode,
  79. struct qstr *name, void **ctx,
  80. u32 *ctxlen);
  81. #ifdef CONFIG_SECURITY_PATH
  82. int (*path_unlink)(struct path *dir, struct dentry *dentry);
  83. int (*path_mkdir)(struct path *dir, struct dentry *dentry,
  84. umode_t mode);
  85. int (*path_rmdir)(struct path *dir, struct dentry *dentry);
  86. int (*path_mknod)(struct path *dir, struct dentry *dentry,
  87. umode_t mode, unsigned int dev);
  88. int (*path_truncate)(struct path *path);
  89. int (*path_symlink)(struct path *dir, struct dentry *dentry,
  90. const char *old_name);
  91. int (*path_link)(struct dentry *old_dentry, struct path *new_dir,
  92. struct dentry *new_dentry);
  93. int (*path_rename)(struct path *old_dir, struct dentry *old_dentry,
  94. struct path *new_dir,
  95. struct dentry *new_dentry);
  96. int (*path_chmod)(struct path *path, umode_t mode);
  97. int (*path_chown)(struct path *path, kuid_t uid, kgid_t gid);
  98. int (*path_chroot)(struct path *path);
  99. #endif
  100. int (*inode_alloc_security)(struct inode *inode);
  101. void (*inode_free_security)(struct inode *inode);
  102. int (*inode_init_security)(struct inode *inode, struct inode *dir,
  103. const struct qstr *qstr,
  104. const char **name, void **value,
  105. size_t *len);
  106. int (*inode_create)(struct inode *dir, struct dentry *dentry,
  107. umode_t mode);
  108. int (*inode_link)(struct dentry *old_dentry, struct inode *dir,
  109. struct dentry *new_dentry);
  110. int (*inode_unlink)(struct inode *dir, struct dentry *dentry);
  111. int (*inode_symlink)(struct inode *dir, struct dentry *dentry,
  112. const char *old_name);
  113. int (*inode_mkdir)(struct inode *dir, struct dentry *dentry,
  114. umode_t mode);
  115. int (*inode_rmdir)(struct inode *dir, struct dentry *dentry);
  116. int (*inode_mknod)(struct inode *dir, struct dentry *dentry,
  117. umode_t mode, dev_t dev);
  118. int (*inode_rename)(struct inode *old_dir, struct dentry *old_dentry,
  119. struct inode *new_dir,
  120. struct dentry *new_dentry);
  121. int (*inode_readlink)(struct dentry *dentry);
  122. int (*inode_follow_link)(struct dentry *dentry, struct nameidata *nd);
  123. int (*inode_permission)(struct inode *inode, int mask);
  124. int (*inode_setattr)(struct dentry *dentry, struct iattr *attr);
  125. int (*inode_getattr)(const struct path *path);
  126. int (*inode_setxattr)(struct dentry *dentry, const char *name,
  127. const void *value, size_t size, int flags);
  128. void (*inode_post_setxattr)(struct dentry *dentry, const char *name,
  129. const void *value, size_t size,
  130. int flags);
  131. int (*inode_getxattr)(struct dentry *dentry, const char *name);
  132. int (*inode_listxattr)(struct dentry *dentry);
  133. int (*inode_removexattr)(struct dentry *dentry, const char *name);
  134. int (*inode_need_killpriv)(struct dentry *dentry);
  135. int (*inode_killpriv)(struct dentry *dentry);
  136. int (*inode_getsecurity)(const struct inode *inode, const char *name,
  137. void **buffer, bool alloc);
  138. int (*inode_setsecurity)(struct inode *inode, const char *name,
  139. const void *value, size_t size,
  140. int flags);
  141. int (*inode_listsecurity)(struct inode *inode, char *buffer,
  142. size_t buffer_size);
  143. void (*inode_getsecid)(const struct inode *inode, u32 *secid);
  144. int (*file_permission)(struct file *file, int mask);
  145. int (*file_alloc_security)(struct file *file);
  146. void (*file_free_security)(struct file *file);
  147. int (*file_ioctl)(struct file *file, unsigned int cmd,
  148. unsigned long arg);
  149. int (*mmap_addr)(unsigned long addr);
  150. int (*mmap_file)(struct file *file, unsigned long reqprot,
  151. unsigned long prot, unsigned long flags);
  152. int (*file_mprotect)(struct vm_area_struct *vma, unsigned long reqprot,
  153. unsigned long prot);
  154. int (*file_lock)(struct file *file, unsigned int cmd);
  155. int (*file_fcntl)(struct file *file, unsigned int cmd,
  156. unsigned long arg);
  157. void (*file_set_fowner)(struct file *file);
  158. int (*file_send_sigiotask)(struct task_struct *tsk,
  159. struct fown_struct *fown, int sig);
  160. int (*file_receive)(struct file *file);
  161. int (*file_open)(struct file *file, const struct cred *cred);
  162. int (*task_create)(unsigned long clone_flags);
  163. void (*task_free)(struct task_struct *task);
  164. int (*cred_alloc_blank)(struct cred *cred, gfp_t gfp);
  165. void (*cred_free)(struct cred *cred);
  166. int (*cred_prepare)(struct cred *new, const struct cred *old,
  167. gfp_t gfp);
  168. void (*cred_transfer)(struct cred *new, const struct cred *old);
  169. int (*kernel_act_as)(struct cred *new, u32 secid);
  170. int (*kernel_create_files_as)(struct cred *new, struct inode *inode);
  171. int (*kernel_fw_from_file)(struct file *file, char *buf, size_t size);
  172. int (*kernel_module_request)(char *kmod_name);
  173. int (*kernel_module_from_file)(struct file *file);
  174. int (*task_fix_setuid)(struct cred *new, const struct cred *old,
  175. int flags);
  176. int (*task_setpgid)(struct task_struct *p, pid_t pgid);
  177. int (*task_getpgid)(struct task_struct *p);
  178. int (*task_getsid)(struct task_struct *p);
  179. void (*task_getsecid)(struct task_struct *p, u32 *secid);
  180. int (*task_setnice)(struct task_struct *p, int nice);
  181. int (*task_setioprio)(struct task_struct *p, int ioprio);
  182. int (*task_getioprio)(struct task_struct *p);
  183. int (*task_setrlimit)(struct task_struct *p, unsigned int resource,
  184. struct rlimit *new_rlim);
  185. int (*task_setscheduler)(struct task_struct *p);
  186. int (*task_getscheduler)(struct task_struct *p);
  187. int (*task_movememory)(struct task_struct *p);
  188. int (*task_kill)(struct task_struct *p, struct siginfo *info,
  189. int sig, u32 secid);
  190. int (*task_wait)(struct task_struct *p);
  191. int (*task_prctl)(int option, unsigned long arg2, unsigned long arg3,
  192. unsigned long arg4, unsigned long arg5);
  193. void (*task_to_inode)(struct task_struct *p, struct inode *inode);
  194. int (*ipc_permission)(struct kern_ipc_perm *ipcp, short flag);
  195. void (*ipc_getsecid)(struct kern_ipc_perm *ipcp, u32 *secid);
  196. int (*msg_msg_alloc_security)(struct msg_msg *msg);
  197. void (*msg_msg_free_security)(struct msg_msg *msg);
  198. int (*msg_queue_alloc_security)(struct msg_queue *msq);
  199. void (*msg_queue_free_security)(struct msg_queue *msq);
  200. int (*msg_queue_associate)(struct msg_queue *msq, int msqflg);
  201. int (*msg_queue_msgctl)(struct msg_queue *msq, int cmd);
  202. int (*msg_queue_msgsnd)(struct msg_queue *msq, struct msg_msg *msg,
  203. int msqflg);
  204. int (*msg_queue_msgrcv)(struct msg_queue *msq, struct msg_msg *msg,
  205. struct task_struct *target, long type,
  206. int mode);
  207. int (*shm_alloc_security)(struct shmid_kernel *shp);
  208. void (*shm_free_security)(struct shmid_kernel *shp);
  209. int (*shm_associate)(struct shmid_kernel *shp, int shmflg);
  210. int (*shm_shmctl)(struct shmid_kernel *shp, int cmd);
  211. int (*shm_shmat)(struct shmid_kernel *shp, char __user *shmaddr,
  212. int shmflg);
  213. int (*sem_alloc_security)(struct sem_array *sma);
  214. void (*sem_free_security)(struct sem_array *sma);
  215. int (*sem_associate)(struct sem_array *sma, int semflg);
  216. int (*sem_semctl)(struct sem_array *sma, int cmd);
  217. int (*sem_semop)(struct sem_array *sma, struct sembuf *sops,
  218. unsigned nsops, int alter);
  219. int (*netlink_send)(struct sock *sk, struct sk_buff *skb);
  220. void (*d_instantiate)(struct dentry *dentry, struct inode *inode);
  221. int (*getprocattr)(struct task_struct *p, char *name, char **value);
  222. int (*setprocattr)(struct task_struct *p, char *name, void *value,
  223. size_t size);
  224. int (*ismaclabel)(const char *name);
  225. int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
  226. int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid);
  227. void (*release_secctx)(char *secdata, u32 seclen);
  228. int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen);
  229. int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen);
  230. int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen);
  231. #ifdef CONFIG_SECURITY_NETWORK
  232. int (*unix_stream_connect)(struct sock *sock, struct sock *other,
  233. struct sock *newsk);
  234. int (*unix_may_send)(struct socket *sock, struct socket *other);
  235. int (*socket_create)(int family, int type, int protocol, int kern);
  236. int (*socket_post_create)(struct socket *sock, int family, int type,
  237. int protocol, int kern);
  238. int (*socket_bind)(struct socket *sock, struct sockaddr *address,
  239. int addrlen);
  240. int (*socket_connect)(struct socket *sock, struct sockaddr *address,
  241. int addrlen);
  242. int (*socket_listen)(struct socket *sock, int backlog);
  243. int (*socket_accept)(struct socket *sock, struct socket *newsock);
  244. int (*socket_sendmsg)(struct socket *sock, struct msghdr *msg,
  245. int size);
  246. int (*socket_recvmsg)(struct socket *sock, struct msghdr *msg,
  247. int size, int flags);
  248. int (*socket_getsockname)(struct socket *sock);
  249. int (*socket_getpeername)(struct socket *sock);
  250. int (*socket_getsockopt)(struct socket *sock, int level, int optname);
  251. int (*socket_setsockopt)(struct socket *sock, int level, int optname);
  252. int (*socket_shutdown)(struct socket *sock, int how);
  253. int (*socket_sock_rcv_skb)(struct sock *sk, struct sk_buff *skb);
  254. int (*socket_getpeersec_stream)(struct socket *sock,
  255. char __user *optval,
  256. int __user *optlen, unsigned len);
  257. int (*socket_getpeersec_dgram)(struct socket *sock,
  258. struct sk_buff *skb, u32 *secid);
  259. int (*sk_alloc_security)(struct sock *sk, int family, gfp_t priority);
  260. void (*sk_free_security)(struct sock *sk);
  261. void (*sk_clone_security)(const struct sock *sk, struct sock *newsk);
  262. void (*sk_getsecid)(struct sock *sk, u32 *secid);
  263. void (*sock_graft)(struct sock *sk, struct socket *parent);
  264. int (*inet_conn_request)(struct sock *sk, struct sk_buff *skb,
  265. struct request_sock *req);
  266. void (*inet_csk_clone)(struct sock *newsk,
  267. const struct request_sock *req);
  268. void (*inet_conn_established)(struct sock *sk, struct sk_buff *skb);
  269. int (*secmark_relabel_packet)(u32 secid);
  270. void (*secmark_refcount_inc)(void);
  271. void (*secmark_refcount_dec)(void);
  272. void (*req_classify_flow)(const struct request_sock *req,
  273. struct flowi *fl);
  274. int (*tun_dev_alloc_security)(void **security);
  275. void (*tun_dev_free_security)(void *security);
  276. int (*tun_dev_create)(void);
  277. int (*tun_dev_attach_queue)(void *security);
  278. int (*tun_dev_attach)(struct sock *sk, void *security);
  279. int (*tun_dev_open)(void *security);
  280. #endif /* CONFIG_SECURITY_NETWORK */
  281. #ifdef CONFIG_SECURITY_NETWORK_XFRM
  282. int (*xfrm_policy_alloc_security)(struct xfrm_sec_ctx **ctxp,
  283. struct xfrm_user_sec_ctx *sec_ctx,
  284. gfp_t gfp);
  285. int (*xfrm_policy_clone_security)(struct xfrm_sec_ctx *old_ctx,
  286. struct xfrm_sec_ctx **new_ctx);
  287. void (*xfrm_policy_free_security)(struct xfrm_sec_ctx *ctx);
  288. int (*xfrm_policy_delete_security)(struct xfrm_sec_ctx *ctx);
  289. int (*xfrm_state_alloc)(struct xfrm_state *x,
  290. struct xfrm_user_sec_ctx *sec_ctx);
  291. int (*xfrm_state_alloc_acquire)(struct xfrm_state *x,
  292. struct xfrm_sec_ctx *polsec,
  293. u32 secid);
  294. void (*xfrm_state_free_security)(struct xfrm_state *x);
  295. int (*xfrm_state_delete_security)(struct xfrm_state *x);
  296. int (*xfrm_policy_lookup)(struct xfrm_sec_ctx *ctx, u32 fl_secid,
  297. u8 dir);
  298. int (*xfrm_state_pol_flow_match)(struct xfrm_state *x,
  299. struct xfrm_policy *xp,
  300. const struct flowi *fl);
  301. int (*xfrm_decode_session)(struct sk_buff *skb, u32 *secid, int ckall);
  302. #endif /* CONFIG_SECURITY_NETWORK_XFRM */
  303. /* key management security hooks */
  304. #ifdef CONFIG_KEYS
  305. int (*key_alloc)(struct key *key, const struct cred *cred,
  306. unsigned long flags);
  307. void (*key_free)(struct key *key);
  308. int (*key_permission)(key_ref_t key_ref, const struct cred *cred,
  309. unsigned perm);
  310. int (*key_getsecurity)(struct key *key, char **_buffer);
  311. #endif /* CONFIG_KEYS */
  312. #ifdef CONFIG_AUDIT
  313. int (*audit_rule_init)(u32 field, u32 op, char *rulestr,
  314. void **lsmrule);
  315. int (*audit_rule_known)(struct audit_krule *krule);
  316. int (*audit_rule_match)(u32 secid, u32 field, u32 op, void *lsmrule,
  317. struct audit_context *actx);
  318. void (*audit_rule_free)(void *lsmrule);
  319. #endif /* CONFIG_AUDIT */
  320. };
  321. /* prototypes */
  322. extern int security_module_enable(struct security_operations *ops);
  323. extern int register_security(struct security_operations *ops);
  324. extern void __init security_fixup_ops(struct security_operations *ops);
  325. extern void reset_security_ops(void);
  326. #endif /* CONFIG_SECURITY */
  327. #endif /* ! __LINUX_LSM_HOOKS_H */