2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Security plug functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
|
|
|
|
* Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
|
|
|
|
* Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.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.
|
|
|
|
*/
|
|
|
|
|
2006-01-12 04:17:46 +08:00
|
|
|
#include <linux/capability.h>
|
2013-05-23 00:50:34 +08:00
|
|
|
#include <linux/dcache.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
2015-05-03 06:10:46 +08:00
|
|
|
#include <linux/lsm_hooks.h>
|
2011-03-10 03:13:22 +08:00
|
|
|
#include <linux/integrity.h>
|
2009-10-23 05:30:13 +08:00
|
|
|
#include <linux/ima.h>
|
2011-03-10 03:38:26 +08:00
|
|
|
#include <linux/evm.h>
|
2012-02-13 11:58:52 +08:00
|
|
|
#include <linux/fsnotify.h>
|
2012-05-31 05:11:23 +08:00
|
|
|
#include <linux/mman.h>
|
|
|
|
#include <linux/mount.h>
|
|
|
|
#include <linux/personality.h>
|
2012-07-02 13:34:11 +08:00
|
|
|
#include <linux/backing-dev.h>
|
2012-02-13 11:58:52 +08:00
|
|
|
#include <net/flow.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-06-16 09:19:10 +08:00
|
|
|
#define MAX_LSM_EVM_XATTR 2
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-03 06:11:42 +08:00
|
|
|
/* Maximum number of letters for an LSM name string */
|
|
|
|
#define SECURITY_NAME_MAX 10
|
|
|
|
|
2008-03-07 00:09:10 +08:00
|
|
|
/* Boot-time LSM user choice */
|
2009-11-06 09:03:20 +08:00
|
|
|
static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
|
|
|
|
CONFIG_DEFAULT_SECURITY;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static void __init do_security_initcalls(void)
|
|
|
|
{
|
|
|
|
initcall_t *call;
|
|
|
|
call = __security_initcall_start;
|
|
|
|
while (call < __security_initcall_end) {
|
|
|
|
(*call) ();
|
|
|
|
call++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* security_init - initializes the security framework
|
|
|
|
*
|
|
|
|
* This should be called early in the kernel initialization sequence.
|
|
|
|
*/
|
|
|
|
int __init security_init(void)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
pr_info("Security Framework initialized\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-03 06:11:42 +08:00
|
|
|
/*
|
2015-07-24 09:02:48 +08:00
|
|
|
* Load minor LSMs, with the capability module always first.
|
2015-05-03 06:11:42 +08:00
|
|
|
*/
|
|
|
|
capability_add_hooks();
|
|
|
|
yama_add_hooks();
|
2015-07-24 09:02:48 +08:00
|
|
|
|
2015-05-03 06:11:42 +08:00
|
|
|
/*
|
2015-07-24 09:02:48 +08:00
|
|
|
* Load all the remaining security modules.
|
2015-05-03 06:11:42 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
do_security_initcalls();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-07 00:09:10 +08:00
|
|
|
/* Save user chosen LSM */
|
|
|
|
static int __init choose_lsm(char *str)
|
|
|
|
{
|
|
|
|
strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("security=", choose_lsm);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* security_module_enable - Load given security module on boot ?
|
2015-05-03 06:11:42 +08:00
|
|
|
* @module: the name of the module
|
2008-03-07 00:09:10 +08:00
|
|
|
*
|
|
|
|
* Each LSM must pass this method before registering its own operations
|
|
|
|
* to avoid security registration races. This method may also be used
|
2008-03-07 09:23:49 +08:00
|
|
|
* to check if your LSM is currently loaded during kernel initialization.
|
2008-03-07 00:09:10 +08:00
|
|
|
*
|
|
|
|
* Return true if:
|
|
|
|
* -The passed LSM is the one chosen by user at boot time,
|
2009-11-06 09:03:20 +08:00
|
|
|
* -or the passed LSM is configured as the default and the user did not
|
2010-08-28 13:58:44 +08:00
|
|
|
* choose an alternate LSM at boot time.
|
2008-03-07 00:09:10 +08:00
|
|
|
* Otherwise, return false.
|
|
|
|
*/
|
2015-05-03 06:11:42 +08:00
|
|
|
int __init security_module_enable(const char *module)
|
2008-03-07 00:09:10 +08:00
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return !strcmp(module, chosen_lsm);
|
2008-03-07 00:09:10 +08:00
|
|
|
}
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
/*
|
2015-05-03 06:11:42 +08:00
|
|
|
* Hook list operation macros.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2015-05-03 06:11:29 +08:00
|
|
|
* call_void_hook:
|
|
|
|
* This is a hook that does not return a value.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2015-05-03 06:11:29 +08:00
|
|
|
* call_int_hook:
|
|
|
|
* This is a hook that returns a value.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2015-05-03 06:11:42 +08:00
|
|
|
#define call_void_hook(FUNC, ...) \
|
|
|
|
do { \
|
|
|
|
struct security_hook_list *P; \
|
|
|
|
\
|
|
|
|
list_for_each_entry(P, &security_hook_heads.FUNC, list) \
|
|
|
|
P->hook.FUNC(__VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define call_int_hook(FUNC, IRC, ...) ({ \
|
|
|
|
int RC = IRC; \
|
|
|
|
do { \
|
|
|
|
struct security_hook_list *P; \
|
|
|
|
\
|
|
|
|
list_for_each_entry(P, &security_hook_heads.FUNC, list) { \
|
|
|
|
RC = P->hook.FUNC(__VA_ARGS__); \
|
|
|
|
if (RC != 0) \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} while (0); \
|
|
|
|
RC; \
|
|
|
|
})
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
/* Security operations */
|
|
|
|
|
2015-01-21 23:54:10 +08:00
|
|
|
int security_binder_set_context_mgr(struct task_struct *mgr)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(binder_set_context_mgr, 0, mgr);
|
2015-01-21 23:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_binder_transaction(struct task_struct *from,
|
|
|
|
struct task_struct *to)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(binder_transaction, 0, from, to);
|
2015-01-21 23:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_binder_transfer_binder(struct task_struct *from,
|
|
|
|
struct task_struct *to)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(binder_transfer_binder, 0, from, to);
|
2015-01-21 23:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_binder_transfer_file(struct task_struct *from,
|
|
|
|
struct task_struct *to, struct file *file)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(binder_transfer_file, 0, from, to, file);
|
2015-01-21 23:54:10 +08:00
|
|
|
}
|
|
|
|
|
2009-05-07 17:26:19 +08:00
|
|
|
int security_ptrace_access_check(struct task_struct *child, unsigned int mode)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(ptrace_access_check, 0, child, mode);
|
security: Fix setting of PF_SUPERPRIV by __capable()
Fix the setting of PF_SUPERPRIV by __capable() as it could corrupt the flags
the target process if that is not the current process and it is trying to
change its own flags in a different way at the same time.
__capable() is using neither atomic ops nor locking to protect t->flags. This
patch removes __capable() and introduces has_capability() that doesn't set
PF_SUPERPRIV on the process being queried.
This patch further splits security_ptrace() in two:
(1) security_ptrace_may_access(). This passes judgement on whether one
process may access another only (PTRACE_MODE_ATTACH for ptrace() and
PTRACE_MODE_READ for /proc), and takes a pointer to the child process.
current is the parent.
(2) security_ptrace_traceme(). This passes judgement on PTRACE_TRACEME only,
and takes only a pointer to the parent process. current is the child.
In Smack and commoncap, this uses has_capability() to determine whether
the parent will be permitted to use PTRACE_ATTACH if normal checks fail.
This does not set PF_SUPERPRIV.
Two of the instances of __capable() actually only act on current, and so have
been changed to calls to capable().
Of the places that were using __capable():
(1) The OOM killer calls __capable() thrice when weighing the killability of a
process. All of these now use has_capability().
(2) cap_ptrace() and smack_ptrace() were using __capable() to check to see
whether the parent was allowed to trace any process. As mentioned above,
these have been split. For PTRACE_ATTACH and /proc, capable() is now
used, and for PTRACE_TRACEME, has_capability() is used.
(3) cap_safe_nice() only ever saw current, so now uses capable().
(4) smack_setprocattr() rejected accesses to tasks other than current just
after calling __capable(), so the order of these two tests have been
switched and capable() is used instead.
(5) In smack_file_send_sigiotask(), we need to allow privileged processes to
receive SIGIO on files they're manipulating.
(6) In smack_task_wait(), we let a process wait for a privileged process,
whether or not the process doing the waiting is privileged.
I've tested this with the LTP SELinux and syscalls testscripts.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Acked-by: Andrew G. Morgan <morgan@kernel.org>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: James Morris <jmorris@namei.org>
2008-08-14 18:37:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_ptrace_traceme(struct task_struct *parent)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(ptrace_traceme, 0, parent);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_capget(struct task_struct *target,
|
|
|
|
kernel_cap_t *effective,
|
|
|
|
kernel_cap_t *inheritable,
|
|
|
|
kernel_cap_t *permitted)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(capget, 0, target,
|
|
|
|
effective, inheritable, permitted);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
int security_capset(struct cred *new, const struct cred *old,
|
|
|
|
const kernel_cap_t *effective,
|
|
|
|
const kernel_cap_t *inheritable,
|
|
|
|
const kernel_cap_t *permitted)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(capset, 0, new, old,
|
|
|
|
effective, inheritable, permitted);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2012-01-04 01:25:15 +08:00
|
|
|
int security_capable(const struct cred *cred, struct user_namespace *ns,
|
userns: security: make capabilities relative to the user namespace
- Introduce ns_capable to test for a capability in a non-default
user namespace.
- Teach cap_capable to handle capabilities in a non-default
user namespace.
The motivation is to get to the unprivileged creation of new
namespaces. It looks like this gets us 90% of the way there, with
only potential uid confusion issues left.
I still need to handle getting all caps after creation but otherwise I
think I have a good starter patch that achieves all of your goals.
Changelog:
11/05/2010: [serge] add apparmor
12/14/2010: [serge] fix capabilities to created user namespaces
Without this, if user serge creates a user_ns, he won't have
capabilities to the user_ns he created. THis is because we
were first checking whether his effective caps had the caps
he needed and returning -EPERM if not, and THEN checking whether
he was the creator. Reverse those checks.
12/16/2010: [serge] security_real_capable needs ns argument in !security case
01/11/2011: [serge] add task_ns_capable helper
01/11/2011: [serge] add nsown_capable() helper per Bastian Blank suggestion
02/16/2011: [serge] fix a logic bug: the root user is always creator of
init_user_ns, but should not always have capabilities to
it! Fix the check in cap_capable().
02/21/2011: Add the required user_ns parameter to security_capable,
fixing a compile failure.
02/23/2011: Convert some macros to functions as per akpm comments. Some
couldn't be converted because we can't easily forward-declare
them (they are inline if !SECURITY, extern if SECURITY). Add
a current_user_ns function so we can use it in capability.h
without #including cred.h. Move all forward declarations
together to the top of the #ifdef __KERNEL__ section, and use
kernel-doc format.
02/23/2011: Per dhowells, clean up comment in cap_capable().
02/23/2011: Per akpm, remove unreachable 'return -EPERM' in cap_capable.
(Original written and signed off by Eric; latest, modified version
acked by him)
[akpm@linux-foundation.org: fix build]
[akpm@linux-foundation.org: export current_user_ns() for ecryptfs]
[serge.hallyn@canonical.com: remove unneeded extra argument in selinux's task_has_capability]
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr>
Acked-by: David Howells <dhowells@redhat.com>
Cc: James Morris <jmorris@namei.org>
Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-03-24 07:43:17 +08:00
|
|
|
int cap)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_AUDIT);
|
2008-11-11 19:02:50 +08:00
|
|
|
}
|
|
|
|
|
2012-01-04 01:25:15 +08:00
|
|
|
int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
|
|
|
|
int cap)
|
2008-11-11 19:02:50 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_NOAUDIT);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_quotactl(int cmds, int type, int id, struct super_block *sb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(quotactl, 0, cmds, type, id, sb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_quota_on(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(quota_on, 0, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2010-11-16 07:36:29 +08:00
|
|
|
int security_syslog(int type)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(syslog, 0, type);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2011-02-01 21:50:58 +08:00
|
|
|
int security_settime(const struct timespec *ts, const struct timezone *tz)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(settime, 0, ts, tz);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
struct security_hook_list *hp;
|
|
|
|
int cap_sys_admin = 1;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The module will respond with a positive value if
|
|
|
|
* it thinks the __vm_enough_memory() call should be
|
|
|
|
* made with the cap_sys_admin set. If all of the modules
|
|
|
|
* agree that it should be set it will. If any module
|
|
|
|
* thinks it should not be set it won't.
|
|
|
|
*/
|
|
|
|
list_for_each_entry(hp, &security_hook_heads.vm_enough_memory, list) {
|
|
|
|
rc = hp->hook.vm_enough_memory(mm, pages);
|
|
|
|
if (rc <= 0) {
|
|
|
|
cap_sys_admin = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return __vm_enough_memory(mm, pages, cap_sys_admin);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
CRED: Make execve() take advantage of copy-on-write credentials
Make execve() take advantage of copy-on-write credentials, allowing it to set
up the credentials in advance, and then commit the whole lot after the point
of no return.
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
The credential bits from struct linux_binprm are, for the most part,
replaced with a single credentials pointer (bprm->cred). This means that
all the creds can be calculated in advance and then applied at the point
of no return with no possibility of failure.
I would like to replace bprm->cap_effective with:
cap_isclear(bprm->cap_effective)
but this seems impossible due to special behaviour for processes of pid 1
(they always retain their parent's capability masks where normally they'd
be changed - see cap_bprm_set_creds()).
The following sequence of events now happens:
(a) At the start of do_execve, the current task's cred_exec_mutex is
locked to prevent PTRACE_ATTACH from obsoleting the calculation of
creds that we make.
(a) prepare_exec_creds() is then called to make a copy of the current
task's credentials and prepare it. This copy is then assigned to
bprm->cred.
This renders security_bprm_alloc() and security_bprm_free()
unnecessary, and so they've been removed.
(b) The determination of unsafe execution is now performed immediately
after (a) rather than later on in the code. The result is stored in
bprm->unsafe for future reference.
(c) prepare_binprm() is called, possibly multiple times.
(i) This applies the result of set[ug]id binaries to the new creds
attached to bprm->cred. Personality bit clearance is recorded,
but now deferred on the basis that the exec procedure may yet
fail.
(ii) This then calls the new security_bprm_set_creds(). This should
calculate the new LSM and capability credentials into *bprm->cred.
This folds together security_bprm_set() and parts of
security_bprm_apply_creds() (these two have been removed).
Anything that might fail must be done at this point.
(iii) bprm->cred_prepared is set to 1.
bprm->cred_prepared is 0 on the first pass of the security
calculations, and 1 on all subsequent passes. This allows SELinux
in (ii) to base its calculations only on the initial script and
not on the interpreter.
(d) flush_old_exec() is called to commit the task to execution. This
performs the following steps with regard to credentials:
(i) Clear pdeath_signal and set dumpable on certain circumstances that
may not be covered by commit_creds().
(ii) Clear any bits in current->personality that were deferred from
(c.i).
(e) install_exec_creds() [compute_creds() as was] is called to install the
new credentials. This performs the following steps with regard to
credentials:
(i) Calls security_bprm_committing_creds() to apply any security
requirements, such as flushing unauthorised files in SELinux, that
must be done before the credentials are changed.
This is made up of bits of security_bprm_apply_creds() and
security_bprm_post_apply_creds(), both of which have been removed.
This function is not allowed to fail; anything that might fail
must have been done in (c.ii).
(ii) Calls commit_creds() to apply the new credentials in a single
assignment (more or less). Possibly pdeath_signal and dumpable
should be part of struct creds.
(iii) Unlocks the task's cred_replace_mutex, thus allowing
PTRACE_ATTACH to take place.
(iv) Clears The bprm->cred pointer as the credentials it was holding
are now immutable.
(v) Calls security_bprm_committed_creds() to apply any security
alterations that must be done after the creds have been changed.
SELinux uses this to flush signals and signal handlers.
(f) If an error occurs before (d.i), bprm_free() will call abort_creds()
to destroy the proposed new credentials and will then unlock
cred_replace_mutex. No changes to the credentials will have been
made.
(2) LSM interface.
A number of functions have been changed, added or removed:
(*) security_bprm_alloc(), ->bprm_alloc_security()
(*) security_bprm_free(), ->bprm_free_security()
Removed in favour of preparing new credentials and modifying those.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
(*) security_bprm_post_apply_creds(), ->bprm_post_apply_creds()
Removed; split between security_bprm_set_creds(),
security_bprm_committing_creds() and security_bprm_committed_creds().
(*) security_bprm_set(), ->bprm_set_security()
Removed; folded into security_bprm_set_creds().
(*) security_bprm_set_creds(), ->bprm_set_creds()
New. The new credentials in bprm->creds should be checked and set up
as appropriate. bprm->cred_prepared is 0 on the first call, 1 on the
second and subsequent calls.
(*) security_bprm_committing_creds(), ->bprm_committing_creds()
(*) security_bprm_committed_creds(), ->bprm_committed_creds()
New. Apply the security effects of the new credentials. This
includes closing unauthorised files in SELinux. This function may not
fail. When the former is called, the creds haven't yet been applied
to the process; when the latter is called, they have.
The former may access bprm->cred, the latter may not.
(3) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) The bprm_security_struct struct has been removed in favour of using
the credentials-under-construction approach.
(c) flush_unauthorized_files() now takes a cred pointer and passes it on
to inode_has_perm(), file_has_perm() and dentry_open().
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:24 +08:00
|
|
|
int security_bprm_set_creds(struct linux_binprm *bprm)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(bprm_set_creds, 0, bprm);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
CRED: Make execve() take advantage of copy-on-write credentials
Make execve() take advantage of copy-on-write credentials, allowing it to set
up the credentials in advance, and then commit the whole lot after the point
of no return.
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
The credential bits from struct linux_binprm are, for the most part,
replaced with a single credentials pointer (bprm->cred). This means that
all the creds can be calculated in advance and then applied at the point
of no return with no possibility of failure.
I would like to replace bprm->cap_effective with:
cap_isclear(bprm->cap_effective)
but this seems impossible due to special behaviour for processes of pid 1
(they always retain their parent's capability masks where normally they'd
be changed - see cap_bprm_set_creds()).
The following sequence of events now happens:
(a) At the start of do_execve, the current task's cred_exec_mutex is
locked to prevent PTRACE_ATTACH from obsoleting the calculation of
creds that we make.
(a) prepare_exec_creds() is then called to make a copy of the current
task's credentials and prepare it. This copy is then assigned to
bprm->cred.
This renders security_bprm_alloc() and security_bprm_free()
unnecessary, and so they've been removed.
(b) The determination of unsafe execution is now performed immediately
after (a) rather than later on in the code. The result is stored in
bprm->unsafe for future reference.
(c) prepare_binprm() is called, possibly multiple times.
(i) This applies the result of set[ug]id binaries to the new creds
attached to bprm->cred. Personality bit clearance is recorded,
but now deferred on the basis that the exec procedure may yet
fail.
(ii) This then calls the new security_bprm_set_creds(). This should
calculate the new LSM and capability credentials into *bprm->cred.
This folds together security_bprm_set() and parts of
security_bprm_apply_creds() (these two have been removed).
Anything that might fail must be done at this point.
(iii) bprm->cred_prepared is set to 1.
bprm->cred_prepared is 0 on the first pass of the security
calculations, and 1 on all subsequent passes. This allows SELinux
in (ii) to base its calculations only on the initial script and
not on the interpreter.
(d) flush_old_exec() is called to commit the task to execution. This
performs the following steps with regard to credentials:
(i) Clear pdeath_signal and set dumpable on certain circumstances that
may not be covered by commit_creds().
(ii) Clear any bits in current->personality that were deferred from
(c.i).
(e) install_exec_creds() [compute_creds() as was] is called to install the
new credentials. This performs the following steps with regard to
credentials:
(i) Calls security_bprm_committing_creds() to apply any security
requirements, such as flushing unauthorised files in SELinux, that
must be done before the credentials are changed.
This is made up of bits of security_bprm_apply_creds() and
security_bprm_post_apply_creds(), both of which have been removed.
This function is not allowed to fail; anything that might fail
must have been done in (c.ii).
(ii) Calls commit_creds() to apply the new credentials in a single
assignment (more or less). Possibly pdeath_signal and dumpable
should be part of struct creds.
(iii) Unlocks the task's cred_replace_mutex, thus allowing
PTRACE_ATTACH to take place.
(iv) Clears The bprm->cred pointer as the credentials it was holding
are now immutable.
(v) Calls security_bprm_committed_creds() to apply any security
alterations that must be done after the creds have been changed.
SELinux uses this to flush signals and signal handlers.
(f) If an error occurs before (d.i), bprm_free() will call abort_creds()
to destroy the proposed new credentials and will then unlock
cred_replace_mutex. No changes to the credentials will have been
made.
(2) LSM interface.
A number of functions have been changed, added or removed:
(*) security_bprm_alloc(), ->bprm_alloc_security()
(*) security_bprm_free(), ->bprm_free_security()
Removed in favour of preparing new credentials and modifying those.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
(*) security_bprm_post_apply_creds(), ->bprm_post_apply_creds()
Removed; split between security_bprm_set_creds(),
security_bprm_committing_creds() and security_bprm_committed_creds().
(*) security_bprm_set(), ->bprm_set_security()
Removed; folded into security_bprm_set_creds().
(*) security_bprm_set_creds(), ->bprm_set_creds()
New. The new credentials in bprm->creds should be checked and set up
as appropriate. bprm->cred_prepared is 0 on the first call, 1 on the
second and subsequent calls.
(*) security_bprm_committing_creds(), ->bprm_committing_creds()
(*) security_bprm_committed_creds(), ->bprm_committed_creds()
New. Apply the security effects of the new credentials. This
includes closing unauthorised files in SELinux. This function may not
fail. When the former is called, the creds haven't yet been applied
to the process; when the latter is called, they have.
The former may access bprm->cred, the latter may not.
(3) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) The bprm_security_struct struct has been removed in favour of using
the credentials-under-construction approach.
(c) flush_unauthorized_files() now takes a cred pointer and passes it on
to inode_has_perm(), file_has_perm() and dentry_open().
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:24 +08:00
|
|
|
int security_bprm_check(struct linux_binprm *bprm)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2009-10-23 05:30:13 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
ret = call_int_hook(bprm_check_security, 0, bprm);
|
2009-10-23 05:30:13 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return ima_bprm_check(bprm);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
CRED: Make execve() take advantage of copy-on-write credentials
Make execve() take advantage of copy-on-write credentials, allowing it to set
up the credentials in advance, and then commit the whole lot after the point
of no return.
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
The credential bits from struct linux_binprm are, for the most part,
replaced with a single credentials pointer (bprm->cred). This means that
all the creds can be calculated in advance and then applied at the point
of no return with no possibility of failure.
I would like to replace bprm->cap_effective with:
cap_isclear(bprm->cap_effective)
but this seems impossible due to special behaviour for processes of pid 1
(they always retain their parent's capability masks where normally they'd
be changed - see cap_bprm_set_creds()).
The following sequence of events now happens:
(a) At the start of do_execve, the current task's cred_exec_mutex is
locked to prevent PTRACE_ATTACH from obsoleting the calculation of
creds that we make.
(a) prepare_exec_creds() is then called to make a copy of the current
task's credentials and prepare it. This copy is then assigned to
bprm->cred.
This renders security_bprm_alloc() and security_bprm_free()
unnecessary, and so they've been removed.
(b) The determination of unsafe execution is now performed immediately
after (a) rather than later on in the code. The result is stored in
bprm->unsafe for future reference.
(c) prepare_binprm() is called, possibly multiple times.
(i) This applies the result of set[ug]id binaries to the new creds
attached to bprm->cred. Personality bit clearance is recorded,
but now deferred on the basis that the exec procedure may yet
fail.
(ii) This then calls the new security_bprm_set_creds(). This should
calculate the new LSM and capability credentials into *bprm->cred.
This folds together security_bprm_set() and parts of
security_bprm_apply_creds() (these two have been removed).
Anything that might fail must be done at this point.
(iii) bprm->cred_prepared is set to 1.
bprm->cred_prepared is 0 on the first pass of the security
calculations, and 1 on all subsequent passes. This allows SELinux
in (ii) to base its calculations only on the initial script and
not on the interpreter.
(d) flush_old_exec() is called to commit the task to execution. This
performs the following steps with regard to credentials:
(i) Clear pdeath_signal and set dumpable on certain circumstances that
may not be covered by commit_creds().
(ii) Clear any bits in current->personality that were deferred from
(c.i).
(e) install_exec_creds() [compute_creds() as was] is called to install the
new credentials. This performs the following steps with regard to
credentials:
(i) Calls security_bprm_committing_creds() to apply any security
requirements, such as flushing unauthorised files in SELinux, that
must be done before the credentials are changed.
This is made up of bits of security_bprm_apply_creds() and
security_bprm_post_apply_creds(), both of which have been removed.
This function is not allowed to fail; anything that might fail
must have been done in (c.ii).
(ii) Calls commit_creds() to apply the new credentials in a single
assignment (more or less). Possibly pdeath_signal and dumpable
should be part of struct creds.
(iii) Unlocks the task's cred_replace_mutex, thus allowing
PTRACE_ATTACH to take place.
(iv) Clears The bprm->cred pointer as the credentials it was holding
are now immutable.
(v) Calls security_bprm_committed_creds() to apply any security
alterations that must be done after the creds have been changed.
SELinux uses this to flush signals and signal handlers.
(f) If an error occurs before (d.i), bprm_free() will call abort_creds()
to destroy the proposed new credentials and will then unlock
cred_replace_mutex. No changes to the credentials will have been
made.
(2) LSM interface.
A number of functions have been changed, added or removed:
(*) security_bprm_alloc(), ->bprm_alloc_security()
(*) security_bprm_free(), ->bprm_free_security()
Removed in favour of preparing new credentials and modifying those.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
(*) security_bprm_post_apply_creds(), ->bprm_post_apply_creds()
Removed; split between security_bprm_set_creds(),
security_bprm_committing_creds() and security_bprm_committed_creds().
(*) security_bprm_set(), ->bprm_set_security()
Removed; folded into security_bprm_set_creds().
(*) security_bprm_set_creds(), ->bprm_set_creds()
New. The new credentials in bprm->creds should be checked and set up
as appropriate. bprm->cred_prepared is 0 on the first call, 1 on the
second and subsequent calls.
(*) security_bprm_committing_creds(), ->bprm_committing_creds()
(*) security_bprm_committed_creds(), ->bprm_committed_creds()
New. Apply the security effects of the new credentials. This
includes closing unauthorised files in SELinux. This function may not
fail. When the former is called, the creds haven't yet been applied
to the process; when the latter is called, they have.
The former may access bprm->cred, the latter may not.
(3) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) The bprm_security_struct struct has been removed in favour of using
the credentials-under-construction approach.
(c) flush_unauthorized_files() now takes a cred pointer and passes it on
to inode_has_perm(), file_has_perm() and dentry_open().
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:24 +08:00
|
|
|
void security_bprm_committing_creds(struct linux_binprm *bprm)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(bprm_committing_creds, bprm);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
CRED: Make execve() take advantage of copy-on-write credentials
Make execve() take advantage of copy-on-write credentials, allowing it to set
up the credentials in advance, and then commit the whole lot after the point
of no return.
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
The credential bits from struct linux_binprm are, for the most part,
replaced with a single credentials pointer (bprm->cred). This means that
all the creds can be calculated in advance and then applied at the point
of no return with no possibility of failure.
I would like to replace bprm->cap_effective with:
cap_isclear(bprm->cap_effective)
but this seems impossible due to special behaviour for processes of pid 1
(they always retain their parent's capability masks where normally they'd
be changed - see cap_bprm_set_creds()).
The following sequence of events now happens:
(a) At the start of do_execve, the current task's cred_exec_mutex is
locked to prevent PTRACE_ATTACH from obsoleting the calculation of
creds that we make.
(a) prepare_exec_creds() is then called to make a copy of the current
task's credentials and prepare it. This copy is then assigned to
bprm->cred.
This renders security_bprm_alloc() and security_bprm_free()
unnecessary, and so they've been removed.
(b) The determination of unsafe execution is now performed immediately
after (a) rather than later on in the code. The result is stored in
bprm->unsafe for future reference.
(c) prepare_binprm() is called, possibly multiple times.
(i) This applies the result of set[ug]id binaries to the new creds
attached to bprm->cred. Personality bit clearance is recorded,
but now deferred on the basis that the exec procedure may yet
fail.
(ii) This then calls the new security_bprm_set_creds(). This should
calculate the new LSM and capability credentials into *bprm->cred.
This folds together security_bprm_set() and parts of
security_bprm_apply_creds() (these two have been removed).
Anything that might fail must be done at this point.
(iii) bprm->cred_prepared is set to 1.
bprm->cred_prepared is 0 on the first pass of the security
calculations, and 1 on all subsequent passes. This allows SELinux
in (ii) to base its calculations only on the initial script and
not on the interpreter.
(d) flush_old_exec() is called to commit the task to execution. This
performs the following steps with regard to credentials:
(i) Clear pdeath_signal and set dumpable on certain circumstances that
may not be covered by commit_creds().
(ii) Clear any bits in current->personality that were deferred from
(c.i).
(e) install_exec_creds() [compute_creds() as was] is called to install the
new credentials. This performs the following steps with regard to
credentials:
(i) Calls security_bprm_committing_creds() to apply any security
requirements, such as flushing unauthorised files in SELinux, that
must be done before the credentials are changed.
This is made up of bits of security_bprm_apply_creds() and
security_bprm_post_apply_creds(), both of which have been removed.
This function is not allowed to fail; anything that might fail
must have been done in (c.ii).
(ii) Calls commit_creds() to apply the new credentials in a single
assignment (more or less). Possibly pdeath_signal and dumpable
should be part of struct creds.
(iii) Unlocks the task's cred_replace_mutex, thus allowing
PTRACE_ATTACH to take place.
(iv) Clears The bprm->cred pointer as the credentials it was holding
are now immutable.
(v) Calls security_bprm_committed_creds() to apply any security
alterations that must be done after the creds have been changed.
SELinux uses this to flush signals and signal handlers.
(f) If an error occurs before (d.i), bprm_free() will call abort_creds()
to destroy the proposed new credentials and will then unlock
cred_replace_mutex. No changes to the credentials will have been
made.
(2) LSM interface.
A number of functions have been changed, added or removed:
(*) security_bprm_alloc(), ->bprm_alloc_security()
(*) security_bprm_free(), ->bprm_free_security()
Removed in favour of preparing new credentials and modifying those.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
(*) security_bprm_post_apply_creds(), ->bprm_post_apply_creds()
Removed; split between security_bprm_set_creds(),
security_bprm_committing_creds() and security_bprm_committed_creds().
(*) security_bprm_set(), ->bprm_set_security()
Removed; folded into security_bprm_set_creds().
(*) security_bprm_set_creds(), ->bprm_set_creds()
New. The new credentials in bprm->creds should be checked and set up
as appropriate. bprm->cred_prepared is 0 on the first call, 1 on the
second and subsequent calls.
(*) security_bprm_committing_creds(), ->bprm_committing_creds()
(*) security_bprm_committed_creds(), ->bprm_committed_creds()
New. Apply the security effects of the new credentials. This
includes closing unauthorised files in SELinux. This function may not
fail. When the former is called, the creds haven't yet been applied
to the process; when the latter is called, they have.
The former may access bprm->cred, the latter may not.
(3) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) The bprm_security_struct struct has been removed in favour of using
the credentials-under-construction approach.
(c) flush_unauthorized_files() now takes a cred pointer and passes it on
to inode_has_perm(), file_has_perm() and dentry_open().
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:24 +08:00
|
|
|
void security_bprm_committed_creds(struct linux_binprm *bprm)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(bprm_committed_creds, bprm);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_bprm_secureexec(struct linux_binprm *bprm)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(bprm_secureexec, 0, bprm);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sb_alloc(struct super_block *sb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_alloc_security, 0, sb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_sb_free(struct super_block *sb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sb_free_security, sb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-03-05 23:31:54 +08:00
|
|
|
int security_sb_copy_data(char *orig, char *copy)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_copy_data, 0, orig, copy);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2008-03-05 23:31:54 +08:00
|
|
|
EXPORT_SYMBOL(security_sb_copy_data);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
2011-03-04 05:09:14 +08:00
|
|
|
int security_sb_remount(struct super_block *sb, void *data)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_remount, 0, sb, data);
|
2011-03-04 05:09:14 +08:00
|
|
|
}
|
|
|
|
|
2008-12-19 07:44:42 +08:00
|
|
|
int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_kern_mount, 0, sb, flags, data);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-07-04 07:47:13 +08:00
|
|
|
int security_sb_show_options(struct seq_file *m, struct super_block *sb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_show_options, 0, m, sb);
|
2008-07-04 07:47:13 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_sb_statfs(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_statfs, 0, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2012-10-11 23:42:01 +08:00
|
|
|
int security_sb_mount(const char *dev_name, struct path *path,
|
|
|
|
const char *type, unsigned long flags, void *data)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sb_umount(struct vfsmount *mnt, int flags)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_umount, 0, mnt, flags);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-03-23 05:48:24 +08:00
|
|
|
int security_sb_pivotroot(struct path *old_path, struct path *new_path)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_pivotroot, 0, old_path, new_path);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2007-12-01 02:00:35 +08:00
|
|
|
int security_sb_set_mnt_opts(struct super_block *sb,
|
2013-05-23 00:50:36 +08:00
|
|
|
struct security_mnt_opts *opts,
|
|
|
|
unsigned long kern_flags,
|
|
|
|
unsigned long *set_kern_flags)
|
2007-12-01 02:00:35 +08:00
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(sb_set_mnt_opts,
|
|
|
|
opts->num_mnt_opts ? -EOPNOTSUPP : 0, sb,
|
|
|
|
opts, kern_flags, set_kern_flags);
|
2007-12-01 02:00:35 +08:00
|
|
|
}
|
2008-03-05 23:31:54 +08:00
|
|
|
EXPORT_SYMBOL(security_sb_set_mnt_opts);
|
2007-12-01 02:00:35 +08:00
|
|
|
|
selinux: make security_sb_clone_mnt_opts return an error on context mismatch
I had the following problem reported a while back. If you mount the
same filesystem twice using NFSv4 with different contexts, then the
second context= option is ignored. For instance:
# mount server:/export /mnt/test1
# mount server:/export /mnt/test2 -o context=system_u:object_r:tmp_t:s0
# ls -dZ /mnt/test1
drwxrwxrwt. root root system_u:object_r:nfs_t:s0 /mnt/test1
# ls -dZ /mnt/test2
drwxrwxrwt. root root system_u:object_r:nfs_t:s0 /mnt/test2
When we call into SELinux to set the context of a "cloned" superblock,
it will currently just bail out when it notices that we're reusing an
existing superblock. Since the existing superblock is already set up and
presumably in use, we can't go overwriting its context with the one from
the "original" sb. Because of this, the second context= option in this
case cannot take effect.
This patch fixes this by turning security_sb_clone_mnt_opts into an int
return operation. When it finds that the "new" superblock that it has
been handed is already set up, it checks to see whether the contexts on
the old superblock match it. If it does, then it will just return
success, otherwise it'll return -EBUSY and emit a printk to tell the
admin why the second mount failed.
Note that this patch may cause casualties. The NFSv4 code relies on
being able to walk down to an export from the pseudoroot. If you mount
filesystems that are nested within one another with different contexts,
then this patch will make those mounts fail in new and "exciting" ways.
For instance, suppose that /export is a separate filesystem on the
server:
# mount server:/ /mnt/test1
# mount salusa:/export /mnt/test2 -o context=system_u:object_r:tmp_t:s0
mount.nfs: an incorrect mount option was specified
...with the printk in the ring buffer. Because we *might* eventually
walk down to /mnt/test1/export, the mount is denied due to this patch.
The second mount needs the pseudoroot superblock, but that's already
present with the wrong context.
OTOH, if we mount these in the reverse order, then both mounts work,
because the pseudoroot superblock created when mounting /export is
discarded once that mount is done. If we then however try to walk into
that directory, the automount fails for the similar reasons:
# cd /mnt/test1/scratch/
-bash: cd: /mnt/test1/scratch: Device or resource busy
The story I've gotten from the SELinux folks that I've talked to is that
this is desirable behavior. In SELinux-land, mounting the same data
under different contexts is wrong -- there can be only one.
Cc: Steve Dickson <steved@redhat.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Acked-by: Eric Paris <eparis@redhat.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
2013-04-01 20:14:24 +08:00
|
|
|
int security_sb_clone_mnt_opts(const struct super_block *oldsb,
|
2007-12-01 02:00:35 +08:00
|
|
|
struct super_block *newsb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_clone_mnt_opts, 0, oldsb, newsb);
|
2007-12-01 02:00:35 +08:00
|
|
|
}
|
2008-03-05 23:31:54 +08:00
|
|
|
EXPORT_SYMBOL(security_sb_clone_mnt_opts);
|
|
|
|
|
|
|
|
int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_parse_opts_str, 0, options, opts);
|
2008-03-05 23:31:54 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sb_parse_opts_str);
|
2007-12-01 02:00:35 +08:00
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_inode_alloc(struct inode *inode)
|
|
|
|
{
|
|
|
|
inode->i_security = NULL;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_alloc_security, 0, inode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_inode_free(struct inode *inode)
|
|
|
|
{
|
2011-03-10 03:13:22 +08:00
|
|
|
integrity_inode_free(inode);
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(inode_free_security, inode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2013-05-23 00:50:34 +08:00
|
|
|
int security_dentry_init_security(struct dentry *dentry, int mode,
|
|
|
|
struct qstr *name, void **ctx,
|
|
|
|
u32 *ctxlen)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode,
|
|
|
|
name, ctx, ctxlen);
|
2013-05-23 00:50:34 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_dentry_init_security);
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_inode_init_security(struct inode *inode, struct inode *dir,
|
2011-06-07 03:29:25 +08:00
|
|
|
const struct qstr *qstr,
|
|
|
|
const initxattrs initxattrs, void *fs_data)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2011-06-16 09:19:10 +08:00
|
|
|
struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1];
|
|
|
|
struct xattr *lsm_xattr, *evm_xattr, *xattr;
|
2011-06-07 03:29:25 +08:00
|
|
|
int ret;
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2011-08-15 22:13:18 +08:00
|
|
|
return 0;
|
2011-06-07 03:29:25 +08:00
|
|
|
|
|
|
|
if (!initxattrs)
|
2015-08-24 20:22:25 +08:00
|
|
|
return call_int_hook(inode_init_security, -EOPNOTSUPP, inode,
|
|
|
|
dir, qstr, NULL, NULL, NULL);
|
2013-07-25 04:44:02 +08:00
|
|
|
memset(new_xattrs, 0, sizeof(new_xattrs));
|
2011-06-07 03:29:25 +08:00
|
|
|
lsm_xattr = new_xattrs;
|
2015-05-03 06:11:42 +08:00
|
|
|
ret = call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir, qstr,
|
2011-06-07 03:29:25 +08:00
|
|
|
&lsm_xattr->name,
|
|
|
|
&lsm_xattr->value,
|
|
|
|
&lsm_xattr->value_len);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2011-06-16 09:19:10 +08:00
|
|
|
|
|
|
|
evm_xattr = lsm_xattr + 1;
|
|
|
|
ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2011-06-07 03:29:25 +08:00
|
|
|
ret = initxattrs(inode, new_xattrs, fs_data);
|
|
|
|
out:
|
2013-07-25 04:44:02 +08:00
|
|
|
for (xattr = new_xattrs; xattr->value != NULL; xattr++)
|
2011-06-16 09:19:10 +08:00
|
|
|
kfree(xattr->value);
|
2011-06-07 03:29:25 +08:00
|
|
|
return (ret == -EOPNOTSUPP) ? 0 : ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_init_security);
|
|
|
|
|
|
|
|
int security_old_inode_init_security(struct inode *inode, struct inode *dir,
|
2013-07-25 04:44:02 +08:00
|
|
|
const struct qstr *qstr, const char **name,
|
2011-06-07 03:29:25 +08:00
|
|
|
void **value, size_t *len)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2012-01-03 20:14:29 +08:00
|
|
|
return -EOPNOTSUPP;
|
2015-08-24 20:22:25 +08:00
|
|
|
return call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir,
|
|
|
|
qstr, name, value, len);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2011-06-07 03:29:25 +08:00
|
|
|
EXPORT_SYMBOL(security_old_inode_init_security);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
2008-12-17 12:24:15 +08:00
|
|
|
#ifdef CONFIG_SECURITY_PATH
|
2011-11-22 03:58:38 +08:00
|
|
|
int security_path_mknod(struct path *dir, struct dentry *dentry, umode_t mode,
|
2008-12-17 12:24:15 +08:00
|
|
|
unsigned int dev)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_mknod, 0, dir, dentry, mode, dev);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_path_mknod);
|
|
|
|
|
2011-11-22 03:56:21 +08:00
|
|
|
int security_path_mkdir(struct path *dir, struct dentry *dentry, umode_t mode)
|
2008-12-17 12:24:15 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_mkdir, 0, dir, dentry, mode);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
2010-12-24 22:48:35 +08:00
|
|
|
EXPORT_SYMBOL(security_path_mkdir);
|
2008-12-17 12:24:15 +08:00
|
|
|
|
2009-11-26 14:24:49 +08:00
|
|
|
int security_path_rmdir(struct path *dir, struct dentry *dentry)
|
2008-12-17 12:24:15 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_rmdir, 0, dir, dentry);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
|
|
|
|
2009-11-26 14:24:49 +08:00
|
|
|
int security_path_unlink(struct path *dir, struct dentry *dentry)
|
2008-12-17 12:24:15 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_unlink, 0, dir, dentry);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
2010-12-24 22:48:35 +08:00
|
|
|
EXPORT_SYMBOL(security_path_unlink);
|
2008-12-17 12:24:15 +08:00
|
|
|
|
2009-11-26 14:24:49 +08:00
|
|
|
int security_path_symlink(struct path *dir, struct dentry *dentry,
|
2008-12-17 12:24:15 +08:00
|
|
|
const char *old_name)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_symlink, 0, dir, dentry, old_name);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_path_link(struct dentry *old_dentry, struct path *new_dir,
|
|
|
|
struct dentry *new_dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
|
2014-04-01 23:08:43 +08:00
|
|
|
struct path *new_dir, struct dentry *new_dentry,
|
|
|
|
unsigned int flags)
|
2008-12-17 12:24:15 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
|
|
|
|
(d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2014-04-01 23:08:43 +08:00
|
|
|
|
|
|
|
if (flags & RENAME_EXCHANGE) {
|
2015-05-03 06:11:29 +08:00
|
|
|
int err = call_int_hook(path_rename, 0, new_dir, new_dentry,
|
|
|
|
old_dir, old_dentry);
|
2014-04-01 23:08:43 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_rename, 0, old_dir, old_dentry, new_dir,
|
|
|
|
new_dentry);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
2010-12-24 22:48:35 +08:00
|
|
|
EXPORT_SYMBOL(security_path_rename);
|
2008-12-17 12:24:15 +08:00
|
|
|
|
2010-06-02 12:24:43 +08:00
|
|
|
int security_path_truncate(struct path *path)
|
2008-12-17 12:24:15 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_truncate, 0, path);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
2009-10-04 20:49:47 +08:00
|
|
|
|
2011-12-08 23:51:53 +08:00
|
|
|
int security_path_chmod(struct path *path, umode_t mode)
|
2009-10-04 20:49:47 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2009-10-04 20:49:47 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_chmod, 0, path, mode);
|
2009-10-04 20:49:47 +08:00
|
|
|
}
|
|
|
|
|
2012-06-02 06:14:19 +08:00
|
|
|
int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
|
2009-10-04 20:49:47 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2009-10-04 20:49:47 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_chown, 0, path, uid, gid);
|
2009-10-04 20:49:47 +08:00
|
|
|
}
|
2009-10-04 20:49:48 +08:00
|
|
|
|
|
|
|
int security_path_chroot(struct path *path)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_chroot, 0, path);
|
2009-10-04 20:49:48 +08:00
|
|
|
}
|
2008-12-17 12:24:15 +08:00
|
|
|
#endif
|
|
|
|
|
2011-07-26 13:42:34 +08:00
|
|
|
int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(dir)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_create, 0, dir, dentry, mode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2009-04-03 23:42:40 +08:00
|
|
|
EXPORT_SYMBOL_GPL(security_inode_create);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
|
|
|
int security_inode_link(struct dentry *old_dentry, struct inode *dir,
|
|
|
|
struct dentry *new_dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_unlink(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_unlink, 0, dir, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_symlink(struct inode *dir, struct dentry *dentry,
|
|
|
|
const char *old_name)
|
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(dir)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_symlink, 0, dir, dentry, old_name);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2011-07-26 13:41:39 +08:00
|
|
|
int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(dir)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_mkdir, 0, dir, dentry, mode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2009-04-03 23:42:40 +08:00
|
|
|
EXPORT_SYMBOL_GPL(security_inode_mkdir);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
|
|
|
int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_rmdir, 0, dir, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2011-07-26 13:52:52 +08:00
|
|
|
int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(dir)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_mknod, 0, dir, dentry, mode, dev);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
|
2014-04-01 23:08:43 +08:00
|
|
|
struct inode *new_dir, struct dentry *new_dentry,
|
|
|
|
unsigned int flags)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
|
|
|
|
(d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2014-04-01 23:08:43 +08:00
|
|
|
|
|
|
|
if (flags & RENAME_EXCHANGE) {
|
2015-05-03 06:11:29 +08:00
|
|
|
int err = call_int_hook(inode_rename, 0, new_dir, new_dentry,
|
2014-04-01 23:08:43 +08:00
|
|
|
old_dir, old_dentry);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_rename, 0, old_dir, old_dentry,
|
2007-10-17 14:31:32 +08:00
|
|
|
new_dir, new_dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_readlink(struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_readlink, 0, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2015-03-23 10:37:39 +08:00
|
|
|
int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
|
|
|
|
bool rcu)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-03-23 10:37:39 +08:00
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-06-28 04:26:03 +08:00
|
|
|
return call_int_hook(inode_follow_link, 0, dentry, inode, rcu);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-07-17 21:37:02 +08:00
|
|
|
int security_inode_permission(struct inode *inode, int mask)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_permission, 0, inode, mask);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
|
|
|
|
{
|
2011-05-14 00:53:38 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
ret = call_int_hook(inode_setattr, 0, dentry, attr);
|
2011-05-14 00:53:38 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return evm_inode_setattr(dentry, attr);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2008-07-01 21:01:28 +08:00
|
|
|
EXPORT_SYMBOL_GPL(security_inode_setattr);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
2015-03-09 07:28:30 +08:00
|
|
|
int security_inode_getattr(const struct path *path)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_getattr, 0, path);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 15:59:41 +08:00
|
|
|
int security_inode_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
const void *value, size_t size, int flags)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2011-03-10 03:38:26 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:42 +08:00
|
|
|
/*
|
|
|
|
* SELinux and Smack integrate the cap call,
|
|
|
|
* so assume that all LSMs supplying this call do so.
|
|
|
|
*/
|
|
|
|
ret = call_int_hook(inode_setxattr, 1, dentry, name, value, size,
|
2015-05-03 06:11:29 +08:00
|
|
|
flags);
|
2015-05-03 06:11:42 +08:00
|
|
|
|
|
|
|
if (ret == 1)
|
|
|
|
ret = cap_inode_setxattr(dentry, name, value, size, flags);
|
2011-03-11 07:54:15 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = ima_inode_setxattr(dentry, name, value, size);
|
2011-03-10 03:38:26 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return evm_inode_setxattr(dentry, name, value, size);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 15:59:41 +08:00
|
|
|
void security_inode_post_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
const void *value, size_t size, int flags)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return;
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(inode_post_setxattr, dentry, name, value, size, flags);
|
2011-03-10 03:38:26 +08:00
|
|
|
evm_inode_post_setxattr(dentry, name, value, size);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 15:59:41 +08:00
|
|
|
int security_inode_getxattr(struct dentry *dentry, const char *name)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_getxattr, 0, dentry, name);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_listxattr(struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_listxattr, 0, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 15:59:41 +08:00
|
|
|
int security_inode_removexattr(struct dentry *dentry, const char *name)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2011-03-10 03:38:26 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:42 +08:00
|
|
|
/*
|
|
|
|
* SELinux and Smack integrate the cap call,
|
|
|
|
* so assume that all LSMs supplying this call do so.
|
|
|
|
*/
|
|
|
|
ret = call_int_hook(inode_removexattr, 1, dentry, name);
|
|
|
|
if (ret == 1)
|
|
|
|
ret = cap_inode_removexattr(dentry, name);
|
2011-03-11 07:54:15 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = ima_inode_removexattr(dentry, name);
|
2011-03-10 03:38:26 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return evm_inode_removexattr(dentry, name);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
Implement file posix capabilities
Implement file posix capabilities. This allows programs to be given a
subset of root's powers regardless of who runs them, without having to use
setuid and giving the binary all of root's powers.
This version works with Kaigai Kohei's userspace tools, found at
http://www.kaigai.gr.jp/index.php. For more information on how to use this
patch, Chris Friedhoff has posted a nice page at
http://www.friedhoff.org/fscaps.html.
Changelog:
Nov 27:
Incorporate fixes from Andrew Morton
(security-introduce-file-caps-tweaks and
security-introduce-file-caps-warning-fix)
Fix Kconfig dependency.
Fix change signaling behavior when file caps are not compiled in.
Nov 13:
Integrate comments from Alexey: Remove CONFIG_ ifdef from
capability.h, and use %zd for printing a size_t.
Nov 13:
Fix endianness warnings by sparse as suggested by Alexey
Dobriyan.
Nov 09:
Address warnings of unused variables at cap_bprm_set_security
when file capabilities are disabled, and simultaneously clean
up the code a little, by pulling the new code into a helper
function.
Nov 08:
For pointers to required userspace tools and how to use
them, see http://www.friedhoff.org/fscaps.html.
Nov 07:
Fix the calculation of the highest bit checked in
check_cap_sanity().
Nov 07:
Allow file caps to be enabled without CONFIG_SECURITY, since
capabilities are the default.
Hook cap_task_setscheduler when !CONFIG_SECURITY.
Move capable(TASK_KILL) to end of cap_task_kill to reduce
audit messages.
Nov 05:
Add secondary calls in selinux/hooks.c to task_setioprio and
task_setscheduler so that selinux and capabilities with file
cap support can be stacked.
Sep 05:
As Seth Arnold points out, uid checks are out of place
for capability code.
Sep 01:
Define task_setscheduler, task_setioprio, cap_task_kill, and
task_setnice to make sure a user cannot affect a process in which
they called a program with some fscaps.
One remaining question is the note under task_setscheduler: are we
ok with CAP_SYS_NICE being sufficient to confine a process to a
cpuset?
It is a semantic change, as without fsccaps, attach_task doesn't
allow CAP_SYS_NICE to override the uid equivalence check. But since
it uses security_task_setscheduler, which elsewhere is used where
CAP_SYS_NICE can be used to override the uid equivalence check,
fixing it might be tough.
task_setscheduler
note: this also controls cpuset:attach_task. Are we ok with
CAP_SYS_NICE being used to confine to a cpuset?
task_setioprio
task_setnice
sys_setpriority uses this (through set_one_prio) for another
process. Need same checks as setrlimit
Aug 21:
Updated secureexec implementation to reflect the fact that
euid and uid might be the same and nonzero, but the process
might still have elevated caps.
Aug 15:
Handle endianness of xattrs.
Enforce capability version match between kernel and disk.
Enforce that no bits beyond the known max capability are
set, else return -EPERM.
With this extra processing, it may be worth reconsidering
doing all the work at bprm_set_security rather than
d_instantiate.
Aug 10:
Always call getxattr at bprm_set_security, rather than
caching it at d_instantiate.
[morgan@kernel.org: file-caps clean up for linux/capability.h]
[bunk@kernel.org: unexport cap_inode_killpriv]
Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: James Morris <jmorris@namei.org>
Cc: Chris Wright <chrisw@sous-sol.org>
Cc: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Adrian Bunk <bunk@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-17 14:31:36 +08:00
|
|
|
int security_inode_need_killpriv(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_need_killpriv, 0, dentry);
|
Implement file posix capabilities
Implement file posix capabilities. This allows programs to be given a
subset of root's powers regardless of who runs them, without having to use
setuid and giving the binary all of root's powers.
This version works with Kaigai Kohei's userspace tools, found at
http://www.kaigai.gr.jp/index.php. For more information on how to use this
patch, Chris Friedhoff has posted a nice page at
http://www.friedhoff.org/fscaps.html.
Changelog:
Nov 27:
Incorporate fixes from Andrew Morton
(security-introduce-file-caps-tweaks and
security-introduce-file-caps-warning-fix)
Fix Kconfig dependency.
Fix change signaling behavior when file caps are not compiled in.
Nov 13:
Integrate comments from Alexey: Remove CONFIG_ ifdef from
capability.h, and use %zd for printing a size_t.
Nov 13:
Fix endianness warnings by sparse as suggested by Alexey
Dobriyan.
Nov 09:
Address warnings of unused variables at cap_bprm_set_security
when file capabilities are disabled, and simultaneously clean
up the code a little, by pulling the new code into a helper
function.
Nov 08:
For pointers to required userspace tools and how to use
them, see http://www.friedhoff.org/fscaps.html.
Nov 07:
Fix the calculation of the highest bit checked in
check_cap_sanity().
Nov 07:
Allow file caps to be enabled without CONFIG_SECURITY, since
capabilities are the default.
Hook cap_task_setscheduler when !CONFIG_SECURITY.
Move capable(TASK_KILL) to end of cap_task_kill to reduce
audit messages.
Nov 05:
Add secondary calls in selinux/hooks.c to task_setioprio and
task_setscheduler so that selinux and capabilities with file
cap support can be stacked.
Sep 05:
As Seth Arnold points out, uid checks are out of place
for capability code.
Sep 01:
Define task_setscheduler, task_setioprio, cap_task_kill, and
task_setnice to make sure a user cannot affect a process in which
they called a program with some fscaps.
One remaining question is the note under task_setscheduler: are we
ok with CAP_SYS_NICE being sufficient to confine a process to a
cpuset?
It is a semantic change, as without fsccaps, attach_task doesn't
allow CAP_SYS_NICE to override the uid equivalence check. But since
it uses security_task_setscheduler, which elsewhere is used where
CAP_SYS_NICE can be used to override the uid equivalence check,
fixing it might be tough.
task_setscheduler
note: this also controls cpuset:attach_task. Are we ok with
CAP_SYS_NICE being used to confine to a cpuset?
task_setioprio
task_setnice
sys_setpriority uses this (through set_one_prio) for another
process. Need same checks as setrlimit
Aug 21:
Updated secureexec implementation to reflect the fact that
euid and uid might be the same and nonzero, but the process
might still have elevated caps.
Aug 15:
Handle endianness of xattrs.
Enforce capability version match between kernel and disk.
Enforce that no bits beyond the known max capability are
set, else return -EPERM.
With this extra processing, it may be worth reconsidering
doing all the work at bprm_set_security rather than
d_instantiate.
Aug 10:
Always call getxattr at bprm_set_security, rather than
caching it at d_instantiate.
[morgan@kernel.org: file-caps clean up for linux/capability.h]
[bunk@kernel.org: unexport cap_inode_killpriv]
Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: James Morris <jmorris@namei.org>
Cc: Chris Wright <chrisw@sous-sol.org>
Cc: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Adrian Bunk <bunk@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-17 14:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_killpriv(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_killpriv, 0, dentry);
|
Implement file posix capabilities
Implement file posix capabilities. This allows programs to be given a
subset of root's powers regardless of who runs them, without having to use
setuid and giving the binary all of root's powers.
This version works with Kaigai Kohei's userspace tools, found at
http://www.kaigai.gr.jp/index.php. For more information on how to use this
patch, Chris Friedhoff has posted a nice page at
http://www.friedhoff.org/fscaps.html.
Changelog:
Nov 27:
Incorporate fixes from Andrew Morton
(security-introduce-file-caps-tweaks and
security-introduce-file-caps-warning-fix)
Fix Kconfig dependency.
Fix change signaling behavior when file caps are not compiled in.
Nov 13:
Integrate comments from Alexey: Remove CONFIG_ ifdef from
capability.h, and use %zd for printing a size_t.
Nov 13:
Fix endianness warnings by sparse as suggested by Alexey
Dobriyan.
Nov 09:
Address warnings of unused variables at cap_bprm_set_security
when file capabilities are disabled, and simultaneously clean
up the code a little, by pulling the new code into a helper
function.
Nov 08:
For pointers to required userspace tools and how to use
them, see http://www.friedhoff.org/fscaps.html.
Nov 07:
Fix the calculation of the highest bit checked in
check_cap_sanity().
Nov 07:
Allow file caps to be enabled without CONFIG_SECURITY, since
capabilities are the default.
Hook cap_task_setscheduler when !CONFIG_SECURITY.
Move capable(TASK_KILL) to end of cap_task_kill to reduce
audit messages.
Nov 05:
Add secondary calls in selinux/hooks.c to task_setioprio and
task_setscheduler so that selinux and capabilities with file
cap support can be stacked.
Sep 05:
As Seth Arnold points out, uid checks are out of place
for capability code.
Sep 01:
Define task_setscheduler, task_setioprio, cap_task_kill, and
task_setnice to make sure a user cannot affect a process in which
they called a program with some fscaps.
One remaining question is the note under task_setscheduler: are we
ok with CAP_SYS_NICE being sufficient to confine a process to a
cpuset?
It is a semantic change, as without fsccaps, attach_task doesn't
allow CAP_SYS_NICE to override the uid equivalence check. But since
it uses security_task_setscheduler, which elsewhere is used where
CAP_SYS_NICE can be used to override the uid equivalence check,
fixing it might be tough.
task_setscheduler
note: this also controls cpuset:attach_task. Are we ok with
CAP_SYS_NICE being used to confine to a cpuset?
task_setioprio
task_setnice
sys_setpriority uses this (through set_one_prio) for another
process. Need same checks as setrlimit
Aug 21:
Updated secureexec implementation to reflect the fact that
euid and uid might be the same and nonzero, but the process
might still have elevated caps.
Aug 15:
Handle endianness of xattrs.
Enforce capability version match between kernel and disk.
Enforce that no bits beyond the known max capability are
set, else return -EPERM.
With this extra processing, it may be worth reconsidering
doing all the work at bprm_set_security rather than
d_instantiate.
Aug 10:
Always call getxattr at bprm_set_security, rather than
caching it at d_instantiate.
[morgan@kernel.org: file-caps clean up for linux/capability.h]
[bunk@kernel.org: unexport cap_inode_killpriv]
Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: James Morris <jmorris@namei.org>
Cc: Chris Wright <chrisw@sous-sol.org>
Cc: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Adrian Bunk <bunk@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-17 14:31:36 +08:00
|
|
|
}
|
|
|
|
|
2015-12-25 00:09:39 +08:00
|
|
|
int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2010-01-14 06:33:28 +08:00
|
|
|
return -EOPNOTSUPP;
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(inode_getsecurity, -EOPNOTSUPP, inode, name,
|
|
|
|
buffer, alloc);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
|
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2010-01-14 06:33:28 +08:00
|
|
|
return -EOPNOTSUPP;
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(inode_setsecurity, -EOPNOTSUPP, inode, name,
|
|
|
|
value, size, flags);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
|
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_listsecurity, 0, inode, buffer, buffer_size);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2013-05-23 00:50:45 +08:00
|
|
|
EXPORT_SYMBOL(security_inode_listsecurity);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
2015-12-25 00:09:39 +08:00
|
|
|
void security_inode_getsecid(struct inode *inode, u32 *secid)
|
2008-03-02 03:51:09 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(inode_getsecid, inode, secid);
|
2008-03-02 03:51:09 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_file_permission(struct file *file, int mask)
|
|
|
|
{
|
2009-12-18 10:24:34 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
ret = call_int_hook(file_permission, 0, file, mask);
|
2009-12-18 10:24:34 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return fsnotify_perm(file, mask);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_alloc(struct file *file)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_alloc_security, 0, file);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_file_free(struct file *file)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(file_free_security, file);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_ioctl, 0, file, cmd, arg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2012-05-31 07:58:30 +08:00
|
|
|
static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2012-05-31 05:11:23 +08:00
|
|
|
/*
|
2012-05-31 07:58:30 +08:00
|
|
|
* Does we have PROT_READ and does the application expect
|
|
|
|
* it to imply PROT_EXEC? If not, nothing to talk about...
|
2012-05-31 05:11:23 +08:00
|
|
|
*/
|
2012-05-31 07:58:30 +08:00
|
|
|
if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ)
|
|
|
|
return prot;
|
2012-05-31 05:11:23 +08:00
|
|
|
if (!(current->personality & READ_IMPLIES_EXEC))
|
2012-05-31 07:58:30 +08:00
|
|
|
return prot;
|
|
|
|
/*
|
|
|
|
* if that's an anonymous mapping, let it.
|
|
|
|
*/
|
|
|
|
if (!file)
|
|
|
|
return prot | PROT_EXEC;
|
|
|
|
/*
|
|
|
|
* ditto if it's not on noexec mount, except that on !MMU we need
|
2015-01-14 17:42:32 +08:00
|
|
|
* NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
|
2012-05-31 07:58:30 +08:00
|
|
|
*/
|
2015-06-30 03:42:03 +08:00
|
|
|
if (!path_noexec(&file->f_path)) {
|
2012-05-31 05:11:23 +08:00
|
|
|
#ifndef CONFIG_MMU
|
2015-01-14 17:42:32 +08:00
|
|
|
if (file->f_op->mmap_capabilities) {
|
|
|
|
unsigned caps = file->f_op->mmap_capabilities(file);
|
|
|
|
if (!(caps & NOMMU_MAP_EXEC))
|
|
|
|
return prot;
|
|
|
|
}
|
2012-05-31 05:11:23 +08:00
|
|
|
#endif
|
2012-05-31 07:58:30 +08:00
|
|
|
return prot | PROT_EXEC;
|
2012-05-31 05:11:23 +08:00
|
|
|
}
|
2012-05-31 07:58:30 +08:00
|
|
|
/* anything on noexec mount won't get PROT_EXEC */
|
|
|
|
return prot;
|
|
|
|
}
|
|
|
|
|
|
|
|
int security_mmap_file(struct file *file, unsigned long prot,
|
|
|
|
unsigned long flags)
|
|
|
|
{
|
|
|
|
int ret;
|
2015-05-03 06:11:29 +08:00
|
|
|
ret = call_int_hook(mmap_file, 0, file, prot,
|
2012-05-31 07:58:30 +08:00
|
|
|
mmap_prot(file, prot), flags);
|
2009-10-23 05:30:13 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return ima_file_mmap(file, prot);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2012-05-31 01:30:51 +08:00
|
|
|
int security_mmap_addr(unsigned long addr)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(mmap_addr, 0, addr);
|
2012-05-31 01:30:51 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
|
|
|
|
unsigned long prot)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_mprotect, 0, vma, reqprot, prot);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_lock(struct file *file, unsigned int cmd)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_lock, 0, file, cmd);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_fcntl, 0, file, cmd, arg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2014-08-22 23:27:32 +08:00
|
|
|
void security_file_set_fowner(struct file *file)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(file_set_fowner, file);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_send_sigiotask(struct task_struct *tsk,
|
|
|
|
struct fown_struct *fown, int sig)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_send_sigiotask, 0, tsk, fown, sig);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_receive(struct file *file)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_receive, 0, file);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2012-04-05 01:45:40 +08:00
|
|
|
int security_file_open(struct file *file, const struct cred *cred)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2009-12-18 10:24:34 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
ret = call_int_hook(file_open, 0, file, cred);
|
2009-12-18 10:24:34 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return fsnotify_perm(file, MAY_OPEN);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_create(unsigned long clone_flags)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_create, 0, clone_flags);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2011-12-22 04:17:03 +08:00
|
|
|
void security_task_free(struct task_struct *task)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(task_free, task);
|
2011-12-22 04:17:03 +08:00
|
|
|
}
|
|
|
|
|
KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]
Add a keyctl to install a process's session keyring onto its parent. This
replaces the parent's session keyring. Because the COW credential code does
not permit one process to change another process's credentials directly, the
change is deferred until userspace next starts executing again. Normally this
will be after a wait*() syscall.
To support this, three new security hooks have been provided:
cred_alloc_blank() to allocate unset security creds, cred_transfer() to fill in
the blank security creds and key_session_to_parent() - which asks the LSM if
the process may replace its parent's session keyring.
The replacement may only happen if the process has the same ownership details
as its parent, and the process has LINK permission on the session keyring, and
the session keyring is owned by the process, and the LSM permits it.
Note that this requires alteration to each architecture's notify_resume path.
This has been done for all arches barring blackfin, m68k* and xtensa, all of
which need assembly alteration to support TIF_NOTIFY_RESUME. This allows the
replacement to be performed at the point the parent process resumes userspace
execution.
This allows the userspace AFS pioctl emulation to fully emulate newpag() and
the VIOCSETTOK and VIOCSETTOK2 pioctls, all of which require the ability to
alter the parent process's PAG membership. However, since kAFS doesn't use
PAGs per se, but rather dumps the keys into the session keyring, the session
keyring of the parent must be replaced if, for example, VIOCSETTOK is passed
the newpag flag.
This can be tested with the following program:
#include <stdio.h>
#include <stdlib.h>
#include <keyutils.h>
#define KEYCTL_SESSION_TO_PARENT 18
#define OSERROR(X, S) do { if ((long)(X) == -1) { perror(S); exit(1); } } while(0)
int main(int argc, char **argv)
{
key_serial_t keyring, key;
long ret;
keyring = keyctl_join_session_keyring(argv[1]);
OSERROR(keyring, "keyctl_join_session_keyring");
key = add_key("user", "a", "b", 1, keyring);
OSERROR(key, "add_key");
ret = keyctl(KEYCTL_SESSION_TO_PARENT);
OSERROR(ret, "KEYCTL_SESSION_TO_PARENT");
return 0;
}
Compiled and linked with -lkeyutils, you should see something like:
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
355907932 --alswrv 4043 -1 \_ keyring: _uid.4043
[dhowells@andromeda ~]$ /tmp/newpag
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
1055658746 --alswrv 4043 4043 \_ user: a
[dhowells@andromeda ~]$ /tmp/newpag hello
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: hello
340417692 --alswrv 4043 4043 \_ user: a
Where the test program creates a new session keyring, sticks a user key named
'a' into it and then installs it on its parent.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
2009-09-02 16:14:21 +08:00
|
|
|
int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(cred_alloc_blank, 0, cred, gfp);
|
KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]
Add a keyctl to install a process's session keyring onto its parent. This
replaces the parent's session keyring. Because the COW credential code does
not permit one process to change another process's credentials directly, the
change is deferred until userspace next starts executing again. Normally this
will be after a wait*() syscall.
To support this, three new security hooks have been provided:
cred_alloc_blank() to allocate unset security creds, cred_transfer() to fill in
the blank security creds and key_session_to_parent() - which asks the LSM if
the process may replace its parent's session keyring.
The replacement may only happen if the process has the same ownership details
as its parent, and the process has LINK permission on the session keyring, and
the session keyring is owned by the process, and the LSM permits it.
Note that this requires alteration to each architecture's notify_resume path.
This has been done for all arches barring blackfin, m68k* and xtensa, all of
which need assembly alteration to support TIF_NOTIFY_RESUME. This allows the
replacement to be performed at the point the parent process resumes userspace
execution.
This allows the userspace AFS pioctl emulation to fully emulate newpag() and
the VIOCSETTOK and VIOCSETTOK2 pioctls, all of which require the ability to
alter the parent process's PAG membership. However, since kAFS doesn't use
PAGs per se, but rather dumps the keys into the session keyring, the session
keyring of the parent must be replaced if, for example, VIOCSETTOK is passed
the newpag flag.
This can be tested with the following program:
#include <stdio.h>
#include <stdlib.h>
#include <keyutils.h>
#define KEYCTL_SESSION_TO_PARENT 18
#define OSERROR(X, S) do { if ((long)(X) == -1) { perror(S); exit(1); } } while(0)
int main(int argc, char **argv)
{
key_serial_t keyring, key;
long ret;
keyring = keyctl_join_session_keyring(argv[1]);
OSERROR(keyring, "keyctl_join_session_keyring");
key = add_key("user", "a", "b", 1, keyring);
OSERROR(key, "add_key");
ret = keyctl(KEYCTL_SESSION_TO_PARENT);
OSERROR(ret, "KEYCTL_SESSION_TO_PARENT");
return 0;
}
Compiled and linked with -lkeyutils, you should see something like:
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
355907932 --alswrv 4043 -1 \_ keyring: _uid.4043
[dhowells@andromeda ~]$ /tmp/newpag
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
1055658746 --alswrv 4043 4043 \_ user: a
[dhowells@andromeda ~]$ /tmp/newpag hello
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: hello
340417692 --alswrv 4043 4043 \_ user: a
Where the test program creates a new session keyring, sticks a user key named
'a' into it and then installs it on its parent.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
2009-09-02 16:14:21 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
void security_cred_free(struct cred *cred)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(cred_free, cred);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(cred_prepare, 0, new, old, gfp);
|
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
|
|
|
}
|
|
|
|
|
KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]
Add a keyctl to install a process's session keyring onto its parent. This
replaces the parent's session keyring. Because the COW credential code does
not permit one process to change another process's credentials directly, the
change is deferred until userspace next starts executing again. Normally this
will be after a wait*() syscall.
To support this, three new security hooks have been provided:
cred_alloc_blank() to allocate unset security creds, cred_transfer() to fill in
the blank security creds and key_session_to_parent() - which asks the LSM if
the process may replace its parent's session keyring.
The replacement may only happen if the process has the same ownership details
as its parent, and the process has LINK permission on the session keyring, and
the session keyring is owned by the process, and the LSM permits it.
Note that this requires alteration to each architecture's notify_resume path.
This has been done for all arches barring blackfin, m68k* and xtensa, all of
which need assembly alteration to support TIF_NOTIFY_RESUME. This allows the
replacement to be performed at the point the parent process resumes userspace
execution.
This allows the userspace AFS pioctl emulation to fully emulate newpag() and
the VIOCSETTOK and VIOCSETTOK2 pioctls, all of which require the ability to
alter the parent process's PAG membership. However, since kAFS doesn't use
PAGs per se, but rather dumps the keys into the session keyring, the session
keyring of the parent must be replaced if, for example, VIOCSETTOK is passed
the newpag flag.
This can be tested with the following program:
#include <stdio.h>
#include <stdlib.h>
#include <keyutils.h>
#define KEYCTL_SESSION_TO_PARENT 18
#define OSERROR(X, S) do { if ((long)(X) == -1) { perror(S); exit(1); } } while(0)
int main(int argc, char **argv)
{
key_serial_t keyring, key;
long ret;
keyring = keyctl_join_session_keyring(argv[1]);
OSERROR(keyring, "keyctl_join_session_keyring");
key = add_key("user", "a", "b", 1, keyring);
OSERROR(key, "add_key");
ret = keyctl(KEYCTL_SESSION_TO_PARENT);
OSERROR(ret, "KEYCTL_SESSION_TO_PARENT");
return 0;
}
Compiled and linked with -lkeyutils, you should see something like:
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
355907932 --alswrv 4043 -1 \_ keyring: _uid.4043
[dhowells@andromeda ~]$ /tmp/newpag
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
1055658746 --alswrv 4043 4043 \_ user: a
[dhowells@andromeda ~]$ /tmp/newpag hello
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: hello
340417692 --alswrv 4043 4043 \_ user: a
Where the test program creates a new session keyring, sticks a user key named
'a' into it and then installs it on its parent.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
2009-09-02 16:14:21 +08:00
|
|
|
void security_transfer_creds(struct cred *new, const struct cred *old)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(cred_transfer, new, old);
|
KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]
Add a keyctl to install a process's session keyring onto its parent. This
replaces the parent's session keyring. Because the COW credential code does
not permit one process to change another process's credentials directly, the
change is deferred until userspace next starts executing again. Normally this
will be after a wait*() syscall.
To support this, three new security hooks have been provided:
cred_alloc_blank() to allocate unset security creds, cred_transfer() to fill in
the blank security creds and key_session_to_parent() - which asks the LSM if
the process may replace its parent's session keyring.
The replacement may only happen if the process has the same ownership details
as its parent, and the process has LINK permission on the session keyring, and
the session keyring is owned by the process, and the LSM permits it.
Note that this requires alteration to each architecture's notify_resume path.
This has been done for all arches barring blackfin, m68k* and xtensa, all of
which need assembly alteration to support TIF_NOTIFY_RESUME. This allows the
replacement to be performed at the point the parent process resumes userspace
execution.
This allows the userspace AFS pioctl emulation to fully emulate newpag() and
the VIOCSETTOK and VIOCSETTOK2 pioctls, all of which require the ability to
alter the parent process's PAG membership. However, since kAFS doesn't use
PAGs per se, but rather dumps the keys into the session keyring, the session
keyring of the parent must be replaced if, for example, VIOCSETTOK is passed
the newpag flag.
This can be tested with the following program:
#include <stdio.h>
#include <stdlib.h>
#include <keyutils.h>
#define KEYCTL_SESSION_TO_PARENT 18
#define OSERROR(X, S) do { if ((long)(X) == -1) { perror(S); exit(1); } } while(0)
int main(int argc, char **argv)
{
key_serial_t keyring, key;
long ret;
keyring = keyctl_join_session_keyring(argv[1]);
OSERROR(keyring, "keyctl_join_session_keyring");
key = add_key("user", "a", "b", 1, keyring);
OSERROR(key, "add_key");
ret = keyctl(KEYCTL_SESSION_TO_PARENT);
OSERROR(ret, "KEYCTL_SESSION_TO_PARENT");
return 0;
}
Compiled and linked with -lkeyutils, you should see something like:
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
355907932 --alswrv 4043 -1 \_ keyring: _uid.4043
[dhowells@andromeda ~]$ /tmp/newpag
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
1055658746 --alswrv 4043 4043 \_ user: a
[dhowells@andromeda ~]$ /tmp/newpag hello
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: hello
340417692 --alswrv 4043 4043 \_ user: a
Where the test program creates a new session keyring, sticks a user key named
'a' into it and then installs it on its parent.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
2009-09-02 16:14:21 +08:00
|
|
|
}
|
|
|
|
|
2008-11-14 07:39:28 +08:00
|
|
|
int security_kernel_act_as(struct cred *new, u32 secid)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(kernel_act_as, 0, new, secid);
|
2008-11-14 07:39:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_kernel_create_files_as(struct cred *new, struct inode *inode)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(kernel_create_files_as, 0, new, inode);
|
2008-11-14 07:39:28 +08:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:35:32 +08:00
|
|
|
int security_kernel_module_request(char *kmod_name)
|
2009-08-13 21:44:57 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(kernel_module_request, 0, kmod_name);
|
2009-08-13 21:44:57 +08:00
|
|
|
}
|
|
|
|
|
2016-01-31 11:23:26 +08:00
|
|
|
int security_kernel_read_file(struct file *file, enum kernel_read_file_id id)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = call_int_hook(kernel_read_file, 0, file, id);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return ima_read_file(file, id);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(security_kernel_read_file);
|
|
|
|
|
2016-01-24 23:07:32 +08:00
|
|
|
int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
|
|
|
|
enum kernel_read_file_id id)
|
2015-12-29 05:02:29 +08:00
|
|
|
{
|
2016-01-15 06:57:47 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = call_int_hook(kernel_post_read_file, 0, file, buf, size, id);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return ima_post_read_file(file, buf, size, id);
|
2015-12-29 05:02:29 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(security_kernel_post_read_file);
|
|
|
|
|
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
|
|
|
int security_task_fix_setuid(struct cred *new, const struct cred *old,
|
|
|
|
int flags)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_fix_setuid, 0, new, old, flags);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_setpgid(struct task_struct *p, pid_t pgid)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_setpgid, 0, p, pgid);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getpgid(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_getpgid, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getsid(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_getsid, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_task_getsecid(struct task_struct *p, u32 *secid)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
*secid = 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(task_getsecid, p, secid);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_task_getsecid);
|
|
|
|
|
|
|
|
int security_task_setnice(struct task_struct *p, int nice)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_setnice, 0, p, nice);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_setioprio(struct task_struct *p, int ioprio)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_setioprio, 0, p, ioprio);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getioprio(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_getioprio, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2009-08-27 00:41:16 +08:00
|
|
|
int security_task_setrlimit(struct task_struct *p, unsigned int resource,
|
|
|
|
struct rlimit *new_rlim)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_setrlimit, 0, p, resource, new_rlim);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2010-10-15 03:21:18 +08:00
|
|
|
int security_task_setscheduler(struct task_struct *p)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_setscheduler, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getscheduler(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_getscheduler, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_movememory(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_movememory, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_kill(struct task_struct *p, struct siginfo *info,
|
|
|
|
int sig, u32 secid)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_kill, 0, p, info, sig, secid);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_wait(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_wait, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
|
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
|
|
|
unsigned long arg4, unsigned long arg5)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
int thisrc;
|
|
|
|
int rc = -ENOSYS;
|
|
|
|
struct security_hook_list *hp;
|
|
|
|
|
|
|
|
list_for_each_entry(hp, &security_hook_heads.task_prctl, list) {
|
|
|
|
thisrc = hp->hook.task_prctl(option, arg2, arg3, arg4, arg5);
|
|
|
|
if (thisrc != -ENOSYS) {
|
|
|
|
rc = thisrc;
|
|
|
|
if (thisrc != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rc;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_task_to_inode(struct task_struct *p, struct inode *inode)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(task_to_inode, p, inode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(ipc_permission, 0, ipcp, flag);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-03-02 03:51:09 +08:00
|
|
|
void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
*secid = 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(ipc_getsecid, ipcp, secid);
|
2008-03-02 03:51:09 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_msg_msg_alloc(struct msg_msg *msg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(msg_msg_alloc_security, 0, msg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_msg_msg_free(struct msg_msg *msg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(msg_msg_free_security, msg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_msg_queue_alloc(struct msg_queue *msq)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(msg_queue_alloc_security, 0, msq);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_msg_queue_free(struct msg_queue *msq)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(msg_queue_free_security, msq);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_msg_queue_associate(struct msg_queue *msq, int msqflg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(msg_queue_associate, 0, msq, msqflg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(msg_queue_msgctl, 0, msq, cmd);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_msg_queue_msgsnd(struct msg_queue *msq,
|
|
|
|
struct msg_msg *msg, int msqflg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(msg_queue_msgsnd, 0, msq, msg, msqflg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
|
|
|
|
struct task_struct *target, long type, int mode)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_shm_alloc(struct shmid_kernel *shp)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(shm_alloc_security, 0, shp);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_shm_free(struct shmid_kernel *shp)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(shm_free_security, shp);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_shm_associate(struct shmid_kernel *shp, int shmflg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(shm_associate, 0, shp, shmflg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(shm_shmctl, 0, shp, cmd);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sem_alloc(struct sem_array *sma)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sem_alloc_security, 0, sma);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_sem_free(struct sem_array *sma)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sem_free_security, sma);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sem_associate(struct sem_array *sma, int semflg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sem_associate, 0, sma, semflg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sem_semctl(struct sem_array *sma, int cmd)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sem_semctl, 0, sma, cmd);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
|
|
|
|
unsigned nsops, int alter)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sem_semop, 0, sma, sops, nsops, alter);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_d_instantiate(struct dentry *dentry, struct inode *inode)
|
|
|
|
{
|
|
|
|
if (unlikely(inode && IS_PRIVATE(inode)))
|
|
|
|
return;
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(d_instantiate, dentry, inode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_d_instantiate);
|
|
|
|
|
|
|
|
int security_getprocattr(struct task_struct *p, char *name, char **value)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(getprocattr, -EINVAL, p, name, value);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(setprocattr, -EINVAL, p, name, value, size);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_netlink_send(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(netlink_send, 0, sk, skb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2013-05-23 00:50:35 +08:00
|
|
|
int security_ismaclabel(const char *name)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(ismaclabel, 0, name);
|
2013-05-23 00:50:35 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_ismaclabel);
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(secid_to_secctx, -EOPNOTSUPP, secid, secdata,
|
|
|
|
seclen);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secid_to_secctx);
|
|
|
|
|
2008-04-30 03:52:51 +08:00
|
|
|
int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
|
2008-01-16 07:47:35 +08:00
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
*secid = 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid);
|
2008-01-16 07:47:35 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secctx_to_secid);
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
void security_release_secctx(char *secdata, u32 seclen)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(release_secctx, secdata, seclen);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_release_secctx);
|
|
|
|
|
2015-12-25 00:09:40 +08:00
|
|
|
void security_inode_invalidate_secctx(struct inode *inode)
|
|
|
|
{
|
|
|
|
call_void_hook(inode_invalidate_secctx, inode);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_invalidate_secctx);
|
|
|
|
|
2009-09-04 02:25:57 +08:00
|
|
|
int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen);
|
2009-09-04 02:25:57 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_notifysecctx);
|
|
|
|
|
|
|
|
int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen);
|
2009-09-04 02:25:57 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_setsecctx);
|
|
|
|
|
|
|
|
int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen);
|
2009-09-04 02:25:57 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_getsecctx);
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
#ifdef CONFIG_SECURITY_NETWORK
|
|
|
|
|
2011-01-06 07:38:53 +08:00
|
|
|
int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(unix_stream_connect, 0, sock, other, newsk);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_unix_stream_connect);
|
|
|
|
|
|
|
|
int security_unix_may_send(struct socket *sock, struct socket *other)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(unix_may_send, 0, sock, other);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_unix_may_send);
|
|
|
|
|
|
|
|
int security_socket_create(int family, int type, int protocol, int kern)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_create, 0, family, type, protocol, kern);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_post_create(struct socket *sock, int family,
|
|
|
|
int type, int protocol, int kern)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_post_create, 0, sock, family, type,
|
2007-10-17 14:31:32 +08:00
|
|
|
protocol, kern);
|
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_bind, 0, sock, address, addrlen);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_connect, 0, sock, address, addrlen);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_listen(struct socket *sock, int backlog)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_listen, 0, sock, backlog);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_accept(struct socket *sock, struct socket *newsock)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_accept, 0, sock, newsock);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_sendmsg, 0, sock, msg, size);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
|
|
|
|
int size, int flags)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_recvmsg, 0, sock, msg, size, flags);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getsockname(struct socket *sock)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_getsockname, 0, sock);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getpeername(struct socket *sock)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_getpeername, 0, sock);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getsockopt(struct socket *sock, int level, int optname)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_getsockopt, 0, sock, level, optname);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_setsockopt(struct socket *sock, int level, int optname)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_setsockopt, 0, sock, level, optname);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_shutdown(struct socket *sock, int how)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_shutdown, 0, sock, how);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_sock_rcv_skb, 0, sk, skb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sock_rcv_skb);
|
|
|
|
|
|
|
|
int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
|
|
|
|
int __user *optlen, unsigned len)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock,
|
|
|
|
optval, optlen, len);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
|
|
|
|
{
|
2015-08-24 20:22:25 +08:00
|
|
|
return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock,
|
|
|
|
skb, secid);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_socket_getpeersec_dgram);
|
|
|
|
|
|
|
|
int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sk_alloc_security, 0, sk, family, priority);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_sk_free(struct sock *sk)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sk_free_security, sk);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_sk_clone(const struct sock *sk, struct sock *newsk)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sk_clone_security, sk, newsk);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2011-10-07 17:40:59 +08:00
|
|
|
EXPORT_SYMBOL(security_sk_clone);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
|
|
|
void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sk_getsecid, sk, &fl->flowi_secid);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sk_classify_flow);
|
|
|
|
|
|
|
|
void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(req_classify_flow, req, fl);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_req_classify_flow);
|
|
|
|
|
|
|
|
void security_sock_graft(struct sock *sk, struct socket *parent)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sock_graft, sk, parent);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sock_graft);
|
|
|
|
|
|
|
|
int security_inet_conn_request(struct sock *sk,
|
|
|
|
struct sk_buff *skb, struct request_sock *req)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inet_conn_request, 0, sk, skb, req);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inet_conn_request);
|
|
|
|
|
|
|
|
void security_inet_csk_clone(struct sock *newsk,
|
|
|
|
const struct request_sock *req)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(inet_csk_clone, newsk, req);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_inet_conn_established(struct sock *sk,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(inet_conn_established, sk, skb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2010-10-14 04:24:41 +08:00
|
|
|
int security_secmark_relabel_packet(u32 secid)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(secmark_relabel_packet, 0, secid);
|
2010-10-14 04:24:41 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secmark_relabel_packet);
|
|
|
|
|
|
|
|
void security_secmark_refcount_inc(void)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(secmark_refcount_inc);
|
2010-10-14 04:24:41 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secmark_refcount_inc);
|
|
|
|
|
|
|
|
void security_secmark_refcount_dec(void)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(secmark_refcount_dec);
|
2010-10-14 04:24:41 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secmark_refcount_dec);
|
|
|
|
|
2013-01-14 15:12:19 +08:00
|
|
|
int security_tun_dev_alloc_security(void **security)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(tun_dev_alloc_security, 0, security);
|
2013-01-14 15:12:19 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_alloc_security);
|
|
|
|
|
|
|
|
void security_tun_dev_free_security(void *security)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(tun_dev_free_security, security);
|
2013-01-14 15:12:19 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_free_security);
|
|
|
|
|
2009-08-29 06:12:43 +08:00
|
|
|
int security_tun_dev_create(void)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(tun_dev_create, 0);
|
2009-08-29 06:12:43 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_create);
|
|
|
|
|
2013-01-14 15:12:19 +08:00
|
|
|
int security_tun_dev_attach_queue(void *security)
|
2009-08-29 06:12:43 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(tun_dev_attach_queue, 0, security);
|
2009-08-29 06:12:43 +08:00
|
|
|
}
|
2013-01-14 15:12:19 +08:00
|
|
|
EXPORT_SYMBOL(security_tun_dev_attach_queue);
|
2009-08-29 06:12:43 +08:00
|
|
|
|
2013-01-14 15:12:19 +08:00
|
|
|
int security_tun_dev_attach(struct sock *sk, void *security)
|
2009-08-29 06:12:43 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(tun_dev_attach, 0, sk, security);
|
2009-08-29 06:12:43 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_attach);
|
|
|
|
|
2013-01-14 15:12:19 +08:00
|
|
|
int security_tun_dev_open(void *security)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(tun_dev_open, 0, security);
|
2013-01-14 15:12:19 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_open);
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
#endif /* CONFIG_SECURITY_NETWORK */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SECURITY_NETWORK_XFRM
|
|
|
|
|
2014-03-07 19:44:19 +08:00
|
|
|
int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
|
|
|
|
struct xfrm_user_sec_ctx *sec_ctx,
|
|
|
|
gfp_t gfp)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_policy_alloc_security, 0, ctxp, sec_ctx, gfp);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_xfrm_policy_alloc);
|
|
|
|
|
2008-04-13 10:07:52 +08:00
|
|
|
int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
|
|
|
|
struct xfrm_sec_ctx **new_ctxp)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-13 10:07:52 +08:00
|
|
|
void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(xfrm_policy_free_security, ctx);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_xfrm_policy_free);
|
|
|
|
|
2008-04-13 10:07:52 +08:00
|
|
|
int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_policy_delete_security, 0, ctx);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 05:38:38 +08:00
|
|
|
int security_xfrm_state_alloc(struct xfrm_state *x,
|
|
|
|
struct xfrm_user_sec_ctx *sec_ctx)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_xfrm_state_alloc);
|
|
|
|
|
|
|
|
int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
|
|
|
|
struct xfrm_sec_ctx *polsec, u32 secid)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_xfrm_state_delete(struct xfrm_state *x)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_state_delete_security, 0, x);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_xfrm_state_delete);
|
|
|
|
|
|
|
|
void security_xfrm_state_free(struct xfrm_state *x)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(xfrm_state_free_security, x);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-13 10:07:52 +08:00
|
|
|
int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid, dir);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
|
2011-02-23 10:13:15 +08:00
|
|
|
struct xfrm_policy *xp,
|
|
|
|
const struct flowi *fl)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
struct security_hook_list *hp;
|
|
|
|
int rc = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since this function is expected to return 0 or 1, the judgment
|
|
|
|
* becomes difficult if multiple LSMs supply this call. Fortunately,
|
|
|
|
* we can use the first LSM's judgment because currently only SELinux
|
|
|
|
* supplies this call.
|
|
|
|
*
|
|
|
|
* For speed optimization, we explicitly break the loop rather than
|
|
|
|
* using the macro
|
|
|
|
*/
|
|
|
|
list_for_each_entry(hp, &security_hook_heads.xfrm_state_pol_flow_match,
|
|
|
|
list) {
|
|
|
|
rc = hp->hook.xfrm_state_pol_flow_match(x, xp, fl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_decode_session, 0, skb, secid, 1);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
int rc = call_int_hook(xfrm_decode_session, 0, skb, &fl->flowi_secid,
|
|
|
|
0);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
|
|
|
BUG_ON(rc);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_skb_classify_flow);
|
|
|
|
|
|
|
|
#endif /* CONFIG_SECURITY_NETWORK_XFRM */
|
|
|
|
|
|
|
|
#ifdef CONFIG_KEYS
|
|
|
|
|
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
|
|
|
int security_key_alloc(struct key *key, const struct cred *cred,
|
|
|
|
unsigned long flags)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(key_alloc, 0, key, cred, flags);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_key_free(struct key *key)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(key_free, key);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_key_permission(key_ref_t key_ref,
|
2014-03-15 01:44:49 +08:00
|
|
|
const struct cred *cred, unsigned perm)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(key_permission, 0, key_ref, cred, perm);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 16:01:26 +08:00
|
|
|
int security_key_getsecurity(struct key *key, char **_buffer)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
*_buffer = NULL;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(key_getsecurity, 0, key, _buffer);
|
2008-04-29 16:01:26 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
#endif /* CONFIG_KEYS */
|
2008-03-02 04:00:05 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIT
|
|
|
|
|
|
|
|
int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(audit_rule_init, 0, field, op, rulestr, lsmrule);
|
2008-03-02 04:00:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_audit_rule_known(struct audit_krule *krule)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(audit_rule_known, 0, krule);
|
2008-03-02 04:00:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_audit_rule_free(void *lsmrule)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(audit_rule_free, lsmrule);
|
2008-03-02 04:00:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
|
|
|
|
struct audit_context *actx)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule,
|
|
|
|
actx);
|
2008-03-02 04:00:05 +08:00
|
|
|
}
|
2015-05-03 06:11:42 +08:00
|
|
|
#endif /* CONFIG_AUDIT */
|
2008-03-02 04:00:05 +08:00
|
|
|
|
2015-05-03 06:11:42 +08:00
|
|
|
struct security_hook_heads security_hook_heads = {
|
|
|
|
.binder_set_context_mgr =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.binder_set_context_mgr),
|
|
|
|
.binder_transaction =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.binder_transaction),
|
|
|
|
.binder_transfer_binder =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.binder_transfer_binder),
|
|
|
|
.binder_transfer_file =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.binder_transfer_file),
|
|
|
|
|
|
|
|
.ptrace_access_check =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.ptrace_access_check),
|
|
|
|
.ptrace_traceme =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.ptrace_traceme),
|
|
|
|
.capget = LIST_HEAD_INIT(security_hook_heads.capget),
|
|
|
|
.capset = LIST_HEAD_INIT(security_hook_heads.capset),
|
|
|
|
.capable = LIST_HEAD_INIT(security_hook_heads.capable),
|
|
|
|
.quotactl = LIST_HEAD_INIT(security_hook_heads.quotactl),
|
|
|
|
.quota_on = LIST_HEAD_INIT(security_hook_heads.quota_on),
|
|
|
|
.syslog = LIST_HEAD_INIT(security_hook_heads.syslog),
|
|
|
|
.settime = LIST_HEAD_INIT(security_hook_heads.settime),
|
|
|
|
.vm_enough_memory =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.vm_enough_memory),
|
|
|
|
.bprm_set_creds =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.bprm_set_creds),
|
|
|
|
.bprm_check_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.bprm_check_security),
|
|
|
|
.bprm_secureexec =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.bprm_secureexec),
|
|
|
|
.bprm_committing_creds =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.bprm_committing_creds),
|
|
|
|
.bprm_committed_creds =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.bprm_committed_creds),
|
|
|
|
.sb_alloc_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sb_alloc_security),
|
|
|
|
.sb_free_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sb_free_security),
|
|
|
|
.sb_copy_data = LIST_HEAD_INIT(security_hook_heads.sb_copy_data),
|
|
|
|
.sb_remount = LIST_HEAD_INIT(security_hook_heads.sb_remount),
|
|
|
|
.sb_kern_mount =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sb_kern_mount),
|
|
|
|
.sb_show_options =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sb_show_options),
|
|
|
|
.sb_statfs = LIST_HEAD_INIT(security_hook_heads.sb_statfs),
|
|
|
|
.sb_mount = LIST_HEAD_INIT(security_hook_heads.sb_mount),
|
|
|
|
.sb_umount = LIST_HEAD_INIT(security_hook_heads.sb_umount),
|
|
|
|
.sb_pivotroot = LIST_HEAD_INIT(security_hook_heads.sb_pivotroot),
|
|
|
|
.sb_set_mnt_opts =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sb_set_mnt_opts),
|
|
|
|
.sb_clone_mnt_opts =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sb_clone_mnt_opts),
|
|
|
|
.sb_parse_opts_str =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sb_parse_opts_str),
|
|
|
|
.dentry_init_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.dentry_init_security),
|
|
|
|
#ifdef CONFIG_SECURITY_PATH
|
|
|
|
.path_unlink = LIST_HEAD_INIT(security_hook_heads.path_unlink),
|
|
|
|
.path_mkdir = LIST_HEAD_INIT(security_hook_heads.path_mkdir),
|
|
|
|
.path_rmdir = LIST_HEAD_INIT(security_hook_heads.path_rmdir),
|
|
|
|
.path_mknod = LIST_HEAD_INIT(security_hook_heads.path_mknod),
|
|
|
|
.path_truncate =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.path_truncate),
|
|
|
|
.path_symlink = LIST_HEAD_INIT(security_hook_heads.path_symlink),
|
|
|
|
.path_link = LIST_HEAD_INIT(security_hook_heads.path_link),
|
|
|
|
.path_rename = LIST_HEAD_INIT(security_hook_heads.path_rename),
|
|
|
|
.path_chmod = LIST_HEAD_INIT(security_hook_heads.path_chmod),
|
|
|
|
.path_chown = LIST_HEAD_INIT(security_hook_heads.path_chown),
|
|
|
|
.path_chroot = LIST_HEAD_INIT(security_hook_heads.path_chroot),
|
|
|
|
#endif
|
|
|
|
.inode_alloc_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_alloc_security),
|
|
|
|
.inode_free_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_free_security),
|
|
|
|
.inode_init_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_init_security),
|
|
|
|
.inode_create = LIST_HEAD_INIT(security_hook_heads.inode_create),
|
|
|
|
.inode_link = LIST_HEAD_INIT(security_hook_heads.inode_link),
|
|
|
|
.inode_unlink = LIST_HEAD_INIT(security_hook_heads.inode_unlink),
|
|
|
|
.inode_symlink =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_symlink),
|
|
|
|
.inode_mkdir = LIST_HEAD_INIT(security_hook_heads.inode_mkdir),
|
|
|
|
.inode_rmdir = LIST_HEAD_INIT(security_hook_heads.inode_rmdir),
|
|
|
|
.inode_mknod = LIST_HEAD_INIT(security_hook_heads.inode_mknod),
|
|
|
|
.inode_rename = LIST_HEAD_INIT(security_hook_heads.inode_rename),
|
|
|
|
.inode_readlink =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_readlink),
|
|
|
|
.inode_follow_link =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_follow_link),
|
|
|
|
.inode_permission =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_permission),
|
|
|
|
.inode_setattr =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_setattr),
|
|
|
|
.inode_getattr =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_getattr),
|
|
|
|
.inode_setxattr =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_setxattr),
|
|
|
|
.inode_post_setxattr =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_post_setxattr),
|
|
|
|
.inode_getxattr =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_getxattr),
|
|
|
|
.inode_listxattr =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_listxattr),
|
|
|
|
.inode_removexattr =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_removexattr),
|
|
|
|
.inode_need_killpriv =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_need_killpriv),
|
|
|
|
.inode_killpriv =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_killpriv),
|
|
|
|
.inode_getsecurity =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_getsecurity),
|
|
|
|
.inode_setsecurity =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_setsecurity),
|
|
|
|
.inode_listsecurity =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_listsecurity),
|
|
|
|
.inode_getsecid =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_getsecid),
|
|
|
|
.file_permission =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.file_permission),
|
|
|
|
.file_alloc_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.file_alloc_security),
|
|
|
|
.file_free_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.file_free_security),
|
|
|
|
.file_ioctl = LIST_HEAD_INIT(security_hook_heads.file_ioctl),
|
|
|
|
.mmap_addr = LIST_HEAD_INIT(security_hook_heads.mmap_addr),
|
|
|
|
.mmap_file = LIST_HEAD_INIT(security_hook_heads.mmap_file),
|
|
|
|
.file_mprotect =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.file_mprotect),
|
|
|
|
.file_lock = LIST_HEAD_INIT(security_hook_heads.file_lock),
|
|
|
|
.file_fcntl = LIST_HEAD_INIT(security_hook_heads.file_fcntl),
|
|
|
|
.file_set_fowner =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.file_set_fowner),
|
|
|
|
.file_send_sigiotask =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.file_send_sigiotask),
|
|
|
|
.file_receive = LIST_HEAD_INIT(security_hook_heads.file_receive),
|
|
|
|
.file_open = LIST_HEAD_INIT(security_hook_heads.file_open),
|
|
|
|
.task_create = LIST_HEAD_INIT(security_hook_heads.task_create),
|
|
|
|
.task_free = LIST_HEAD_INIT(security_hook_heads.task_free),
|
|
|
|
.cred_alloc_blank =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.cred_alloc_blank),
|
|
|
|
.cred_free = LIST_HEAD_INIT(security_hook_heads.cred_free),
|
|
|
|
.cred_prepare = LIST_HEAD_INIT(security_hook_heads.cred_prepare),
|
|
|
|
.cred_transfer =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.cred_transfer),
|
|
|
|
.kernel_act_as =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.kernel_act_as),
|
|
|
|
.kernel_create_files_as =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.kernel_create_files_as),
|
|
|
|
.kernel_module_request =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.kernel_module_request),
|
2016-01-31 11:23:26 +08:00
|
|
|
.kernel_read_file =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.kernel_read_file),
|
2015-12-29 05:02:29 +08:00
|
|
|
.kernel_post_read_file =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.kernel_post_read_file),
|
2015-05-03 06:11:42 +08:00
|
|
|
.task_fix_setuid =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.task_fix_setuid),
|
|
|
|
.task_setpgid = LIST_HEAD_INIT(security_hook_heads.task_setpgid),
|
|
|
|
.task_getpgid = LIST_HEAD_INIT(security_hook_heads.task_getpgid),
|
|
|
|
.task_getsid = LIST_HEAD_INIT(security_hook_heads.task_getsid),
|
|
|
|
.task_getsecid =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.task_getsecid),
|
|
|
|
.task_setnice = LIST_HEAD_INIT(security_hook_heads.task_setnice),
|
|
|
|
.task_setioprio =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.task_setioprio),
|
|
|
|
.task_getioprio =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.task_getioprio),
|
|
|
|
.task_setrlimit =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.task_setrlimit),
|
|
|
|
.task_setscheduler =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.task_setscheduler),
|
|
|
|
.task_getscheduler =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.task_getscheduler),
|
|
|
|
.task_movememory =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.task_movememory),
|
|
|
|
.task_kill = LIST_HEAD_INIT(security_hook_heads.task_kill),
|
|
|
|
.task_wait = LIST_HEAD_INIT(security_hook_heads.task_wait),
|
|
|
|
.task_prctl = LIST_HEAD_INIT(security_hook_heads.task_prctl),
|
|
|
|
.task_to_inode =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.task_to_inode),
|
|
|
|
.ipc_permission =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.ipc_permission),
|
|
|
|
.ipc_getsecid = LIST_HEAD_INIT(security_hook_heads.ipc_getsecid),
|
|
|
|
.msg_msg_alloc_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.msg_msg_alloc_security),
|
|
|
|
.msg_msg_free_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.msg_msg_free_security),
|
|
|
|
.msg_queue_alloc_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.msg_queue_alloc_security),
|
|
|
|
.msg_queue_free_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.msg_queue_free_security),
|
|
|
|
.msg_queue_associate =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.msg_queue_associate),
|
|
|
|
.msg_queue_msgctl =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.msg_queue_msgctl),
|
|
|
|
.msg_queue_msgsnd =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.msg_queue_msgsnd),
|
|
|
|
.msg_queue_msgrcv =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.msg_queue_msgrcv),
|
|
|
|
.shm_alloc_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.shm_alloc_security),
|
|
|
|
.shm_free_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.shm_free_security),
|
|
|
|
.shm_associate =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.shm_associate),
|
|
|
|
.shm_shmctl = LIST_HEAD_INIT(security_hook_heads.shm_shmctl),
|
|
|
|
.shm_shmat = LIST_HEAD_INIT(security_hook_heads.shm_shmat),
|
|
|
|
.sem_alloc_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sem_alloc_security),
|
|
|
|
.sem_free_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sem_free_security),
|
|
|
|
.sem_associate =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sem_associate),
|
|
|
|
.sem_semctl = LIST_HEAD_INIT(security_hook_heads.sem_semctl),
|
|
|
|
.sem_semop = LIST_HEAD_INIT(security_hook_heads.sem_semop),
|
|
|
|
.netlink_send = LIST_HEAD_INIT(security_hook_heads.netlink_send),
|
|
|
|
.d_instantiate =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.d_instantiate),
|
|
|
|
.getprocattr = LIST_HEAD_INIT(security_hook_heads.getprocattr),
|
|
|
|
.setprocattr = LIST_HEAD_INIT(security_hook_heads.setprocattr),
|
|
|
|
.ismaclabel = LIST_HEAD_INIT(security_hook_heads.ismaclabel),
|
|
|
|
.secid_to_secctx =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.secid_to_secctx),
|
|
|
|
.secctx_to_secid =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.secctx_to_secid),
|
|
|
|
.release_secctx =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.release_secctx),
|
2015-12-25 00:09:40 +08:00
|
|
|
.inode_invalidate_secctx =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_invalidate_secctx),
|
2015-05-03 06:11:42 +08:00
|
|
|
.inode_notifysecctx =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_notifysecctx),
|
|
|
|
.inode_setsecctx =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_setsecctx),
|
|
|
|
.inode_getsecctx =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inode_getsecctx),
|
|
|
|
#ifdef CONFIG_SECURITY_NETWORK
|
|
|
|
.unix_stream_connect =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.unix_stream_connect),
|
|
|
|
.unix_may_send =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.unix_may_send),
|
|
|
|
.socket_create =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_create),
|
|
|
|
.socket_post_create =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_post_create),
|
|
|
|
.socket_bind = LIST_HEAD_INIT(security_hook_heads.socket_bind),
|
|
|
|
.socket_connect =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_connect),
|
|
|
|
.socket_listen =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_listen),
|
|
|
|
.socket_accept =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_accept),
|
|
|
|
.socket_sendmsg =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_sendmsg),
|
|
|
|
.socket_recvmsg =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_recvmsg),
|
|
|
|
.socket_getsockname =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_getsockname),
|
|
|
|
.socket_getpeername =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_getpeername),
|
|
|
|
.socket_getsockopt =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_getsockopt),
|
|
|
|
.socket_setsockopt =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_setsockopt),
|
|
|
|
.socket_shutdown =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_shutdown),
|
|
|
|
.socket_sock_rcv_skb =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_sock_rcv_skb),
|
|
|
|
.socket_getpeersec_stream =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_getpeersec_stream),
|
|
|
|
.socket_getpeersec_dgram =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.socket_getpeersec_dgram),
|
|
|
|
.sk_alloc_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sk_alloc_security),
|
|
|
|
.sk_free_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sk_free_security),
|
|
|
|
.sk_clone_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.sk_clone_security),
|
|
|
|
.sk_getsecid = LIST_HEAD_INIT(security_hook_heads.sk_getsecid),
|
|
|
|
.sock_graft = LIST_HEAD_INIT(security_hook_heads.sock_graft),
|
|
|
|
.inet_conn_request =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inet_conn_request),
|
|
|
|
.inet_csk_clone =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inet_csk_clone),
|
|
|
|
.inet_conn_established =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.inet_conn_established),
|
|
|
|
.secmark_relabel_packet =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.secmark_relabel_packet),
|
|
|
|
.secmark_refcount_inc =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.secmark_refcount_inc),
|
|
|
|
.secmark_refcount_dec =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.secmark_refcount_dec),
|
|
|
|
.req_classify_flow =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.req_classify_flow),
|
|
|
|
.tun_dev_alloc_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.tun_dev_alloc_security),
|
|
|
|
.tun_dev_free_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.tun_dev_free_security),
|
|
|
|
.tun_dev_create =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.tun_dev_create),
|
|
|
|
.tun_dev_attach_queue =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.tun_dev_attach_queue),
|
|
|
|
.tun_dev_attach =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.tun_dev_attach),
|
|
|
|
.tun_dev_open = LIST_HEAD_INIT(security_hook_heads.tun_dev_open),
|
|
|
|
.skb_owned_by = LIST_HEAD_INIT(security_hook_heads.skb_owned_by),
|
|
|
|
#endif /* CONFIG_SECURITY_NETWORK */
|
|
|
|
#ifdef CONFIG_SECURITY_NETWORK_XFRM
|
|
|
|
.xfrm_policy_alloc_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.xfrm_policy_alloc_security),
|
|
|
|
.xfrm_policy_clone_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.xfrm_policy_clone_security),
|
|
|
|
.xfrm_policy_free_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.xfrm_policy_free_security),
|
|
|
|
.xfrm_policy_delete_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.xfrm_policy_delete_security),
|
|
|
|
.xfrm_state_alloc =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.xfrm_state_alloc),
|
|
|
|
.xfrm_state_alloc_acquire =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.xfrm_state_alloc_acquire),
|
|
|
|
.xfrm_state_free_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.xfrm_state_free_security),
|
|
|
|
.xfrm_state_delete_security =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.xfrm_state_delete_security),
|
|
|
|
.xfrm_policy_lookup =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.xfrm_policy_lookup),
|
|
|
|
.xfrm_state_pol_flow_match =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.xfrm_state_pol_flow_match),
|
|
|
|
.xfrm_decode_session =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.xfrm_decode_session),
|
|
|
|
#endif /* CONFIG_SECURITY_NETWORK_XFRM */
|
|
|
|
#ifdef CONFIG_KEYS
|
|
|
|
.key_alloc = LIST_HEAD_INIT(security_hook_heads.key_alloc),
|
|
|
|
.key_free = LIST_HEAD_INIT(security_hook_heads.key_free),
|
|
|
|
.key_permission =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.key_permission),
|
|
|
|
.key_getsecurity =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.key_getsecurity),
|
|
|
|
#endif /* CONFIG_KEYS */
|
|
|
|
#ifdef CONFIG_AUDIT
|
|
|
|
.audit_rule_init =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.audit_rule_init),
|
|
|
|
.audit_rule_known =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.audit_rule_known),
|
|
|
|
.audit_rule_match =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.audit_rule_match),
|
|
|
|
.audit_rule_free =
|
|
|
|
LIST_HEAD_INIT(security_hook_heads.audit_rule_free),
|
2008-03-02 04:00:05 +08:00
|
|
|
#endif /* CONFIG_AUDIT */
|
2015-05-03 06:11:42 +08:00
|
|
|
};
|