security.h 45 KB

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