security.h 48 KB

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