security.h 47 KB

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