Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/skbuff.h> |
| 20 | #include <linux/netlink.h> |
| 21 | #include <linux/ptrace.h> |
| 22 | #include <linux/moduleparam.h> |
| 23 | |
| 24 | static struct security_operations capability_ops = { |
| 25 | .ptrace = cap_ptrace, |
| 26 | .capget = cap_capget, |
| 27 | .capset_check = cap_capset_check, |
| 28 | .capset_set = cap_capset_set, |
| 29 | .capable = cap_capable, |
| 30 | .settime = cap_settime, |
| 31 | .netlink_send = cap_netlink_send, |
| 32 | .netlink_recv = cap_netlink_recv, |
| 33 | |
| 34 | .bprm_apply_creds = cap_bprm_apply_creds, |
| 35 | .bprm_set_security = cap_bprm_set_security, |
| 36 | .bprm_secureexec = cap_bprm_secureexec, |
| 37 | |
| 38 | .inode_setxattr = cap_inode_setxattr, |
| 39 | .inode_removexattr = cap_inode_removexattr, |
Serge E. Hallyn | b537677 | 2007-10-16 23:31:36 -0700 | [diff] [blame] | 40 | .inode_need_killpriv = cap_inode_need_killpriv, |
| 41 | .inode_killpriv = cap_inode_killpriv, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Serge E. Hallyn | b537677 | 2007-10-16 23:31:36 -0700 | [diff] [blame] | 43 | .task_setscheduler = cap_task_setscheduler, |
| 44 | .task_setioprio = cap_task_setioprio, |
| 45 | .task_setnice = cap_task_setnice, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | .task_post_setuid = cap_task_post_setuid, |
Andrew G. Morgan | 3898b1b | 2008-04-28 02:13:40 -0700 | [diff] [blame] | 47 | .task_prctl = cap_task_prctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | .task_reparent_to_init = cap_task_reparent_to_init, |
| 49 | |
| 50 | .syslog = cap_syslog, |
| 51 | |
| 52 | .vm_enough_memory = cap_vm_enough_memory, |
| 53 | }; |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /* flag to keep track of how we were registered */ |
| 56 | static int secondary; |
| 57 | |
| 58 | static int capability_disable; |
| 59 | module_param_named(disable, capability_disable, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | static int __init capability_init (void) |
| 62 | { |
| 63 | if (capability_disable) { |
| 64 | printk(KERN_INFO "Capabilities disabled at initialization\n"); |
| 65 | return 0; |
| 66 | } |
| 67 | /* register ourselves with the security framework */ |
| 68 | if (register_security (&capability_ops)) { |
| 69 | /* try registering with primary module */ |
Sam Ravnborg | 367cb70 | 2006-01-06 21:17:50 +0100 | [diff] [blame] | 70 | if (mod_reg_security (KBUILD_MODNAME, &capability_ops)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | printk (KERN_INFO "Failure registering capabilities " |
| 72 | "with primary security module.\n"); |
| 73 | return -EINVAL; |
| 74 | } |
| 75 | secondary = 1; |
| 76 | } |
| 77 | printk (KERN_INFO "Capability LSM initialized%s\n", |
| 78 | secondary ? " as secondary" : ""); |
| 79 | return 0; |
| 80 | } |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | security_initcall (capability_init); |