capability.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #define MY_NAME __stringify(KBUILD_MODNAME)
  45. /* flag to keep track of how we were registered */
  46. static int secondary;
  47. static int capability_disable;
  48. module_param_named(disable, capability_disable, int, 0);
  49. MODULE_PARM_DESC(disable, "To disable capabilities module set disable = 1");
  50. static int __init capability_init (void)
  51. {
  52. if (capability_disable) {
  53. printk(KERN_INFO "Capabilities disabled at initialization\n");
  54. return 0;
  55. }
  56. /* register ourselves with the security framework */
  57. if (register_security (&capability_ops)) {
  58. /* try registering with primary module */
  59. if (mod_reg_security (MY_NAME, &capability_ops)) {
  60. printk (KERN_INFO "Failure registering capabilities "
  61. "with primary security module.\n");
  62. return -EINVAL;
  63. }
  64. secondary = 1;
  65. }
  66. printk (KERN_INFO "Capability LSM initialized%s\n",
  67. secondary ? " as secondary" : "");
  68. return 0;
  69. }
  70. static void __exit capability_exit (void)
  71. {
  72. if (capability_disable)
  73. return;
  74. /* remove ourselves from the security framework */
  75. if (secondary) {
  76. if (mod_unreg_security (MY_NAME, &capability_ops))
  77. printk (KERN_INFO "Failure unregistering capabilities "
  78. "with primary module.\n");
  79. return;
  80. }
  81. if (unregister_security (&capability_ops)) {
  82. printk (KERN_INFO
  83. "Failure unregistering capabilities with the kernel\n");
  84. }
  85. }
  86. security_initcall (capability_init);
  87. module_exit (capability_exit);
  88. MODULE_DESCRIPTION("Standard Linux Capabilities Security Module");
  89. MODULE_LICENSE("GPL");