aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/capability.h
diff options
context:
space:
mode:
authorSerge E. Hallyn <serue@us.ibm.com>2007-10-17 02:31:36 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-17 11:43:07 -0400
commitb53767719b6cd8789392ea3e7e2eb7b8906898f0 (patch)
treea0279dc93c79b94d3865b0f19f6b7b353e20608c /include/linux/capability.h
parent57c521ce6125e15e99e56c902cb8da96bee7b36d (diff)
Implement file posix capabilities
Implement file posix capabilities. This allows programs to be given a subset of root's powers regardless of who runs them, without having to use setuid and giving the binary all of root's powers. This version works with Kaigai Kohei's userspace tools, found at http://www.kaigai.gr.jp/index.php. For more information on how to use this patch, Chris Friedhoff has posted a nice page at http://www.friedhoff.org/fscaps.html. Changelog: Nov 27: Incorporate fixes from Andrew Morton (security-introduce-file-caps-tweaks and security-introduce-file-caps-warning-fix) Fix Kconfig dependency. Fix change signaling behavior when file caps are not compiled in. Nov 13: Integrate comments from Alexey: Remove CONFIG_ ifdef from capability.h, and use %zd for printing a size_t. Nov 13: Fix endianness warnings by sparse as suggested by Alexey Dobriyan. Nov 09: Address warnings of unused variables at cap_bprm_set_security when file capabilities are disabled, and simultaneously clean up the code a little, by pulling the new code into a helper function. Nov 08: For pointers to required userspace tools and how to use them, see http://www.friedhoff.org/fscaps.html. Nov 07: Fix the calculation of the highest bit checked in check_cap_sanity(). Nov 07: Allow file caps to be enabled without CONFIG_SECURITY, since capabilities are the default. Hook cap_task_setscheduler when !CONFIG_SECURITY. Move capable(TASK_KILL) to end of cap_task_kill to reduce audit messages. Nov 05: Add secondary calls in selinux/hooks.c to task_setioprio and task_setscheduler so that selinux and capabilities with file cap support can be stacked. Sep 05: As Seth Arnold points out, uid checks are out of place for capability code. Sep 01: Define task_setscheduler, task_setioprio, cap_task_kill, and task_setnice to make sure a user cannot affect a process in which they called a program with some fscaps. One remaining question is the note under task_setscheduler: are we ok with CAP_SYS_NICE being sufficient to confine a process to a cpuset? It is a semantic change, as without fsccaps, attach_task doesn't allow CAP_SYS_NICE to override the uid equivalence check. But since it uses security_task_setscheduler, which elsewhere is used where CAP_SYS_NICE can be used to override the uid equivalence check, fixing it might be tough. task_setscheduler note: this also controls cpuset:attach_task. Are we ok with CAP_SYS_NICE being used to confine to a cpuset? task_setioprio task_setnice sys_setpriority uses this (through set_one_prio) for another process. Need same checks as setrlimit Aug 21: Updated secureexec implementation to reflect the fact that euid and uid might be the same and nonzero, but the process might still have elevated caps. Aug 15: Handle endianness of xattrs. Enforce capability version match between kernel and disk. Enforce that no bits beyond the known max capability are set, else return -EPERM. With this extra processing, it may be worth reconsidering doing all the work at bprm_set_security rather than d_instantiate. Aug 10: Always call getxattr at bprm_set_security, rather than caching it at d_instantiate. [morgan@kernel.org: file-caps clean up for linux/capability.h] [bunk@kernel.org: unexport cap_inode_killpriv] Signed-off-by: Serge E. Hallyn <serue@us.ibm.com> Cc: Stephen Smalley <sds@tycho.nsa.gov> Cc: James Morris <jmorris@namei.org> Cc: Chris Wright <chrisw@sous-sol.org> Cc: Andrew Morgan <morgan@kernel.org> Signed-off-by: Andrew Morgan <morgan@kernel.org> Signed-off-by: Adrian Bunk <bunk@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/capability.h')
-rw-r--r--include/linux/capability.h48
1 files changed, 34 insertions, 14 deletions
diff --git a/include/linux/capability.h b/include/linux/capability.h
index 2dfa58555934..8961e7fb755c 100644
--- a/include/linux/capability.h
+++ b/include/linux/capability.h
@@ -1,14 +1,14 @@
1/* 1/*
2 * This is <linux/capability.h> 2 * This is <linux/capability.h>
3 * 3 *
4 * Andrew G. Morgan <morgan@transmeta.com> 4 * Andrew G. Morgan <morgan@kernel.org>
5 * Alexander Kjeldaas <astor@guardian.no> 5 * Alexander Kjeldaas <astor@guardian.no>
6 * with help from Aleph1, Roland Buresund and Andrew Main. 6 * with help from Aleph1, Roland Buresund and Andrew Main.
7 * 7 *
8 * See here for the libcap library ("POSIX draft" compliance): 8 * See here for the libcap library ("POSIX draft" compliance):
9 * 9 *
10 * ftp://linux.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.2/ 10 * ftp://linux.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.6/
11 */ 11 */
12 12
13#ifndef _LINUX_CAPABILITY_H 13#ifndef _LINUX_CAPABILITY_H
14#define _LINUX_CAPABILITY_H 14#define _LINUX_CAPABILITY_H
@@ -28,23 +28,41 @@ struct task_struct;
28 following structure to such a composite is better handled in a user 28 following structure to such a composite is better handled in a user
29 library since the draft standard requires the use of malloc/free 29 library since the draft standard requires the use of malloc/free
30 etc.. */ 30 etc.. */
31 31
32#define _LINUX_CAPABILITY_VERSION 0x19980330 32#define _LINUX_CAPABILITY_VERSION 0x19980330
33 33
34typedef struct __user_cap_header_struct { 34typedef struct __user_cap_header_struct {
35 __u32 version; 35 __u32 version;
36 int pid; 36 int pid;
37} __user *cap_user_header_t; 37} __user *cap_user_header_t;
38 38
39typedef struct __user_cap_data_struct { 39typedef struct __user_cap_data_struct {
40 __u32 effective; 40 __u32 effective;
41 __u32 permitted; 41 __u32 permitted;
42 __u32 inheritable; 42 __u32 inheritable;
43} __user *cap_user_data_t; 43} __user *cap_user_data_t;
44
45#ifdef __KERNEL__
46 44
47#include <asm/current.h> 45#define XATTR_CAPS_SUFFIX "capability"
46#define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
47
48#define XATTR_CAPS_SZ (3*sizeof(__le32))
49#define VFS_CAP_REVISION_MASK 0xFF000000
50#define VFS_CAP_REVISION_1 0x01000000
51
52#define VFS_CAP_REVISION VFS_CAP_REVISION_1
53
54#define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK
55#define VFS_CAP_FLAGS_EFFECTIVE 0x000001
56
57struct vfs_cap_data {
58 __u32 magic_etc; /* Little endian */
59 struct {
60 __u32 permitted; /* Little endian */
61 __u32 inheritable; /* Little endian */
62 } data[1];
63};
64
65#ifdef __KERNEL__
48 66
49/* #define STRICT_CAP_T_TYPECHECKS */ 67/* #define STRICT_CAP_T_TYPECHECKS */
50 68
@@ -59,7 +77,7 @@ typedef struct kernel_cap_struct {
59typedef __u32 kernel_cap_t; 77typedef __u32 kernel_cap_t;
60 78
61#endif 79#endif
62 80
63#define _USER_CAP_HEADER_SIZE (2*sizeof(__u32)) 81#define _USER_CAP_HEADER_SIZE (2*sizeof(__u32))
64#define _KERNEL_CAP_T_SIZE (sizeof(kernel_cap_t)) 82#define _KERNEL_CAP_T_SIZE (sizeof(kernel_cap_t))
65 83
@@ -67,7 +85,7 @@ typedef __u32 kernel_cap_t;
67 85
68 86
69/** 87/**
70 ** POSIX-draft defined capabilities. 88 ** POSIX-draft defined capabilities.
71 **/ 89 **/
72 90
73/* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this 91/* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
@@ -87,7 +105,7 @@ typedef __u32 kernel_cap_t;
87 defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */ 105 defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */
88 106
89#define CAP_DAC_READ_SEARCH 2 107#define CAP_DAC_READ_SEARCH 2
90 108
91/* Overrides all restrictions about allowed operations on files, where 109/* Overrides all restrictions about allowed operations on files, where
92 file owner ID must be equal to the user ID, except where CAP_FSETID 110 file owner ID must be equal to the user ID, except where CAP_FSETID
93 is applicable. It doesn't override MAC and DAC restrictions. */ 111 is applicable. It doesn't override MAC and DAC restrictions. */
@@ -257,7 +275,7 @@ typedef __u32 kernel_cap_t;
257/* Override reserved space on ext2 filesystem */ 275/* Override reserved space on ext2 filesystem */
258/* Modify data journaling mode on ext3 filesystem (uses journaling 276/* Modify data journaling mode on ext3 filesystem (uses journaling
259 resources) */ 277 resources) */
260/* NOTE: ext2 honors fsuid when checking for resource overrides, so 278/* NOTE: ext2 honors fsuid when checking for resource overrides, so
261 you can override using fsuid too */ 279 you can override using fsuid too */
262/* Override size restrictions on IPC message queues */ 280/* Override size restrictions on IPC message queues */
263/* Allow more than 64hz interrupts from the real-time clock */ 281/* Allow more than 64hz interrupts from the real-time clock */
@@ -289,8 +307,10 @@ typedef __u32 kernel_cap_t;
289 307
290#define CAP_AUDIT_CONTROL 30 308#define CAP_AUDIT_CONTROL 30
291 309
310#define CAP_SETFCAP 31
311
292#ifdef __KERNEL__ 312#ifdef __KERNEL__
293/* 313/*
294 * Bounding set 314 * Bounding set
295 */ 315 */
296extern kernel_cap_t cap_bset; 316extern kernel_cap_t cap_bset;
@@ -298,7 +318,7 @@ extern kernel_cap_t cap_bset;
298/* 318/*
299 * Internal kernel functions only 319 * Internal kernel functions only
300 */ 320 */
301 321
302#ifdef STRICT_CAP_T_TYPECHECKS 322#ifdef STRICT_CAP_T_TYPECHECKS
303 323
304#define to_cap_t(x) { x } 324#define to_cap_t(x) { x }