diff options
-rw-r--r-- | include/linux/capability.h | 3 | ||||
-rw-r--r-- | include/linux/security.h | 22 | ||||
-rw-r--r-- | kernel/capability.c | 16 | ||||
-rw-r--r-- | kernel/sys.c | 12 | ||||
-rw-r--r-- | security/security.c | 23 |
5 files changed, 34 insertions, 42 deletions
diff --git a/include/linux/capability.h b/include/linux/capability.h index 5a23ce752629..6548b35ab9f6 100644 --- a/include/linux/capability.h +++ b/include/linux/capability.h | |||
@@ -357,7 +357,8 @@ static inline kernel_cap_t cap_invert(kernel_cap_t c) | |||
357 | 357 | ||
358 | #define cap_is_fs_cap(c) (CAP_TO_MASK(c) & CAP_FS_MASK) | 358 | #define cap_is_fs_cap(c) (CAP_TO_MASK(c) & CAP_FS_MASK) |
359 | 359 | ||
360 | extern int capable(int cap); | 360 | int capable(int cap); |
361 | int __capable(struct task_struct *t, int cap); | ||
361 | 362 | ||
362 | #endif /* __KERNEL__ */ | 363 | #endif /* __KERNEL__ */ |
363 | 364 | ||
diff --git a/include/linux/security.h b/include/linux/security.h index b18eb8cfa639..3c19be35124b 100644 --- a/include/linux/security.h +++ b/include/linux/security.h | |||
@@ -1040,6 +1040,11 @@ struct swap_info_struct; | |||
1040 | * @effective contains the effective capability set. | 1040 | * @effective contains the effective capability set. |
1041 | * @inheritable contains the inheritable capability set. | 1041 | * @inheritable contains the inheritable capability set. |
1042 | * @permitted contains the permitted capability set. | 1042 | * @permitted contains the permitted capability set. |
1043 | * @capable: | ||
1044 | * Check whether the @tsk process has the @cap capability. | ||
1045 | * @tsk contains the task_struct for the process. | ||
1046 | * @cap contains the capability <include/linux/capability.h>. | ||
1047 | * Return 0 if the capability is granted for @tsk. | ||
1043 | * @acct: | 1048 | * @acct: |
1044 | * Check permission before enabling or disabling process accounting. If | 1049 | * Check permission before enabling or disabling process accounting. If |
1045 | * accounting is being enabled, then @file refers to the open file used to | 1050 | * accounting is being enabled, then @file refers to the open file used to |
@@ -1053,11 +1058,6 @@ struct swap_info_struct; | |||
1053 | * @table contains the ctl_table structure for the sysctl variable. | 1058 | * @table contains the ctl_table structure for the sysctl variable. |
1054 | * @op contains the operation (001 = search, 002 = write, 004 = read). | 1059 | * @op contains the operation (001 = search, 002 = write, 004 = read). |
1055 | * Return 0 if permission is granted. | 1060 | * Return 0 if permission is granted. |
1056 | * @capable: | ||
1057 | * Check whether the @tsk process has the @cap capability. | ||
1058 | * @tsk contains the task_struct for the process. | ||
1059 | * @cap contains the capability <include/linux/capability.h>. | ||
1060 | * Return 0 if the capability is granted for @tsk. | ||
1061 | * @syslog: | 1061 | * @syslog: |
1062 | * Check permission before accessing the kernel message ring or changing | 1062 | * Check permission before accessing the kernel message ring or changing |
1063 | * logging to the console. | 1063 | * logging to the console. |
@@ -1099,9 +1099,9 @@ struct security_operations { | |||
1099 | kernel_cap_t * effective, | 1099 | kernel_cap_t * effective, |
1100 | kernel_cap_t * inheritable, | 1100 | kernel_cap_t * inheritable, |
1101 | kernel_cap_t * permitted); | 1101 | kernel_cap_t * permitted); |
1102 | int (*capable) (struct task_struct * tsk, int cap); | ||
1102 | int (*acct) (struct file * file); | 1103 | int (*acct) (struct file * file); |
1103 | int (*sysctl) (struct ctl_table * table, int op); | 1104 | int (*sysctl) (struct ctl_table * table, int op); |
1104 | int (*capable) (struct task_struct * tsk, int cap); | ||
1105 | int (*quotactl) (int cmds, int type, int id, struct super_block * sb); | 1105 | int (*quotactl) (int cmds, int type, int id, struct super_block * sb); |
1106 | int (*quota_on) (struct dentry * dentry); | 1106 | int (*quota_on) (struct dentry * dentry); |
1107 | int (*syslog) (int type); | 1107 | int (*syslog) (int type); |
@@ -1347,6 +1347,11 @@ static inline void security_capset_set (struct task_struct *target, | |||
1347 | security_ops->capset_set (target, effective, inheritable, permitted); | 1347 | security_ops->capset_set (target, effective, inheritable, permitted); |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | static inline int security_capable(struct task_struct *tsk, int cap) | ||
1351 | { | ||
1352 | return security_ops->capable(tsk, cap); | ||
1353 | } | ||
1354 | |||
1350 | static inline int security_acct (struct file *file) | 1355 | static inline int security_acct (struct file *file) |
1351 | { | 1356 | { |
1352 | return security_ops->acct (file); | 1357 | return security_ops->acct (file); |
@@ -2050,6 +2055,11 @@ static inline void security_capset_set (struct task_struct *target, | |||
2050 | cap_capset_set (target, effective, inheritable, permitted); | 2055 | cap_capset_set (target, effective, inheritable, permitted); |
2051 | } | 2056 | } |
2052 | 2057 | ||
2058 | static inline int security_capable(struct task_struct *tsk, int cap) | ||
2059 | { | ||
2060 | return cap_capable(tsk, cap); | ||
2061 | } | ||
2062 | |||
2053 | static inline int security_acct (struct file *file) | 2063 | static inline int security_acct (struct file *file) |
2054 | { | 2064 | { |
2055 | return 0; | 2065 | return 0; |
diff --git a/kernel/capability.c b/kernel/capability.c index bfa3c92e16f2..1a4d8a40d3f9 100644 --- a/kernel/capability.c +++ b/kernel/capability.c | |||
@@ -233,3 +233,19 @@ out: | |||
233 | 233 | ||
234 | return ret; | 234 | return ret; |
235 | } | 235 | } |
236 | |||
237 | int __capable(struct task_struct *t, int cap) | ||
238 | { | ||
239 | if (security_capable(t, cap) == 0) { | ||
240 | t->flags |= PF_SUPERPRIV; | ||
241 | return 1; | ||
242 | } | ||
243 | return 0; | ||
244 | } | ||
245 | EXPORT_SYMBOL(__capable); | ||
246 | |||
247 | int capable(int cap) | ||
248 | { | ||
249 | return __capable(current, cap); | ||
250 | } | ||
251 | EXPORT_SYMBOL(capable); | ||
diff --git a/kernel/sys.c b/kernel/sys.c index 19d058be49d4..421009cedb51 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -224,18 +224,6 @@ int unregister_reboot_notifier(struct notifier_block * nb) | |||
224 | 224 | ||
225 | EXPORT_SYMBOL(unregister_reboot_notifier); | 225 | EXPORT_SYMBOL(unregister_reboot_notifier); |
226 | 226 | ||
227 | #ifndef CONFIG_SECURITY | ||
228 | int capable(int cap) | ||
229 | { | ||
230 | if (cap_raised(current->cap_effective, cap)) { | ||
231 | current->flags |= PF_SUPERPRIV; | ||
232 | return 1; | ||
233 | } | ||
234 | return 0; | ||
235 | } | ||
236 | EXPORT_SYMBOL(capable); | ||
237 | #endif | ||
238 | |||
239 | static int set_one_prio(struct task_struct *p, int niceval, int error) | 227 | static int set_one_prio(struct task_struct *p, int niceval, int error) |
240 | { | 228 | { |
241 | int no_nice; | 229 | int no_nice; |
diff --git a/security/security.c b/security/security.c index f693e1f66b98..51ef509710b9 100644 --- a/security/security.c +++ b/security/security.c | |||
@@ -174,31 +174,8 @@ int mod_unreg_security(const char *name, struct security_operations *ops) | |||
174 | return security_ops->unregister_security(name, ops); | 174 | return security_ops->unregister_security(name, ops); |
175 | } | 175 | } |
176 | 176 | ||
177 | /** | ||
178 | * capable - calls the currently loaded security module's capable() function with the specified capability | ||
179 | * @cap: the requested capability level. | ||
180 | * | ||
181 | * This function calls the currently loaded security module's capable() | ||
182 | * function with a pointer to the current task and the specified @cap value. | ||
183 | * | ||
184 | * This allows the security module to implement the capable function call | ||
185 | * however it chooses to. | ||
186 | */ | ||
187 | int capable(int cap) | ||
188 | { | ||
189 | if (security_ops->capable(current, cap)) { | ||
190 | /* capability denied */ | ||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | /* capability granted */ | ||
195 | current->flags |= PF_SUPERPRIV; | ||
196 | return 1; | ||
197 | } | ||
198 | |||
199 | EXPORT_SYMBOL_GPL(register_security); | 177 | EXPORT_SYMBOL_GPL(register_security); |
200 | EXPORT_SYMBOL_GPL(unregister_security); | 178 | EXPORT_SYMBOL_GPL(unregister_security); |
201 | EXPORT_SYMBOL_GPL(mod_reg_security); | 179 | EXPORT_SYMBOL_GPL(mod_reg_security); |
202 | EXPORT_SYMBOL_GPL(mod_unreg_security); | 180 | EXPORT_SYMBOL_GPL(mod_unreg_security); |
203 | EXPORT_SYMBOL(capable); | ||
204 | EXPORT_SYMBOL(security_ops); | 181 | EXPORT_SYMBOL(security_ops); |