security.h 48 KB

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