capability.c 2.7 KB

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