security.h 46 KB

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