security.h 44 KB

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