capability.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Capabilities Linux Security Module
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. */
  10. #include <linux/config.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/security.h>
  15. #include <linux/file.h>
  16. #include <linux/mm.h>
  17. #include <linux/mman.h>
  18. #include <linux/pagemap.h>
  19. #include <linux/swap.h>
  20. #include <linux/smp_lock.h>
  21. #include <linux/skbuff.h>
  22. #include <linux/netlink.h>
  23. #include <linux/ptrace.h>
  24. #include <linux/moduleparam.h>
  25. static struct security_operations capability_ops = {
  26. .ptrace = cap_ptrace,
  27. .capget = cap_capget,
  28. .capset_check = cap_capset_check,
  29. .capset_set = cap_capset_set,
  30. .capable = cap_capable,
  31. .settime = cap_settime,
  32. .netlink_send = cap_netlink_send,
  33. .netlink_recv = cap_netlink_recv,
  34. .bprm_apply_creds = cap_bprm_apply_creds,
  35. .bprm_set_security = cap_bprm_set_security,
  36. .bprm_secureexec = cap_bprm_secureexec,
  37. .inode_setxattr = cap_inode_setxattr,
  38. .inode_removexattr = cap_inode_removexattr,
  39. .task_post_setuid = cap_task_post_setuid,
  40. .task_reparent_to_init = cap_task_reparent_to_init,
  41. .syslog = cap_syslog,
  42. .vm_enough_memory = cap_vm_enough_memory,
  43. };
  44. /* flag to keep track of how we were registered */
  45. static int secondary;
  46. static int capability_disable;
  47. module_param_named(disable, capability_disable, int, 0);
  48. MODULE_PARM_DESC(disable, "To disable capabilities module set disable = 1");
  49. static int __init capability_init (void)
  50. {
  51. if (capability_disable) {
  52. printk(KERN_INFO "Capabilities disabled at initialization\n");
  53. return 0;
  54. }
  55. /* register ourselves with the security framework */
  56. if (register_security (&capability_ops)) {
  57. /* try registering with primary module */
  58. if (mod_reg_security (KBUILD_MODNAME, &capability_ops)) {
  59. printk (KERN_INFO "Failure registering capabilities "
  60. "with primary security module.\n");
  61. return -EINVAL;
  62. }
  63. secondary = 1;
  64. }
  65. printk (KERN_INFO "Capability LSM initialized%s\n",
  66. secondary ? " as secondary" : "");
  67. return 0;
  68. }
  69. static void __exit capability_exit (void)
  70. {
  71. if (capability_disable)
  72. return;
  73. /* remove ourselves from the security framework */
  74. if (secondary) {
  75. if (mod_unreg_security (KBUILD_MODNAME, &capability_ops))
  76. printk (KERN_INFO "Failure unregistering capabilities "
  77. "with primary module.\n");
  78. return;
  79. }
  80. if (unregister_security (&capability_ops)) {
  81. printk (KERN_INFO
  82. "Failure unregistering capabilities with the kernel\n");
  83. }
  84. }
  85. security_initcall (capability_init);
  86. module_exit (capability_exit);
  87. MODULE_DESCRIPTION("Standard Linux Capabilities Security Module");
  88. MODULE_LICENSE("GPL");