security.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. /*
  2. * Security plug functions
  3. *
  4. * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
  5. * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
  6. * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/capability.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/security.h>
  18. /* Boot-time LSM user choice */
  19. static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1];
  20. /* things that live in dummy.c */
  21. extern struct security_operations dummy_security_ops;
  22. extern void security_fixup_ops(struct security_operations *ops);
  23. struct security_operations *security_ops; /* Initialized to NULL */
  24. /* amount of vm to protect from userspace access */
  25. unsigned long mmap_min_addr = CONFIG_SECURITY_DEFAULT_MMAP_MIN_ADDR;
  26. static inline int verify(struct security_operations *ops)
  27. {
  28. /* verify the security_operations structure exists */
  29. if (!ops)
  30. return -EINVAL;
  31. security_fixup_ops(ops);
  32. return 0;
  33. }
  34. static void __init do_security_initcalls(void)
  35. {
  36. initcall_t *call;
  37. call = __security_initcall_start;
  38. while (call < __security_initcall_end) {
  39. (*call) ();
  40. call++;
  41. }
  42. }
  43. /**
  44. * security_init - initializes the security framework
  45. *
  46. * This should be called early in the kernel initialization sequence.
  47. */
  48. int __init security_init(void)
  49. {
  50. printk(KERN_INFO "Security Framework initialized\n");
  51. if (verify(&dummy_security_ops)) {
  52. printk(KERN_ERR "%s could not verify "
  53. "dummy_security_ops structure.\n", __func__);
  54. return -EIO;
  55. }
  56. security_ops = &dummy_security_ops;
  57. do_security_initcalls();
  58. return 0;
  59. }
  60. /* Save user chosen LSM */
  61. static int __init choose_lsm(char *str)
  62. {
  63. strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
  64. return 1;
  65. }
  66. __setup("security=", choose_lsm);
  67. /**
  68. * security_module_enable - Load given security module on boot ?
  69. * @ops: a pointer to the struct security_operations that is to be checked.
  70. *
  71. * Each LSM must pass this method before registering its own operations
  72. * to avoid security registration races. This method may also be used
  73. * to check if your LSM is currently loaded during kernel initialization.
  74. *
  75. * Return true if:
  76. * -The passed LSM is the one chosen by user at boot time,
  77. * -or user didsn't specify a specific LSM and we're the first to ask
  78. * for registeration permissoin,
  79. * -or the passed LSM is currently loaded.
  80. * Otherwise, return false.
  81. */
  82. int __init security_module_enable(struct security_operations *ops)
  83. {
  84. if (!*chosen_lsm)
  85. strncpy(chosen_lsm, ops->name, SECURITY_NAME_MAX);
  86. else if (strncmp(ops->name, chosen_lsm, SECURITY_NAME_MAX))
  87. return 0;
  88. return 1;
  89. }
  90. /**
  91. * register_security - registers a security framework with the kernel
  92. * @ops: a pointer to the struct security_options that is to be registered
  93. *
  94. * This function is to allow a security module to register itself with the
  95. * kernel security subsystem. Some rudimentary checking is done on the @ops
  96. * value passed to this function. You'll need to check first if your LSM
  97. * is allowed to register its @ops by calling security_module_enable(@ops).
  98. *
  99. * If there is already a security module registered with the kernel,
  100. * an error will be returned. Otherwise 0 is returned on success.
  101. */
  102. int register_security(struct security_operations *ops)
  103. {
  104. if (verify(ops)) {
  105. printk(KERN_DEBUG "%s could not verify "
  106. "security_operations structure.\n", __func__);
  107. return -EINVAL;
  108. }
  109. if (security_ops != &dummy_security_ops)
  110. return -EAGAIN;
  111. security_ops = ops;
  112. return 0;
  113. }
  114. /**
  115. * mod_reg_security - allows security modules to be "stacked"
  116. * @name: a pointer to a string with the name of the security_options to be registered
  117. * @ops: a pointer to the struct security_options that is to be registered
  118. *
  119. * This function allows security modules to be stacked if the currently loaded
  120. * security module allows this to happen. It passes the @name and @ops to the
  121. * register_security function of the currently loaded security module.
  122. *
  123. * The return value depends on the currently loaded security module, with 0 as
  124. * success.
  125. */
  126. int mod_reg_security(const char *name, struct security_operations *ops)
  127. {
  128. if (verify(ops)) {
  129. printk(KERN_INFO "%s could not verify "
  130. "security operations.\n", __func__);
  131. return -EINVAL;
  132. }
  133. if (ops == security_ops) {
  134. printk(KERN_INFO "%s security operations "
  135. "already registered.\n", __func__);
  136. return -EINVAL;
  137. }
  138. return security_ops->register_security(name, ops);
  139. }
  140. /* Security operations */
  141. int security_ptrace(struct task_struct *parent, struct task_struct *child,
  142. unsigned int mode)
  143. {
  144. return security_ops->ptrace(parent, child, mode);
  145. }
  146. int security_capget(struct task_struct *target,
  147. kernel_cap_t *effective,
  148. kernel_cap_t *inheritable,
  149. kernel_cap_t *permitted)
  150. {
  151. return security_ops->capget(target, effective, inheritable, permitted);
  152. }
  153. int security_capset_check(struct task_struct *target,
  154. kernel_cap_t *effective,
  155. kernel_cap_t *inheritable,
  156. kernel_cap_t *permitted)
  157. {
  158. return security_ops->capset_check(target, effective, inheritable, permitted);
  159. }
  160. void security_capset_set(struct task_struct *target,
  161. kernel_cap_t *effective,
  162. kernel_cap_t *inheritable,
  163. kernel_cap_t *permitted)
  164. {
  165. security_ops->capset_set(target, effective, inheritable, permitted);
  166. }
  167. int security_capable(struct task_struct *tsk, int cap)
  168. {
  169. return security_ops->capable(tsk, cap);
  170. }
  171. int security_acct(struct file *file)
  172. {
  173. return security_ops->acct(file);
  174. }
  175. int security_sysctl(struct ctl_table *table, int op)
  176. {
  177. return security_ops->sysctl(table, op);
  178. }
  179. int security_quotactl(int cmds, int type, int id, struct super_block *sb)
  180. {
  181. return security_ops->quotactl(cmds, type, id, sb);
  182. }
  183. int security_quota_on(struct dentry *dentry)
  184. {
  185. return security_ops->quota_on(dentry);
  186. }
  187. int security_syslog(int type)
  188. {
  189. return security_ops->syslog(type);
  190. }
  191. int security_settime(struct timespec *ts, struct timezone *tz)
  192. {
  193. return security_ops->settime(ts, tz);
  194. }
  195. int security_vm_enough_memory(long pages)
  196. {
  197. return security_ops->vm_enough_memory(current->mm, pages);
  198. }
  199. int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
  200. {
  201. return security_ops->vm_enough_memory(mm, pages);
  202. }
  203. int security_bprm_alloc(struct linux_binprm *bprm)
  204. {
  205. return security_ops->bprm_alloc_security(bprm);
  206. }
  207. void security_bprm_free(struct linux_binprm *bprm)
  208. {
  209. security_ops->bprm_free_security(bprm);
  210. }
  211. void security_bprm_apply_creds(struct linux_binprm *bprm, int unsafe)
  212. {
  213. security_ops->bprm_apply_creds(bprm, unsafe);
  214. }
  215. void security_bprm_post_apply_creds(struct linux_binprm *bprm)
  216. {
  217. security_ops->bprm_post_apply_creds(bprm);
  218. }
  219. int security_bprm_set(struct linux_binprm *bprm)
  220. {
  221. return security_ops->bprm_set_security(bprm);
  222. }
  223. int security_bprm_check(struct linux_binprm *bprm)
  224. {
  225. return security_ops->bprm_check_security(bprm);
  226. }
  227. int security_bprm_secureexec(struct linux_binprm *bprm)
  228. {
  229. return security_ops->bprm_secureexec(bprm);
  230. }
  231. int security_sb_alloc(struct super_block *sb)
  232. {
  233. return security_ops->sb_alloc_security(sb);
  234. }
  235. void security_sb_free(struct super_block *sb)
  236. {
  237. security_ops->sb_free_security(sb);
  238. }
  239. int security_sb_copy_data(char *orig, char *copy)
  240. {
  241. return security_ops->sb_copy_data(orig, copy);
  242. }
  243. EXPORT_SYMBOL(security_sb_copy_data);
  244. int security_sb_kern_mount(struct super_block *sb, void *data)
  245. {
  246. return security_ops->sb_kern_mount(sb, data);
  247. }
  248. int security_sb_statfs(struct dentry *dentry)
  249. {
  250. return security_ops->sb_statfs(dentry);
  251. }
  252. int security_sb_mount(char *dev_name, struct path *path,
  253. char *type, unsigned long flags, void *data)
  254. {
  255. return security_ops->sb_mount(dev_name, path, type, flags, data);
  256. }
  257. int security_sb_check_sb(struct vfsmount *mnt, struct path *path)
  258. {
  259. return security_ops->sb_check_sb(mnt, path);
  260. }
  261. int security_sb_umount(struct vfsmount *mnt, int flags)
  262. {
  263. return security_ops->sb_umount(mnt, flags);
  264. }
  265. void security_sb_umount_close(struct vfsmount *mnt)
  266. {
  267. security_ops->sb_umount_close(mnt);
  268. }
  269. void security_sb_umount_busy(struct vfsmount *mnt)
  270. {
  271. security_ops->sb_umount_busy(mnt);
  272. }
  273. void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *data)
  274. {
  275. security_ops->sb_post_remount(mnt, flags, data);
  276. }
  277. void security_sb_post_addmount(struct vfsmount *mnt, struct path *mountpoint)
  278. {
  279. security_ops->sb_post_addmount(mnt, mountpoint);
  280. }
  281. int security_sb_pivotroot(struct path *old_path, struct path *new_path)
  282. {
  283. return security_ops->sb_pivotroot(old_path, new_path);
  284. }
  285. void security_sb_post_pivotroot(struct path *old_path, struct path *new_path)
  286. {
  287. security_ops->sb_post_pivotroot(old_path, new_path);
  288. }
  289. int security_sb_get_mnt_opts(const struct super_block *sb,
  290. struct security_mnt_opts *opts)
  291. {
  292. return security_ops->sb_get_mnt_opts(sb, opts);
  293. }
  294. int security_sb_set_mnt_opts(struct super_block *sb,
  295. struct security_mnt_opts *opts)
  296. {
  297. return security_ops->sb_set_mnt_opts(sb, opts);
  298. }
  299. EXPORT_SYMBOL(security_sb_set_mnt_opts);
  300. void security_sb_clone_mnt_opts(const struct super_block *oldsb,
  301. struct super_block *newsb)
  302. {
  303. security_ops->sb_clone_mnt_opts(oldsb, newsb);
  304. }
  305. EXPORT_SYMBOL(security_sb_clone_mnt_opts);
  306. int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
  307. {
  308. return security_ops->sb_parse_opts_str(options, opts);
  309. }
  310. EXPORT_SYMBOL(security_sb_parse_opts_str);
  311. int security_inode_alloc(struct inode *inode)
  312. {
  313. inode->i_security = NULL;
  314. return security_ops->inode_alloc_security(inode);
  315. }
  316. void security_inode_free(struct inode *inode)
  317. {
  318. security_ops->inode_free_security(inode);
  319. }
  320. int security_inode_init_security(struct inode *inode, struct inode *dir,
  321. char **name, void **value, size_t *len)
  322. {
  323. if (unlikely(IS_PRIVATE(inode)))
  324. return -EOPNOTSUPP;
  325. return security_ops->inode_init_security(inode, dir, name, value, len);
  326. }
  327. EXPORT_SYMBOL(security_inode_init_security);
  328. int security_inode_create(struct inode *dir, struct dentry *dentry, int mode)
  329. {
  330. if (unlikely(IS_PRIVATE(dir)))
  331. return 0;
  332. return security_ops->inode_create(dir, dentry, mode);
  333. }
  334. int security_inode_link(struct dentry *old_dentry, struct inode *dir,
  335. struct dentry *new_dentry)
  336. {
  337. if (unlikely(IS_PRIVATE(old_dentry->d_inode)))
  338. return 0;
  339. return security_ops->inode_link(old_dentry, dir, new_dentry);
  340. }
  341. int security_inode_unlink(struct inode *dir, struct dentry *dentry)
  342. {
  343. if (unlikely(IS_PRIVATE(dentry->d_inode)))
  344. return 0;
  345. return security_ops->inode_unlink(dir, dentry);
  346. }
  347. int security_inode_symlink(struct inode *dir, struct dentry *dentry,
  348. const char *old_name)
  349. {
  350. if (unlikely(IS_PRIVATE(dir)))
  351. return 0;
  352. return security_ops->inode_symlink(dir, dentry, old_name);
  353. }
  354. int security_inode_mkdir(struct inode *dir, struct dentry *dentry, int mode)
  355. {
  356. if (unlikely(IS_PRIVATE(dir)))
  357. return 0;
  358. return security_ops->inode_mkdir(dir, dentry, mode);
  359. }
  360. int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
  361. {
  362. if (unlikely(IS_PRIVATE(dentry->d_inode)))
  363. return 0;
  364. return security_ops->inode_rmdir(dir, dentry);
  365. }
  366. int security_inode_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
  367. {
  368. if (unlikely(IS_PRIVATE(dir)))
  369. return 0;
  370. return security_ops->inode_mknod(dir, dentry, mode, dev);
  371. }
  372. int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
  373. struct inode *new_dir, struct dentry *new_dentry)
  374. {
  375. if (unlikely(IS_PRIVATE(old_dentry->d_inode) ||
  376. (new_dentry->d_inode && IS_PRIVATE(new_dentry->d_inode))))
  377. return 0;
  378. return security_ops->inode_rename(old_dir, old_dentry,
  379. new_dir, new_dentry);
  380. }
  381. int security_inode_readlink(struct dentry *dentry)
  382. {
  383. if (unlikely(IS_PRIVATE(dentry->d_inode)))
  384. return 0;
  385. return security_ops->inode_readlink(dentry);
  386. }
  387. int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
  388. {
  389. if (unlikely(IS_PRIVATE(dentry->d_inode)))
  390. return 0;
  391. return security_ops->inode_follow_link(dentry, nd);
  392. }
  393. int security_inode_permission(struct inode *inode, int mask, struct nameidata *nd)
  394. {
  395. if (unlikely(IS_PRIVATE(inode)))
  396. return 0;
  397. return security_ops->inode_permission(inode, mask, nd);
  398. }
  399. int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
  400. {
  401. if (unlikely(IS_PRIVATE(dentry->d_inode)))
  402. return 0;
  403. return security_ops->inode_setattr(dentry, attr);
  404. }
  405. int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
  406. {
  407. if (unlikely(IS_PRIVATE(dentry->d_inode)))
  408. return 0;
  409. return security_ops->inode_getattr(mnt, dentry);
  410. }
  411. void security_inode_delete(struct inode *inode)
  412. {
  413. if (unlikely(IS_PRIVATE(inode)))
  414. return;
  415. security_ops->inode_delete(inode);
  416. }
  417. int security_inode_setxattr(struct dentry *dentry, const char *name,
  418. const void *value, size_t size, int flags)
  419. {
  420. if (unlikely(IS_PRIVATE(dentry->d_inode)))
  421. return 0;
  422. return security_ops->inode_setxattr(dentry, name, value, size, flags);
  423. }
  424. void security_inode_post_setxattr(struct dentry *dentry, const char *name,
  425. const void *value, size_t size, int flags)
  426. {
  427. if (unlikely(IS_PRIVATE(dentry->d_inode)))
  428. return;
  429. security_ops->inode_post_setxattr(dentry, name, value, size, flags);
  430. }
  431. int security_inode_getxattr(struct dentry *dentry, const char *name)
  432. {
  433. if (unlikely(IS_PRIVATE(dentry->d_inode)))
  434. return 0;
  435. return security_ops->inode_getxattr(dentry, name);
  436. }
  437. int security_inode_listxattr(struct dentry *dentry)
  438. {
  439. if (unlikely(IS_PRIVATE(dentry->d_inode)))
  440. return 0;
  441. return security_ops->inode_listxattr(dentry);
  442. }
  443. int security_inode_removexattr(struct dentry *dentry, const char *name)
  444. {
  445. if (unlikely(IS_PRIVATE(dentry->d_inode)))
  446. return 0;
  447. return security_ops->inode_removexattr(dentry, name);
  448. }
  449. int security_inode_need_killpriv(struct dentry *dentry)
  450. {
  451. return security_ops->inode_need_killpriv(dentry);
  452. }
  453. int security_inode_killpriv(struct dentry *dentry)
  454. {
  455. return security_ops->inode_killpriv(dentry);
  456. }
  457. int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
  458. {
  459. if (unlikely(IS_PRIVATE(inode)))
  460. return 0;
  461. return security_ops->inode_getsecurity(inode, name, buffer, alloc);
  462. }
  463. int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
  464. {
  465. if (unlikely(IS_PRIVATE(inode)))
  466. return 0;
  467. return security_ops->inode_setsecurity(inode, name, value, size, flags);
  468. }
  469. int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
  470. {
  471. if (unlikely(IS_PRIVATE(inode)))
  472. return 0;
  473. return security_ops->inode_listsecurity(inode, buffer, buffer_size);
  474. }
  475. void security_inode_getsecid(const struct inode *inode, u32 *secid)
  476. {
  477. security_ops->inode_getsecid(inode, secid);
  478. }
  479. int security_file_permission(struct file *file, int mask)
  480. {
  481. return security_ops->file_permission(file, mask);
  482. }
  483. int security_file_alloc(struct file *file)
  484. {
  485. return security_ops->file_alloc_security(file);
  486. }
  487. void security_file_free(struct file *file)
  488. {
  489. security_ops->file_free_security(file);
  490. }
  491. int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  492. {
  493. return security_ops->file_ioctl(file, cmd, arg);
  494. }
  495. int security_file_mmap(struct file *file, unsigned long reqprot,
  496. unsigned long prot, unsigned long flags,
  497. unsigned long addr, unsigned long addr_only)
  498. {
  499. return security_ops->file_mmap(file, reqprot, prot, flags, addr, addr_only);
  500. }
  501. int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
  502. unsigned long prot)
  503. {
  504. return security_ops->file_mprotect(vma, reqprot, prot);
  505. }
  506. int security_file_lock(struct file *file, unsigned int cmd)
  507. {
  508. return security_ops->file_lock(file, cmd);
  509. }
  510. int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
  511. {
  512. return security_ops->file_fcntl(file, cmd, arg);
  513. }
  514. int security_file_set_fowner(struct file *file)
  515. {
  516. return security_ops->file_set_fowner(file);
  517. }
  518. int security_file_send_sigiotask(struct task_struct *tsk,
  519. struct fown_struct *fown, int sig)
  520. {
  521. return security_ops->file_send_sigiotask(tsk, fown, sig);
  522. }
  523. int security_file_receive(struct file *file)
  524. {
  525. return security_ops->file_receive(file);
  526. }
  527. int security_dentry_open(struct file *file)
  528. {
  529. return security_ops->dentry_open(file);
  530. }
  531. int security_task_create(unsigned long clone_flags)
  532. {
  533. return security_ops->task_create(clone_flags);
  534. }
  535. int security_task_alloc(struct task_struct *p)
  536. {
  537. return security_ops->task_alloc_security(p);
  538. }
  539. void security_task_free(struct task_struct *p)
  540. {
  541. security_ops->task_free_security(p);
  542. }
  543. int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags)
  544. {
  545. return security_ops->task_setuid(id0, id1, id2, flags);
  546. }
  547. int security_task_post_setuid(uid_t old_ruid, uid_t old_euid,
  548. uid_t old_suid, int flags)
  549. {
  550. return security_ops->task_post_setuid(old_ruid, old_euid, old_suid, flags);
  551. }
  552. int security_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags)
  553. {
  554. return security_ops->task_setgid(id0, id1, id2, flags);
  555. }
  556. int security_task_setpgid(struct task_struct *p, pid_t pgid)
  557. {
  558. return security_ops->task_setpgid(p, pgid);
  559. }
  560. int security_task_getpgid(struct task_struct *p)
  561. {
  562. return security_ops->task_getpgid(p);
  563. }
  564. int security_task_getsid(struct task_struct *p)
  565. {
  566. return security_ops->task_getsid(p);
  567. }
  568. void security_task_getsecid(struct task_struct *p, u32 *secid)
  569. {
  570. security_ops->task_getsecid(p, secid);
  571. }
  572. EXPORT_SYMBOL(security_task_getsecid);
  573. int security_task_setgroups(struct group_info *group_info)
  574. {
  575. return security_ops->task_setgroups(group_info);
  576. }
  577. int security_task_setnice(struct task_struct *p, int nice)
  578. {
  579. return security_ops->task_setnice(p, nice);
  580. }
  581. int security_task_setioprio(struct task_struct *p, int ioprio)
  582. {
  583. return security_ops->task_setioprio(p, ioprio);
  584. }
  585. int security_task_getioprio(struct task_struct *p)
  586. {
  587. return security_ops->task_getioprio(p);
  588. }
  589. int security_task_setrlimit(unsigned int resource, struct rlimit *new_rlim)
  590. {
  591. return security_ops->task_setrlimit(resource, new_rlim);
  592. }
  593. int security_task_setscheduler(struct task_struct *p,
  594. int policy, struct sched_param *lp)
  595. {
  596. return security_ops->task_setscheduler(p, policy, lp);
  597. }
  598. int security_task_getscheduler(struct task_struct *p)
  599. {
  600. return security_ops->task_getscheduler(p);
  601. }
  602. int security_task_movememory(struct task_struct *p)
  603. {
  604. return security_ops->task_movememory(p);
  605. }
  606. int security_task_kill(struct task_struct *p, struct siginfo *info,
  607. int sig, u32 secid)
  608. {
  609. return security_ops->task_kill(p, info, sig, secid);
  610. }
  611. int security_task_wait(struct task_struct *p)
  612. {
  613. return security_ops->task_wait(p);
  614. }
  615. int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
  616. unsigned long arg4, unsigned long arg5, long *rc_p)
  617. {
  618. return security_ops->task_prctl(option, arg2, arg3, arg4, arg5, rc_p);
  619. }
  620. void security_task_reparent_to_init(struct task_struct *p)
  621. {
  622. security_ops->task_reparent_to_init(p);
  623. }
  624. void security_task_to_inode(struct task_struct *p, struct inode *inode)
  625. {
  626. security_ops->task_to_inode(p, inode);
  627. }
  628. int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
  629. {
  630. return security_ops->ipc_permission(ipcp, flag);
  631. }
  632. void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
  633. {
  634. security_ops->ipc_getsecid(ipcp, secid);
  635. }
  636. int security_msg_msg_alloc(struct msg_msg *msg)
  637. {
  638. return security_ops->msg_msg_alloc_security(msg);
  639. }
  640. void security_msg_msg_free(struct msg_msg *msg)
  641. {
  642. security_ops->msg_msg_free_security(msg);
  643. }
  644. int security_msg_queue_alloc(struct msg_queue *msq)
  645. {
  646. return security_ops->msg_queue_alloc_security(msq);
  647. }
  648. void security_msg_queue_free(struct msg_queue *msq)
  649. {
  650. security_ops->msg_queue_free_security(msq);
  651. }
  652. int security_msg_queue_associate(struct msg_queue *msq, int msqflg)
  653. {
  654. return security_ops->msg_queue_associate(msq, msqflg);
  655. }
  656. int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
  657. {
  658. return security_ops->msg_queue_msgctl(msq, cmd);
  659. }
  660. int security_msg_queue_msgsnd(struct msg_queue *msq,
  661. struct msg_msg *msg, int msqflg)
  662. {
  663. return security_ops->msg_queue_msgsnd(msq, msg, msqflg);
  664. }
  665. int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
  666. struct task_struct *target, long type, int mode)
  667. {
  668. return security_ops->msg_queue_msgrcv(msq, msg, target, type, mode);
  669. }
  670. int security_shm_alloc(struct shmid_kernel *shp)
  671. {
  672. return security_ops->shm_alloc_security(shp);
  673. }
  674. void security_shm_free(struct shmid_kernel *shp)
  675. {
  676. security_ops->shm_free_security(shp);
  677. }
  678. int security_shm_associate(struct shmid_kernel *shp, int shmflg)
  679. {
  680. return security_ops->shm_associate(shp, shmflg);
  681. }
  682. int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
  683. {
  684. return security_ops->shm_shmctl(shp, cmd);
  685. }
  686. int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg)
  687. {
  688. return security_ops->shm_shmat(shp, shmaddr, shmflg);
  689. }
  690. int security_sem_alloc(struct sem_array *sma)
  691. {
  692. return security_ops->sem_alloc_security(sma);
  693. }
  694. void security_sem_free(struct sem_array *sma)
  695. {
  696. security_ops->sem_free_security(sma);
  697. }
  698. int security_sem_associate(struct sem_array *sma, int semflg)
  699. {
  700. return security_ops->sem_associate(sma, semflg);
  701. }
  702. int security_sem_semctl(struct sem_array *sma, int cmd)
  703. {
  704. return security_ops->sem_semctl(sma, cmd);
  705. }
  706. int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
  707. unsigned nsops, int alter)
  708. {
  709. return security_ops->sem_semop(sma, sops, nsops, alter);
  710. }
  711. void security_d_instantiate(struct dentry *dentry, struct inode *inode)
  712. {
  713. if (unlikely(inode && IS_PRIVATE(inode)))
  714. return;
  715. security_ops->d_instantiate(dentry, inode);
  716. }
  717. EXPORT_SYMBOL(security_d_instantiate);
  718. int security_getprocattr(struct task_struct *p, char *name, char **value)
  719. {
  720. return security_ops->getprocattr(p, name, value);
  721. }
  722. int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
  723. {
  724. return security_ops->setprocattr(p, name, value, size);
  725. }
  726. int security_netlink_send(struct sock *sk, struct sk_buff *skb)
  727. {
  728. return security_ops->netlink_send(sk, skb);
  729. }
  730. int security_netlink_recv(struct sk_buff *skb, int cap)
  731. {
  732. return security_ops->netlink_recv(skb, cap);
  733. }
  734. EXPORT_SYMBOL(security_netlink_recv);
  735. int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
  736. {
  737. return security_ops->secid_to_secctx(secid, secdata, seclen);
  738. }
  739. EXPORT_SYMBOL(security_secid_to_secctx);
  740. int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
  741. {
  742. return security_ops->secctx_to_secid(secdata, seclen, secid);
  743. }
  744. EXPORT_SYMBOL(security_secctx_to_secid);
  745. void security_release_secctx(char *secdata, u32 seclen)
  746. {
  747. return security_ops->release_secctx(secdata, seclen);
  748. }
  749. EXPORT_SYMBOL(security_release_secctx);
  750. #ifdef CONFIG_SECURITY_NETWORK
  751. int security_unix_stream_connect(struct socket *sock, struct socket *other,
  752. struct sock *newsk)
  753. {
  754. return security_ops->unix_stream_connect(sock, other, newsk);
  755. }
  756. EXPORT_SYMBOL(security_unix_stream_connect);
  757. int security_unix_may_send(struct socket *sock, struct socket *other)
  758. {
  759. return security_ops->unix_may_send(sock, other);
  760. }
  761. EXPORT_SYMBOL(security_unix_may_send);
  762. int security_socket_create(int family, int type, int protocol, int kern)
  763. {
  764. return security_ops->socket_create(family, type, protocol, kern);
  765. }
  766. int security_socket_post_create(struct socket *sock, int family,
  767. int type, int protocol, int kern)
  768. {
  769. return security_ops->socket_post_create(sock, family, type,
  770. protocol, kern);
  771. }
  772. int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
  773. {
  774. return security_ops->socket_bind(sock, address, addrlen);
  775. }
  776. int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
  777. {
  778. return security_ops->socket_connect(sock, address, addrlen);
  779. }
  780. int security_socket_listen(struct socket *sock, int backlog)
  781. {
  782. return security_ops->socket_listen(sock, backlog);
  783. }
  784. int security_socket_accept(struct socket *sock, struct socket *newsock)
  785. {
  786. return security_ops->socket_accept(sock, newsock);
  787. }
  788. void security_socket_post_accept(struct socket *sock, struct socket *newsock)
  789. {
  790. security_ops->socket_post_accept(sock, newsock);
  791. }
  792. int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
  793. {
  794. return security_ops->socket_sendmsg(sock, msg, size);
  795. }
  796. int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
  797. int size, int flags)
  798. {
  799. return security_ops->socket_recvmsg(sock, msg, size, flags);
  800. }
  801. int security_socket_getsockname(struct socket *sock)
  802. {
  803. return security_ops->socket_getsockname(sock);
  804. }
  805. int security_socket_getpeername(struct socket *sock)
  806. {
  807. return security_ops->socket_getpeername(sock);
  808. }
  809. int security_socket_getsockopt(struct socket *sock, int level, int optname)
  810. {
  811. return security_ops->socket_getsockopt(sock, level, optname);
  812. }
  813. int security_socket_setsockopt(struct socket *sock, int level, int optname)
  814. {
  815. return security_ops->socket_setsockopt(sock, level, optname);
  816. }
  817. int security_socket_shutdown(struct socket *sock, int how)
  818. {
  819. return security_ops->socket_shutdown(sock, how);
  820. }
  821. int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
  822. {
  823. return security_ops->socket_sock_rcv_skb(sk, skb);
  824. }
  825. EXPORT_SYMBOL(security_sock_rcv_skb);
  826. int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
  827. int __user *optlen, unsigned len)
  828. {
  829. return security_ops->socket_getpeersec_stream(sock, optval, optlen, len);
  830. }
  831. int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
  832. {
  833. return security_ops->socket_getpeersec_dgram(sock, skb, secid);
  834. }
  835. EXPORT_SYMBOL(security_socket_getpeersec_dgram);
  836. int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
  837. {
  838. return security_ops->sk_alloc_security(sk, family, priority);
  839. }
  840. void security_sk_free(struct sock *sk)
  841. {
  842. return security_ops->sk_free_security(sk);
  843. }
  844. void security_sk_clone(const struct sock *sk, struct sock *newsk)
  845. {
  846. return security_ops->sk_clone_security(sk, newsk);
  847. }
  848. void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
  849. {
  850. security_ops->sk_getsecid(sk, &fl->secid);
  851. }
  852. EXPORT_SYMBOL(security_sk_classify_flow);
  853. void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
  854. {
  855. security_ops->req_classify_flow(req, fl);
  856. }
  857. EXPORT_SYMBOL(security_req_classify_flow);
  858. void security_sock_graft(struct sock *sk, struct socket *parent)
  859. {
  860. security_ops->sock_graft(sk, parent);
  861. }
  862. EXPORT_SYMBOL(security_sock_graft);
  863. int security_inet_conn_request(struct sock *sk,
  864. struct sk_buff *skb, struct request_sock *req)
  865. {
  866. return security_ops->inet_conn_request(sk, skb, req);
  867. }
  868. EXPORT_SYMBOL(security_inet_conn_request);
  869. void security_inet_csk_clone(struct sock *newsk,
  870. const struct request_sock *req)
  871. {
  872. security_ops->inet_csk_clone(newsk, req);
  873. }
  874. void security_inet_conn_established(struct sock *sk,
  875. struct sk_buff *skb)
  876. {
  877. security_ops->inet_conn_established(sk, skb);
  878. }
  879. #endif /* CONFIG_SECURITY_NETWORK */
  880. #ifdef CONFIG_SECURITY_NETWORK_XFRM
  881. int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx)
  882. {
  883. return security_ops->xfrm_policy_alloc_security(ctxp, sec_ctx);
  884. }
  885. EXPORT_SYMBOL(security_xfrm_policy_alloc);
  886. int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
  887. struct xfrm_sec_ctx **new_ctxp)
  888. {
  889. return security_ops->xfrm_policy_clone_security(old_ctx, new_ctxp);
  890. }
  891. void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
  892. {
  893. security_ops->xfrm_policy_free_security(ctx);
  894. }
  895. EXPORT_SYMBOL(security_xfrm_policy_free);
  896. int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
  897. {
  898. return security_ops->xfrm_policy_delete_security(ctx);
  899. }
  900. int security_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx)
  901. {
  902. return security_ops->xfrm_state_alloc_security(x, sec_ctx, 0);
  903. }
  904. EXPORT_SYMBOL(security_xfrm_state_alloc);
  905. int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
  906. struct xfrm_sec_ctx *polsec, u32 secid)
  907. {
  908. if (!polsec)
  909. return 0;
  910. /*
  911. * We want the context to be taken from secid which is usually
  912. * from the sock.
  913. */
  914. return security_ops->xfrm_state_alloc_security(x, NULL, secid);
  915. }
  916. int security_xfrm_state_delete(struct xfrm_state *x)
  917. {
  918. return security_ops->xfrm_state_delete_security(x);
  919. }
  920. EXPORT_SYMBOL(security_xfrm_state_delete);
  921. void security_xfrm_state_free(struct xfrm_state *x)
  922. {
  923. security_ops->xfrm_state_free_security(x);
  924. }
  925. int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
  926. {
  927. return security_ops->xfrm_policy_lookup(ctx, fl_secid, dir);
  928. }
  929. int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
  930. struct xfrm_policy *xp, struct flowi *fl)
  931. {
  932. return security_ops->xfrm_state_pol_flow_match(x, xp, fl);
  933. }
  934. int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
  935. {
  936. return security_ops->xfrm_decode_session(skb, secid, 1);
  937. }
  938. void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
  939. {
  940. int rc = security_ops->xfrm_decode_session(skb, &fl->secid, 0);
  941. BUG_ON(rc);
  942. }
  943. EXPORT_SYMBOL(security_skb_classify_flow);
  944. #endif /* CONFIG_SECURITY_NETWORK_XFRM */
  945. #ifdef CONFIG_KEYS
  946. int security_key_alloc(struct key *key, struct task_struct *tsk, unsigned long flags)
  947. {
  948. return security_ops->key_alloc(key, tsk, flags);
  949. }
  950. void security_key_free(struct key *key)
  951. {
  952. security_ops->key_free(key);
  953. }
  954. int security_key_permission(key_ref_t key_ref,
  955. struct task_struct *context, key_perm_t perm)
  956. {
  957. return security_ops->key_permission(key_ref, context, perm);
  958. }
  959. int security_key_getsecurity(struct key *key, char **_buffer)
  960. {
  961. return security_ops->key_getsecurity(key, _buffer);
  962. }
  963. #endif /* CONFIG_KEYS */
  964. #ifdef CONFIG_AUDIT
  965. int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
  966. {
  967. return security_ops->audit_rule_init(field, op, rulestr, lsmrule);
  968. }
  969. int security_audit_rule_known(struct audit_krule *krule)
  970. {
  971. return security_ops->audit_rule_known(krule);
  972. }
  973. void security_audit_rule_free(void *lsmrule)
  974. {
  975. security_ops->audit_rule_free(lsmrule);
  976. }
  977. int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
  978. struct audit_context *actx)
  979. {
  980. return security_ops->audit_rule_match(secid, field, op, lsmrule, actx);
  981. }
  982. #endif /* CONFIG_AUDIT */