diff options
author | David Howells <dhowells@redhat.com> | 2008-11-13 18:39:23 -0500 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2008-11-13 18:39:23 -0500 |
commit | d84f4f992cbd76e8f39c488cf0c5d123843923b1 (patch) | |
tree | fc4a0349c42995715b93d0f7a3c78e9ea9b3f36e /include/linux/security.h | |
parent | 745ca2475a6ac596e3d8d37c2759c0fbe2586227 (diff) |
CRED: Inaugurate COW credentials
Inaugurate copy-on-write credentials management. This uses RCU to manage the
credentials pointer in the task_struct with respect to accesses by other tasks.
A process may only modify its own credentials, and so does not need locking to
access or modify its own credentials.
A mutex (cred_replace_mutex) is added to the task_struct to control the effect
of PTRACE_ATTACHED on credential calculations, particularly with respect to
execve().
With this patch, the contents of an active credentials struct may not be
changed directly; rather a new set of credentials must be prepared, modified
and committed using something like the following sequence of events:
struct cred *new = prepare_creds();
int ret = blah(new);
if (ret < 0) {
abort_creds(new);
return ret;
}
return commit_creds(new);
There are some exceptions to this rule: the keyrings pointed to by the active
credentials may be instantiated - keyrings violate the COW rule as managing
COW keyrings is tricky, given that it is possible for a task to directly alter
the keys in a keyring in use by another task.
To help enforce this, various pointers to sets of credentials, such as those in
the task_struct, are declared const. The purpose of this is compile-time
discouragement of altering credentials through those pointers. Once a set of
credentials has been made public through one of these pointers, it may not be
modified, except under special circumstances:
(1) Its reference count may incremented and decremented.
(2) The keyrings to which it points may be modified, but not replaced.
The only safe way to modify anything else is to create a replacement and commit
using the functions described in Documentation/credentials.txt (which will be
added by a later patch).
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
This now prepares and commits credentials in various places in the
security code rather than altering the current creds directly.
(2) Temporary credential overrides.
do_coredump() and sys_faccessat() now prepare their own credentials and
temporarily override the ones currently on the acting thread, whilst
preventing interference from other threads by holding cred_replace_mutex
on the thread being dumped.
This will be replaced in a future patch by something that hands down the
credentials directly to the functions being called, rather than altering
the task's objective credentials.
(3) LSM interface.
A number of functions have been changed, added or removed:
(*) security_capset_check(), ->capset_check()
(*) security_capset_set(), ->capset_set()
Removed in favour of security_capset().
(*) security_capset(), ->capset()
New. This is passed a pointer to the new creds, a pointer to the old
creds and the proposed capability sets. It should fill in the new
creds or return an error. All pointers, barring the pointer to the
new creds, are now const.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
Changed; now returns a value, which will cause the process to be
killed if it's an error.
(*) security_task_alloc(), ->task_alloc_security()
Removed in favour of security_prepare_creds().
(*) security_cred_free(), ->cred_free()
New. Free security data attached to cred->security.
(*) security_prepare_creds(), ->cred_prepare()
New. Duplicate any security data attached to cred->security.
(*) security_commit_creds(), ->cred_commit()
New. Apply any security effects for the upcoming installation of new
security by commit_creds().
(*) security_task_post_setuid(), ->task_post_setuid()
Removed in favour of security_task_fix_setuid().
(*) security_task_fix_setuid(), ->task_fix_setuid()
Fix up the proposed new credentials for setuid(). This is used by
cap_set_fix_setuid() to implicitly adjust capabilities in line with
setuid() changes. Changes are made to the new credentials, rather
than the task itself as in security_task_post_setuid().
(*) security_task_reparent_to_init(), ->task_reparent_to_init()
Removed. Instead the task being reparented to init is referred
directly to init's credentials.
NOTE! This results in the loss of some state: SELinux's osid no
longer records the sid of the thread that forked it.
(*) security_key_alloc(), ->key_alloc()
(*) security_key_permission(), ->key_permission()
Changed. These now take cred pointers rather than task pointers to
refer to the security context.
(4) sys_capset().
This has been simplified and uses less locking. The LSM functions it
calls have been merged.
(5) reparent_to_kthreadd().
This gives the current thread the same credentials as init by simply using
commit_thread() to point that way.
(6) __sigqueue_alloc() and switch_uid()
__sigqueue_alloc() can't stop the target task from changing its creds
beneath it, so this function gets a reference to the currently applicable
user_struct which it then passes into the sigqueue struct it returns if
successful.
switch_uid() is now called from commit_creds(), and possibly should be
folded into that. commit_creds() should take care of protecting
__sigqueue_alloc().
(7) [sg]et[ug]id() and co and [sg]et_current_groups.
The set functions now all use prepare_creds(), commit_creds() and
abort_creds() to build and check a new set of credentials before applying
it.
security_task_set[ug]id() is called inside the prepared section. This
guarantees that nothing else will affect the creds until we've finished.
The calling of set_dumpable() has been moved into commit_creds().
Much of the functionality of set_user() has been moved into
commit_creds().
The get functions all simply access the data directly.
(8) security_task_prctl() and cap_task_prctl().
security_task_prctl() has been modified to return -ENOSYS if it doesn't
want to handle a function, or otherwise return the return value directly
rather than through an argument.
Additionally, cap_task_prctl() now prepares a new set of credentials, even
if it doesn't end up using it.
(9) Keyrings.
A number of changes have been made to the keyrings code:
(a) switch_uid_keyring(), copy_keys(), exit_keys() and suid_keys() have
all been dropped and built in to the credentials functions directly.
They may want separating out again later.
(b) key_alloc() and search_process_keyrings() now take a cred pointer
rather than a task pointer to specify the security context.
(c) copy_creds() gives a new thread within the same thread group a new
thread keyring if its parent had one, otherwise it discards the thread
keyring.
(d) The authorisation key now points directly to the credentials to extend
the search into rather pointing to the task that carries them.
(e) Installing thread, process or session keyrings causes a new set of
credentials to be created, even though it's not strictly necessary for
process or session keyrings (they're shared).
(10) Usermode helper.
The usermode helper code now carries a cred struct pointer in its
subprocess_info struct instead of a new session keyring pointer. This set
of credentials is derived from init_cred and installed on the new process
after it has been cloned.
call_usermodehelper_setup() allocates the new credentials and
call_usermodehelper_freeinfo() discards them if they haven't been used. A
special cred function (prepare_usermodeinfo_creds()) is provided
specifically for call_usermodehelper_setup() to call.
call_usermodehelper_setkeys() adjusts the credentials to sport the
supplied keyring as the new session keyring.
(11) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) selinux_setprocattr() no longer does its check for whether the
current ptracer can access processes with the new SID inside the lock
that covers getting the ptracer's SID. Whilst this lock ensures that
the check is done with the ptracer pinned, the result is only valid
until the lock is released, so there's no point doing it inside the
lock.
(12) is_single_threaded().
This function has been extracted from selinux_setprocattr() and put into
a file of its own in the lib/ directory as join_session_keyring() now
wants to use it too.
The code in SELinux just checked to see whether a task shared mm_structs
with other tasks (CLONE_VM), but that isn't good enough. We really want
to know if they're part of the same thread group (CLONE_THREAD).
(13) nfsd.
The NFS server daemon now has to use the COW credentials to set the
credentials it is going to use. It really needs to pass the credentials
down to the functions it calls, but it can't do that until other patches
in this series have been applied.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'include/linux/security.h')
-rw-r--r-- | include/linux/security.h | 178 |
1 files changed, 82 insertions, 96 deletions
diff --git a/include/linux/security.h b/include/linux/security.h index 7e9fe046a0d..68be1125144 100644 --- a/include/linux/security.h +++ b/include/linux/security.h | |||
@@ -53,24 +53,21 @@ extern int cap_settime(struct timespec *ts, struct timezone *tz); | |||
53 | extern int cap_ptrace_may_access(struct task_struct *child, unsigned int mode); | 53 | extern int cap_ptrace_may_access(struct task_struct *child, unsigned int mode); |
54 | extern int cap_ptrace_traceme(struct task_struct *parent); | 54 | extern int cap_ptrace_traceme(struct task_struct *parent); |
55 | extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); | 55 | extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); |
56 | extern int cap_capset_check(const kernel_cap_t *effective, | 56 | extern int cap_capset(struct cred *new, const struct cred *old, |
57 | const kernel_cap_t *inheritable, | 57 | const kernel_cap_t *effective, |
58 | const kernel_cap_t *permitted); | 58 | const kernel_cap_t *inheritable, |
59 | extern void cap_capset_set(const kernel_cap_t *effective, | 59 | const kernel_cap_t *permitted); |
60 | const kernel_cap_t *inheritable, | ||
61 | const kernel_cap_t *permitted); | ||
62 | extern int cap_bprm_set_security(struct linux_binprm *bprm); | 60 | extern int cap_bprm_set_security(struct linux_binprm *bprm); |
63 | extern void cap_bprm_apply_creds(struct linux_binprm *bprm, int unsafe); | 61 | extern int cap_bprm_apply_creds(struct linux_binprm *bprm, int unsafe); |
64 | extern int cap_bprm_secureexec(struct linux_binprm *bprm); | 62 | extern int cap_bprm_secureexec(struct linux_binprm *bprm); |
65 | extern int cap_inode_setxattr(struct dentry *dentry, const char *name, | 63 | extern int cap_inode_setxattr(struct dentry *dentry, const char *name, |
66 | const void *value, size_t size, int flags); | 64 | const void *value, size_t size, int flags); |
67 | extern int cap_inode_removexattr(struct dentry *dentry, const char *name); | 65 | extern int cap_inode_removexattr(struct dentry *dentry, const char *name); |
68 | extern int cap_inode_need_killpriv(struct dentry *dentry); | 66 | extern int cap_inode_need_killpriv(struct dentry *dentry); |
69 | extern int cap_inode_killpriv(struct dentry *dentry); | 67 | extern int cap_inode_killpriv(struct dentry *dentry); |
70 | extern int cap_task_post_setuid(uid_t old_ruid, uid_t old_euid, uid_t old_suid, int flags); | 68 | extern int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags); |
71 | extern void cap_task_reparent_to_init(struct task_struct *p); | ||
72 | extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3, | 69 | extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3, |
73 | unsigned long arg4, unsigned long arg5, long *rc_p); | 70 | unsigned long arg4, unsigned long arg5); |
74 | extern int cap_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp); | 71 | extern int cap_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp); |
75 | extern int cap_task_setioprio(struct task_struct *p, int ioprio); | 72 | extern int cap_task_setioprio(struct task_struct *p, int ioprio); |
76 | extern int cap_task_setnice(struct task_struct *p, int nice); | 73 | extern int cap_task_setnice(struct task_struct *p, int nice); |
@@ -170,8 +167,8 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
170 | * Compute and set the security attributes of a process being transformed | 167 | * Compute and set the security attributes of a process being transformed |
171 | * by an execve operation based on the old attributes (current->security) | 168 | * by an execve operation based on the old attributes (current->security) |
172 | * and the information saved in @bprm->security by the set_security hook. | 169 | * and the information saved in @bprm->security by the set_security hook. |
173 | * Since this hook function (and its caller) are void, this hook can not | 170 | * Since this function may return an error, in which case the process will |
174 | * return an error. However, it can leave the security attributes of the | 171 | * be killed. However, it can leave the security attributes of the |
175 | * process unchanged if an access failure occurs at this point. | 172 | * process unchanged if an access failure occurs at this point. |
176 | * bprm_apply_creds is called under task_lock. @unsafe indicates various | 173 | * bprm_apply_creds is called under task_lock. @unsafe indicates various |
177 | * reasons why it may be unsafe to change security state. | 174 | * reasons why it may be unsafe to change security state. |
@@ -593,15 +590,18 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
593 | * manual page for definitions of the @clone_flags. | 590 | * manual page for definitions of the @clone_flags. |
594 | * @clone_flags contains the flags indicating what should be shared. | 591 | * @clone_flags contains the flags indicating what should be shared. |
595 | * Return 0 if permission is granted. | 592 | * Return 0 if permission is granted. |
596 | * @cred_alloc_security: | ||
597 | * @cred contains the cred struct for child process. | ||
598 | * Allocate and attach a security structure to the cred->security field. | ||
599 | * The security field is initialized to NULL when the task structure is | ||
600 | * allocated. | ||
601 | * Return 0 if operation was successful. | ||
602 | * @cred_free: | 593 | * @cred_free: |
603 | * @cred points to the credentials. | 594 | * @cred points to the credentials. |
604 | * Deallocate and clear the cred->security field in a set of credentials. | 595 | * Deallocate and clear the cred->security field in a set of credentials. |
596 | * @cred_prepare: | ||
597 | * @new points to the new credentials. | ||
598 | * @old points to the original credentials. | ||
599 | * @gfp indicates the atomicity of any memory allocations. | ||
600 | * Prepare a new set of credentials by copying the data from the old set. | ||
601 | * @cred_commit: | ||
602 | * @new points to the new credentials. | ||
603 | * @old points to the original credentials. | ||
604 | * Install a new set of credentials. | ||
605 | * @task_setuid: | 605 | * @task_setuid: |
606 | * Check permission before setting one or more of the user identity | 606 | * Check permission before setting one or more of the user identity |
607 | * attributes of the current process. The @flags parameter indicates | 607 | * attributes of the current process. The @flags parameter indicates |
@@ -614,15 +614,13 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
614 | * @id2 contains a uid. | 614 | * @id2 contains a uid. |
615 | * @flags contains one of the LSM_SETID_* values. | 615 | * @flags contains one of the LSM_SETID_* values. |
616 | * Return 0 if permission is granted. | 616 | * Return 0 if permission is granted. |
617 | * @task_post_setuid: | 617 | * @task_fix_setuid: |
618 | * Update the module's state after setting one or more of the user | 618 | * Update the module's state after setting one or more of the user |
619 | * identity attributes of the current process. The @flags parameter | 619 | * identity attributes of the current process. The @flags parameter |
620 | * indicates which of the set*uid system calls invoked this hook. If | 620 | * indicates which of the set*uid system calls invoked this hook. If |
621 | * @flags is LSM_SETID_FS, then @old_ruid is the old fs uid and the other | 621 | * @new is the set of credentials that will be installed. Modifications |
622 | * parameters are not used. | 622 | * should be made to this rather than to @current->cred. |
623 | * @old_ruid contains the old real uid (or fs uid if LSM_SETID_FS). | 623 | * @old is the set of credentials that are being replaces |
624 | * @old_euid contains the old effective uid (or -1 if LSM_SETID_FS). | ||
625 | * @old_suid contains the old saved uid (or -1 if LSM_SETID_FS). | ||
626 | * @flags contains one of the LSM_SETID_* values. | 624 | * @flags contains one of the LSM_SETID_* values. |
627 | * Return 0 on success. | 625 | * Return 0 on success. |
628 | * @task_setgid: | 626 | * @task_setgid: |
@@ -725,13 +723,8 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
725 | * @arg3 contains a argument. | 723 | * @arg3 contains a argument. |
726 | * @arg4 contains a argument. | 724 | * @arg4 contains a argument. |
727 | * @arg5 contains a argument. | 725 | * @arg5 contains a argument. |
728 | * @rc_p contains a pointer to communicate back the forced return code | 726 | * Return -ENOSYS if no-one wanted to handle this op, any other value to |
729 | * Return 0 if permission is granted, and non-zero if the security module | 727 | * cause prctl() to return immediately with that value. |
730 | * has taken responsibility (setting *rc_p) for the prctl call. | ||
731 | * @task_reparent_to_init: | ||
732 | * Set the security attributes in @p->security for a kernel thread that | ||
733 | * is being reparented to the init task. | ||
734 | * @p contains the task_struct for the kernel thread. | ||
735 | * @task_to_inode: | 728 | * @task_to_inode: |
736 | * Set the security attributes for an inode based on an associated task's | 729 | * Set the security attributes for an inode based on an associated task's |
737 | * security attributes, e.g. for /proc/pid inodes. | 730 | * security attributes, e.g. for /proc/pid inodes. |
@@ -1008,7 +1001,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
1008 | * See whether a specific operational right is granted to a process on a | 1001 | * See whether a specific operational right is granted to a process on a |
1009 | * key. | 1002 | * key. |
1010 | * @key_ref refers to the key (key pointer + possession attribute bit). | 1003 | * @key_ref refers to the key (key pointer + possession attribute bit). |
1011 | * @context points to the process to provide the context against which to | 1004 | * @cred points to the credentials to provide the context against which to |
1012 | * evaluate the security data on the key. | 1005 | * evaluate the security data on the key. |
1013 | * @perm describes the combination of permissions required of this key. | 1006 | * @perm describes the combination of permissions required of this key. |
1014 | * Return 1 if permission granted, 0 if permission denied and -ve it the | 1007 | * Return 1 if permission granted, 0 if permission denied and -ve it the |
@@ -1170,6 +1163,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
1170 | * @child process. | 1163 | * @child process. |
1171 | * Security modules may also want to perform a process tracing check | 1164 | * Security modules may also want to perform a process tracing check |
1172 | * during an execve in the set_security or apply_creds hooks of | 1165 | * during an execve in the set_security or apply_creds hooks of |
1166 | * tracing check during an execve in the bprm_set_creds hook of | ||
1173 | * binprm_security_ops if the process is being traced and its security | 1167 | * binprm_security_ops if the process is being traced and its security |
1174 | * attributes would be changed by the execve. | 1168 | * attributes would be changed by the execve. |
1175 | * @child contains the task_struct structure for the target process. | 1169 | * @child contains the task_struct structure for the target process. |
@@ -1193,19 +1187,15 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
1193 | * @inheritable contains the inheritable capability set. | 1187 | * @inheritable contains the inheritable capability set. |
1194 | * @permitted contains the permitted capability set. | 1188 | * @permitted contains the permitted capability set. |
1195 | * Return 0 if the capability sets were successfully obtained. | 1189 | * Return 0 if the capability sets were successfully obtained. |
1196 | * @capset_check: | 1190 | * @capset: |
1197 | * Check permission before setting the @effective, @inheritable, and | ||
1198 | * @permitted capability sets for the current process. | ||
1199 | * @effective contains the effective capability set. | ||
1200 | * @inheritable contains the inheritable capability set. | ||
1201 | * @permitted contains the permitted capability set. | ||
1202 | * Return 0 if permission is granted. | ||
1203 | * @capset_set: | ||
1204 | * Set the @effective, @inheritable, and @permitted capability sets for | 1191 | * Set the @effective, @inheritable, and @permitted capability sets for |
1205 | * the current process. | 1192 | * the current process. |
1193 | * @new contains the new credentials structure for target process. | ||
1194 | * @old contains the current credentials structure for target process. | ||
1206 | * @effective contains the effective capability set. | 1195 | * @effective contains the effective capability set. |
1207 | * @inheritable contains the inheritable capability set. | 1196 | * @inheritable contains the inheritable capability set. |
1208 | * @permitted contains the permitted capability set. | 1197 | * @permitted contains the permitted capability set. |
1198 | * Return 0 and update @new if permission is granted. | ||
1209 | * @capable: | 1199 | * @capable: |
1210 | * Check whether the @tsk process has the @cap capability. | 1200 | * Check whether the @tsk process has the @cap capability. |
1211 | * @tsk contains the task_struct for the process. | 1201 | * @tsk contains the task_struct for the process. |
@@ -1297,12 +1287,11 @@ struct security_operations { | |||
1297 | int (*capget) (struct task_struct *target, | 1287 | int (*capget) (struct task_struct *target, |
1298 | kernel_cap_t *effective, | 1288 | kernel_cap_t *effective, |
1299 | kernel_cap_t *inheritable, kernel_cap_t *permitted); | 1289 | kernel_cap_t *inheritable, kernel_cap_t *permitted); |
1300 | int (*capset_check) (const kernel_cap_t *effective, | 1290 | int (*capset) (struct cred *new, |
1301 | const kernel_cap_t *inheritable, | 1291 | const struct cred *old, |
1302 | const kernel_cap_t *permitted); | 1292 | const kernel_cap_t *effective, |
1303 | void (*capset_set) (const kernel_cap_t *effective, | 1293 | const kernel_cap_t *inheritable, |
1304 | const kernel_cap_t *inheritable, | 1294 | const kernel_cap_t *permitted); |
1305 | const kernel_cap_t *permitted); | ||
1306 | int (*capable) (struct task_struct *tsk, int cap, int audit); | 1295 | int (*capable) (struct task_struct *tsk, int cap, int audit); |
1307 | int (*acct) (struct file *file); | 1296 | int (*acct) (struct file *file); |
1308 | int (*sysctl) (struct ctl_table *table, int op); | 1297 | int (*sysctl) (struct ctl_table *table, int op); |
@@ -1314,7 +1303,7 @@ struct security_operations { | |||
1314 | 1303 | ||
1315 | int (*bprm_alloc_security) (struct linux_binprm *bprm); | 1304 | int (*bprm_alloc_security) (struct linux_binprm *bprm); |
1316 | void (*bprm_free_security) (struct linux_binprm *bprm); | 1305 | void (*bprm_free_security) (struct linux_binprm *bprm); |
1317 | void (*bprm_apply_creds) (struct linux_binprm *bprm, int unsafe); | 1306 | int (*bprm_apply_creds) (struct linux_binprm *bprm, int unsafe); |
1318 | void (*bprm_post_apply_creds) (struct linux_binprm *bprm); | 1307 | void (*bprm_post_apply_creds) (struct linux_binprm *bprm); |
1319 | int (*bprm_set_security) (struct linux_binprm *bprm); | 1308 | int (*bprm_set_security) (struct linux_binprm *bprm); |
1320 | int (*bprm_check_security) (struct linux_binprm *bprm); | 1309 | int (*bprm_check_security) (struct linux_binprm *bprm); |
@@ -1405,11 +1394,13 @@ struct security_operations { | |||
1405 | int (*dentry_open) (struct file *file, const struct cred *cred); | 1394 | int (*dentry_open) (struct file *file, const struct cred *cred); |
1406 | 1395 | ||
1407 | int (*task_create) (unsigned long clone_flags); | 1396 | int (*task_create) (unsigned long clone_flags); |
1408 | int (*cred_alloc_security) (struct cred *cred); | ||
1409 | void (*cred_free) (struct cred *cred); | 1397 | void (*cred_free) (struct cred *cred); |
1398 | int (*cred_prepare)(struct cred *new, const struct cred *old, | ||
1399 | gfp_t gfp); | ||
1400 | void (*cred_commit)(struct cred *new, const struct cred *old); | ||
1410 | int (*task_setuid) (uid_t id0, uid_t id1, uid_t id2, int flags); | 1401 | int (*task_setuid) (uid_t id0, uid_t id1, uid_t id2, int flags); |
1411 | int (*task_post_setuid) (uid_t old_ruid /* or fsuid */ , | 1402 | int (*task_fix_setuid) (struct cred *new, const struct cred *old, |
1412 | uid_t old_euid, uid_t old_suid, int flags); | 1403 | int flags); |
1413 | int (*task_setgid) (gid_t id0, gid_t id1, gid_t id2, int flags); | 1404 | int (*task_setgid) (gid_t id0, gid_t id1, gid_t id2, int flags); |
1414 | int (*task_setpgid) (struct task_struct *p, pid_t pgid); | 1405 | int (*task_setpgid) (struct task_struct *p, pid_t pgid); |
1415 | int (*task_getpgid) (struct task_struct *p); | 1406 | int (*task_getpgid) (struct task_struct *p); |
@@ -1429,8 +1420,7 @@ struct security_operations { | |||
1429 | int (*task_wait) (struct task_struct *p); | 1420 | int (*task_wait) (struct task_struct *p); |
1430 | int (*task_prctl) (int option, unsigned long arg2, | 1421 | int (*task_prctl) (int option, unsigned long arg2, |
1431 | unsigned long arg3, unsigned long arg4, | 1422 | unsigned long arg3, unsigned long arg4, |
1432 | unsigned long arg5, long *rc_p); | 1423 | unsigned long arg5); |
1433 | void (*task_reparent_to_init) (struct task_struct *p); | ||
1434 | void (*task_to_inode) (struct task_struct *p, struct inode *inode); | 1424 | void (*task_to_inode) (struct task_struct *p, struct inode *inode); |
1435 | 1425 | ||
1436 | int (*ipc_permission) (struct kern_ipc_perm *ipcp, short flag); | 1426 | int (*ipc_permission) (struct kern_ipc_perm *ipcp, short flag); |
@@ -1535,10 +1525,10 @@ struct security_operations { | |||
1535 | 1525 | ||
1536 | /* key management security hooks */ | 1526 | /* key management security hooks */ |
1537 | #ifdef CONFIG_KEYS | 1527 | #ifdef CONFIG_KEYS |
1538 | int (*key_alloc) (struct key *key, struct task_struct *tsk, unsigned long flags); | 1528 | int (*key_alloc) (struct key *key, const struct cred *cred, unsigned long flags); |
1539 | void (*key_free) (struct key *key); | 1529 | void (*key_free) (struct key *key); |
1540 | int (*key_permission) (key_ref_t key_ref, | 1530 | int (*key_permission) (key_ref_t key_ref, |
1541 | struct task_struct *context, | 1531 | const struct cred *cred, |
1542 | key_perm_t perm); | 1532 | key_perm_t perm); |
1543 | int (*key_getsecurity)(struct key *key, char **_buffer); | 1533 | int (*key_getsecurity)(struct key *key, char **_buffer); |
1544 | #endif /* CONFIG_KEYS */ | 1534 | #endif /* CONFIG_KEYS */ |
@@ -1564,12 +1554,10 @@ int security_capget(struct task_struct *target, | |||
1564 | kernel_cap_t *effective, | 1554 | kernel_cap_t *effective, |
1565 | kernel_cap_t *inheritable, | 1555 | kernel_cap_t *inheritable, |
1566 | kernel_cap_t *permitted); | 1556 | kernel_cap_t *permitted); |
1567 | int security_capset_check(const kernel_cap_t *effective, | 1557 | int security_capset(struct cred *new, const struct cred *old, |
1568 | const kernel_cap_t *inheritable, | 1558 | const kernel_cap_t *effective, |
1569 | const kernel_cap_t *permitted); | 1559 | const kernel_cap_t *inheritable, |
1570 | void security_capset_set(const kernel_cap_t *effective, | 1560 | const kernel_cap_t *permitted); |
1571 | const kernel_cap_t *inheritable, | ||
1572 | const kernel_cap_t *permitted); | ||
1573 | int security_capable(struct task_struct *tsk, int cap); | 1561 | int security_capable(struct task_struct *tsk, int cap); |
1574 | int security_capable_noaudit(struct task_struct *tsk, int cap); | 1562 | int security_capable_noaudit(struct task_struct *tsk, int cap); |
1575 | int security_acct(struct file *file); | 1563 | int security_acct(struct file *file); |
@@ -1583,7 +1571,7 @@ int security_vm_enough_memory_mm(struct mm_struct *mm, long pages); | |||
1583 | int security_vm_enough_memory_kern(long pages); | 1571 | int security_vm_enough_memory_kern(long pages); |
1584 | int security_bprm_alloc(struct linux_binprm *bprm); | 1572 | int security_bprm_alloc(struct linux_binprm *bprm); |
1585 | void security_bprm_free(struct linux_binprm *bprm); | 1573 | void security_bprm_free(struct linux_binprm *bprm); |
1586 | void security_bprm_apply_creds(struct linux_binprm *bprm, int unsafe); | 1574 | int security_bprm_apply_creds(struct linux_binprm *bprm, int unsafe); |
1587 | void security_bprm_post_apply_creds(struct linux_binprm *bprm); | 1575 | void security_bprm_post_apply_creds(struct linux_binprm *bprm); |
1588 | int security_bprm_set(struct linux_binprm *bprm); | 1576 | int security_bprm_set(struct linux_binprm *bprm); |
1589 | int security_bprm_check(struct linux_binprm *bprm); | 1577 | int security_bprm_check(struct linux_binprm *bprm); |
@@ -1660,11 +1648,12 @@ int security_file_send_sigiotask(struct task_struct *tsk, | |||
1660 | int security_file_receive(struct file *file); | 1648 | int security_file_receive(struct file *file); |
1661 | int security_dentry_open(struct file *file, const struct cred *cred); | 1649 | int security_dentry_open(struct file *file, const struct cred *cred); |
1662 | int security_task_create(unsigned long clone_flags); | 1650 | int security_task_create(unsigned long clone_flags); |
1663 | int security_cred_alloc(struct cred *cred); | ||
1664 | void security_cred_free(struct cred *cred); | 1651 | void security_cred_free(struct cred *cred); |
1652 | int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp); | ||
1653 | void security_commit_creds(struct cred *new, const struct cred *old); | ||
1665 | int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags); | 1654 | int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags); |
1666 | int security_task_post_setuid(uid_t old_ruid, uid_t old_euid, | 1655 | int security_task_fix_setuid(struct cred *new, const struct cred *old, |
1667 | uid_t old_suid, int flags); | 1656 | int flags); |
1668 | int security_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags); | 1657 | int security_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags); |
1669 | int security_task_setpgid(struct task_struct *p, pid_t pgid); | 1658 | int security_task_setpgid(struct task_struct *p, pid_t pgid); |
1670 | int security_task_getpgid(struct task_struct *p); | 1659 | int security_task_getpgid(struct task_struct *p); |
@@ -1683,8 +1672,7 @@ int security_task_kill(struct task_struct *p, struct siginfo *info, | |||
1683 | int sig, u32 secid); | 1672 | int sig, u32 secid); |
1684 | int security_task_wait(struct task_struct *p); | 1673 | int security_task_wait(struct task_struct *p); |
1685 | int security_task_prctl(int option, unsigned long arg2, unsigned long arg3, | 1674 | int security_task_prctl(int option, unsigned long arg2, unsigned long arg3, |
1686 | unsigned long arg4, unsigned long arg5, long *rc_p); | 1675 | unsigned long arg4, unsigned long arg5); |
1687 | void security_task_reparent_to_init(struct task_struct *p); | ||
1688 | void security_task_to_inode(struct task_struct *p, struct inode *inode); | 1676 | void security_task_to_inode(struct task_struct *p, struct inode *inode); |
1689 | int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag); | 1677 | int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag); |
1690 | void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid); | 1678 | void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid); |
@@ -1759,18 +1747,13 @@ static inline int security_capget(struct task_struct *target, | |||
1759 | return cap_capget(target, effective, inheritable, permitted); | 1747 | return cap_capget(target, effective, inheritable, permitted); |
1760 | } | 1748 | } |
1761 | 1749 | ||
1762 | static inline int security_capset_check(const kernel_cap_t *effective, | 1750 | static inline int security_capset(struct cred *new, |
1763 | const kernel_cap_t *inheritable, | 1751 | const struct cred *old, |
1764 | const kernel_cap_t *permitted) | 1752 | const kernel_cap_t *effective, |
1753 | const kernel_cap_t *inheritable, | ||
1754 | const kernel_cap_t *permitted) | ||
1765 | { | 1755 | { |
1766 | return cap_capset_check(effective, inheritable, permitted); | 1756 | return cap_capset(new, old, effective, inheritable, permitted); |
1767 | } | ||
1768 | |||
1769 | static inline void security_capset_set(const kernel_cap_t *effective, | ||
1770 | const kernel_cap_t *inheritable, | ||
1771 | const kernel_cap_t *permitted) | ||
1772 | { | ||
1773 | cap_capset_set(effective, inheritable, permitted); | ||
1774 | } | 1757 | } |
1775 | 1758 | ||
1776 | static inline int security_capable(struct task_struct *tsk, int cap) | 1759 | static inline int security_capable(struct task_struct *tsk, int cap) |
@@ -1837,9 +1820,9 @@ static inline int security_bprm_alloc(struct linux_binprm *bprm) | |||
1837 | static inline void security_bprm_free(struct linux_binprm *bprm) | 1820 | static inline void security_bprm_free(struct linux_binprm *bprm) |
1838 | { } | 1821 | { } |
1839 | 1822 | ||
1840 | static inline void security_bprm_apply_creds(struct linux_binprm *bprm, int unsafe) | 1823 | static inline int security_bprm_apply_creds(struct linux_binprm *bprm, int unsafe) |
1841 | { | 1824 | { |
1842 | cap_bprm_apply_creds(bprm, unsafe); | 1825 | return cap_bprm_apply_creds(bprm, unsafe); |
1843 | } | 1826 | } |
1844 | 1827 | ||
1845 | static inline void security_bprm_post_apply_creds(struct linux_binprm *bprm) | 1828 | static inline void security_bprm_post_apply_creds(struct linux_binprm *bprm) |
@@ -2182,13 +2165,20 @@ static inline int security_task_create(unsigned long clone_flags) | |||
2182 | return 0; | 2165 | return 0; |
2183 | } | 2166 | } |
2184 | 2167 | ||
2185 | static inline int security_cred_alloc(struct cred *cred) | 2168 | static inline void security_cred_free(struct cred *cred) |
2169 | { } | ||
2170 | |||
2171 | static inline int security_prepare_creds(struct cred *new, | ||
2172 | const struct cred *old, | ||
2173 | gfp_t gfp) | ||
2186 | { | 2174 | { |
2187 | return 0; | 2175 | return 0; |
2188 | } | 2176 | } |
2189 | 2177 | ||
2190 | static inline void security_cred_free(struct cred *cred) | 2178 | static inline void security_commit_creds(struct cred *new, |
2191 | { } | 2179 | const struct cred *old) |
2180 | { | ||
2181 | } | ||
2192 | 2182 | ||
2193 | static inline int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, | 2183 | static inline int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, |
2194 | int flags) | 2184 | int flags) |
@@ -2196,10 +2186,11 @@ static inline int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, | |||
2196 | return 0; | 2186 | return 0; |
2197 | } | 2187 | } |
2198 | 2188 | ||
2199 | static inline int security_task_post_setuid(uid_t old_ruid, uid_t old_euid, | 2189 | static inline int security_task_fix_setuid(struct cred *new, |
2200 | uid_t old_suid, int flags) | 2190 | const struct cred *old, |
2191 | int flags) | ||
2201 | { | 2192 | { |
2202 | return cap_task_post_setuid(old_ruid, old_euid, old_suid, flags); | 2193 | return cap_task_fix_setuid(new, old, flags); |
2203 | } | 2194 | } |
2204 | 2195 | ||
2205 | static inline int security_task_setgid(gid_t id0, gid_t id1, gid_t id2, | 2196 | static inline int security_task_setgid(gid_t id0, gid_t id1, gid_t id2, |
@@ -2286,14 +2277,9 @@ static inline int security_task_wait(struct task_struct *p) | |||
2286 | static inline int security_task_prctl(int option, unsigned long arg2, | 2277 | static inline int security_task_prctl(int option, unsigned long arg2, |
2287 | unsigned long arg3, | 2278 | unsigned long arg3, |
2288 | unsigned long arg4, | 2279 | unsigned long arg4, |
2289 | unsigned long arg5, long *rc_p) | 2280 | unsigned long arg5) |
2290 | { | ||
2291 | return cap_task_prctl(option, arg2, arg3, arg3, arg5, rc_p); | ||
2292 | } | ||
2293 | |||
2294 | static inline void security_task_reparent_to_init(struct task_struct *p) | ||
2295 | { | 2281 | { |
2296 | cap_task_reparent_to_init(p); | 2282 | return cap_task_prctl(option, arg2, arg3, arg3, arg5); |
2297 | } | 2283 | } |
2298 | 2284 | ||
2299 | static inline void security_task_to_inode(struct task_struct *p, struct inode *inode) | 2285 | static inline void security_task_to_inode(struct task_struct *p, struct inode *inode) |
@@ -2719,16 +2705,16 @@ static inline void security_skb_classify_flow(struct sk_buff *skb, struct flowi | |||
2719 | #ifdef CONFIG_KEYS | 2705 | #ifdef CONFIG_KEYS |
2720 | #ifdef CONFIG_SECURITY | 2706 | #ifdef CONFIG_SECURITY |
2721 | 2707 | ||
2722 | int security_key_alloc(struct key *key, struct task_struct *tsk, unsigned long flags); | 2708 | int security_key_alloc(struct key *key, const struct cred *cred, unsigned long flags); |
2723 | void security_key_free(struct key *key); | 2709 | void security_key_free(struct key *key); |
2724 | int security_key_permission(key_ref_t key_ref, | 2710 | int security_key_permission(key_ref_t key_ref, |
2725 | struct task_struct *context, key_perm_t perm); | 2711 | const struct cred *cred, key_perm_t perm); |
2726 | int security_key_getsecurity(struct key *key, char **_buffer); | 2712 | int security_key_getsecurity(struct key *key, char **_buffer); |
2727 | 2713 | ||
2728 | #else | 2714 | #else |
2729 | 2715 | ||
2730 | static inline int security_key_alloc(struct key *key, | 2716 | static inline int security_key_alloc(struct key *key, |
2731 | struct task_struct *tsk, | 2717 | const struct cred *cred, |
2732 | unsigned long flags) | 2718 | unsigned long flags) |
2733 | { | 2719 | { |
2734 | return 0; | 2720 | return 0; |
@@ -2739,7 +2725,7 @@ static inline void security_key_free(struct key *key) | |||
2739 | } | 2725 | } |
2740 | 2726 | ||
2741 | static inline int security_key_permission(key_ref_t key_ref, | 2727 | static inline int security_key_permission(key_ref_t key_ref, |
2742 | struct task_struct *context, | 2728 | const struct cred *cred, |
2743 | key_perm_t perm) | 2729 | key_perm_t perm) |
2744 | { | 2730 | { |
2745 | return 0; | 2731 | return 0; |