security.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678
  1. /*
  2. * Linux Security plug
  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. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * Due to this file being licensed under the GPL there is controversy over
  16. * whether this permits you to write a module that #includes this file
  17. * without placing your module under the GPL. Please consult a lawyer for
  18. * advice before doing this.
  19. *
  20. */
  21. #ifndef __LINUX_SECURITY_H
  22. #define __LINUX_SECURITY_H
  23. #include <linux/key.h>
  24. #include <linux/capability.h>
  25. #include <linux/slab.h>
  26. #include <linux/err.h>
  27. #include <linux/string.h>
  28. struct linux_binprm;
  29. struct cred;
  30. struct rlimit;
  31. struct siginfo;
  32. struct sem_array;
  33. struct sembuf;
  34. struct kern_ipc_perm;
  35. struct audit_context;
  36. struct super_block;
  37. struct inode;
  38. struct dentry;
  39. struct file;
  40. struct vfsmount;
  41. struct path;
  42. struct qstr;
  43. struct nameidata;
  44. struct iattr;
  45. struct fown_struct;
  46. struct file_operations;
  47. struct shmid_kernel;
  48. struct msg_msg;
  49. struct msg_queue;
  50. struct xattr;
  51. struct xfrm_sec_ctx;
  52. struct mm_struct;
  53. /* Maximum number of letters for an LSM name string */
  54. #define SECURITY_NAME_MAX 10
  55. /* If capable should audit the security request */
  56. #define SECURITY_CAP_NOAUDIT 0
  57. #define SECURITY_CAP_AUDIT 1
  58. /* LSM Agnostic defines for sb_set_mnt_opts */
  59. #define SECURITY_LSM_NATIVE_LABELS 1
  60. struct ctl_table;
  61. struct audit_krule;
  62. struct user_namespace;
  63. struct timezone;
  64. /*
  65. * These functions are in security/capability.c and are used
  66. * as the default capabilities functions
  67. */
  68. extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
  69. int cap, int audit);
  70. extern int cap_settime(const struct timespec *ts, const struct timezone *tz);
  71. extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode);
  72. extern int cap_ptrace_traceme(struct task_struct *parent);
  73. extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
  74. extern int cap_capset(struct cred *new, const struct cred *old,
  75. const kernel_cap_t *effective,
  76. const kernel_cap_t *inheritable,
  77. const kernel_cap_t *permitted);
  78. extern int cap_bprm_set_creds(struct linux_binprm *bprm);
  79. extern int cap_bprm_secureexec(struct linux_binprm *bprm);
  80. extern int cap_inode_setxattr(struct dentry *dentry, const char *name,
  81. const void *value, size_t size, int flags);
  82. extern int cap_inode_removexattr(struct dentry *dentry, const char *name);
  83. extern int cap_inode_need_killpriv(struct dentry *dentry);
  84. extern int cap_inode_killpriv(struct dentry *dentry);
  85. extern int cap_mmap_addr(unsigned long addr);
  86. extern int cap_mmap_file(struct file *file, unsigned long reqprot,
  87. unsigned long prot, unsigned long flags);
  88. extern int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags);
  89. extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
  90. unsigned long arg4, unsigned long arg5);
  91. extern int cap_task_setscheduler(struct task_struct *p);
  92. extern int cap_task_setioprio(struct task_struct *p, int ioprio);
  93. extern int cap_task_setnice(struct task_struct *p, int nice);
  94. extern int cap_vm_enough_memory(struct mm_struct *mm, long pages);
  95. struct msghdr;
  96. struct sk_buff;
  97. struct sock;
  98. struct sockaddr;
  99. struct socket;
  100. struct flowi;
  101. struct dst_entry;
  102. struct xfrm_selector;
  103. struct xfrm_policy;
  104. struct xfrm_state;
  105. struct xfrm_user_sec_ctx;
  106. struct seq_file;
  107. extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
  108. #ifdef CONFIG_MMU
  109. extern unsigned long mmap_min_addr;
  110. extern unsigned long dac_mmap_min_addr;
  111. #else
  112. #define mmap_min_addr 0UL
  113. #define dac_mmap_min_addr 0UL
  114. #endif
  115. /*
  116. * Values used in the task_security_ops calls
  117. */
  118. /* setuid or setgid, id0 == uid or gid */
  119. #define LSM_SETID_ID 1
  120. /* setreuid or setregid, id0 == real, id1 == eff */
  121. #define LSM_SETID_RE 2
  122. /* setresuid or setresgid, id0 == real, id1 == eff, uid2 == saved */
  123. #define LSM_SETID_RES 4
  124. /* setfsuid or setfsgid, id0 == fsuid or fsgid */
  125. #define LSM_SETID_FS 8
  126. /* forward declares to avoid warnings */
  127. struct sched_param;
  128. struct request_sock;
  129. /* bprm->unsafe reasons */
  130. #define LSM_UNSAFE_SHARE 1
  131. #define LSM_UNSAFE_PTRACE 2
  132. #define LSM_UNSAFE_PTRACE_CAP 4
  133. #define LSM_UNSAFE_NO_NEW_PRIVS 8
  134. #ifdef CONFIG_MMU
  135. extern int mmap_min_addr_handler(struct ctl_table *table, int write,
  136. void __user *buffer, size_t *lenp, loff_t *ppos);
  137. #endif
  138. /* security_inode_init_security callback function to write xattrs */
  139. typedef int (*initxattrs) (struct inode *inode,
  140. const struct xattr *xattr_array, void *fs_data);
  141. #ifdef CONFIG_SECURITY
  142. struct security_mnt_opts {
  143. char **mnt_opts;
  144. int *mnt_opts_flags;
  145. int num_mnt_opts;
  146. };
  147. static inline void security_init_mnt_opts(struct security_mnt_opts *opts)
  148. {
  149. opts->mnt_opts = NULL;
  150. opts->mnt_opts_flags = NULL;
  151. opts->num_mnt_opts = 0;
  152. }
  153. static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  154. {
  155. int i;
  156. if (opts->mnt_opts)
  157. for (i = 0; i < opts->num_mnt_opts; i++)
  158. kfree(opts->mnt_opts[i]);
  159. kfree(opts->mnt_opts);
  160. opts->mnt_opts = NULL;
  161. kfree(opts->mnt_opts_flags);
  162. opts->mnt_opts_flags = NULL;
  163. opts->num_mnt_opts = 0;
  164. }
  165. /* prototypes */
  166. extern int security_init(void);
  167. /* Security operations */
  168. int security_binder_set_context_mgr(struct task_struct *mgr);
  169. int security_binder_transaction(struct task_struct *from,
  170. struct task_struct *to);
  171. int security_binder_transfer_binder(struct task_struct *from,
  172. struct task_struct *to);
  173. int security_binder_transfer_file(struct task_struct *from,
  174. struct task_struct *to, struct file *file);
  175. int security_ptrace_access_check(struct task_struct *child, unsigned int mode);
  176. int security_ptrace_traceme(struct task_struct *parent);
  177. int security_capget(struct task_struct *target,
  178. kernel_cap_t *effective,
  179. kernel_cap_t *inheritable,
  180. kernel_cap_t *permitted);
  181. int security_capset(struct cred *new, const struct cred *old,
  182. const kernel_cap_t *effective,
  183. const kernel_cap_t *inheritable,
  184. const kernel_cap_t *permitted);
  185. int security_capable(const struct cred *cred, struct user_namespace *ns,
  186. int cap);
  187. int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
  188. int cap);
  189. int security_quotactl(int cmds, int type, int id, struct super_block *sb);
  190. int security_quota_on(struct dentry *dentry);
  191. int security_syslog(int type);
  192. int security_settime(const struct timespec *ts, const struct timezone *tz);
  193. int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
  194. int security_bprm_set_creds(struct linux_binprm *bprm);
  195. int security_bprm_check(struct linux_binprm *bprm);
  196. void security_bprm_committing_creds(struct linux_binprm *bprm);
  197. void security_bprm_committed_creds(struct linux_binprm *bprm);
  198. int security_bprm_secureexec(struct linux_binprm *bprm);
  199. int security_sb_alloc(struct super_block *sb);
  200. void security_sb_free(struct super_block *sb);
  201. int security_sb_copy_data(char *orig, char *copy);
  202. int security_sb_remount(struct super_block *sb, void *data);
  203. int security_sb_kern_mount(struct super_block *sb, int flags, void *data);
  204. int security_sb_show_options(struct seq_file *m, struct super_block *sb);
  205. int security_sb_statfs(struct dentry *dentry);
  206. int security_sb_mount(const char *dev_name, struct path *path,
  207. const char *type, unsigned long flags, void *data);
  208. int security_sb_umount(struct vfsmount *mnt, int flags);
  209. int security_sb_pivotroot(struct path *old_path, struct path *new_path);
  210. int security_sb_set_mnt_opts(struct super_block *sb,
  211. struct security_mnt_opts *opts,
  212. unsigned long kern_flags,
  213. unsigned long *set_kern_flags);
  214. int security_sb_clone_mnt_opts(const struct super_block *oldsb,
  215. struct super_block *newsb);
  216. int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts);
  217. int security_dentry_init_security(struct dentry *dentry, int mode,
  218. struct qstr *name, void **ctx,
  219. u32 *ctxlen);
  220. int security_inode_alloc(struct inode *inode);
  221. void security_inode_free(struct inode *inode);
  222. int security_inode_init_security(struct inode *inode, struct inode *dir,
  223. const struct qstr *qstr,
  224. initxattrs initxattrs, void *fs_data);
  225. int security_old_inode_init_security(struct inode *inode, struct inode *dir,
  226. const struct qstr *qstr, const char **name,
  227. void **value, size_t *len);
  228. int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode);
  229. int security_inode_link(struct dentry *old_dentry, struct inode *dir,
  230. struct dentry *new_dentry);
  231. int security_inode_unlink(struct inode *dir, struct dentry *dentry);
  232. int security_inode_symlink(struct inode *dir, struct dentry *dentry,
  233. const char *old_name);
  234. int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
  235. int security_inode_rmdir(struct inode *dir, struct dentry *dentry);
  236. int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev);
  237. int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
  238. struct inode *new_dir, struct dentry *new_dentry,
  239. unsigned int flags);
  240. int security_inode_readlink(struct dentry *dentry);
  241. int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd);
  242. int security_inode_permission(struct inode *inode, int mask);
  243. int security_inode_setattr(struct dentry *dentry, struct iattr *attr);
  244. int security_inode_getattr(const struct path *path);
  245. int security_inode_setxattr(struct dentry *dentry, const char *name,
  246. const void *value, size_t size, int flags);
  247. void security_inode_post_setxattr(struct dentry *dentry, const char *name,
  248. const void *value, size_t size, int flags);
  249. int security_inode_getxattr(struct dentry *dentry, const char *name);
  250. int security_inode_listxattr(struct dentry *dentry);
  251. int security_inode_removexattr(struct dentry *dentry, const char *name);
  252. int security_inode_need_killpriv(struct dentry *dentry);
  253. int security_inode_killpriv(struct dentry *dentry);
  254. int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc);
  255. int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags);
  256. int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size);
  257. void security_inode_getsecid(const struct inode *inode, u32 *secid);
  258. int security_file_permission(struct file *file, int mask);
  259. int security_file_alloc(struct file *file);
  260. void security_file_free(struct file *file);
  261. int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  262. int security_mmap_file(struct file *file, unsigned long prot,
  263. unsigned long flags);
  264. int security_mmap_addr(unsigned long addr);
  265. int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
  266. unsigned long prot);
  267. int security_file_lock(struct file *file, unsigned int cmd);
  268. int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg);
  269. void security_file_set_fowner(struct file *file);
  270. int security_file_send_sigiotask(struct task_struct *tsk,
  271. struct fown_struct *fown, int sig);
  272. int security_file_receive(struct file *file);
  273. int security_file_open(struct file *file, const struct cred *cred);
  274. int security_task_create(unsigned long clone_flags);
  275. void security_task_free(struct task_struct *task);
  276. int security_cred_alloc_blank(struct cred *cred, gfp_t gfp);
  277. void security_cred_free(struct cred *cred);
  278. int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp);
  279. void security_transfer_creds(struct cred *new, const struct cred *old);
  280. int security_kernel_act_as(struct cred *new, u32 secid);
  281. int security_kernel_create_files_as(struct cred *new, struct inode *inode);
  282. int security_kernel_fw_from_file(struct file *file, char *buf, size_t size);
  283. int security_kernel_module_request(char *kmod_name);
  284. int security_kernel_module_from_file(struct file *file);
  285. int security_task_fix_setuid(struct cred *new, const struct cred *old,
  286. int flags);
  287. int security_task_setpgid(struct task_struct *p, pid_t pgid);
  288. int security_task_getpgid(struct task_struct *p);
  289. int security_task_getsid(struct task_struct *p);
  290. void security_task_getsecid(struct task_struct *p, u32 *secid);
  291. int security_task_setnice(struct task_struct *p, int nice);
  292. int security_task_setioprio(struct task_struct *p, int ioprio);
  293. int security_task_getioprio(struct task_struct *p);
  294. int security_task_setrlimit(struct task_struct *p, unsigned int resource,
  295. struct rlimit *new_rlim);
  296. int security_task_setscheduler(struct task_struct *p);
  297. int security_task_getscheduler(struct task_struct *p);
  298. int security_task_movememory(struct task_struct *p);
  299. int security_task_kill(struct task_struct *p, struct siginfo *info,
  300. int sig, u32 secid);
  301. int security_task_wait(struct task_struct *p);
  302. int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
  303. unsigned long arg4, unsigned long arg5);
  304. void security_task_to_inode(struct task_struct *p, struct inode *inode);
  305. int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag);
  306. void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid);
  307. int security_msg_msg_alloc(struct msg_msg *msg);
  308. void security_msg_msg_free(struct msg_msg *msg);
  309. int security_msg_queue_alloc(struct msg_queue *msq);
  310. void security_msg_queue_free(struct msg_queue *msq);
  311. int security_msg_queue_associate(struct msg_queue *msq, int msqflg);
  312. int security_msg_queue_msgctl(struct msg_queue *msq, int cmd);
  313. int security_msg_queue_msgsnd(struct msg_queue *msq,
  314. struct msg_msg *msg, int msqflg);
  315. int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
  316. struct task_struct *target, long type, int mode);
  317. int security_shm_alloc(struct shmid_kernel *shp);
  318. void security_shm_free(struct shmid_kernel *shp);
  319. int security_shm_associate(struct shmid_kernel *shp, int shmflg);
  320. int security_shm_shmctl(struct shmid_kernel *shp, int cmd);
  321. int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg);
  322. int security_sem_alloc(struct sem_array *sma);
  323. void security_sem_free(struct sem_array *sma);
  324. int security_sem_associate(struct sem_array *sma, int semflg);
  325. int security_sem_semctl(struct sem_array *sma, int cmd);
  326. int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
  327. unsigned nsops, int alter);
  328. void security_d_instantiate(struct dentry *dentry, struct inode *inode);
  329. int security_getprocattr(struct task_struct *p, char *name, char **value);
  330. int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
  331. int security_netlink_send(struct sock *sk, struct sk_buff *skb);
  332. int security_ismaclabel(const char *name);
  333. int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
  334. int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);
  335. void security_release_secctx(char *secdata, u32 seclen);
  336. int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);
  337. int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen);
  338. int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen);
  339. #else /* CONFIG_SECURITY */
  340. struct security_mnt_opts {
  341. };
  342. static inline void security_init_mnt_opts(struct security_mnt_opts *opts)
  343. {
  344. }
  345. static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  346. {
  347. }
  348. /*
  349. * This is the default capabilities functionality. Most of these functions
  350. * are just stubbed out, but a few must call the proper capable code.
  351. */
  352. static inline int security_init(void)
  353. {
  354. return 0;
  355. }
  356. static inline int security_binder_set_context_mgr(struct task_struct *mgr)
  357. {
  358. return 0;
  359. }
  360. static inline int security_binder_transaction(struct task_struct *from,
  361. struct task_struct *to)
  362. {
  363. return 0;
  364. }
  365. static inline int security_binder_transfer_binder(struct task_struct *from,
  366. struct task_struct *to)
  367. {
  368. return 0;
  369. }
  370. static inline int security_binder_transfer_file(struct task_struct *from,
  371. struct task_struct *to,
  372. struct file *file)
  373. {
  374. return 0;
  375. }
  376. static inline int security_ptrace_access_check(struct task_struct *child,
  377. unsigned int mode)
  378. {
  379. return cap_ptrace_access_check(child, mode);
  380. }
  381. static inline int security_ptrace_traceme(struct task_struct *parent)
  382. {
  383. return cap_ptrace_traceme(parent);
  384. }
  385. static inline int security_capget(struct task_struct *target,
  386. kernel_cap_t *effective,
  387. kernel_cap_t *inheritable,
  388. kernel_cap_t *permitted)
  389. {
  390. return cap_capget(target, effective, inheritable, permitted);
  391. }
  392. static inline int security_capset(struct cred *new,
  393. const struct cred *old,
  394. const kernel_cap_t *effective,
  395. const kernel_cap_t *inheritable,
  396. const kernel_cap_t *permitted)
  397. {
  398. return cap_capset(new, old, effective, inheritable, permitted);
  399. }
  400. static inline int security_capable(const struct cred *cred,
  401. struct user_namespace *ns, int cap)
  402. {
  403. return cap_capable(cred, ns, cap, SECURITY_CAP_AUDIT);
  404. }
  405. static inline int security_capable_noaudit(const struct cred *cred,
  406. struct user_namespace *ns, int cap) {
  407. return cap_capable(cred, ns, cap, SECURITY_CAP_NOAUDIT);
  408. }
  409. static inline int security_quotactl(int cmds, int type, int id,
  410. struct super_block *sb)
  411. {
  412. return 0;
  413. }
  414. static inline int security_quota_on(struct dentry *dentry)
  415. {
  416. return 0;
  417. }
  418. static inline int security_syslog(int type)
  419. {
  420. return 0;
  421. }
  422. static inline int security_settime(const struct timespec *ts,
  423. const struct timezone *tz)
  424. {
  425. return cap_settime(ts, tz);
  426. }
  427. static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
  428. {
  429. return cap_vm_enough_memory(mm, pages);
  430. }
  431. static inline int security_bprm_set_creds(struct linux_binprm *bprm)
  432. {
  433. return cap_bprm_set_creds(bprm);
  434. }
  435. static inline int security_bprm_check(struct linux_binprm *bprm)
  436. {
  437. return 0;
  438. }
  439. static inline void security_bprm_committing_creds(struct linux_binprm *bprm)
  440. {
  441. }
  442. static inline void security_bprm_committed_creds(struct linux_binprm *bprm)
  443. {
  444. }
  445. static inline int security_bprm_secureexec(struct linux_binprm *bprm)
  446. {
  447. return cap_bprm_secureexec(bprm);
  448. }
  449. static inline int security_sb_alloc(struct super_block *sb)
  450. {
  451. return 0;
  452. }
  453. static inline void security_sb_free(struct super_block *sb)
  454. { }
  455. static inline int security_sb_copy_data(char *orig, char *copy)
  456. {
  457. return 0;
  458. }
  459. static inline int security_sb_remount(struct super_block *sb, void *data)
  460. {
  461. return 0;
  462. }
  463. static inline int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
  464. {
  465. return 0;
  466. }
  467. static inline int security_sb_show_options(struct seq_file *m,
  468. struct super_block *sb)
  469. {
  470. return 0;
  471. }
  472. static inline int security_sb_statfs(struct dentry *dentry)
  473. {
  474. return 0;
  475. }
  476. static inline int security_sb_mount(const char *dev_name, struct path *path,
  477. const char *type, unsigned long flags,
  478. void *data)
  479. {
  480. return 0;
  481. }
  482. static inline int security_sb_umount(struct vfsmount *mnt, int flags)
  483. {
  484. return 0;
  485. }
  486. static inline int security_sb_pivotroot(struct path *old_path,
  487. struct path *new_path)
  488. {
  489. return 0;
  490. }
  491. static inline int security_sb_set_mnt_opts(struct super_block *sb,
  492. struct security_mnt_opts *opts,
  493. unsigned long kern_flags,
  494. unsigned long *set_kern_flags)
  495. {
  496. return 0;
  497. }
  498. static inline int security_sb_clone_mnt_opts(const struct super_block *oldsb,
  499. struct super_block *newsb)
  500. {
  501. return 0;
  502. }
  503. static inline int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
  504. {
  505. return 0;
  506. }
  507. static inline int security_inode_alloc(struct inode *inode)
  508. {
  509. return 0;
  510. }
  511. static inline void security_inode_free(struct inode *inode)
  512. { }
  513. static inline int security_dentry_init_security(struct dentry *dentry,
  514. int mode,
  515. struct qstr *name,
  516. void **ctx,
  517. u32 *ctxlen)
  518. {
  519. return -EOPNOTSUPP;
  520. }
  521. static inline int security_inode_init_security(struct inode *inode,
  522. struct inode *dir,
  523. const struct qstr *qstr,
  524. const initxattrs xattrs,
  525. void *fs_data)
  526. {
  527. return 0;
  528. }
  529. static inline int security_old_inode_init_security(struct inode *inode,
  530. struct inode *dir,
  531. const struct qstr *qstr,
  532. const char **name,
  533. void **value, size_t *len)
  534. {
  535. return -EOPNOTSUPP;
  536. }
  537. static inline int security_inode_create(struct inode *dir,
  538. struct dentry *dentry,
  539. umode_t mode)
  540. {
  541. return 0;
  542. }
  543. static inline int security_inode_link(struct dentry *old_dentry,
  544. struct inode *dir,
  545. struct dentry *new_dentry)
  546. {
  547. return 0;
  548. }
  549. static inline int security_inode_unlink(struct inode *dir,
  550. struct dentry *dentry)
  551. {
  552. return 0;
  553. }
  554. static inline int security_inode_symlink(struct inode *dir,
  555. struct dentry *dentry,
  556. const char *old_name)
  557. {
  558. return 0;
  559. }
  560. static inline int security_inode_mkdir(struct inode *dir,
  561. struct dentry *dentry,
  562. int mode)
  563. {
  564. return 0;
  565. }
  566. static inline int security_inode_rmdir(struct inode *dir,
  567. struct dentry *dentry)
  568. {
  569. return 0;
  570. }
  571. static inline int security_inode_mknod(struct inode *dir,
  572. struct dentry *dentry,
  573. int mode, dev_t dev)
  574. {
  575. return 0;
  576. }
  577. static inline int security_inode_rename(struct inode *old_dir,
  578. struct dentry *old_dentry,
  579. struct inode *new_dir,
  580. struct dentry *new_dentry,
  581. unsigned int flags)
  582. {
  583. return 0;
  584. }
  585. static inline int security_inode_readlink(struct dentry *dentry)
  586. {
  587. return 0;
  588. }
  589. static inline int security_inode_follow_link(struct dentry *dentry,
  590. struct nameidata *nd)
  591. {
  592. return 0;
  593. }
  594. static inline int security_inode_permission(struct inode *inode, int mask)
  595. {
  596. return 0;
  597. }
  598. static inline int security_inode_setattr(struct dentry *dentry,
  599. struct iattr *attr)
  600. {
  601. return 0;
  602. }
  603. static inline int security_inode_getattr(const struct path *path)
  604. {
  605. return 0;
  606. }
  607. static inline int security_inode_setxattr(struct dentry *dentry,
  608. const char *name, const void *value, size_t size, int flags)
  609. {
  610. return cap_inode_setxattr(dentry, name, value, size, flags);
  611. }
  612. static inline void security_inode_post_setxattr(struct dentry *dentry,
  613. const char *name, const void *value, size_t size, int flags)
  614. { }
  615. static inline int security_inode_getxattr(struct dentry *dentry,
  616. const char *name)
  617. {
  618. return 0;
  619. }
  620. static inline int security_inode_listxattr(struct dentry *dentry)
  621. {
  622. return 0;
  623. }
  624. static inline int security_inode_removexattr(struct dentry *dentry,
  625. const char *name)
  626. {
  627. return cap_inode_removexattr(dentry, name);
  628. }
  629. static inline int security_inode_need_killpriv(struct dentry *dentry)
  630. {
  631. return cap_inode_need_killpriv(dentry);
  632. }
  633. static inline int security_inode_killpriv(struct dentry *dentry)
  634. {
  635. return cap_inode_killpriv(dentry);
  636. }
  637. static inline int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
  638. {
  639. return -EOPNOTSUPP;
  640. }
  641. static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
  642. {
  643. return -EOPNOTSUPP;
  644. }
  645. static inline int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
  646. {
  647. return 0;
  648. }
  649. static inline void security_inode_getsecid(const struct inode *inode, u32 *secid)
  650. {
  651. *secid = 0;
  652. }
  653. static inline int security_file_permission(struct file *file, int mask)
  654. {
  655. return 0;
  656. }
  657. static inline int security_file_alloc(struct file *file)
  658. {
  659. return 0;
  660. }
  661. static inline void security_file_free(struct file *file)
  662. { }
  663. static inline int security_file_ioctl(struct file *file, unsigned int cmd,
  664. unsigned long arg)
  665. {
  666. return 0;
  667. }
  668. static inline int security_mmap_file(struct file *file, unsigned long prot,
  669. unsigned long flags)
  670. {
  671. return 0;
  672. }
  673. static inline int security_mmap_addr(unsigned long addr)
  674. {
  675. return cap_mmap_addr(addr);
  676. }
  677. static inline int security_file_mprotect(struct vm_area_struct *vma,
  678. unsigned long reqprot,
  679. unsigned long prot)
  680. {
  681. return 0;
  682. }
  683. static inline int security_file_lock(struct file *file, unsigned int cmd)
  684. {
  685. return 0;
  686. }
  687. static inline int security_file_fcntl(struct file *file, unsigned int cmd,
  688. unsigned long arg)
  689. {
  690. return 0;
  691. }
  692. static inline void security_file_set_fowner(struct file *file)
  693. {
  694. return;
  695. }
  696. static inline int security_file_send_sigiotask(struct task_struct *tsk,
  697. struct fown_struct *fown,
  698. int sig)
  699. {
  700. return 0;
  701. }
  702. static inline int security_file_receive(struct file *file)
  703. {
  704. return 0;
  705. }
  706. static inline int security_file_open(struct file *file,
  707. const struct cred *cred)
  708. {
  709. return 0;
  710. }
  711. static inline int security_task_create(unsigned long clone_flags)
  712. {
  713. return 0;
  714. }
  715. static inline void security_task_free(struct task_struct *task)
  716. { }
  717. static inline int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
  718. {
  719. return 0;
  720. }
  721. static inline void security_cred_free(struct cred *cred)
  722. { }
  723. static inline int security_prepare_creds(struct cred *new,
  724. const struct cred *old,
  725. gfp_t gfp)
  726. {
  727. return 0;
  728. }
  729. static inline void security_transfer_creds(struct cred *new,
  730. const struct cred *old)
  731. {
  732. }
  733. static inline int security_kernel_act_as(struct cred *cred, u32 secid)
  734. {
  735. return 0;
  736. }
  737. static inline int security_kernel_create_files_as(struct cred *cred,
  738. struct inode *inode)
  739. {
  740. return 0;
  741. }
  742. static inline int security_kernel_fw_from_file(struct file *file,
  743. char *buf, size_t size)
  744. {
  745. return 0;
  746. }
  747. static inline int security_kernel_module_request(char *kmod_name)
  748. {
  749. return 0;
  750. }
  751. static inline int security_kernel_module_from_file(struct file *file)
  752. {
  753. return 0;
  754. }
  755. static inline int security_task_fix_setuid(struct cred *new,
  756. const struct cred *old,
  757. int flags)
  758. {
  759. return cap_task_fix_setuid(new, old, flags);
  760. }
  761. static inline int security_task_setpgid(struct task_struct *p, pid_t pgid)
  762. {
  763. return 0;
  764. }
  765. static inline int security_task_getpgid(struct task_struct *p)
  766. {
  767. return 0;
  768. }
  769. static inline int security_task_getsid(struct task_struct *p)
  770. {
  771. return 0;
  772. }
  773. static inline void security_task_getsecid(struct task_struct *p, u32 *secid)
  774. {
  775. *secid = 0;
  776. }
  777. static inline int security_task_setnice(struct task_struct *p, int nice)
  778. {
  779. return cap_task_setnice(p, nice);
  780. }
  781. static inline int security_task_setioprio(struct task_struct *p, int ioprio)
  782. {
  783. return cap_task_setioprio(p, ioprio);
  784. }
  785. static inline int security_task_getioprio(struct task_struct *p)
  786. {
  787. return 0;
  788. }
  789. static inline int security_task_setrlimit(struct task_struct *p,
  790. unsigned int resource,
  791. struct rlimit *new_rlim)
  792. {
  793. return 0;
  794. }
  795. static inline int security_task_setscheduler(struct task_struct *p)
  796. {
  797. return cap_task_setscheduler(p);
  798. }
  799. static inline int security_task_getscheduler(struct task_struct *p)
  800. {
  801. return 0;
  802. }
  803. static inline int security_task_movememory(struct task_struct *p)
  804. {
  805. return 0;
  806. }
  807. static inline int security_task_kill(struct task_struct *p,
  808. struct siginfo *info, int sig,
  809. u32 secid)
  810. {
  811. return 0;
  812. }
  813. static inline int security_task_wait(struct task_struct *p)
  814. {
  815. return 0;
  816. }
  817. static inline int security_task_prctl(int option, unsigned long arg2,
  818. unsigned long arg3,
  819. unsigned long arg4,
  820. unsigned long arg5)
  821. {
  822. return cap_task_prctl(option, arg2, arg3, arg3, arg5);
  823. }
  824. static inline void security_task_to_inode(struct task_struct *p, struct inode *inode)
  825. { }
  826. static inline int security_ipc_permission(struct kern_ipc_perm *ipcp,
  827. short flag)
  828. {
  829. return 0;
  830. }
  831. static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
  832. {
  833. *secid = 0;
  834. }
  835. static inline int security_msg_msg_alloc(struct msg_msg *msg)
  836. {
  837. return 0;
  838. }
  839. static inline void security_msg_msg_free(struct msg_msg *msg)
  840. { }
  841. static inline int security_msg_queue_alloc(struct msg_queue *msq)
  842. {
  843. return 0;
  844. }
  845. static inline void security_msg_queue_free(struct msg_queue *msq)
  846. { }
  847. static inline int security_msg_queue_associate(struct msg_queue *msq,
  848. int msqflg)
  849. {
  850. return 0;
  851. }
  852. static inline int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
  853. {
  854. return 0;
  855. }
  856. static inline int security_msg_queue_msgsnd(struct msg_queue *msq,
  857. struct msg_msg *msg, int msqflg)
  858. {
  859. return 0;
  860. }
  861. static inline int security_msg_queue_msgrcv(struct msg_queue *msq,
  862. struct msg_msg *msg,
  863. struct task_struct *target,
  864. long type, int mode)
  865. {
  866. return 0;
  867. }
  868. static inline int security_shm_alloc(struct shmid_kernel *shp)
  869. {
  870. return 0;
  871. }
  872. static inline void security_shm_free(struct shmid_kernel *shp)
  873. { }
  874. static inline int security_shm_associate(struct shmid_kernel *shp,
  875. int shmflg)
  876. {
  877. return 0;
  878. }
  879. static inline int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
  880. {
  881. return 0;
  882. }
  883. static inline int security_shm_shmat(struct shmid_kernel *shp,
  884. char __user *shmaddr, int shmflg)
  885. {
  886. return 0;
  887. }
  888. static inline int security_sem_alloc(struct sem_array *sma)
  889. {
  890. return 0;
  891. }
  892. static inline void security_sem_free(struct sem_array *sma)
  893. { }
  894. static inline int security_sem_associate(struct sem_array *sma, int semflg)
  895. {
  896. return 0;
  897. }
  898. static inline int security_sem_semctl(struct sem_array *sma, int cmd)
  899. {
  900. return 0;
  901. }
  902. static inline int security_sem_semop(struct sem_array *sma,
  903. struct sembuf *sops, unsigned nsops,
  904. int alter)
  905. {
  906. return 0;
  907. }
  908. static inline void security_d_instantiate(struct dentry *dentry, struct inode *inode)
  909. { }
  910. static inline int security_getprocattr(struct task_struct *p, char *name, char **value)
  911. {
  912. return -EINVAL;
  913. }
  914. static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
  915. {
  916. return -EINVAL;
  917. }
  918. static inline int security_netlink_send(struct sock *sk, struct sk_buff *skb)
  919. {
  920. return cap_netlink_send(sk, skb);
  921. }
  922. static inline int security_ismaclabel(const char *name)
  923. {
  924. return 0;
  925. }
  926. static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
  927. {
  928. return -EOPNOTSUPP;
  929. }
  930. static inline int security_secctx_to_secid(const char *secdata,
  931. u32 seclen,
  932. u32 *secid)
  933. {
  934. return -EOPNOTSUPP;
  935. }
  936. static inline void security_release_secctx(char *secdata, u32 seclen)
  937. {
  938. }
  939. static inline int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
  940. {
  941. return -EOPNOTSUPP;
  942. }
  943. static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
  944. {
  945. return -EOPNOTSUPP;
  946. }
  947. static inline int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
  948. {
  949. return -EOPNOTSUPP;
  950. }
  951. #endif /* CONFIG_SECURITY */
  952. #ifdef CONFIG_SECURITY_NETWORK
  953. int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk);
  954. int security_unix_may_send(struct socket *sock, struct socket *other);
  955. int security_socket_create(int family, int type, int protocol, int kern);
  956. int security_socket_post_create(struct socket *sock, int family,
  957. int type, int protocol, int kern);
  958. int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen);
  959. int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen);
  960. int security_socket_listen(struct socket *sock, int backlog);
  961. int security_socket_accept(struct socket *sock, struct socket *newsock);
  962. int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size);
  963. int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
  964. int size, int flags);
  965. int security_socket_getsockname(struct socket *sock);
  966. int security_socket_getpeername(struct socket *sock);
  967. int security_socket_getsockopt(struct socket *sock, int level, int optname);
  968. int security_socket_setsockopt(struct socket *sock, int level, int optname);
  969. int security_socket_shutdown(struct socket *sock, int how);
  970. int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb);
  971. int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
  972. int __user *optlen, unsigned len);
  973. int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid);
  974. int security_sk_alloc(struct sock *sk, int family, gfp_t priority);
  975. void security_sk_free(struct sock *sk);
  976. void security_sk_clone(const struct sock *sk, struct sock *newsk);
  977. void security_sk_classify_flow(struct sock *sk, struct flowi *fl);
  978. void security_req_classify_flow(const struct request_sock *req, struct flowi *fl);
  979. void security_sock_graft(struct sock*sk, struct socket *parent);
  980. int security_inet_conn_request(struct sock *sk,
  981. struct sk_buff *skb, struct request_sock *req);
  982. void security_inet_csk_clone(struct sock *newsk,
  983. const struct request_sock *req);
  984. void security_inet_conn_established(struct sock *sk,
  985. struct sk_buff *skb);
  986. int security_secmark_relabel_packet(u32 secid);
  987. void security_secmark_refcount_inc(void);
  988. void security_secmark_refcount_dec(void);
  989. int security_tun_dev_alloc_security(void **security);
  990. void security_tun_dev_free_security(void *security);
  991. int security_tun_dev_create(void);
  992. int security_tun_dev_attach_queue(void *security);
  993. int security_tun_dev_attach(struct sock *sk, void *security);
  994. int security_tun_dev_open(void *security);
  995. #else /* CONFIG_SECURITY_NETWORK */
  996. static inline int security_unix_stream_connect(struct sock *sock,
  997. struct sock *other,
  998. struct sock *newsk)
  999. {
  1000. return 0;
  1001. }
  1002. static inline int security_unix_may_send(struct socket *sock,
  1003. struct socket *other)
  1004. {
  1005. return 0;
  1006. }
  1007. static inline int security_socket_create(int family, int type,
  1008. int protocol, int kern)
  1009. {
  1010. return 0;
  1011. }
  1012. static inline int security_socket_post_create(struct socket *sock,
  1013. int family,
  1014. int type,
  1015. int protocol, int kern)
  1016. {
  1017. return 0;
  1018. }
  1019. static inline int security_socket_bind(struct socket *sock,
  1020. struct sockaddr *address,
  1021. int addrlen)
  1022. {
  1023. return 0;
  1024. }
  1025. static inline int security_socket_connect(struct socket *sock,
  1026. struct sockaddr *address,
  1027. int addrlen)
  1028. {
  1029. return 0;
  1030. }
  1031. static inline int security_socket_listen(struct socket *sock, int backlog)
  1032. {
  1033. return 0;
  1034. }
  1035. static inline int security_socket_accept(struct socket *sock,
  1036. struct socket *newsock)
  1037. {
  1038. return 0;
  1039. }
  1040. static inline int security_socket_sendmsg(struct socket *sock,
  1041. struct msghdr *msg, int size)
  1042. {
  1043. return 0;
  1044. }
  1045. static inline int security_socket_recvmsg(struct socket *sock,
  1046. struct msghdr *msg, int size,
  1047. int flags)
  1048. {
  1049. return 0;
  1050. }
  1051. static inline int security_socket_getsockname(struct socket *sock)
  1052. {
  1053. return 0;
  1054. }
  1055. static inline int security_socket_getpeername(struct socket *sock)
  1056. {
  1057. return 0;
  1058. }
  1059. static inline int security_socket_getsockopt(struct socket *sock,
  1060. int level, int optname)
  1061. {
  1062. return 0;
  1063. }
  1064. static inline int security_socket_setsockopt(struct socket *sock,
  1065. int level, int optname)
  1066. {
  1067. return 0;
  1068. }
  1069. static inline int security_socket_shutdown(struct socket *sock, int how)
  1070. {
  1071. return 0;
  1072. }
  1073. static inline int security_sock_rcv_skb(struct sock *sk,
  1074. struct sk_buff *skb)
  1075. {
  1076. return 0;
  1077. }
  1078. static inline int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
  1079. int __user *optlen, unsigned len)
  1080. {
  1081. return -ENOPROTOOPT;
  1082. }
  1083. static inline int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
  1084. {
  1085. return -ENOPROTOOPT;
  1086. }
  1087. static inline int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
  1088. {
  1089. return 0;
  1090. }
  1091. static inline void security_sk_free(struct sock *sk)
  1092. {
  1093. }
  1094. static inline void security_sk_clone(const struct sock *sk, struct sock *newsk)
  1095. {
  1096. }
  1097. static inline void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
  1098. {
  1099. }
  1100. static inline void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
  1101. {
  1102. }
  1103. static inline void security_sock_graft(struct sock *sk, struct socket *parent)
  1104. {
  1105. }
  1106. static inline int security_inet_conn_request(struct sock *sk,
  1107. struct sk_buff *skb, struct request_sock *req)
  1108. {
  1109. return 0;
  1110. }
  1111. static inline void security_inet_csk_clone(struct sock *newsk,
  1112. const struct request_sock *req)
  1113. {
  1114. }
  1115. static inline void security_inet_conn_established(struct sock *sk,
  1116. struct sk_buff *skb)
  1117. {
  1118. }
  1119. static inline int security_secmark_relabel_packet(u32 secid)
  1120. {
  1121. return 0;
  1122. }
  1123. static inline void security_secmark_refcount_inc(void)
  1124. {
  1125. }
  1126. static inline void security_secmark_refcount_dec(void)
  1127. {
  1128. }
  1129. static inline int security_tun_dev_alloc_security(void **security)
  1130. {
  1131. return 0;
  1132. }
  1133. static inline void security_tun_dev_free_security(void *security)
  1134. {
  1135. }
  1136. static inline int security_tun_dev_create(void)
  1137. {
  1138. return 0;
  1139. }
  1140. static inline int security_tun_dev_attach_queue(void *security)
  1141. {
  1142. return 0;
  1143. }
  1144. static inline int security_tun_dev_attach(struct sock *sk, void *security)
  1145. {
  1146. return 0;
  1147. }
  1148. static inline int security_tun_dev_open(void *security)
  1149. {
  1150. return 0;
  1151. }
  1152. #endif /* CONFIG_SECURITY_NETWORK */
  1153. #ifdef CONFIG_SECURITY_NETWORK_XFRM
  1154. int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
  1155. struct xfrm_user_sec_ctx *sec_ctx, gfp_t gfp);
  1156. int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctxp);
  1157. void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx);
  1158. int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx);
  1159. int security_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx);
  1160. int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
  1161. struct xfrm_sec_ctx *polsec, u32 secid);
  1162. int security_xfrm_state_delete(struct xfrm_state *x);
  1163. void security_xfrm_state_free(struct xfrm_state *x);
  1164. int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir);
  1165. int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
  1166. struct xfrm_policy *xp,
  1167. const struct flowi *fl);
  1168. int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid);
  1169. void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl);
  1170. #else /* CONFIG_SECURITY_NETWORK_XFRM */
  1171. static inline int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
  1172. struct xfrm_user_sec_ctx *sec_ctx,
  1173. gfp_t gfp)
  1174. {
  1175. return 0;
  1176. }
  1177. static inline int security_xfrm_policy_clone(struct xfrm_sec_ctx *old, struct xfrm_sec_ctx **new_ctxp)
  1178. {
  1179. return 0;
  1180. }
  1181. static inline void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
  1182. {
  1183. }
  1184. static inline int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
  1185. {
  1186. return 0;
  1187. }
  1188. static inline int security_xfrm_state_alloc(struct xfrm_state *x,
  1189. struct xfrm_user_sec_ctx *sec_ctx)
  1190. {
  1191. return 0;
  1192. }
  1193. static inline int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
  1194. struct xfrm_sec_ctx *polsec, u32 secid)
  1195. {
  1196. return 0;
  1197. }
  1198. static inline void security_xfrm_state_free(struct xfrm_state *x)
  1199. {
  1200. }
  1201. static inline int security_xfrm_state_delete(struct xfrm_state *x)
  1202. {
  1203. return 0;
  1204. }
  1205. static inline int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
  1206. {
  1207. return 0;
  1208. }
  1209. static inline int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
  1210. struct xfrm_policy *xp, const struct flowi *fl)
  1211. {
  1212. return 1;
  1213. }
  1214. static inline int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
  1215. {
  1216. return 0;
  1217. }
  1218. static inline void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
  1219. {
  1220. }
  1221. #endif /* CONFIG_SECURITY_NETWORK_XFRM */
  1222. #ifdef CONFIG_SECURITY_PATH
  1223. int security_path_unlink(struct path *dir, struct dentry *dentry);
  1224. int security_path_mkdir(struct path *dir, struct dentry *dentry, umode_t mode);
  1225. int security_path_rmdir(struct path *dir, struct dentry *dentry);
  1226. int security_path_mknod(struct path *dir, struct dentry *dentry, umode_t mode,
  1227. unsigned int dev);
  1228. int security_path_truncate(struct path *path);
  1229. int security_path_symlink(struct path *dir, struct dentry *dentry,
  1230. const char *old_name);
  1231. int security_path_link(struct dentry *old_dentry, struct path *new_dir,
  1232. struct dentry *new_dentry);
  1233. int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
  1234. struct path *new_dir, struct dentry *new_dentry,
  1235. unsigned int flags);
  1236. int security_path_chmod(struct path *path, umode_t mode);
  1237. int security_path_chown(struct path *path, kuid_t uid, kgid_t gid);
  1238. int security_path_chroot(struct path *path);
  1239. #else /* CONFIG_SECURITY_PATH */
  1240. static inline int security_path_unlink(struct path *dir, struct dentry *dentry)
  1241. {
  1242. return 0;
  1243. }
  1244. static inline int security_path_mkdir(struct path *dir, struct dentry *dentry,
  1245. umode_t mode)
  1246. {
  1247. return 0;
  1248. }
  1249. static inline int security_path_rmdir(struct path *dir, struct dentry *dentry)
  1250. {
  1251. return 0;
  1252. }
  1253. static inline int security_path_mknod(struct path *dir, struct dentry *dentry,
  1254. umode_t mode, unsigned int dev)
  1255. {
  1256. return 0;
  1257. }
  1258. static inline int security_path_truncate(struct path *path)
  1259. {
  1260. return 0;
  1261. }
  1262. static inline int security_path_symlink(struct path *dir, struct dentry *dentry,
  1263. const char *old_name)
  1264. {
  1265. return 0;
  1266. }
  1267. static inline int security_path_link(struct dentry *old_dentry,
  1268. struct path *new_dir,
  1269. struct dentry *new_dentry)
  1270. {
  1271. return 0;
  1272. }
  1273. static inline int security_path_rename(struct path *old_dir,
  1274. struct dentry *old_dentry,
  1275. struct path *new_dir,
  1276. struct dentry *new_dentry,
  1277. unsigned int flags)
  1278. {
  1279. return 0;
  1280. }
  1281. static inline int security_path_chmod(struct path *path, umode_t mode)
  1282. {
  1283. return 0;
  1284. }
  1285. static inline int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
  1286. {
  1287. return 0;
  1288. }
  1289. static inline int security_path_chroot(struct path *path)
  1290. {
  1291. return 0;
  1292. }
  1293. #endif /* CONFIG_SECURITY_PATH */
  1294. #ifdef CONFIG_KEYS
  1295. #ifdef CONFIG_SECURITY
  1296. int security_key_alloc(struct key *key, const struct cred *cred, unsigned long flags);
  1297. void security_key_free(struct key *key);
  1298. int security_key_permission(key_ref_t key_ref,
  1299. const struct cred *cred, unsigned perm);
  1300. int security_key_getsecurity(struct key *key, char **_buffer);
  1301. #else
  1302. static inline int security_key_alloc(struct key *key,
  1303. const struct cred *cred,
  1304. unsigned long flags)
  1305. {
  1306. return 0;
  1307. }
  1308. static inline void security_key_free(struct key *key)
  1309. {
  1310. }
  1311. static inline int security_key_permission(key_ref_t key_ref,
  1312. const struct cred *cred,
  1313. unsigned perm)
  1314. {
  1315. return 0;
  1316. }
  1317. static inline int security_key_getsecurity(struct key *key, char **_buffer)
  1318. {
  1319. *_buffer = NULL;
  1320. return 0;
  1321. }
  1322. #endif
  1323. #endif /* CONFIG_KEYS */
  1324. #ifdef CONFIG_AUDIT
  1325. #ifdef CONFIG_SECURITY
  1326. int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule);
  1327. int security_audit_rule_known(struct audit_krule *krule);
  1328. int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
  1329. struct audit_context *actx);
  1330. void security_audit_rule_free(void *lsmrule);
  1331. #else
  1332. static inline int security_audit_rule_init(u32 field, u32 op, char *rulestr,
  1333. void **lsmrule)
  1334. {
  1335. return 0;
  1336. }
  1337. static inline int security_audit_rule_known(struct audit_krule *krule)
  1338. {
  1339. return 0;
  1340. }
  1341. static inline int security_audit_rule_match(u32 secid, u32 field, u32 op,
  1342. void *lsmrule, struct audit_context *actx)
  1343. {
  1344. return 0;
  1345. }
  1346. static inline void security_audit_rule_free(void *lsmrule)
  1347. { }
  1348. #endif /* CONFIG_SECURITY */
  1349. #endif /* CONFIG_AUDIT */
  1350. #ifdef CONFIG_SECURITYFS
  1351. extern struct dentry *securityfs_create_file(const char *name, umode_t mode,
  1352. struct dentry *parent, void *data,
  1353. const struct file_operations *fops);
  1354. extern struct dentry *securityfs_create_dir(const char *name, struct dentry *parent);
  1355. extern void securityfs_remove(struct dentry *dentry);
  1356. #else /* CONFIG_SECURITYFS */
  1357. static inline struct dentry *securityfs_create_dir(const char *name,
  1358. struct dentry *parent)
  1359. {
  1360. return ERR_PTR(-ENODEV);
  1361. }
  1362. static inline struct dentry *securityfs_create_file(const char *name,
  1363. umode_t mode,
  1364. struct dentry *parent,
  1365. void *data,
  1366. const struct file_operations *fops)
  1367. {
  1368. return ERR_PTR(-ENODEV);
  1369. }
  1370. static inline void securityfs_remove(struct dentry *dentry)
  1371. {}
  1372. #endif
  1373. #ifdef CONFIG_SECURITY
  1374. static inline char *alloc_secdata(void)
  1375. {
  1376. return (char *)get_zeroed_page(GFP_KERNEL);
  1377. }
  1378. static inline void free_secdata(void *secdata)
  1379. {
  1380. free_page((unsigned long)secdata);
  1381. }
  1382. #else
  1383. static inline char *alloc_secdata(void)
  1384. {
  1385. return (char *)1;
  1386. }
  1387. static inline void free_secdata(void *secdata)
  1388. { }
  1389. #endif /* CONFIG_SECURITY */
  1390. #ifdef CONFIG_SECURITY_YAMA
  1391. extern int yama_ptrace_access_check(struct task_struct *child,
  1392. unsigned int mode);
  1393. extern int yama_ptrace_traceme(struct task_struct *parent);
  1394. extern void yama_task_free(struct task_struct *task);
  1395. extern int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
  1396. unsigned long arg4, unsigned long arg5);
  1397. #else
  1398. static inline int yama_ptrace_access_check(struct task_struct *child,
  1399. unsigned int mode)
  1400. {
  1401. return 0;
  1402. }
  1403. static inline int yama_ptrace_traceme(struct task_struct *parent)
  1404. {
  1405. return 0;
  1406. }
  1407. static inline void yama_task_free(struct task_struct *task)
  1408. {
  1409. }
  1410. static inline int yama_task_prctl(int option, unsigned long arg2,
  1411. unsigned long arg3, unsigned long arg4,
  1412. unsigned long arg5)
  1413. {
  1414. return -ENOSYS;
  1415. }
  1416. #endif /* CONFIG_SECURITY_YAMA */
  1417. #endif /* ! __LINUX_SECURITY_H */