2007-10-17 14:29:46 +08:00
|
|
|
/* Authentication token and access key management
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2007-10-17 14:29:46 +08:00
|
|
|
* Copyright (C) 2004, 2007 Red Hat, Inc. All Rights Reserved.
|
2005-04-17 06:20:36 +08:00
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
*
|
2011-05-20 06:59:38 +08:00
|
|
|
* See Documentation/security/keys.txt for information on keys/keyrings.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_KEY_H
|
|
|
|
#define _LINUX_KEY_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/rbtree.h>
|
2005-06-24 13:00:49 +08:00
|
|
|
#include <linux/rcupdate.h>
|
2008-04-29 16:01:32 +08:00
|
|
|
#include <linux/sysctl.h>
|
2009-03-24 16:54:46 +08:00
|
|
|
#include <linux/rwsem.h>
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2013-09-24 17:35:18 +08:00
|
|
|
#include <linux/assoc_array.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
2012-02-08 23:53:04 +08:00
|
|
|
#include <linux/uidgid.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* key handle serial number */
|
|
|
|
typedef int32_t key_serial_t;
|
|
|
|
|
|
|
|
/* key handle permissions mask */
|
|
|
|
typedef uint32_t key_perm_t;
|
|
|
|
|
|
|
|
struct key;
|
|
|
|
|
|
|
|
#ifdef CONFIG_KEYS
|
|
|
|
|
|
|
|
#undef KEY_DEBUGGING
|
|
|
|
|
2005-09-29 00:03:15 +08:00
|
|
|
#define KEY_POS_VIEW 0x01000000 /* possessor can view a key's attributes */
|
|
|
|
#define KEY_POS_READ 0x02000000 /* possessor can read key payload / view keyring */
|
|
|
|
#define KEY_POS_WRITE 0x04000000 /* possessor can update key payload / add link to keyring */
|
|
|
|
#define KEY_POS_SEARCH 0x08000000 /* possessor can find a key in search / search a keyring */
|
|
|
|
#define KEY_POS_LINK 0x10000000 /* possessor can create a link to a key/keyring */
|
2005-10-31 07:02:44 +08:00
|
|
|
#define KEY_POS_SETATTR 0x20000000 /* possessor can set key attributes */
|
|
|
|
#define KEY_POS_ALL 0x3f000000
|
2005-09-29 00:03:15 +08:00
|
|
|
|
|
|
|
#define KEY_USR_VIEW 0x00010000 /* user permissions... */
|
|
|
|
#define KEY_USR_READ 0x00020000
|
|
|
|
#define KEY_USR_WRITE 0x00040000
|
|
|
|
#define KEY_USR_SEARCH 0x00080000
|
|
|
|
#define KEY_USR_LINK 0x00100000
|
2005-10-31 07:02:44 +08:00
|
|
|
#define KEY_USR_SETATTR 0x00200000
|
|
|
|
#define KEY_USR_ALL 0x003f0000
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define KEY_GRP_VIEW 0x00000100 /* group permissions... */
|
|
|
|
#define KEY_GRP_READ 0x00000200
|
|
|
|
#define KEY_GRP_WRITE 0x00000400
|
|
|
|
#define KEY_GRP_SEARCH 0x00000800
|
|
|
|
#define KEY_GRP_LINK 0x00001000
|
2005-10-31 07:02:44 +08:00
|
|
|
#define KEY_GRP_SETATTR 0x00002000
|
|
|
|
#define KEY_GRP_ALL 0x00003f00
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define KEY_OTH_VIEW 0x00000001 /* third party permissions... */
|
|
|
|
#define KEY_OTH_READ 0x00000002
|
|
|
|
#define KEY_OTH_WRITE 0x00000004
|
|
|
|
#define KEY_OTH_SEARCH 0x00000008
|
|
|
|
#define KEY_OTH_LINK 0x00000010
|
2005-10-31 07:02:44 +08:00
|
|
|
#define KEY_OTH_SETATTR 0x00000020
|
|
|
|
#define KEY_OTH_ALL 0x0000003f
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-29 16:01:28 +08:00
|
|
|
#define KEY_PERM_UNDEF 0xffffffff
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct seq_file;
|
|
|
|
struct user_struct;
|
|
|
|
struct signal_struct;
|
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>
2008-11-14 07:39:23 +08:00
|
|
|
struct cred;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct key_type;
|
|
|
|
struct key_owner;
|
|
|
|
struct keyring_list;
|
|
|
|
struct keyring_name;
|
|
|
|
|
2013-09-24 17:35:15 +08:00
|
|
|
struct keyring_index_key {
|
|
|
|
struct key_type *type;
|
|
|
|
const char *description;
|
|
|
|
size_t desc_len;
|
|
|
|
};
|
|
|
|
|
2015-10-21 21:04:48 +08:00
|
|
|
union key_payload {
|
|
|
|
void __rcu *rcu_data0;
|
|
|
|
void *data[4];
|
|
|
|
};
|
|
|
|
|
2005-09-29 00:03:15 +08:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* key reference with possession attribute handling
|
|
|
|
*
|
|
|
|
* NOTE! key_ref_t is a typedef'd pointer to a type that is not actually
|
|
|
|
* defined. This is because we abuse the bottom bit of the reference to carry a
|
|
|
|
* flag to indicate whether the calling process possesses that key in one of
|
|
|
|
* its keyrings.
|
|
|
|
*
|
|
|
|
* the key_ref_t has been made a separate type so that the compiler can reject
|
|
|
|
* attempts to dereference it without proper conversion.
|
|
|
|
*
|
|
|
|
* the three functions are used to assemble and disassemble references
|
|
|
|
*/
|
|
|
|
typedef struct __key_reference_with_attributes *key_ref_t;
|
|
|
|
|
|
|
|
static inline key_ref_t make_key_ref(const struct key *key,
|
2013-09-24 17:35:14 +08:00
|
|
|
bool possession)
|
2005-09-29 00:03:15 +08:00
|
|
|
{
|
|
|
|
return (key_ref_t) ((unsigned long) key | possession);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct key *key_ref_to_ptr(const key_ref_t key_ref)
|
|
|
|
{
|
|
|
|
return (struct key *) ((unsigned long) key_ref & ~1UL);
|
|
|
|
}
|
|
|
|
|
2013-09-24 17:35:14 +08:00
|
|
|
static inline bool is_key_possessed(const key_ref_t key_ref)
|
2005-09-29 00:03:15 +08:00
|
|
|
{
|
|
|
|
return (unsigned long) key_ref & 1UL;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* authentication token / access credential / keyring
|
|
|
|
* - types of key include:
|
|
|
|
* - keyrings
|
|
|
|
* - disk encryption IDs
|
|
|
|
* - Kerberos TGTs and tickets
|
|
|
|
*/
|
|
|
|
struct key {
|
|
|
|
atomic_t usage; /* number of references */
|
|
|
|
key_serial_t serial; /* key serial number */
|
2012-05-11 17:56:56 +08:00
|
|
|
union {
|
|
|
|
struct list_head graveyard_link;
|
|
|
|
struct rb_node serial_node;
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
struct rw_semaphore sem; /* change vs change sem */
|
|
|
|
struct key_user *user; /* owner of this key */
|
2005-10-31 07:02:44 +08:00
|
|
|
void *security; /* security data for this key */
|
2009-09-02 16:14:00 +08:00
|
|
|
union {
|
|
|
|
time_t expiry; /* time at which key expires (or 0) */
|
|
|
|
time_t revoked_at; /* time at which key was revoked */
|
|
|
|
};
|
2012-05-11 17:56:56 +08:00
|
|
|
time_t last_used_at; /* last time used for LRU keyring discard */
|
2012-02-08 23:53:04 +08:00
|
|
|
kuid_t uid;
|
|
|
|
kgid_t gid;
|
2005-04-17 06:20:36 +08:00
|
|
|
key_perm_t perm; /* access permissions */
|
|
|
|
unsigned short quotalen; /* length added to quota */
|
2005-06-24 13:00:49 +08:00
|
|
|
unsigned short datalen; /* payload data length
|
|
|
|
* - may not match RCU dereferenced payload
|
|
|
|
* - payload should contain own length
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef KEY_DEBUGGING
|
|
|
|
unsigned magic;
|
|
|
|
#define KEY_DEBUG_MAGIC 0x18273645u
|
|
|
|
#define KEY_DEBUG_MAGIC_X 0xf8e9dacbu
|
|
|
|
#endif
|
|
|
|
|
2005-06-24 13:00:49 +08:00
|
|
|
unsigned long flags; /* status flags (change with bitops) */
|
|
|
|
#define KEY_FLAG_INSTANTIATED 0 /* set if key has been instantiated */
|
|
|
|
#define KEY_FLAG_DEAD 1 /* set if key type has been deleted */
|
|
|
|
#define KEY_FLAG_REVOKED 2 /* set if key had been revoked */
|
|
|
|
#define KEY_FLAG_IN_QUOTA 3 /* set if key consumes quota */
|
|
|
|
#define KEY_FLAG_USER_CONSTRUCT 4 /* set if key is being constructed in userspace */
|
|
|
|
#define KEY_FLAG_NEGATIVE 5 /* set if key is negative */
|
2012-01-18 23:31:45 +08:00
|
|
|
#define KEY_FLAG_ROOT_CAN_CLEAR 6 /* set if key can be cleared by root without permission */
|
2012-05-11 17:56:56 +08:00
|
|
|
#define KEY_FLAG_INVALIDATED 7 /* set if key has been invalidated */
|
2013-08-30 23:07:37 +08:00
|
|
|
#define KEY_FLAG_TRUSTED 8 /* set if key is trusted */
|
|
|
|
#define KEY_FLAG_TRUSTED_ONLY 9 /* set if keyring only accepts links to trusted keys */
|
2014-06-17 16:56:59 +08:00
|
|
|
#define KEY_FLAG_BUILTIN 10 /* set if key is builtin */
|
2014-07-18 03:45:08 +08:00
|
|
|
#define KEY_FLAG_ROOT_CAN_INVAL 11 /* set if key can be invalidated by root without permission */
|
2015-11-10 21:34:46 +08:00
|
|
|
#define KEY_FLAG_KEEP 12 /* set if key should not be removed */
|
2005-06-24 13:00:49 +08:00
|
|
|
|
2013-09-24 17:35:15 +08:00
|
|
|
/* the key type and key description string
|
|
|
|
* - the desc is used to match a key against search criteria
|
|
|
|
* - it should be a printable string
|
2005-04-17 06:20:36 +08:00
|
|
|
* - eg: for krb5 AFS, this might be "afs@REDHAT.COM"
|
|
|
|
*/
|
2013-09-24 17:35:15 +08:00
|
|
|
union {
|
|
|
|
struct keyring_index_key index_key;
|
|
|
|
struct {
|
|
|
|
struct key_type *type; /* type of key */
|
|
|
|
char *description;
|
|
|
|
};
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* key data
|
|
|
|
* - this is used to hold the data actually used in cryptography or
|
|
|
|
* whatever
|
|
|
|
*/
|
|
|
|
union {
|
2015-10-21 21:04:48 +08:00
|
|
|
union key_payload payload;
|
|
|
|
struct {
|
|
|
|
/* Keyring bits */
|
|
|
|
struct list_head name_link;
|
|
|
|
struct assoc_array keys;
|
|
|
|
};
|
|
|
|
int reject_error;
|
2013-09-24 17:35:18 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct key *key_alloc(struct key_type *type,
|
|
|
|
const char *desc,
|
2012-02-08 23:53:04 +08:00
|
|
|
kuid_t uid, kgid_t gid,
|
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>
2008-11-14 07:39:23 +08:00
|
|
|
const struct cred *cred,
|
2006-06-26 15:24:50 +08:00
|
|
|
key_perm_t perm,
|
|
|
|
unsigned long flags);
|
|
|
|
|
|
|
|
|
|
|
|
#define KEY_ALLOC_IN_QUOTA 0x0000 /* add to quota, reject if would overrun */
|
|
|
|
#define KEY_ALLOC_QUOTA_OVERRUN 0x0001 /* add to quota, permit even if overrun */
|
|
|
|
#define KEY_ALLOC_NOT_IN_QUOTA 0x0002 /* not in quota */
|
2013-08-30 23:07:37 +08:00
|
|
|
#define KEY_ALLOC_TRUSTED 0x0004 /* Key should be flagged as trusted */
|
2006-06-26 15:24:50 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
extern void key_revoke(struct key *key);
|
2012-05-11 17:56:56 +08:00
|
|
|
extern void key_invalidate(struct key *key);
|
2005-04-17 06:20:36 +08:00
|
|
|
extern void key_put(struct key *key);
|
|
|
|
|
2013-09-24 17:35:16 +08:00
|
|
|
static inline struct key *__key_get(struct key *key)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-09-24 17:35:16 +08:00
|
|
|
atomic_inc(&key->usage);
|
2005-04-17 06:20:36 +08:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2013-09-24 17:35:16 +08:00
|
|
|
static inline struct key *key_get(struct key *key)
|
|
|
|
{
|
|
|
|
return key ? __key_get(key) : key;
|
|
|
|
}
|
|
|
|
|
2005-09-29 00:03:15 +08:00
|
|
|
static inline void key_ref_put(key_ref_t key_ref)
|
|
|
|
{
|
|
|
|
key_put(key_ref_to_ptr(key_ref));
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
extern struct key *request_key(struct key_type *type,
|
|
|
|
const char *description,
|
|
|
|
const char *callout_info);
|
|
|
|
|
2006-06-29 17:24:28 +08:00
|
|
|
extern struct key *request_key_with_auxdata(struct key_type *type,
|
|
|
|
const char *description,
|
2008-04-29 16:01:24 +08:00
|
|
|
const void *callout_info,
|
|
|
|
size_t callout_len,
|
2006-06-29 17:24:28 +08:00
|
|
|
void *aux);
|
|
|
|
|
2007-10-17 14:29:46 +08:00
|
|
|
extern struct key *request_key_async(struct key_type *type,
|
|
|
|
const char *description,
|
2008-04-29 16:01:24 +08:00
|
|
|
const void *callout_info,
|
|
|
|
size_t callout_len);
|
2007-10-17 14:29:46 +08:00
|
|
|
|
|
|
|
extern struct key *request_key_async_with_auxdata(struct key_type *type,
|
|
|
|
const char *description,
|
2008-04-29 16:01:24 +08:00
|
|
|
const void *callout_info,
|
|
|
|
size_t callout_len,
|
2007-10-17 14:29:46 +08:00
|
|
|
void *aux);
|
|
|
|
|
|
|
|
extern int wait_for_key_construction(struct key *key, bool intr);
|
|
|
|
|
2012-05-15 21:11:11 +08:00
|
|
|
extern int key_validate(const struct key *key);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-29 00:03:15 +08:00
|
|
|
extern key_ref_t key_create_or_update(key_ref_t keyring,
|
|
|
|
const char *type,
|
|
|
|
const char *description,
|
|
|
|
const void *payload,
|
|
|
|
size_t plen,
|
2008-04-29 16:01:28 +08:00
|
|
|
key_perm_t perm,
|
2006-06-26 15:24:50 +08:00
|
|
|
unsigned long flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-29 00:03:15 +08:00
|
|
|
extern int key_update(key_ref_t key,
|
2005-04-17 06:20:36 +08:00
|
|
|
const void *payload,
|
|
|
|
size_t plen);
|
|
|
|
|
|
|
|
extern int key_link(struct key *keyring,
|
|
|
|
struct key *key);
|
|
|
|
|
|
|
|
extern int key_unlink(struct key *keyring,
|
|
|
|
struct key *key);
|
|
|
|
|
2012-02-08 23:53:04 +08:00
|
|
|
extern struct key *keyring_alloc(const char *description, kuid_t uid, kgid_t gid,
|
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>
2008-11-14 07:39:23 +08:00
|
|
|
const struct cred *cred,
|
2012-10-03 02:24:56 +08:00
|
|
|
key_perm_t perm,
|
2006-06-26 15:24:50 +08:00
|
|
|
unsigned long flags,
|
2006-06-23 05:47:17 +08:00
|
|
|
struct key *dest);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
extern int keyring_clear(struct key *keyring);
|
|
|
|
|
2005-09-29 00:03:15 +08:00
|
|
|
extern key_ref_t keyring_search(key_ref_t keyring,
|
|
|
|
struct key_type *type,
|
|
|
|
const char *description);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
extern int keyring_add_key(struct key *keyring,
|
|
|
|
struct key *key);
|
|
|
|
|
|
|
|
extern struct key *key_lookup(key_serial_t id);
|
|
|
|
|
2012-01-18 18:04:29 +08:00
|
|
|
static inline key_serial_t key_serial(const struct key *key)
|
2008-04-29 16:01:34 +08:00
|
|
|
{
|
|
|
|
return key ? key->serial : 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-02-25 03:14:50 +08:00
|
|
|
extern void key_set_timeout(struct key *, unsigned);
|
|
|
|
|
2014-03-15 01:44:49 +08:00
|
|
|
/*
|
|
|
|
* The permissions required on a key that we're looking up.
|
|
|
|
*/
|
|
|
|
#define KEY_NEED_VIEW 0x01 /* Require permission to view attributes */
|
|
|
|
#define KEY_NEED_READ 0x02 /* Require permission to read content */
|
|
|
|
#define KEY_NEED_WRITE 0x04 /* Require permission to update / modify */
|
|
|
|
#define KEY_NEED_SEARCH 0x08 /* Require permission to search (keyring) or find (key) */
|
|
|
|
#define KEY_NEED_LINK 0x10 /* Require permission to link */
|
|
|
|
#define KEY_NEED_SETATTR 0x20 /* Require permission to change attributes */
|
|
|
|
#define KEY_NEED_ALL 0x3f /* All the above permissions */
|
|
|
|
|
2011-03-12 01:57:23 +08:00
|
|
|
/**
|
|
|
|
* key_is_instantiated - Determine if a key has been positively instantiated
|
|
|
|
* @key: The key to check.
|
|
|
|
*
|
|
|
|
* Return true if the specified key has been positively instantiated, false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
static inline bool key_is_instantiated(const struct key *key)
|
|
|
|
{
|
|
|
|
return test_bit(KEY_FLAG_INSTANTIATED, &key->flags) &&
|
|
|
|
!test_bit(KEY_FLAG_NEGATIVE, &key->flags);
|
|
|
|
}
|
|
|
|
|
2011-03-07 23:05:51 +08:00
|
|
|
#define rcu_dereference_key(KEY) \
|
2015-10-21 21:04:48 +08:00
|
|
|
(rcu_dereference_protected((KEY)->payload.rcu_data0, \
|
2011-03-07 23:05:51 +08:00
|
|
|
rwsem_is_locked(&((struct key *)(KEY))->sem)))
|
|
|
|
|
2012-01-18 04:39:51 +08:00
|
|
|
#define rcu_assign_keypointer(KEY, PAYLOAD) \
|
2012-05-17 07:31:38 +08:00
|
|
|
do { \
|
2015-10-21 21:04:48 +08:00
|
|
|
rcu_assign_pointer((KEY)->payload.rcu_data0, (PAYLOAD)); \
|
2012-05-17 07:31:38 +08:00
|
|
|
} while (0)
|
2012-01-18 04:39:51 +08:00
|
|
|
|
2008-04-29 16:01:32 +08:00
|
|
|
#ifdef CONFIG_SYSCTL
|
2014-06-07 05:38:06 +08:00
|
|
|
extern struct ctl_table key_sysctls[];
|
2008-04-29 16:01:32 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* the userspace interface
|
|
|
|
*/
|
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>
2008-11-14 07:39:23 +08:00
|
|
|
extern int install_thread_keyring_to_cred(struct cred *cred);
|
2005-04-17 06:20:36 +08:00
|
|
|
extern void key_fsuid_changed(struct task_struct *tsk);
|
|
|
|
extern void key_fsgid_changed(struct task_struct *tsk);
|
|
|
|
extern void key_init(void);
|
|
|
|
|
|
|
|
#else /* CONFIG_KEYS */
|
|
|
|
|
|
|
|
#define key_validate(k) 0
|
|
|
|
#define key_serial(k) 0
|
2005-06-24 13:00:51 +08:00
|
|
|
#define key_get(k) ({ NULL; })
|
2008-10-12 12:10:50 +08:00
|
|
|
#define key_revoke(k) do { } while(0)
|
2012-05-11 17:56:56 +08:00
|
|
|
#define key_invalidate(k) do { } while(0)
|
2005-04-17 06:20:36 +08:00
|
|
|
#define key_put(k) do { } while(0)
|
2005-09-29 00:03:15 +08:00
|
|
|
#define key_ref_put(k) do { } while(0)
|
KEYS: Alter use of key instantiation link-to-keyring argument
Alter the use of the key instantiation and negation functions' link-to-keyring
arguments. Currently this specifies a keyring in the target process to link
the key into, creating the keyring if it doesn't exist. This, however, can be
a problem for copy-on-write credentials as it means that the instantiating
process can alter the credentials of the requesting process.
This patch alters the behaviour such that:
(1) If keyctl_instantiate_key() or keyctl_negate_key() are given a specific
keyring by ID (ringid >= 0), then that keyring will be used.
(2) If keyctl_instantiate_key() or keyctl_negate_key() are given one of the
special constants that refer to the requesting process's keyrings
(KEY_SPEC_*_KEYRING, all <= 0), then:
(a) If sys_request_key() was given a keyring to use (destringid) then the
key will be attached to that keyring.
(b) If sys_request_key() was given a NULL keyring, then the key being
instantiated will be attached to the default keyring as set by
keyctl_set_reqkey_keyring().
(3) No extra link will be made.
Decision point (1) follows current behaviour, and allows those instantiators
who've searched for a specifically named keyring in the requestor's keyring so
as to partition the keys by type to still have their named keyrings.
Decision point (2) allows the requestor to make sure that the key or keys that
get produced by request_key() go where they want, whilst allowing the
instantiator to request that the key is retained. This is mainly useful for
situations where the instantiator makes a secondary request, the key for which
should be retained by the initial requestor:
+-----------+ +--------------+ +--------------+
| | | | | |
| Requestor |------->| Instantiator |------->| Instantiator |
| | | | | |
+-----------+ +--------------+ +--------------+
request_key() request_key()
This might be useful, for example, in Kerberos, where the requestor requests a
ticket, and then the ticket instantiator requests the TGT, which someone else
then has to go and fetch. The TGT, however, should be retained in the
keyrings of the requestor, not the first instantiator. To make this explict
an extra special keyring constant is also added.
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:14 +08:00
|
|
|
#define make_key_ref(k, p) NULL
|
|
|
|
#define key_ref_to_ptr(k) NULL
|
2005-09-29 00:03:15 +08:00
|
|
|
#define is_key_possessed(k) 0
|
2005-04-17 06:20:36 +08:00
|
|
|
#define key_fsuid_changed(t) do { } while(0)
|
|
|
|
#define key_fsgid_changed(t) do { } while(0)
|
|
|
|
#define key_init() do { } while(0)
|
|
|
|
|
|
|
|
#endif /* CONFIG_KEYS */
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
#endif /* _LINUX_KEY_H */
|