security.h 45 KB

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