2005-04-17 02:20:36 +04: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>
|
IB/core: Enforce PKey security on QPs
Add new LSM hooks to allocate and free security contexts and check for
permission to access a PKey.
Allocate and free a security context when creating and destroying a QP.
This context is used for controlling access to PKeys.
When a request is made to modify a QP that changes the port, PKey index,
or alternate path, check that the QP has permission for the PKey in the
PKey table index on the subnet prefix of the port. If the QP is shared
make sure all handles to the QP also have access.
Store which port and PKey index a QP is using. After the reset to init
transition the user can modify the port, PKey index and alternate path
independently. So port and PKey settings changes can be a merge of the
previous settings and the new ones.
In order to maintain access control if there are PKey table or subnet
prefix change keep a list of all QPs are using each PKey index on
each port. If a change occurs all QPs using that device and port must
have access enforced for the new cache settings.
These changes add a transaction to the QP modify process. Association
with the old port and PKey index must be maintained if the modify fails,
and must be removed if it succeeds. Association with the new port and
PKey index must be established prior to the modify and removed if the
modify fails.
1. When a QP is modified to a particular Port, PKey index or alternate
path insert that QP into the appropriate lists.
2. Check permission to access the new settings.
3. If step 2 grants access attempt to modify the QP.
4a. If steps 2 and 3 succeed remove any prior associations.
4b. If ether fails remove the new setting associations.
If a PKey table or subnet prefix changes walk the list of QPs and
check that they have permission. If not send the QP to the error state
and raise a fatal error event. If it's a shared QP make sure all the
QPs that share the real_qp have permission as well. If the QP that
owns a security structure is denied access the security structure is
marked as such and the QP is added to an error_list. Once the moving
the QP to error is complete the security structure mark is cleared.
Maintaining the lists correctly turns QP destroy into a transaction.
The hardware driver for the device frees the ib_qp structure, so while
the destroy is in progress the ib_qp pointer in the ib_qp_security
struct is undefined. When the destroy process begins the ib_qp_security
structure is marked as destroying. This prevents any action from being
taken on the QP pointer. After the QP is destroyed successfully it
could still listed on an error_list wait for it to be processed by that
flow before cleaning up the structure.
If the destroy fails the QPs port and PKey settings are reinserted into
the appropriate lists, the destroying flag is cleared, and access control
is enforced, in case there were any cache changes during the destroy
flow.
To keep the security changes isolated a new file is used to hold security
related functionality.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Acked-by: Doug Ledford <dledford@redhat.com>
[PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2017-05-19 15:48:52 +03:00
|
|
|
* Copyright (C) 2016 Mellanox Technologies
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2017-10-18 23:00:24 +03:00
|
|
|
#include <linux/bpf.h>
|
2006-01-11 23:17:46 +03:00
|
|
|
#include <linux/capability.h>
|
2013-05-22 20:50:34 +04:00
|
|
|
#include <linux/dcache.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
2015-05-03 01:10:46 +03:00
|
|
|
#include <linux/lsm_hooks.h>
|
2011-03-09 22:13:22 +03:00
|
|
|
#include <linux/integrity.h>
|
2009-10-23 01:30:13 +04:00
|
|
|
#include <linux/ima.h>
|
2011-03-09 22:38:26 +03:00
|
|
|
#include <linux/evm.h>
|
2012-02-13 07:58:52 +04:00
|
|
|
#include <linux/fsnotify.h>
|
2012-05-31 01:11:23 +04:00
|
|
|
#include <linux/mman.h>
|
|
|
|
#include <linux/mount.h>
|
|
|
|
#include <linux/personality.h>
|
2012-07-02 09:34:11 +04:00
|
|
|
#include <linux/backing-dev.h>
|
LSM: Enable multiple calls to security_add_hooks() for the same LSM
The commit d69dece5f5b6 ("LSM: Add /sys/kernel/security/lsm") extend
security_add_hooks() with a new parameter to register the LSM name,
which may be useful to make the list of currently loaded LSM available
to userspace. However, there is no clean way for an LSM to split its
hook declarations into multiple files, which may reduce the mess with
all the included files (needed for LSM hook argument types) and make the
source code easier to review and maintain.
This change allows an LSM to register multiple times its hook while
keeping a consistent list of LSM names as described in
Documentation/security/LSM.txt . The list reflects the order in which
checks are made. This patch only check for the last registered LSM. If
an LSM register multiple times its hooks, interleaved with other LSM
registrations (which should not happen), its name will still appear in
the same order that the hooks are called, hence multiple times.
To sum up, "capability,selinux,foo,foo" will be replaced with
"capability,selinux,foo", however "capability,foo,selinux,foo" will
remain as is.
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
2017-05-10 23:48:48 +03:00
|
|
|
#include <linux/string.h>
|
2012-02-13 07:58:52 +04:00
|
|
|
#include <net/flow.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-03-23 03:33:28 +03:00
|
|
|
#include <trace/events/initcall.h>
|
|
|
|
|
2011-06-16 05:19:10 +04:00
|
|
|
#define MAX_LSM_EVM_XATTR 2
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2015-05-03 01:11:42 +03:00
|
|
|
/* Maximum number of letters for an LSM name string */
|
|
|
|
#define SECURITY_NAME_MAX 10
|
|
|
|
|
2017-03-22 13:46:19 +03:00
|
|
|
struct security_hook_heads security_hook_heads __lsm_ro_after_init;
|
2017-05-19 15:48:53 +03:00
|
|
|
static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
|
|
|
|
|
2017-01-19 04:09:05 +03:00
|
|
|
char *lsm_names;
|
2008-03-06 19:09:10 +03:00
|
|
|
/* Boot-time LSM user choice */
|
2009-11-06 04:03:20 +03:00
|
|
|
static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
|
|
|
|
CONFIG_DEFAULT_SECURITY;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
static void __init do_security_initcalls(void)
|
|
|
|
{
|
2018-03-23 03:33:28 +03:00
|
|
|
int ret;
|
2005-04-17 02:20:36 +04:00
|
|
|
initcall_t *call;
|
|
|
|
call = __security_initcall_start;
|
2018-03-23 03:33:28 +03:00
|
|
|
trace_initcall_level("security");
|
2005-04-17 02:20:36 +04:00
|
|
|
while (call < __security_initcall_end) {
|
2018-03-23 03:33:28 +03:00
|
|
|
trace_initcall_start((*call));
|
|
|
|
ret = (*call) ();
|
|
|
|
trace_initcall_finish((*call), ret);
|
2005-04-17 02:20:36 +04:00
|
|
|
call++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* security_init - initializes the security framework
|
|
|
|
*
|
|
|
|
* This should be called early in the kernel initialization sequence.
|
|
|
|
*/
|
|
|
|
int __init security_init(void)
|
|
|
|
{
|
2017-03-22 13:46:19 +03:00
|
|
|
int i;
|
2018-03-29 04:28:23 +03:00
|
|
|
struct hlist_head *list = (struct hlist_head *) &security_hook_heads;
|
2017-03-22 13:46:19 +03:00
|
|
|
|
2018-03-29 04:28:23 +03:00
|
|
|
for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head);
|
2017-03-22 13:46:19 +03:00
|
|
|
i++)
|
2018-03-29 04:28:23 +03:00
|
|
|
INIT_HLIST_HEAD(&list[i]);
|
2015-05-03 01:11:42 +03:00
|
|
|
pr_info("Security Framework initialized\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2015-05-03 01:11:42 +03:00
|
|
|
/*
|
2015-07-24 04:02:48 +03:00
|
|
|
* Load minor LSMs, with the capability module always first.
|
2015-05-03 01:11:42 +03:00
|
|
|
*/
|
|
|
|
capability_add_hooks();
|
|
|
|
yama_add_hooks();
|
2016-04-21 01:46:28 +03:00
|
|
|
loadpin_add_hooks();
|
2015-07-24 04:02:48 +03:00
|
|
|
|
2015-05-03 01:11:42 +03:00
|
|
|
/*
|
2015-07-24 04:02:48 +03:00
|
|
|
* Load all the remaining security modules.
|
2015-05-03 01:11:42 +03:00
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
do_security_initcalls();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-06 19:09:10 +03: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);
|
|
|
|
|
LSM: Enable multiple calls to security_add_hooks() for the same LSM
The commit d69dece5f5b6 ("LSM: Add /sys/kernel/security/lsm") extend
security_add_hooks() with a new parameter to register the LSM name,
which may be useful to make the list of currently loaded LSM available
to userspace. However, there is no clean way for an LSM to split its
hook declarations into multiple files, which may reduce the mess with
all the included files (needed for LSM hook argument types) and make the
source code easier to review and maintain.
This change allows an LSM to register multiple times its hook while
keeping a consistent list of LSM names as described in
Documentation/security/LSM.txt . The list reflects the order in which
checks are made. This patch only check for the last registered LSM. If
an LSM register multiple times its hooks, interleaved with other LSM
registrations (which should not happen), its name will still appear in
the same order that the hooks are called, hence multiple times.
To sum up, "capability,selinux,foo,foo" will be replaced with
"capability,selinux,foo", however "capability,foo,selinux,foo" will
remain as is.
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
2017-05-10 23:48:48 +03:00
|
|
|
static bool match_last_lsm(const char *list, const char *lsm)
|
|
|
|
{
|
|
|
|
const char *last;
|
|
|
|
|
|
|
|
if (WARN_ON(!list || !lsm))
|
|
|
|
return false;
|
|
|
|
last = strrchr(list, ',');
|
|
|
|
if (last)
|
|
|
|
/* Pass the comma, strcmp() will check for '\0' */
|
|
|
|
last++;
|
|
|
|
else
|
|
|
|
last = list;
|
|
|
|
return !strcmp(last, lsm);
|
|
|
|
}
|
|
|
|
|
2017-01-19 04:09:05 +03:00
|
|
|
static int lsm_append(char *new, char **result)
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (*result == NULL) {
|
|
|
|
*result = kstrdup(new, GFP_KERNEL);
|
|
|
|
} else {
|
LSM: Enable multiple calls to security_add_hooks() for the same LSM
The commit d69dece5f5b6 ("LSM: Add /sys/kernel/security/lsm") extend
security_add_hooks() with a new parameter to register the LSM name,
which may be useful to make the list of currently loaded LSM available
to userspace. However, there is no clean way for an LSM to split its
hook declarations into multiple files, which may reduce the mess with
all the included files (needed for LSM hook argument types) and make the
source code easier to review and maintain.
This change allows an LSM to register multiple times its hook while
keeping a consistent list of LSM names as described in
Documentation/security/LSM.txt . The list reflects the order in which
checks are made. This patch only check for the last registered LSM. If
an LSM register multiple times its hooks, interleaved with other LSM
registrations (which should not happen), its name will still appear in
the same order that the hooks are called, hence multiple times.
To sum up, "capability,selinux,foo,foo" will be replaced with
"capability,selinux,foo", however "capability,foo,selinux,foo" will
remain as is.
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
2017-05-10 23:48:48 +03:00
|
|
|
/* Check if it is the last registered name */
|
|
|
|
if (match_last_lsm(*result, new))
|
|
|
|
return 0;
|
2017-01-19 04:09:05 +03:00
|
|
|
cp = kasprintf(GFP_KERNEL, "%s,%s", *result, new);
|
|
|
|
if (cp == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
kfree(*result);
|
|
|
|
*result = cp;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-06 19:09:10 +03:00
|
|
|
/**
|
|
|
|
* security_module_enable - Load given security module on boot ?
|
2015-05-03 01:11:42 +03:00
|
|
|
* @module: the name of the module
|
2008-03-06 19:09:10 +03: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 04:23:49 +03:00
|
|
|
* to check if your LSM is currently loaded during kernel initialization.
|
2008-03-06 19:09:10 +03:00
|
|
|
*
|
2017-03-30 23:11:36 +03:00
|
|
|
* Returns:
|
|
|
|
*
|
|
|
|
* true if:
|
|
|
|
*
|
|
|
|
* - The passed LSM is the one chosen by user at boot time,
|
|
|
|
* - or the passed LSM is configured as the default and the user did not
|
|
|
|
* choose an alternate LSM at boot time.
|
|
|
|
*
|
2008-03-06 19:09:10 +03:00
|
|
|
* Otherwise, return false.
|
|
|
|
*/
|
2015-05-03 01:11:42 +03:00
|
|
|
int __init security_module_enable(const char *module)
|
2008-03-06 19:09:10 +03:00
|
|
|
{
|
2015-05-03 01:11:42 +03:00
|
|
|
return !strcmp(module, chosen_lsm);
|
2008-03-06 19:09:10 +03:00
|
|
|
}
|
|
|
|
|
2017-01-19 04:09:05 +03:00
|
|
|
/**
|
|
|
|
* security_add_hooks - Add a modules hooks to the hook lists.
|
|
|
|
* @hooks: the hooks to add
|
|
|
|
* @count: the number of hooks to add
|
|
|
|
* @lsm: the name of the security module
|
|
|
|
*
|
|
|
|
* Each LSM has to register its hooks with the infrastructure.
|
|
|
|
*/
|
|
|
|
void __init security_add_hooks(struct security_hook_list *hooks, int count,
|
|
|
|
char *lsm)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
hooks[i].lsm = lsm;
|
2018-03-29 04:28:23 +03:00
|
|
|
hlist_add_tail_rcu(&hooks[i].list, hooks[i].head);
|
2017-01-19 04:09:05 +03:00
|
|
|
}
|
|
|
|
if (lsm_append(lsm, &lsm_names) < 0)
|
|
|
|
panic("%s - Cannot get early memory.\n", __func__);
|
|
|
|
}
|
|
|
|
|
2017-05-19 15:48:53 +03:00
|
|
|
int call_lsm_notifier(enum lsm_event event, void *data)
|
|
|
|
{
|
|
|
|
return atomic_notifier_call_chain(&lsm_notifier_chain, event, data);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(call_lsm_notifier);
|
|
|
|
|
|
|
|
int register_lsm_notifier(struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
return atomic_notifier_chain_register(&lsm_notifier_chain, nb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(register_lsm_notifier);
|
|
|
|
|
|
|
|
int unregister_lsm_notifier(struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
return atomic_notifier_chain_unregister(&lsm_notifier_chain, nb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(unregister_lsm_notifier);
|
|
|
|
|
2015-05-03 01:11:29 +03:00
|
|
|
/*
|
2015-05-03 01:11:42 +03:00
|
|
|
* Hook list operation macros.
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
2015-05-03 01:11:29 +03:00
|
|
|
* call_void_hook:
|
|
|
|
* This is a hook that does not return a value.
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
2015-05-03 01:11:29 +03:00
|
|
|
* call_int_hook:
|
|
|
|
* This is a hook that returns a value.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
|
2015-05-03 01:11:42 +03:00
|
|
|
#define call_void_hook(FUNC, ...) \
|
|
|
|
do { \
|
|
|
|
struct security_hook_list *P; \
|
|
|
|
\
|
2018-03-29 04:28:23 +03:00
|
|
|
hlist_for_each_entry(P, &security_hook_heads.FUNC, list) \
|
2015-05-03 01:11:42 +03:00
|
|
|
P->hook.FUNC(__VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define call_int_hook(FUNC, IRC, ...) ({ \
|
|
|
|
int RC = IRC; \
|
|
|
|
do { \
|
|
|
|
struct security_hook_list *P; \
|
|
|
|
\
|
2018-03-29 04:28:23 +03:00
|
|
|
hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \
|
2015-05-03 01:11:42 +03:00
|
|
|
RC = P->hook.FUNC(__VA_ARGS__); \
|
|
|
|
if (RC != 0) \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} while (0); \
|
|
|
|
RC; \
|
|
|
|
})
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
/* Security operations */
|
|
|
|
|
2015-01-21 18:54:10 +03:00
|
|
|
int security_binder_set_context_mgr(struct task_struct *mgr)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(binder_set_context_mgr, 0, mgr);
|
2015-01-21 18:54:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_binder_transaction(struct task_struct *from,
|
|
|
|
struct task_struct *to)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(binder_transaction, 0, from, to);
|
2015-01-21 18:54:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_binder_transfer_binder(struct task_struct *from,
|
|
|
|
struct task_struct *to)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(binder_transfer_binder, 0, from, to);
|
2015-01-21 18:54:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_binder_transfer_file(struct task_struct *from,
|
|
|
|
struct task_struct *to, struct file *file)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(binder_transfer_file, 0, from, to, file);
|
2015-01-21 18:54:10 +03:00
|
|
|
}
|
|
|
|
|
2009-05-07 13:26:19 +04:00
|
|
|
int security_ptrace_access_check(struct task_struct *child, unsigned int mode)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03: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 14:37:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_ptrace_traceme(struct task_struct *parent)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(ptrace_traceme, 0, parent);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_capget(struct task_struct *target,
|
|
|
|
kernel_cap_t *effective,
|
|
|
|
kernel_cap_t *inheritable,
|
|
|
|
kernel_cap_t *permitted)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(capget, 0, target,
|
|
|
|
effective, inheritable, permitted);
|
2007-10-17 10:31:32 +04: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 02:39:23 +03: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 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(capset, 0, new, old,
|
|
|
|
effective, inheritable, permitted);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2012-01-03 21:25:15 +04: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 02:43:17 +03:00
|
|
|
int cap)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_AUDIT);
|
2008-11-11 14:02:50 +03:00
|
|
|
}
|
|
|
|
|
2012-01-03 21:25:15 +04:00
|
|
|
int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
|
|
|
|
int cap)
|
2008-11-11 14:02:50 +03:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_NOAUDIT);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_quotactl(int cmds, int type, int id, struct super_block *sb)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(quotactl, 0, cmds, type, id, sb);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_quota_on(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(quota_on, 0, dentry);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2010-11-16 02:36:29 +03:00
|
|
|
int security_syslog(int type)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(syslog, 0, type);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2016-04-08 09:02:11 +03:00
|
|
|
int security_settime64(const struct timespec64 *ts, const struct timezone *tz)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(settime, 0, ts, tz);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
|
|
|
|
{
|
2015-05-03 01:11:42 +03: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.
|
|
|
|
*/
|
2018-03-29 04:28:23 +03:00
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.vm_enough_memory, list) {
|
2015-05-03 01:11:42 +03:00
|
|
|
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 10:31:32 +04: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 02:39:24 +03:00
|
|
|
int security_bprm_set_creds(struct linux_binprm *bprm)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(bprm_set_creds, 0, bprm);
|
2007-10-17 10:31:32 +04: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 02:39:24 +03:00
|
|
|
int security_bprm_check(struct linux_binprm *bprm)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2009-10-23 01:30:13 +04:00
|
|
|
int ret;
|
|
|
|
|
2015-05-03 01:11:29 +03:00
|
|
|
ret = call_int_hook(bprm_check_security, 0, bprm);
|
2009-10-23 01:30:13 +04:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return ima_bprm_check(bprm);
|
2007-10-17 10:31:32 +04: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 02:39:24 +03:00
|
|
|
void security_bprm_committing_creds(struct linux_binprm *bprm)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(bprm_committing_creds, bprm);
|
2007-10-17 10:31:32 +04: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 02:39:24 +03:00
|
|
|
void security_bprm_committed_creds(struct linux_binprm *bprm)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(bprm_committed_creds, bprm);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sb_alloc(struct super_block *sb)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sb_alloc_security, 0, sb);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_sb_free(struct super_block *sb)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(sb_free_security, sb);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2008-03-05 18:31:54 +03:00
|
|
|
int security_sb_copy_data(char *orig, char *copy)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sb_copy_data, 0, orig, copy);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
2008-03-05 18:31:54 +03:00
|
|
|
EXPORT_SYMBOL(security_sb_copy_data);
|
2007-10-17 10:31:32 +04:00
|
|
|
|
2011-03-04 00:09:14 +03:00
|
|
|
int security_sb_remount(struct super_block *sb, void *data)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sb_remount, 0, sb, data);
|
2011-03-04 00:09:14 +03:00
|
|
|
}
|
|
|
|
|
2008-12-19 02:44:42 +03:00
|
|
|
int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sb_kern_mount, 0, sb, flags, data);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2008-07-04 03:47:13 +04:00
|
|
|
int security_sb_show_options(struct seq_file *m, struct super_block *sb)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sb_show_options, 0, m, sb);
|
2008-07-04 03:47:13 +04:00
|
|
|
}
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
int security_sb_statfs(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sb_statfs, 0, dentry);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2016-03-25 21:52:53 +03:00
|
|
|
int security_sb_mount(const char *dev_name, const struct path *path,
|
2012-10-11 19:42:01 +04:00
|
|
|
const char *type, unsigned long flags, void *data)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sb_umount(struct vfsmount *mnt, int flags)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sb_umount, 0, mnt, flags);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2016-03-25 22:31:19 +03:00
|
|
|
int security_sb_pivotroot(const struct path *old_path, const struct path *new_path)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sb_pivotroot, 0, old_path, new_path);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2007-11-30 21:00:35 +03:00
|
|
|
int security_sb_set_mnt_opts(struct super_block *sb,
|
2013-05-22 20:50:36 +04:00
|
|
|
struct security_mnt_opts *opts,
|
|
|
|
unsigned long kern_flags,
|
|
|
|
unsigned long *set_kern_flags)
|
2007-11-30 21:00:35 +03:00
|
|
|
{
|
2015-05-03 01:11:42 +03:00
|
|
|
return call_int_hook(sb_set_mnt_opts,
|
|
|
|
opts->num_mnt_opts ? -EOPNOTSUPP : 0, sb,
|
|
|
|
opts, kern_flags, set_kern_flags);
|
2007-11-30 21:00:35 +03:00
|
|
|
}
|
2008-03-05 18:31:54 +03:00
|
|
|
EXPORT_SYMBOL(security_sb_set_mnt_opts);
|
2007-11-30 21:00:35 +03: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 16:14:24 +04:00
|
|
|
int security_sb_clone_mnt_opts(const struct super_block *oldsb,
|
2017-06-05 18:45:04 +03:00
|
|
|
struct super_block *newsb,
|
|
|
|
unsigned long kern_flags,
|
|
|
|
unsigned long *set_kern_flags)
|
2007-11-30 21:00:35 +03:00
|
|
|
{
|
2017-06-05 18:45:04 +03:00
|
|
|
return call_int_hook(sb_clone_mnt_opts, 0, oldsb, newsb,
|
|
|
|
kern_flags, set_kern_flags);
|
2007-11-30 21:00:35 +03:00
|
|
|
}
|
2008-03-05 18:31:54 +03:00
|
|
|
EXPORT_SYMBOL(security_sb_clone_mnt_opts);
|
|
|
|
|
|
|
|
int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sb_parse_opts_str, 0, options, opts);
|
2008-03-05 18:31:54 +03:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sb_parse_opts_str);
|
2007-11-30 21:00:35 +03:00
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
int security_inode_alloc(struct inode *inode)
|
|
|
|
{
|
|
|
|
inode->i_security = NULL;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_alloc_security, 0, inode);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_inode_free(struct inode *inode)
|
|
|
|
{
|
2011-03-09 22:13:22 +03:00
|
|
|
integrity_inode_free(inode);
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(inode_free_security, inode);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2013-05-22 20:50:34 +04:00
|
|
|
int security_dentry_init_security(struct dentry *dentry, int mode,
|
2016-07-20 23:06:15 +03:00
|
|
|
const struct qstr *name, void **ctx,
|
2013-05-22 20:50:34 +04:00
|
|
|
u32 *ctxlen)
|
|
|
|
{
|
2015-05-03 01:11:42 +03:00
|
|
|
return call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode,
|
|
|
|
name, ctx, ctxlen);
|
2013-05-22 20:50:34 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_dentry_init_security);
|
|
|
|
|
2016-07-13 17:44:52 +03:00
|
|
|
int security_dentry_create_files_as(struct dentry *dentry, int mode,
|
|
|
|
struct qstr *name,
|
|
|
|
const struct cred *old, struct cred *new)
|
|
|
|
{
|
|
|
|
return call_int_hook(dentry_create_files_as, 0, dentry, mode,
|
|
|
|
name, old, new);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_dentry_create_files_as);
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
int security_inode_init_security(struct inode *inode, struct inode *dir,
|
2011-06-06 23:29:25 +04:00
|
|
|
const struct qstr *qstr,
|
|
|
|
const initxattrs initxattrs, void *fs_data)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2011-06-16 05:19:10 +04:00
|
|
|
struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1];
|
|
|
|
struct xattr *lsm_xattr, *evm_xattr, *xattr;
|
2011-06-06 23:29:25 +04:00
|
|
|
int ret;
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2011-08-15 18:13:18 +04:00
|
|
|
return 0;
|
2011-06-06 23:29:25 +04:00
|
|
|
|
|
|
|
if (!initxattrs)
|
2015-08-24 15:22:25 +03:00
|
|
|
return call_int_hook(inode_init_security, -EOPNOTSUPP, inode,
|
|
|
|
dir, qstr, NULL, NULL, NULL);
|
2013-07-25 00:44:02 +04:00
|
|
|
memset(new_xattrs, 0, sizeof(new_xattrs));
|
2011-06-06 23:29:25 +04:00
|
|
|
lsm_xattr = new_xattrs;
|
2015-05-03 01:11:42 +03:00
|
|
|
ret = call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir, qstr,
|
2011-06-06 23:29:25 +04:00
|
|
|
&lsm_xattr->name,
|
|
|
|
&lsm_xattr->value,
|
|
|
|
&lsm_xattr->value_len);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2011-06-16 05:19:10 +04:00
|
|
|
|
|
|
|
evm_xattr = lsm_xattr + 1;
|
|
|
|
ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2011-06-06 23:29:25 +04:00
|
|
|
ret = initxattrs(inode, new_xattrs, fs_data);
|
|
|
|
out:
|
2013-07-25 00:44:02 +04:00
|
|
|
for (xattr = new_xattrs; xattr->value != NULL; xattr++)
|
2011-06-16 05:19:10 +04:00
|
|
|
kfree(xattr->value);
|
2011-06-06 23:29:25 +04: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 00:44:02 +04:00
|
|
|
const struct qstr *qstr, const char **name,
|
2011-06-06 23:29:25 +04:00
|
|
|
void **value, size_t *len)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2012-01-03 16:14:29 +04:00
|
|
|
return -EOPNOTSUPP;
|
2015-08-24 15:22:25 +03:00
|
|
|
return call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir,
|
|
|
|
qstr, name, value, len);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
2011-06-06 23:29:25 +04:00
|
|
|
EXPORT_SYMBOL(security_old_inode_init_security);
|
2007-10-17 10:31:32 +04:00
|
|
|
|
2008-12-17 07:24:15 +03:00
|
|
|
#ifdef CONFIG_SECURITY_PATH
|
2016-03-25 22:21:09 +03:00
|
|
|
int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode,
|
2008-12-17 07:24:15 +03:00
|
|
|
unsigned int dev)
|
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 07:24:15 +03:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(path_mknod, 0, dir, dentry, mode, dev);
|
2008-12-17 07:24:15 +03:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_path_mknod);
|
|
|
|
|
2016-03-25 22:21:09 +03:00
|
|
|
int security_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t mode)
|
2008-12-17 07:24:15 +03:00
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 07:24:15 +03:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(path_mkdir, 0, dir, dentry, mode);
|
2008-12-17 07:24:15 +03:00
|
|
|
}
|
2010-12-24 17:48:35 +03:00
|
|
|
EXPORT_SYMBOL(security_path_mkdir);
|
2008-12-17 07:24:15 +03:00
|
|
|
|
2016-03-25 22:13:39 +03:00
|
|
|
int security_path_rmdir(const struct path *dir, struct dentry *dentry)
|
2008-12-17 07:24:15 +03:00
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 07:24:15 +03:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(path_rmdir, 0, dir, dentry);
|
2008-12-17 07:24:15 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 22:13:39 +03:00
|
|
|
int security_path_unlink(const struct path *dir, struct dentry *dentry)
|
2008-12-17 07:24:15 +03:00
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 07:24:15 +03:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(path_unlink, 0, dir, dentry);
|
2008-12-17 07:24:15 +03:00
|
|
|
}
|
2010-12-24 17:48:35 +03:00
|
|
|
EXPORT_SYMBOL(security_path_unlink);
|
2008-12-17 07:24:15 +03:00
|
|
|
|
2016-03-25 22:21:09 +03:00
|
|
|
int security_path_symlink(const struct path *dir, struct dentry *dentry,
|
2008-12-17 07:24:15 +03:00
|
|
|
const char *old_name)
|
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 07:24:15 +03:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(path_symlink, 0, dir, dentry, old_name);
|
2008-12-17 07:24:15 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 22:27:45 +03:00
|
|
|
int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
|
2008-12-17 07:24:15 +03:00
|
|
|
struct dentry *new_dentry)
|
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
|
2008-12-17 07:24:15 +03:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
|
2008-12-17 07:24:15 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 22:27:45 +03:00
|
|
|
int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
|
|
|
|
const struct path *new_dir, struct dentry *new_dentry,
|
2014-04-01 19:08:43 +04:00
|
|
|
unsigned int flags)
|
2008-12-17 07:24:15 +03:00
|
|
|
{
|
2015-03-18 01:26:22 +03: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 07:24:15 +03:00
|
|
|
return 0;
|
2014-04-01 19:08:43 +04:00
|
|
|
|
|
|
|
if (flags & RENAME_EXCHANGE) {
|
2015-05-03 01:11:29 +03:00
|
|
|
int err = call_int_hook(path_rename, 0, new_dir, new_dentry,
|
|
|
|
old_dir, old_dentry);
|
2014-04-01 19:08:43 +04:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(path_rename, 0, old_dir, old_dentry, new_dir,
|
|
|
|
new_dentry);
|
2008-12-17 07:24:15 +03:00
|
|
|
}
|
2010-12-24 17:48:35 +03:00
|
|
|
EXPORT_SYMBOL(security_path_rename);
|
2008-12-17 07:24:15 +03:00
|
|
|
|
2016-03-25 21:22:01 +03:00
|
|
|
int security_path_truncate(const struct path *path)
|
2008-12-17 07:24:15 +03:00
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2008-12-17 07:24:15 +03:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(path_truncate, 0, path);
|
2008-12-17 07:24:15 +03:00
|
|
|
}
|
2009-10-04 16:49:47 +04:00
|
|
|
|
2016-03-25 21:56:23 +03:00
|
|
|
int security_path_chmod(const struct path *path, umode_t mode)
|
2009-10-04 16:49:47 +04:00
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2009-10-04 16:49:47 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(path_chmod, 0, path, mode);
|
2009-10-04 16:49:47 +04:00
|
|
|
}
|
|
|
|
|
2016-03-25 21:44:41 +03:00
|
|
|
int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
|
2009-10-04 16:49:47 +04:00
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2009-10-04 16:49:47 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(path_chown, 0, path, uid, gid);
|
2009-10-04 16:49:47 +04:00
|
|
|
}
|
2009-10-04 16:49:48 +04:00
|
|
|
|
2016-03-25 22:28:43 +03:00
|
|
|
int security_path_chroot(const struct path *path)
|
2009-10-04 16:49:48 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(path_chroot, 0, path);
|
2009-10-04 16:49:48 +04:00
|
|
|
}
|
2008-12-17 07:24:15 +03:00
|
|
|
#endif
|
|
|
|
|
2011-07-26 09:42:34 +04:00
|
|
|
int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(dir)))
|
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_create, 0, dir, dentry, mode);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
2009-04-03 19:42:40 +04:00
|
|
|
EXPORT_SYMBOL_GPL(security_inode_create);
|
2007-10-17 10:31:32 +04:00
|
|
|
|
|
|
|
int security_inode_link(struct dentry *old_dentry, struct inode *dir,
|
|
|
|
struct dentry *new_dentry)
|
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
|
2007-10-17 10:31:32 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_unlink(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 10:31:32 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_unlink, 0, dir, dentry);
|
2007-10-17 10:31:32 +04: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 01:11:29 +03:00
|
|
|
return call_int_hook(inode_symlink, 0, dir, dentry, old_name);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2011-07-26 09:41:39 +04:00
|
|
|
int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(dir)))
|
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_mkdir, 0, dir, dentry, mode);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
2009-04-03 19:42:40 +04:00
|
|
|
EXPORT_SYMBOL_GPL(security_inode_mkdir);
|
2007-10-17 10:31:32 +04:00
|
|
|
|
|
|
|
int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 10:31:32 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_rmdir, 0, dir, dentry);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2011-07-26 09:52:52 +04:00
|
|
|
int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(dir)))
|
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_mknod, 0, dir, dentry, mode, dev);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
|
2014-04-01 19:08:43 +04:00
|
|
|
struct inode *new_dir, struct dentry *new_dentry,
|
|
|
|
unsigned int flags)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-03-18 01:26:22 +03: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 10:31:32 +04:00
|
|
|
return 0;
|
2014-04-01 19:08:43 +04:00
|
|
|
|
|
|
|
if (flags & RENAME_EXCHANGE) {
|
2015-05-03 01:11:29 +03:00
|
|
|
int err = call_int_hook(inode_rename, 0, new_dir, new_dentry,
|
2014-04-01 19:08:43 +04:00
|
|
|
old_dir, old_dentry);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_rename, 0, old_dir, old_dentry,
|
2007-10-17 10:31:32 +04:00
|
|
|
new_dir, new_dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_readlink(struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 10:31:32 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_readlink, 0, dentry);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2015-03-23 05:37:39 +03:00
|
|
|
int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
|
|
|
|
bool rcu)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-03-23 05:37:39 +03:00
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2007-10-17 10:31:32 +04:00
|
|
|
return 0;
|
2015-06-27 23:26:03 +03:00
|
|
|
return call_int_hook(inode_follow_link, 0, dentry, inode, rcu);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2008-07-17 17:37:02 +04:00
|
|
|
int security_inode_permission(struct inode *inode, int mask)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_permission, 0, inode, mask);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
|
|
|
|
{
|
2011-05-13 20:53:38 +04:00
|
|
|
int ret;
|
|
|
|
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 10:31:32 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
ret = call_int_hook(inode_setattr, 0, dentry, attr);
|
2011-05-13 20:53:38 +04:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return evm_inode_setattr(dentry, attr);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
2008-07-01 17:01:28 +04:00
|
|
|
EXPORT_SYMBOL_GPL(security_inode_setattr);
|
2007-10-17 10:31:32 +04:00
|
|
|
|
2015-03-09 02:28:30 +03:00
|
|
|
int security_inode_getattr(const struct path *path)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2007-10-17 10:31:32 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_getattr, 0, path);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2008-04-29 11:59:41 +04:00
|
|
|
int security_inode_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
const void *value, size_t size, int flags)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2011-03-09 22:38:26 +03:00
|
|
|
int ret;
|
|
|
|
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 10:31:32 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:42 +03: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 01:11:29 +03:00
|
|
|
flags);
|
2015-05-03 01:11:42 +03:00
|
|
|
|
|
|
|
if (ret == 1)
|
|
|
|
ret = cap_inode_setxattr(dentry, name, value, size, flags);
|
2011-03-11 02:54:15 +03:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = ima_inode_setxattr(dentry, name, value, size);
|
2011-03-09 22:38:26 +03:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return evm_inode_setxattr(dentry, name, value, size);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2008-04-29 11:59:41 +04:00
|
|
|
void security_inode_post_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
const void *value, size_t size, int flags)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 10:31:32 +04:00
|
|
|
return;
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(inode_post_setxattr, dentry, name, value, size, flags);
|
2011-03-09 22:38:26 +03:00
|
|
|
evm_inode_post_setxattr(dentry, name, value, size);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2008-04-29 11:59:41 +04:00
|
|
|
int security_inode_getxattr(struct dentry *dentry, const char *name)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 10:31:32 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_getxattr, 0, dentry, name);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_listxattr(struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 10:31:32 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_listxattr, 0, dentry);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2008-04-29 11:59:41 +04:00
|
|
|
int security_inode_removexattr(struct dentry *dentry, const char *name)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2011-03-09 22:38:26 +03:00
|
|
|
int ret;
|
|
|
|
|
2015-03-18 01:26:22 +03:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 10:31:32 +04:00
|
|
|
return 0;
|
2015-05-03 01:11:42 +03: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 02:54:15 +03:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = ima_inode_removexattr(dentry, name);
|
2011-03-09 22:38:26 +03:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return evm_inode_removexattr(dentry, name);
|
2007-10-17 10:31:32 +04: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 10:31:36 +04:00
|
|
|
int security_inode_need_killpriv(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 01:11:29 +03: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 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_killpriv(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 01:11:29 +03: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 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
2015-12-24 19:09:39 +03:00
|
|
|
int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2016-06-01 03:24:15 +03:00
|
|
|
struct security_hook_list *hp;
|
|
|
|
int rc;
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2010-01-14 01:33:28 +03:00
|
|
|
return -EOPNOTSUPP;
|
2016-06-01 03:24:15 +03:00
|
|
|
/*
|
|
|
|
* Only one module will provide an attribute with a given name.
|
|
|
|
*/
|
2018-03-29 04:28:23 +03:00
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.inode_getsecurity, list) {
|
2016-06-01 03:24:15 +03:00
|
|
|
rc = hp->hook.inode_getsecurity(inode, name, buffer, alloc);
|
|
|
|
if (rc != -EOPNOTSUPP)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
return -EOPNOTSUPP;
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
|
|
|
|
{
|
2016-06-01 03:24:15 +03:00
|
|
|
struct security_hook_list *hp;
|
|
|
|
int rc;
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2010-01-14 01:33:28 +03:00
|
|
|
return -EOPNOTSUPP;
|
2016-06-01 03:24:15 +03:00
|
|
|
/*
|
|
|
|
* Only one module will provide an attribute with a given name.
|
|
|
|
*/
|
2018-03-29 04:28:23 +03:00
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) {
|
2016-06-01 03:24:15 +03:00
|
|
|
rc = hp->hook.inode_setsecurity(inode, name, value, size,
|
|
|
|
flags);
|
|
|
|
if (rc != -EOPNOTSUPP)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
return -EOPNOTSUPP;
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
|
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
|
|
|
return 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_listsecurity, 0, inode, buffer, buffer_size);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
2013-05-22 20:50:45 +04:00
|
|
|
EXPORT_SYMBOL(security_inode_listsecurity);
|
2007-10-17 10:31:32 +04:00
|
|
|
|
2015-12-24 19:09:39 +03:00
|
|
|
void security_inode_getsecid(struct inode *inode, u32 *secid)
|
2008-03-01 22:51:09 +03:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(inode_getsecid, inode, secid);
|
2008-03-01 22:51:09 +03:00
|
|
|
}
|
|
|
|
|
2016-07-13 18:13:56 +03:00
|
|
|
int security_inode_copy_up(struct dentry *src, struct cred **new)
|
|
|
|
{
|
|
|
|
return call_int_hook(inode_copy_up, 0, src, new);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_copy_up);
|
|
|
|
|
2016-07-13 17:44:49 +03:00
|
|
|
int security_inode_copy_up_xattr(const char *name)
|
|
|
|
{
|
|
|
|
return call_int_hook(inode_copy_up_xattr, -EOPNOTSUPP, name);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_copy_up_xattr);
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
int security_file_permission(struct file *file, int mask)
|
|
|
|
{
|
2009-12-18 05:24:34 +03:00
|
|
|
int ret;
|
|
|
|
|
2015-05-03 01:11:29 +03:00
|
|
|
ret = call_int_hook(file_permission, 0, file, mask);
|
2009-12-18 05:24:34 +03:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return fsnotify_perm(file, mask);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_alloc(struct file *file)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(file_alloc_security, 0, file);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_file_free(struct file *file)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(file_free_security, file);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(file_ioctl, 0, file, cmd, arg);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2012-05-31 03:58:30 +04:00
|
|
|
static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2012-05-31 01:11:23 +04:00
|
|
|
/*
|
2012-05-31 03:58:30 +04: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 01:11:23 +04:00
|
|
|
*/
|
2012-05-31 03:58:30 +04:00
|
|
|
if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ)
|
|
|
|
return prot;
|
2012-05-31 01:11:23 +04:00
|
|
|
if (!(current->personality & READ_IMPLIES_EXEC))
|
2012-05-31 03:58:30 +04: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 12:42:32 +03:00
|
|
|
* NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
|
2012-05-31 03:58:30 +04:00
|
|
|
*/
|
2015-06-29 22:42:03 +03:00
|
|
|
if (!path_noexec(&file->f_path)) {
|
2012-05-31 01:11:23 +04:00
|
|
|
#ifndef CONFIG_MMU
|
2015-01-14 12:42:32 +03: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 01:11:23 +04:00
|
|
|
#endif
|
2012-05-31 03:58:30 +04:00
|
|
|
return prot | PROT_EXEC;
|
2012-05-31 01:11:23 +04:00
|
|
|
}
|
2012-05-31 03:58:30 +04: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 01:11:29 +03:00
|
|
|
ret = call_int_hook(mmap_file, 0, file, prot,
|
2012-05-31 03:58:30 +04:00
|
|
|
mmap_prot(file, prot), flags);
|
2009-10-23 01:30:13 +04:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return ima_file_mmap(file, prot);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2012-05-30 21:30:51 +04:00
|
|
|
int security_mmap_addr(unsigned long addr)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(mmap_addr, 0, addr);
|
2012-05-30 21:30:51 +04:00
|
|
|
}
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
|
|
|
|
unsigned long prot)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(file_mprotect, 0, vma, reqprot, prot);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_lock(struct file *file, unsigned int cmd)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(file_lock, 0, file, cmd);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(file_fcntl, 0, file, cmd, arg);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2014-08-22 19:27:32 +04:00
|
|
|
void security_file_set_fowner(struct file *file)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(file_set_fowner, file);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_send_sigiotask(struct task_struct *tsk,
|
|
|
|
struct fown_struct *fown, int sig)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(file_send_sigiotask, 0, tsk, fown, sig);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_receive(struct file *file)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(file_receive, 0, file);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2012-04-04 21:45:40 +04:00
|
|
|
int security_file_open(struct file *file, const struct cred *cred)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2009-12-18 05:24:34 +03:00
|
|
|
int ret;
|
|
|
|
|
2015-05-03 01:11:29 +03:00
|
|
|
ret = call_int_hook(file_open, 0, file, cred);
|
2009-12-18 05:24:34 +03:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return fsnotify_perm(file, MAY_OPEN);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2017-03-24 14:46:33 +03:00
|
|
|
int security_task_alloc(struct task_struct *task, unsigned long clone_flags)
|
|
|
|
{
|
|
|
|
return call_int_hook(task_alloc, 0, task, clone_flags);
|
|
|
|
}
|
|
|
|
|
2011-12-22 00:17:03 +04:00
|
|
|
void security_task_free(struct task_struct *task)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(task_free, task);
|
2011-12-22 00:17:03 +04: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 12:14:21 +04:00
|
|
|
int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
|
|
|
|
{
|
2015-05-03 01:11:29 +03: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 12:14:21 +04: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 02:39:23 +03:00
|
|
|
void security_cred_free(struct cred *cred)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(cred_free, cred);
|
2007-10-17 10:31:32 +04: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 02:39:23 +03:00
|
|
|
int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03: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 02:39:23 +03: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 12:14:21 +04:00
|
|
|
void security_transfer_creds(struct cred *new, const struct cred *old)
|
|
|
|
{
|
2015-05-03 01:11:29 +03: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 12:14:21 +04:00
|
|
|
}
|
|
|
|
|
2018-01-09 00:36:19 +03:00
|
|
|
void security_cred_getsecid(const struct cred *c, u32 *secid)
|
|
|
|
{
|
|
|
|
*secid = 0;
|
|
|
|
call_void_hook(cred_getsecid, c, secid);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_cred_getsecid);
|
|
|
|
|
2008-11-14 02:39:28 +03:00
|
|
|
int security_kernel_act_as(struct cred *new, u32 secid)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(kernel_act_as, 0, new, secid);
|
2008-11-14 02:39:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_kernel_create_files_as(struct cred *new, struct inode *inode)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(kernel_create_files_as, 0, new, inode);
|
2008-11-14 02:39:28 +03:00
|
|
|
}
|
|
|
|
|
2009-11-03 08:35:32 +03:00
|
|
|
int security_kernel_module_request(char *kmod_name)
|
2009-08-13 17:44:57 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(kernel_module_request, 0, kmod_name);
|
2009-08-13 17:44:57 +04:00
|
|
|
}
|
|
|
|
|
2016-01-31 06:23:26 +03: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 18:07:32 +03:00
|
|
|
int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
|
|
|
|
enum kernel_read_file_id id)
|
2015-12-29 00:02:29 +03:00
|
|
|
{
|
2016-01-15 01:57:47 +03: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 00:02:29 +03: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 02:39:23 +03:00
|
|
|
int security_task_fix_setuid(struct cred *new, const struct cred *old,
|
|
|
|
int flags)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(task_fix_setuid, 0, new, old, flags);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_setpgid(struct task_struct *p, pid_t pgid)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(task_setpgid, 0, p, pgid);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getpgid(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(task_getpgid, 0, p);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getsid(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(task_getsid, 0, p);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_task_getsecid(struct task_struct *p, u32 *secid)
|
|
|
|
{
|
2015-05-03 01:11:42 +03:00
|
|
|
*secid = 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(task_getsecid, p, secid);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_task_getsecid);
|
|
|
|
|
|
|
|
int security_task_setnice(struct task_struct *p, int nice)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(task_setnice, 0, p, nice);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_setioprio(struct task_struct *p, int ioprio)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(task_setioprio, 0, p, ioprio);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getioprio(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(task_getioprio, 0, p);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
prlimit,security,selinux: add a security hook for prlimit
When SELinux was first added to the kernel, a process could only get
and set its own resource limits via getrlimit(2) and setrlimit(2), so no
MAC checks were required for those operations, and thus no security hooks
were defined for them. Later, SELinux introduced a hook for setlimit(2)
with a check if the hard limit was being changed in order to be able to
rely on the hard limit value as a safe reset point upon context
transitions.
Later on, when prlimit(2) was added to the kernel with the ability to get
or set resource limits (hard or soft) of another process, LSM/SELinux was
not updated other than to pass the target process to the setrlimit hook.
This resulted in incomplete control over both getting and setting the
resource limits of another process.
Add a new security_task_prlimit() hook to the check_prlimit_permission()
function to provide complete mediation. The hook is only called when
acting on another task, and only if the existing DAC/capability checks
would allow access. Pass flags down to the hook to indicate whether the
prlimit(2) call will read, write, or both read and write the resource
limits of the target process.
The existing security_task_setrlimit() hook is left alone; it continues
to serve a purpose in supporting the ability to make decisions based on
the old and/or new resource limit values when setting limits. This
is consistent with the DAC/capability logic, where
check_prlimit_permission() performs generic DAC/capability checks for
acting on another task, while do_prlimit() performs a capability check
based on a comparison of the old and new resource limits. Fix the
inline documentation for the hook to match the code.
Implement the new hook for SELinux. For setting resource limits, we
reuse the existing setrlimit permission. Note that this does overload
the setrlimit permission to mean the ability to set the resource limit
(soft or hard) of another process or the ability to change one's own
hard limit. For getting resource limits, a new getrlimit permission
is defined. This was not originally defined since getrlimit(2) could
only be used to obtain a process' own limits.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <james.l.morris@oracle.com>
2017-02-17 15:57:00 +03:00
|
|
|
int security_task_prlimit(const struct cred *cred, const struct cred *tcred,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
return call_int_hook(task_prlimit, 0, cred, tcred, flags);
|
|
|
|
}
|
|
|
|
|
2009-08-26 20:41:16 +04:00
|
|
|
int security_task_setrlimit(struct task_struct *p, unsigned int resource,
|
|
|
|
struct rlimit *new_rlim)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(task_setrlimit, 0, p, resource, new_rlim);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2010-10-14 23:21:18 +04:00
|
|
|
int security_task_setscheduler(struct task_struct *p)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(task_setscheduler, 0, p);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getscheduler(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(task_getscheduler, 0, p);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_movememory(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(task_movememory, 0, p);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_kill(struct task_struct *p, struct siginfo *info,
|
usb, signal, security: only pass the cred, not the secid, to kill_pid_info_as_cred and security_task_kill
commit d178bc3a708f39cbfefc3fab37032d3f2511b4ec ("user namespace: usb:
make usb urbs user namespace aware (v2)") changed kill_pid_info_as_uid
to kill_pid_info_as_cred, saving and passing a cred structure instead of
uids. Since the secid can be obtained from the cred, drop the secid fields
from the usb_dev_state and async structures, and drop the secid argument to
kill_pid_info_as_cred. Replace the secid argument to security_task_kill
with the cred. Update SELinux, Smack, and AppArmor to use the cred, which
avoids the need for Smack and AppArmor to use a secid at all in this hook.
Further changes to Smack might still be required to take full advantage of
this change, since it should now be possible to perform capability
checking based on the supplied cred. The changes to Smack and AppArmor
have only been compile-tested.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Acked-by: Paul Moore <paul@paul-moore.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: James Morris <james.morris@microsoft.com>
2017-09-08 19:40:01 +03:00
|
|
|
int sig, const struct cred *cred)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
usb, signal, security: only pass the cred, not the secid, to kill_pid_info_as_cred and security_task_kill
commit d178bc3a708f39cbfefc3fab37032d3f2511b4ec ("user namespace: usb:
make usb urbs user namespace aware (v2)") changed kill_pid_info_as_uid
to kill_pid_info_as_cred, saving and passing a cred structure instead of
uids. Since the secid can be obtained from the cred, drop the secid fields
from the usb_dev_state and async structures, and drop the secid argument to
kill_pid_info_as_cred. Replace the secid argument to security_task_kill
with the cred. Update SELinux, Smack, and AppArmor to use the cred, which
avoids the need for Smack and AppArmor to use a secid at all in this hook.
Further changes to Smack might still be required to take full advantage of
this change, since it should now be possible to perform capability
checking based on the supplied cred. The changes to Smack and AppArmor
have only been compile-tested.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Acked-by: Paul Moore <paul@paul-moore.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: James Morris <james.morris@microsoft.com>
2017-09-08 19:40:01 +03:00
|
|
|
return call_int_hook(task_kill, 0, p, info, sig, cred);
|
2007-10-17 10:31:32 +04: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 02:39:23 +03:00
|
|
|
unsigned long arg4, unsigned long arg5)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:42 +03:00
|
|
|
int thisrc;
|
|
|
|
int rc = -ENOSYS;
|
|
|
|
struct security_hook_list *hp;
|
|
|
|
|
2018-03-29 04:28:23 +03:00
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.task_prctl, list) {
|
2015-05-03 01:11:42 +03:00
|
|
|
thisrc = hp->hook.task_prctl(option, arg2, arg3, arg4, arg5);
|
|
|
|
if (thisrc != -ENOSYS) {
|
|
|
|
rc = thisrc;
|
|
|
|
if (thisrc != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rc;
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_task_to_inode(struct task_struct *p, struct inode *inode)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(task_to_inode, p, inode);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(ipc_permission, 0, ipcp, flag);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2008-03-01 22:51:09 +03:00
|
|
|
void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
|
|
|
|
{
|
2015-05-03 01:11:42 +03:00
|
|
|
*secid = 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(ipc_getsecid, ipcp, secid);
|
2008-03-01 22:51:09 +03:00
|
|
|
}
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
int security_msg_msg_alloc(struct msg_msg *msg)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(msg_msg_alloc_security, 0, msg);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_msg_msg_free(struct msg_msg *msg)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(msg_msg_free_security, msg);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 05:22:26 +03:00
|
|
|
int security_msg_queue_alloc(struct kern_ipc_perm *msq)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(msg_queue_alloc_security, 0, msq);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 05:22:26 +03:00
|
|
|
void security_msg_queue_free(struct kern_ipc_perm *msq)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(msg_queue_free_security, msq);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 05:22:26 +03:00
|
|
|
int security_msg_queue_associate(struct kern_ipc_perm *msq, int msqflg)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(msg_queue_associate, 0, msq, msqflg);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 05:22:26 +03:00
|
|
|
int security_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(msg_queue_msgctl, 0, msq, cmd);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 05:22:26 +03:00
|
|
|
int security_msg_queue_msgsnd(struct kern_ipc_perm *msq,
|
2007-10-17 10:31:32 +04:00
|
|
|
struct msg_msg *msg, int msqflg)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(msg_queue_msgsnd, 0, msq, msg, msqflg);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 05:22:26 +03:00
|
|
|
int security_msg_queue_msgrcv(struct kern_ipc_perm *msq, struct msg_msg *msg,
|
2007-10-17 10:31:32 +04:00
|
|
|
struct task_struct *target, long type, int mode)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 05:08:27 +03:00
|
|
|
int security_shm_alloc(struct kern_ipc_perm *shp)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(shm_alloc_security, 0, shp);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 05:08:27 +03:00
|
|
|
void security_shm_free(struct kern_ipc_perm *shp)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(shm_free_security, shp);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 05:08:27 +03:00
|
|
|
int security_shm_associate(struct kern_ipc_perm *shp, int shmflg)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(shm_associate, 0, shp, shmflg);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 05:08:27 +03:00
|
|
|
int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(shm_shmctl, 0, shp, cmd);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 05:08:27 +03:00
|
|
|
int security_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr, int shmflg)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 04:52:43 +03:00
|
|
|
int security_sem_alloc(struct kern_ipc_perm *sma)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sem_alloc_security, 0, sma);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 04:52:43 +03:00
|
|
|
void security_sem_free(struct kern_ipc_perm *sma)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(sem_free_security, sma);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 04:52:43 +03:00
|
|
|
int security_sem_associate(struct kern_ipc_perm *sma, int semflg)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sem_associate, 0, sma, semflg);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 04:52:43 +03:00
|
|
|
int security_sem_semctl(struct kern_ipc_perm *sma, int cmd)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sem_semctl, 0, sma, cmd);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2018-03-23 04:52:43 +03:00
|
|
|
int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops,
|
2007-10-17 10:31:32 +04:00
|
|
|
unsigned nsops, int alter)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sem_semop, 0, sma, sops, nsops, alter);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_d_instantiate(struct dentry *dentry, struct inode *inode)
|
|
|
|
{
|
|
|
|
if (unlikely(inode && IS_PRIVATE(inode)))
|
|
|
|
return;
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(d_instantiate, dentry, inode);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_d_instantiate);
|
|
|
|
|
|
|
|
int security_getprocattr(struct task_struct *p, char *name, char **value)
|
|
|
|
{
|
2015-05-03 01:11:42 +03:00
|
|
|
return call_int_hook(getprocattr, -EINVAL, p, name, value);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2017-01-09 18:07:31 +03:00
|
|
|
int security_setprocattr(const char *name, void *value, size_t size)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2017-01-09 18:07:31 +03:00
|
|
|
return call_int_hook(setprocattr, -EINVAL, name, value, size);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_netlink_send(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(netlink_send, 0, sk, skb);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2013-05-22 20:50:35 +04:00
|
|
|
int security_ismaclabel(const char *name)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(ismaclabel, 0, name);
|
2013-05-22 20:50:35 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_ismaclabel);
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
|
|
|
|
{
|
2015-05-03 01:11:42 +03:00
|
|
|
return call_int_hook(secid_to_secctx, -EOPNOTSUPP, secid, secdata,
|
|
|
|
seclen);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secid_to_secctx);
|
|
|
|
|
2008-04-29 23:52:51 +04:00
|
|
|
int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
|
2008-01-16 02:47:35 +03:00
|
|
|
{
|
2015-05-03 01:11:42 +03:00
|
|
|
*secid = 0;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid);
|
2008-01-16 02:47:35 +03:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secctx_to_secid);
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
void security_release_secctx(char *secdata, u32 seclen)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(release_secctx, secdata, seclen);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_release_secctx);
|
|
|
|
|
2015-12-24 19:09:40 +03:00
|
|
|
void security_inode_invalidate_secctx(struct inode *inode)
|
|
|
|
{
|
|
|
|
call_void_hook(inode_invalidate_secctx, inode);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_invalidate_secctx);
|
|
|
|
|
2009-09-03 22:25:57 +04:00
|
|
|
int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen);
|
2009-09-03 22:25:57 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_notifysecctx);
|
|
|
|
|
|
|
|
int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen);
|
2009-09-03 22:25:57 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_setsecctx);
|
|
|
|
|
|
|
|
int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
|
|
|
|
{
|
2015-05-03 01:11:42 +03:00
|
|
|
return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen);
|
2009-09-03 22:25:57 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_getsecctx);
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
#ifdef CONFIG_SECURITY_NETWORK
|
|
|
|
|
2011-01-06 02:38:53 +03:00
|
|
|
int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(unix_stream_connect, 0, sock, other, newsk);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_unix_stream_connect);
|
|
|
|
|
|
|
|
int security_unix_may_send(struct socket *sock, struct socket *other)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(unix_may_send, 0, sock, other);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_unix_may_send);
|
|
|
|
|
|
|
|
int security_socket_create(int family, int type, int protocol, int kern)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_create, 0, family, type, protocol, kern);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_post_create(struct socket *sock, int family,
|
|
|
|
int type, int protocol, int kern)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_post_create, 0, sock, family, type,
|
2007-10-17 10:31:32 +04:00
|
|
|
protocol, kern);
|
|
|
|
}
|
|
|
|
|
2018-05-04 17:28:19 +03:00
|
|
|
int security_socket_socketpair(struct socket *socka, struct socket *sockb)
|
|
|
|
{
|
|
|
|
return call_int_hook(socket_socketpair, 0, socka, sockb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_socket_socketpair);
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_bind, 0, sock, address, addrlen);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_connect, 0, sock, address, addrlen);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_listen(struct socket *sock, int backlog)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_listen, 0, sock, backlog);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_accept(struct socket *sock, struct socket *newsock)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_accept, 0, sock, newsock);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_sendmsg, 0, sock, msg, size);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
|
|
|
|
int size, int flags)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_recvmsg, 0, sock, msg, size, flags);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getsockname(struct socket *sock)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_getsockname, 0, sock);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getpeername(struct socket *sock)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_getpeername, 0, sock);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getsockopt(struct socket *sock, int level, int optname)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_getsockopt, 0, sock, level, optname);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_setsockopt(struct socket *sock, int level, int optname)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_setsockopt, 0, sock, level, optname);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_shutdown(struct socket *sock, int how)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_shutdown, 0, sock, how);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(socket_sock_rcv_skb, 0, sk, skb);
|
2007-10-17 10:31:32 +04: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 01:11:42 +03:00
|
|
|
return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock,
|
|
|
|
optval, optlen, len);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
|
|
|
|
{
|
2015-08-24 15:22:25 +03:00
|
|
|
return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock,
|
|
|
|
skb, secid);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_socket_getpeersec_dgram);
|
|
|
|
|
|
|
|
int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(sk_alloc_security, 0, sk, family, priority);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_sk_free(struct sock *sk)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(sk_free_security, sk);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_sk_clone(const struct sock *sk, struct sock *newsk)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(sk_clone_security, sk, newsk);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
2011-10-07 13:40:59 +04:00
|
|
|
EXPORT_SYMBOL(security_sk_clone);
|
2007-10-17 10:31:32 +04:00
|
|
|
|
|
|
|
void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(sk_getsecid, sk, &fl->flowi_secid);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sk_classify_flow);
|
|
|
|
|
|
|
|
void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(req_classify_flow, req, fl);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_req_classify_flow);
|
|
|
|
|
|
|
|
void security_sock_graft(struct sock *sk, struct socket *parent)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(sock_graft, sk, parent);
|
2007-10-17 10:31:32 +04: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 01:11:29 +03:00
|
|
|
return call_int_hook(inet_conn_request, 0, sk, skb, req);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inet_conn_request);
|
|
|
|
|
|
|
|
void security_inet_csk_clone(struct sock *newsk,
|
|
|
|
const struct request_sock *req)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(inet_csk_clone, newsk, req);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_inet_conn_established(struct sock *sk,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(inet_conn_established, sk, skb);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
2018-02-13 23:53:21 +03:00
|
|
|
EXPORT_SYMBOL(security_inet_conn_established);
|
2007-10-17 10:31:32 +04:00
|
|
|
|
2010-10-14 00:24:41 +04:00
|
|
|
int security_secmark_relabel_packet(u32 secid)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(secmark_relabel_packet, 0, secid);
|
2010-10-14 00:24:41 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secmark_relabel_packet);
|
|
|
|
|
|
|
|
void security_secmark_refcount_inc(void)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(secmark_refcount_inc);
|
2010-10-14 00:24:41 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secmark_refcount_inc);
|
|
|
|
|
|
|
|
void security_secmark_refcount_dec(void)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(secmark_refcount_dec);
|
2010-10-14 00:24:41 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secmark_refcount_dec);
|
|
|
|
|
2013-01-14 11:12:19 +04:00
|
|
|
int security_tun_dev_alloc_security(void **security)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(tun_dev_alloc_security, 0, security);
|
2013-01-14 11:12:19 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_alloc_security);
|
|
|
|
|
|
|
|
void security_tun_dev_free_security(void *security)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(tun_dev_free_security, security);
|
2013-01-14 11:12:19 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_free_security);
|
|
|
|
|
2009-08-29 02:12:43 +04:00
|
|
|
int security_tun_dev_create(void)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(tun_dev_create, 0);
|
2009-08-29 02:12:43 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_create);
|
|
|
|
|
2013-01-14 11:12:19 +04:00
|
|
|
int security_tun_dev_attach_queue(void *security)
|
2009-08-29 02:12:43 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(tun_dev_attach_queue, 0, security);
|
2009-08-29 02:12:43 +04:00
|
|
|
}
|
2013-01-14 11:12:19 +04:00
|
|
|
EXPORT_SYMBOL(security_tun_dev_attach_queue);
|
2009-08-29 02:12:43 +04:00
|
|
|
|
2013-01-14 11:12:19 +04:00
|
|
|
int security_tun_dev_attach(struct sock *sk, void *security)
|
2009-08-29 02:12:43 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(tun_dev_attach, 0, sk, security);
|
2009-08-29 02:12:43 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_attach);
|
|
|
|
|
2013-01-14 11:12:19 +04:00
|
|
|
int security_tun_dev_open(void *security)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(tun_dev_open, 0, security);
|
2013-01-14 11:12:19 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_open);
|
|
|
|
|
2018-02-13 23:53:21 +03:00
|
|
|
int security_sctp_assoc_request(struct sctp_endpoint *ep, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
return call_int_hook(sctp_assoc_request, 0, ep, skb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sctp_assoc_request);
|
|
|
|
|
|
|
|
int security_sctp_bind_connect(struct sock *sk, int optname,
|
|
|
|
struct sockaddr *address, int addrlen)
|
|
|
|
{
|
|
|
|
return call_int_hook(sctp_bind_connect, 0, sk, optname,
|
|
|
|
address, addrlen);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sctp_bind_connect);
|
|
|
|
|
|
|
|
void security_sctp_sk_clone(struct sctp_endpoint *ep, struct sock *sk,
|
|
|
|
struct sock *newsk)
|
|
|
|
{
|
|
|
|
call_void_hook(sctp_sk_clone, ep, sk, newsk);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sctp_sk_clone);
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
#endif /* CONFIG_SECURITY_NETWORK */
|
|
|
|
|
IB/core: Enforce PKey security on QPs
Add new LSM hooks to allocate and free security contexts and check for
permission to access a PKey.
Allocate and free a security context when creating and destroying a QP.
This context is used for controlling access to PKeys.
When a request is made to modify a QP that changes the port, PKey index,
or alternate path, check that the QP has permission for the PKey in the
PKey table index on the subnet prefix of the port. If the QP is shared
make sure all handles to the QP also have access.
Store which port and PKey index a QP is using. After the reset to init
transition the user can modify the port, PKey index and alternate path
independently. So port and PKey settings changes can be a merge of the
previous settings and the new ones.
In order to maintain access control if there are PKey table or subnet
prefix change keep a list of all QPs are using each PKey index on
each port. If a change occurs all QPs using that device and port must
have access enforced for the new cache settings.
These changes add a transaction to the QP modify process. Association
with the old port and PKey index must be maintained if the modify fails,
and must be removed if it succeeds. Association with the new port and
PKey index must be established prior to the modify and removed if the
modify fails.
1. When a QP is modified to a particular Port, PKey index or alternate
path insert that QP into the appropriate lists.
2. Check permission to access the new settings.
3. If step 2 grants access attempt to modify the QP.
4a. If steps 2 and 3 succeed remove any prior associations.
4b. If ether fails remove the new setting associations.
If a PKey table or subnet prefix changes walk the list of QPs and
check that they have permission. If not send the QP to the error state
and raise a fatal error event. If it's a shared QP make sure all the
QPs that share the real_qp have permission as well. If the QP that
owns a security structure is denied access the security structure is
marked as such and the QP is added to an error_list. Once the moving
the QP to error is complete the security structure mark is cleared.
Maintaining the lists correctly turns QP destroy into a transaction.
The hardware driver for the device frees the ib_qp structure, so while
the destroy is in progress the ib_qp pointer in the ib_qp_security
struct is undefined. When the destroy process begins the ib_qp_security
structure is marked as destroying. This prevents any action from being
taken on the QP pointer. After the QP is destroyed successfully it
could still listed on an error_list wait for it to be processed by that
flow before cleaning up the structure.
If the destroy fails the QPs port and PKey settings are reinserted into
the appropriate lists, the destroying flag is cleared, and access control
is enforced, in case there were any cache changes during the destroy
flow.
To keep the security changes isolated a new file is used to hold security
related functionality.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Acked-by: Doug Ledford <dledford@redhat.com>
[PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2017-05-19 15:48:52 +03:00
|
|
|
#ifdef CONFIG_SECURITY_INFINIBAND
|
|
|
|
|
|
|
|
int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey)
|
|
|
|
{
|
|
|
|
return call_int_hook(ib_pkey_access, 0, sec, subnet_prefix, pkey);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_ib_pkey_access);
|
|
|
|
|
2017-05-19 15:48:54 +03:00
|
|
|
int security_ib_endport_manage_subnet(void *sec, const char *dev_name, u8 port_num)
|
|
|
|
{
|
|
|
|
return call_int_hook(ib_endport_manage_subnet, 0, sec, dev_name, port_num);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_ib_endport_manage_subnet);
|
|
|
|
|
IB/core: Enforce PKey security on QPs
Add new LSM hooks to allocate and free security contexts and check for
permission to access a PKey.
Allocate and free a security context when creating and destroying a QP.
This context is used for controlling access to PKeys.
When a request is made to modify a QP that changes the port, PKey index,
or alternate path, check that the QP has permission for the PKey in the
PKey table index on the subnet prefix of the port. If the QP is shared
make sure all handles to the QP also have access.
Store which port and PKey index a QP is using. After the reset to init
transition the user can modify the port, PKey index and alternate path
independently. So port and PKey settings changes can be a merge of the
previous settings and the new ones.
In order to maintain access control if there are PKey table or subnet
prefix change keep a list of all QPs are using each PKey index on
each port. If a change occurs all QPs using that device and port must
have access enforced for the new cache settings.
These changes add a transaction to the QP modify process. Association
with the old port and PKey index must be maintained if the modify fails,
and must be removed if it succeeds. Association with the new port and
PKey index must be established prior to the modify and removed if the
modify fails.
1. When a QP is modified to a particular Port, PKey index or alternate
path insert that QP into the appropriate lists.
2. Check permission to access the new settings.
3. If step 2 grants access attempt to modify the QP.
4a. If steps 2 and 3 succeed remove any prior associations.
4b. If ether fails remove the new setting associations.
If a PKey table or subnet prefix changes walk the list of QPs and
check that they have permission. If not send the QP to the error state
and raise a fatal error event. If it's a shared QP make sure all the
QPs that share the real_qp have permission as well. If the QP that
owns a security structure is denied access the security structure is
marked as such and the QP is added to an error_list. Once the moving
the QP to error is complete the security structure mark is cleared.
Maintaining the lists correctly turns QP destroy into a transaction.
The hardware driver for the device frees the ib_qp structure, so while
the destroy is in progress the ib_qp pointer in the ib_qp_security
struct is undefined. When the destroy process begins the ib_qp_security
structure is marked as destroying. This prevents any action from being
taken on the QP pointer. After the QP is destroyed successfully it
could still listed on an error_list wait for it to be processed by that
flow before cleaning up the structure.
If the destroy fails the QPs port and PKey settings are reinserted into
the appropriate lists, the destroying flag is cleared, and access control
is enforced, in case there were any cache changes during the destroy
flow.
To keep the security changes isolated a new file is used to hold security
related functionality.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Acked-by: Doug Ledford <dledford@redhat.com>
[PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2017-05-19 15:48:52 +03:00
|
|
|
int security_ib_alloc_security(void **sec)
|
|
|
|
{
|
|
|
|
return call_int_hook(ib_alloc_security, 0, sec);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_ib_alloc_security);
|
|
|
|
|
|
|
|
void security_ib_free_security(void *sec)
|
|
|
|
{
|
|
|
|
call_void_hook(ib_free_security, sec);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_ib_free_security);
|
|
|
|
#endif /* CONFIG_SECURITY_INFINIBAND */
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
#ifdef CONFIG_SECURITY_NETWORK_XFRM
|
|
|
|
|
2014-03-07 15:44:19 +04:00
|
|
|
int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
|
|
|
|
struct xfrm_user_sec_ctx *sec_ctx,
|
|
|
|
gfp_t gfp)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(xfrm_policy_alloc_security, 0, ctxp, sec_ctx, gfp);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_xfrm_policy_alloc);
|
|
|
|
|
2008-04-13 06:07:52 +04:00
|
|
|
int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
|
|
|
|
struct xfrm_sec_ctx **new_ctxp)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2008-04-13 06:07:52 +04:00
|
|
|
void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(xfrm_policy_free_security, ctx);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_xfrm_policy_free);
|
|
|
|
|
2008-04-13 06:07:52 +04:00
|
|
|
int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(xfrm_policy_delete_security, 0, ctx);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2013-07-24 01:38:38 +04:00
|
|
|
int security_xfrm_state_alloc(struct xfrm_state *x,
|
|
|
|
struct xfrm_user_sec_ctx *sec_ctx)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx);
|
2007-10-17 10:31:32 +04: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 01:11:29 +03:00
|
|
|
return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_xfrm_state_delete(struct xfrm_state *x)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(xfrm_state_delete_security, 0, x);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_xfrm_state_delete);
|
|
|
|
|
|
|
|
void security_xfrm_state_free(struct xfrm_state *x)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(xfrm_state_free_security, x);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2008-04-13 06:07:52 +04:00
|
|
|
int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid, dir);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
|
2011-02-23 05:13:15 +03:00
|
|
|
struct xfrm_policy *xp,
|
|
|
|
const struct flowi *fl)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:42 +03: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
|
|
|
|
*/
|
2018-03-29 04:28:23 +03:00
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.xfrm_state_pol_flow_match,
|
2015-05-03 01:11:42 +03:00
|
|
|
list) {
|
|
|
|
rc = hp->hook.xfrm_state_pol_flow_match(x, xp, fl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(xfrm_decode_session, 0, skb, secid, 1);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
int rc = call_int_hook(xfrm_decode_session, 0, skb, &fl->flowi_secid,
|
|
|
|
0);
|
2007-10-17 10:31:32 +04: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 02:39:23 +03:00
|
|
|
int security_key_alloc(struct key *key, const struct cred *cred,
|
|
|
|
unsigned long flags)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(key_alloc, 0, key, cred, flags);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_key_free(struct key *key)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(key_free, key);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_key_permission(key_ref_t key_ref,
|
2014-03-14 21:44:49 +04:00
|
|
|
const struct cred *cred, unsigned perm)
|
2007-10-17 10:31:32 +04:00
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(key_permission, 0, key_ref, cred, perm);
|
2007-10-17 10:31:32 +04:00
|
|
|
}
|
|
|
|
|
2008-04-29 12:01:26 +04:00
|
|
|
int security_key_getsecurity(struct key *key, char **_buffer)
|
|
|
|
{
|
2015-05-03 01:11:42 +03:00
|
|
|
*_buffer = NULL;
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(key_getsecurity, 0, key, _buffer);
|
2008-04-29 12:01:26 +04:00
|
|
|
}
|
|
|
|
|
2007-10-17 10:31:32 +04:00
|
|
|
#endif /* CONFIG_KEYS */
|
2008-03-01 23:00:05 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIT
|
|
|
|
|
|
|
|
int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(audit_rule_init, 0, field, op, rulestr, lsmrule);
|
2008-03-01 23:00:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_audit_rule_known(struct audit_krule *krule)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(audit_rule_known, 0, krule);
|
2008-03-01 23:00:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_audit_rule_free(void *lsmrule)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
call_void_hook(audit_rule_free, lsmrule);
|
2008-03-01 23:00:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
|
|
|
|
struct audit_context *actx)
|
|
|
|
{
|
2015-05-03 01:11:29 +03:00
|
|
|
return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule,
|
|
|
|
actx);
|
2008-03-01 23:00:05 +03:00
|
|
|
}
|
2015-05-03 01:11:42 +03:00
|
|
|
#endif /* CONFIG_AUDIT */
|
2017-10-18 23:00:24 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_BPF_SYSCALL
|
|
|
|
int security_bpf(int cmd, union bpf_attr *attr, unsigned int size)
|
|
|
|
{
|
|
|
|
return call_int_hook(bpf, 0, cmd, attr, size);
|
|
|
|
}
|
|
|
|
int security_bpf_map(struct bpf_map *map, fmode_t fmode)
|
|
|
|
{
|
|
|
|
return call_int_hook(bpf_map, 0, map, fmode);
|
|
|
|
}
|
|
|
|
int security_bpf_prog(struct bpf_prog *prog)
|
|
|
|
{
|
|
|
|
return call_int_hook(bpf_prog, 0, prog);
|
|
|
|
}
|
|
|
|
int security_bpf_map_alloc(struct bpf_map *map)
|
|
|
|
{
|
|
|
|
return call_int_hook(bpf_map_alloc_security, 0, map);
|
|
|
|
}
|
|
|
|
int security_bpf_prog_alloc(struct bpf_prog_aux *aux)
|
|
|
|
{
|
|
|
|
return call_int_hook(bpf_prog_alloc_security, 0, aux);
|
|
|
|
}
|
|
|
|
void security_bpf_map_free(struct bpf_map *map)
|
|
|
|
{
|
|
|
|
call_void_hook(bpf_map_free_security, map);
|
|
|
|
}
|
|
|
|
void security_bpf_prog_free(struct bpf_prog_aux *aux)
|
|
|
|
{
|
|
|
|
call_void_hook(bpf_prog_free_security, aux);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_BPF_SYSCALL */
|