security.h 46 KB

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