security.h 49 KB

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