security.h 46 KB

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