security.h 45 KB

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