2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Security plug functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
|
|
|
|
* Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
|
|
|
|
* Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
|
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 20:48:52 +08:00
|
|
|
* Copyright (C) 2016 Mellanox Technologies
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2018-10-11 08:18:25 +08:00
|
|
|
#define pr_fmt(fmt) "LSM: " fmt
|
|
|
|
|
2017-10-19 04:00:24 +08:00
|
|
|
#include <linux/bpf.h>
|
2006-01-12 04:17:46 +08:00
|
|
|
#include <linux/capability.h>
|
2013-05-23 00:50:34 +08:00
|
|
|
#include <linux/dcache.h>
|
2018-12-10 04:36:29 +08:00
|
|
|
#include <linux/export.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
2015-05-03 06:10:46 +08:00
|
|
|
#include <linux/lsm_hooks.h>
|
2011-03-10 03:13:22 +08:00
|
|
|
#include <linux/integrity.h>
|
2009-10-23 05:30:13 +08:00
|
|
|
#include <linux/ima.h>
|
2011-03-10 03:38:26 +08:00
|
|
|
#include <linux/evm.h>
|
2012-02-13 11:58:52 +08:00
|
|
|
#include <linux/fsnotify.h>
|
2012-05-31 05:11:23 +08:00
|
|
|
#include <linux/mman.h>
|
|
|
|
#include <linux/mount.h>
|
|
|
|
#include <linux/personality.h>
|
2012-07-02 13:34:11 +08:00
|
|
|
#include <linux/backing-dev.h>
|
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-11 04:48:48 +08:00
|
|
|
#include <linux/string.h>
|
2018-11-21 03:55:02 +08:00
|
|
|
#include <linux/msg.h>
|
2012-02-13 11:58:52 +08:00
|
|
|
#include <net/flow.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-06-16 09:19:10 +08:00
|
|
|
#define MAX_LSM_EVM_XATTR 2
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-20 07:58:31 +08:00
|
|
|
/* How many LSMs were built into the kernel? */
|
|
|
|
#define LSM_COUNT (__end_lsm_info - __start_lsm_info)
|
2019-08-20 08:17:37 +08:00
|
|
|
#define EARLY_LSM_COUNT (__end_early_lsm_info - __start_early_lsm_info)
|
2018-09-20 07:58:31 +08:00
|
|
|
|
2017-03-22 18:46:19 +08:00
|
|
|
struct security_hook_heads security_hook_heads __lsm_ro_after_init;
|
2019-06-14 20:20:14 +08:00
|
|
|
static BLOCKING_NOTIFIER_HEAD(blocking_lsm_notifier_chain);
|
2017-05-19 20:48:53 +08:00
|
|
|
|
2018-11-13 04:02:49 +08:00
|
|
|
static struct kmem_cache *lsm_file_cache;
|
2018-09-22 08:19:29 +08:00
|
|
|
static struct kmem_cache *lsm_inode_cache;
|
2018-11-13 04:02:49 +08:00
|
|
|
|
2017-01-19 09:09:05 +08:00
|
|
|
char *lsm_names;
|
2018-11-13 01:30:56 +08:00
|
|
|
static struct lsm_blob_sizes blob_sizes __lsm_ro_after_init;
|
|
|
|
|
2008-03-07 00:09:10 +08:00
|
|
|
/* Boot-time LSM user choice */
|
2018-09-20 08:30:09 +08:00
|
|
|
static __initdata const char *chosen_lsm_order;
|
2018-09-20 04:11:41 +08:00
|
|
|
static __initdata const char *chosen_major_lsm;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-10-10 05:27:46 +08:00
|
|
|
static __initconst const char * const builtin_lsm_order = CONFIG_LSM;
|
|
|
|
|
2018-09-20 07:58:31 +08:00
|
|
|
/* Ordered list of LSMs to initialize. */
|
|
|
|
static __initdata struct lsm_info **ordered_lsms;
|
2018-09-20 10:57:06 +08:00
|
|
|
static __initdata struct lsm_info *exclusive;
|
2018-09-20 07:58:31 +08:00
|
|
|
|
2018-10-11 08:18:25 +08:00
|
|
|
static __initdata bool debug;
|
|
|
|
#define init_debug(...) \
|
|
|
|
do { \
|
|
|
|
if (debug) \
|
|
|
|
pr_info(__VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
2018-09-14 14:17:50 +08:00
|
|
|
static bool __init is_enabled(struct lsm_info *lsm)
|
|
|
|
{
|
2018-10-10 05:42:57 +08:00
|
|
|
if (!lsm->enabled)
|
|
|
|
return false;
|
2018-09-14 14:17:50 +08:00
|
|
|
|
2018-10-10 05:42:57 +08:00
|
|
|
return *lsm->enabled;
|
2018-09-14 14:17:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark an LSM's enabled flag. */
|
|
|
|
static int lsm_enabled_true __initdata = 1;
|
|
|
|
static int lsm_enabled_false __initdata = 0;
|
|
|
|
static void __init set_enabled(struct lsm_info *lsm, bool enabled)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* When an LSM hasn't configured an enable variable, we can use
|
|
|
|
* a hard-coded location for storing the default enabled state.
|
|
|
|
*/
|
|
|
|
if (!lsm->enabled) {
|
|
|
|
if (enabled)
|
|
|
|
lsm->enabled = &lsm_enabled_true;
|
|
|
|
else
|
|
|
|
lsm->enabled = &lsm_enabled_false;
|
|
|
|
} else if (lsm->enabled == &lsm_enabled_true) {
|
|
|
|
if (!enabled)
|
|
|
|
lsm->enabled = &lsm_enabled_false;
|
|
|
|
} else if (lsm->enabled == &lsm_enabled_false) {
|
|
|
|
if (enabled)
|
|
|
|
lsm->enabled = &lsm_enabled_true;
|
|
|
|
} else {
|
|
|
|
*lsm->enabled = enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 07:58:31 +08:00
|
|
|
/* Is an LSM already listed in the ordered LSMs list? */
|
|
|
|
static bool __init exists_ordered_lsm(struct lsm_info *lsm)
|
|
|
|
{
|
|
|
|
struct lsm_info **check;
|
|
|
|
|
|
|
|
for (check = ordered_lsms; *check; check++)
|
|
|
|
if (*check == lsm)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append an LSM to the list of ordered LSMs to initialize. */
|
|
|
|
static int last_lsm __initdata;
|
|
|
|
static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from)
|
|
|
|
{
|
|
|
|
/* Ignore duplicate selections. */
|
|
|
|
if (exists_ordered_lsm(lsm))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM slots!?\n", from))
|
|
|
|
return;
|
|
|
|
|
2018-10-10 05:42:57 +08:00
|
|
|
/* Enable this LSM, if it is not already set. */
|
|
|
|
if (!lsm->enabled)
|
|
|
|
lsm->enabled = &lsm_enabled_true;
|
2018-09-20 07:58:31 +08:00
|
|
|
ordered_lsms[last_lsm++] = lsm;
|
2018-10-10 05:42:57 +08:00
|
|
|
|
2018-09-20 07:58:31 +08:00
|
|
|
init_debug("%s ordering: %s (%sabled)\n", from, lsm->name,
|
|
|
|
is_enabled(lsm) ? "en" : "dis");
|
|
|
|
}
|
|
|
|
|
2018-09-14 14:17:50 +08:00
|
|
|
/* Is an LSM allowed to be initialized? */
|
|
|
|
static bool __init lsm_allowed(struct lsm_info *lsm)
|
|
|
|
{
|
|
|
|
/* Skip if the LSM is disabled. */
|
|
|
|
if (!is_enabled(lsm))
|
|
|
|
return false;
|
|
|
|
|
2018-09-20 10:57:06 +08:00
|
|
|
/* Not allowed if another exclusive LSM already initialized. */
|
|
|
|
if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && exclusive) {
|
|
|
|
init_debug("exclusive disabled: %s\n", lsm->name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-14 14:17:50 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-13 01:30:56 +08:00
|
|
|
static void __init lsm_set_blob_size(int *need, int *lbs)
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
if (*need > 0) {
|
|
|
|
offset = *lbs;
|
|
|
|
*lbs += *need;
|
|
|
|
*need = offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
|
|
|
|
{
|
|
|
|
if (!needed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lsm_set_blob_size(&needed->lbs_cred, &blob_sizes.lbs_cred);
|
2018-11-13 04:02:49 +08:00
|
|
|
lsm_set_blob_size(&needed->lbs_file, &blob_sizes.lbs_file);
|
2018-09-22 08:19:29 +08:00
|
|
|
/*
|
|
|
|
* The inode blob gets an rcu_head in addition to
|
|
|
|
* what the modules might need.
|
|
|
|
*/
|
|
|
|
if (needed->lbs_inode && blob_sizes.lbs_inode == 0)
|
|
|
|
blob_sizes.lbs_inode = sizeof(struct rcu_head);
|
|
|
|
lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode);
|
2018-11-21 03:55:02 +08:00
|
|
|
lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc);
|
|
|
|
lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg);
|
2018-09-22 08:19:37 +08:00
|
|
|
lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task);
|
2018-11-13 01:30:56 +08:00
|
|
|
}
|
|
|
|
|
2018-10-11 06:45:22 +08:00
|
|
|
/* Prepare LSM for initialization. */
|
|
|
|
static void __init prepare_lsm(struct lsm_info *lsm)
|
2018-09-14 14:17:50 +08:00
|
|
|
{
|
|
|
|
int enabled = lsm_allowed(lsm);
|
|
|
|
|
|
|
|
/* Record enablement (to handle any following exclusive LSMs). */
|
|
|
|
set_enabled(lsm, enabled);
|
|
|
|
|
2018-10-11 06:45:22 +08:00
|
|
|
/* If enabled, do pre-initialization work. */
|
2018-09-14 14:17:50 +08:00
|
|
|
if (enabled) {
|
2018-09-20 10:57:06 +08:00
|
|
|
if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) {
|
|
|
|
exclusive = lsm;
|
|
|
|
init_debug("exclusive chosen: %s\n", lsm->name);
|
|
|
|
}
|
2018-11-13 01:30:56 +08:00
|
|
|
|
|
|
|
lsm_set_blob_sizes(lsm->blobs);
|
2018-10-11 06:45:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize a given LSM, if it is enabled. */
|
|
|
|
static void __init initialize_lsm(struct lsm_info *lsm)
|
|
|
|
{
|
|
|
|
if (is_enabled(lsm)) {
|
|
|
|
int ret;
|
2018-09-20 10:57:06 +08:00
|
|
|
|
2018-09-14 14:17:50 +08:00
|
|
|
init_debug("initializing %s\n", lsm->name);
|
|
|
|
ret = lsm->init();
|
|
|
|
WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-10 05:27:46 +08:00
|
|
|
/* Populate ordered LSMs list from comma-separated LSM name list. */
|
2018-09-20 07:58:31 +08:00
|
|
|
static void __init ordered_lsm_parse(const char *order, const char *origin)
|
2018-09-20 07:16:55 +08:00
|
|
|
{
|
|
|
|
struct lsm_info *lsm;
|
2018-10-10 05:27:46 +08:00
|
|
|
char *sep, *name, *next;
|
|
|
|
|
2018-09-20 08:48:21 +08:00
|
|
|
/* LSM_ORDER_FIRST is always first. */
|
|
|
|
for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
|
|
|
|
if (lsm->order == LSM_ORDER_FIRST)
|
|
|
|
append_ordered_lsm(lsm, "first");
|
|
|
|
}
|
|
|
|
|
2018-09-20 04:32:15 +08:00
|
|
|
/* Process "security=", if given. */
|
|
|
|
if (chosen_major_lsm) {
|
|
|
|
struct lsm_info *major;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To match the original "security=" behavior, this
|
|
|
|
* explicitly does NOT fallback to another Legacy Major
|
|
|
|
* if the selected one was separately disabled: disable
|
|
|
|
* all non-matching Legacy Major LSMs.
|
|
|
|
*/
|
|
|
|
for (major = __start_lsm_info; major < __end_lsm_info;
|
|
|
|
major++) {
|
|
|
|
if ((major->flags & LSM_FLAG_LEGACY_MAJOR) &&
|
|
|
|
strcmp(major->name, chosen_major_lsm) != 0) {
|
|
|
|
set_enabled(major, false);
|
|
|
|
init_debug("security=%s disabled: %s\n",
|
|
|
|
chosen_major_lsm, major->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-20 04:11:41 +08:00
|
|
|
|
2018-10-10 05:27:46 +08:00
|
|
|
sep = kstrdup(order, GFP_KERNEL);
|
|
|
|
next = sep;
|
|
|
|
/* Walk the list, looking for matching LSMs. */
|
|
|
|
while ((name = strsep(&next, ",")) != NULL) {
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
|
2018-09-20 08:48:21 +08:00
|
|
|
if (lsm->order == LSM_ORDER_MUTABLE &&
|
|
|
|
strcmp(lsm->name, name) == 0) {
|
2018-10-10 05:27:46 +08:00
|
|
|
append_ordered_lsm(lsm, origin);
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
init_debug("%s ignored: %s\n", origin, name);
|
2018-09-20 07:16:55 +08:00
|
|
|
}
|
2018-11-20 10:04:32 +08:00
|
|
|
|
|
|
|
/* Process "security=", if given. */
|
|
|
|
if (chosen_major_lsm) {
|
|
|
|
for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
|
|
|
|
if (exists_ordered_lsm(lsm))
|
|
|
|
continue;
|
|
|
|
if (strcmp(lsm->name, chosen_major_lsm) == 0)
|
|
|
|
append_ordered_lsm(lsm, "security=");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable all LSMs not in the ordered list. */
|
|
|
|
for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
|
|
|
|
if (exists_ordered_lsm(lsm))
|
|
|
|
continue;
|
|
|
|
set_enabled(lsm, false);
|
|
|
|
init_debug("%s disabled: %s\n", origin, lsm->name);
|
|
|
|
}
|
|
|
|
|
2018-10-10 05:27:46 +08:00
|
|
|
kfree(sep);
|
2018-09-20 07:16:55 +08:00
|
|
|
}
|
|
|
|
|
2019-01-18 18:15:59 +08:00
|
|
|
static void __init lsm_early_cred(struct cred *cred);
|
|
|
|
static void __init lsm_early_task(struct task_struct *task);
|
|
|
|
|
2019-08-20 08:17:37 +08:00
|
|
|
static int lsm_append(const char *new, char **result);
|
|
|
|
|
2018-09-20 07:58:31 +08:00
|
|
|
static void __init ordered_lsm_init(void)
|
|
|
|
{
|
|
|
|
struct lsm_info **lsm;
|
|
|
|
|
|
|
|
ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms),
|
|
|
|
GFP_KERNEL);
|
|
|
|
|
2019-02-13 02:23:18 +08:00
|
|
|
if (chosen_lsm_order) {
|
|
|
|
if (chosen_major_lsm) {
|
|
|
|
pr_info("security= is ignored because it is superseded by lsm=\n");
|
|
|
|
chosen_major_lsm = NULL;
|
|
|
|
}
|
2018-09-20 08:30:09 +08:00
|
|
|
ordered_lsm_parse(chosen_lsm_order, "cmdline");
|
2019-02-13 02:23:18 +08:00
|
|
|
} else
|
2018-09-20 08:30:09 +08:00
|
|
|
ordered_lsm_parse(builtin_lsm_order, "builtin");
|
2018-09-20 07:58:31 +08:00
|
|
|
|
|
|
|
for (lsm = ordered_lsms; *lsm; lsm++)
|
2018-10-11 06:45:22 +08:00
|
|
|
prepare_lsm(*lsm);
|
|
|
|
|
2018-11-13 01:30:56 +08:00
|
|
|
init_debug("cred blob size = %d\n", blob_sizes.lbs_cred);
|
2018-11-13 04:02:49 +08:00
|
|
|
init_debug("file blob size = %d\n", blob_sizes.lbs_file);
|
2018-09-22 08:19:29 +08:00
|
|
|
init_debug("inode blob size = %d\n", blob_sizes.lbs_inode);
|
2018-11-21 03:55:02 +08:00
|
|
|
init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc);
|
|
|
|
init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg);
|
2018-09-22 08:19:37 +08:00
|
|
|
init_debug("task blob size = %d\n", blob_sizes.lbs_task);
|
2018-11-13 04:02:49 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create any kmem_caches needed for blobs
|
|
|
|
*/
|
|
|
|
if (blob_sizes.lbs_file)
|
|
|
|
lsm_file_cache = kmem_cache_create("lsm_file_cache",
|
|
|
|
blob_sizes.lbs_file, 0,
|
|
|
|
SLAB_PANIC, NULL);
|
2018-09-22 08:19:29 +08:00
|
|
|
if (blob_sizes.lbs_inode)
|
|
|
|
lsm_inode_cache = kmem_cache_create("lsm_inode_cache",
|
|
|
|
blob_sizes.lbs_inode, 0,
|
|
|
|
SLAB_PANIC, NULL);
|
2018-11-13 01:30:56 +08:00
|
|
|
|
2019-01-18 18:15:59 +08:00
|
|
|
lsm_early_cred((struct cred *) current->cred);
|
|
|
|
lsm_early_task(current);
|
2018-10-11 06:45:22 +08:00
|
|
|
for (lsm = ordered_lsms; *lsm; lsm++)
|
|
|
|
initialize_lsm(*lsm);
|
2018-09-20 07:58:31 +08:00
|
|
|
|
|
|
|
kfree(ordered_lsms);
|
|
|
|
}
|
|
|
|
|
2019-08-20 08:17:37 +08:00
|
|
|
int __init early_security_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct hlist_head *list = (struct hlist_head *) &security_hook_heads;
|
|
|
|
struct lsm_info *lsm;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head);
|
|
|
|
i++)
|
|
|
|
INIT_HLIST_HEAD(&list[i]);
|
|
|
|
|
|
|
|
for (lsm = __start_early_lsm_info; lsm < __end_early_lsm_info; lsm++) {
|
|
|
|
if (!lsm->enabled)
|
|
|
|
lsm->enabled = &lsm_enabled_true;
|
|
|
|
prepare_lsm(lsm);
|
|
|
|
initialize_lsm(lsm);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* security_init - initializes the security framework
|
|
|
|
*
|
|
|
|
* This should be called early in the kernel initialization sequence.
|
|
|
|
*/
|
|
|
|
int __init security_init(void)
|
|
|
|
{
|
2019-08-20 08:17:37 +08:00
|
|
|
struct lsm_info *lsm;
|
2017-03-22 18:46:19 +08:00
|
|
|
|
2018-10-11 08:18:17 +08:00
|
|
|
pr_info("Security Framework initializing\n");
|
|
|
|
|
2019-08-20 08:17:37 +08:00
|
|
|
/*
|
|
|
|
* Append the names of the early LSM modules now that kmalloc() is
|
|
|
|
* available
|
|
|
|
*/
|
|
|
|
for (lsm = __start_early_lsm_info; lsm < __end_early_lsm_info; lsm++) {
|
|
|
|
if (lsm->enabled)
|
|
|
|
lsm_append(lsm->name, &lsm_names);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-20 07:16:55 +08:00
|
|
|
/* Load LSMs in specified order. */
|
|
|
|
ordered_lsm_init();
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-07 00:09:10 +08:00
|
|
|
/* Save user chosen LSM */
|
2018-09-20 04:11:41 +08:00
|
|
|
static int __init choose_major_lsm(char *str)
|
2008-03-07 00:09:10 +08:00
|
|
|
{
|
2018-09-20 04:11:41 +08:00
|
|
|
chosen_major_lsm = str;
|
2008-03-07 00:09:10 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2018-09-20 04:11:41 +08:00
|
|
|
__setup("security=", choose_major_lsm);
|
2008-03-07 00:09:10 +08:00
|
|
|
|
2018-09-20 08:30:09 +08:00
|
|
|
/* Explicitly choose LSM initialization order. */
|
|
|
|
static int __init choose_lsm_order(char *str)
|
|
|
|
{
|
|
|
|
chosen_lsm_order = str;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("lsm=", choose_lsm_order);
|
|
|
|
|
2018-10-11 08:18:25 +08:00
|
|
|
/* Enable LSM order debugging. */
|
|
|
|
static int __init enable_debug(char *str)
|
|
|
|
{
|
|
|
|
debug = true;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("lsm.debug", enable_debug);
|
|
|
|
|
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-11 04:48:48 +08: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);
|
|
|
|
}
|
|
|
|
|
2019-08-20 08:17:37 +08:00
|
|
|
static int lsm_append(const char *new, char **result)
|
2017-01-19 09:09:05 +08:00
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (*result == NULL) {
|
|
|
|
*result = kstrdup(new, GFP_KERNEL);
|
2018-07-18 01:36:04 +08:00
|
|
|
if (*result == NULL)
|
|
|
|
return -ENOMEM;
|
2017-01-19 09:09:05 +08:00
|
|
|
} 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-11 04:48:48 +08:00
|
|
|
/* Check if it is the last registered name */
|
|
|
|
if (match_last_lsm(*result, new))
|
|
|
|
return 0;
|
2017-01-19 09:09:05 +08:00
|
|
|
cp = kasprintf(GFP_KERNEL, "%s,%s", *result, new);
|
|
|
|
if (cp == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
kfree(*result);
|
|
|
|
*result = cp;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 09:28:23 +08:00
|
|
|
hlist_add_tail_rcu(&hooks[i].list, hooks[i].head);
|
2017-01-19 09:09:05 +08:00
|
|
|
}
|
2019-08-20 08:17:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't try to append during early_security_init(), we'll come back
|
|
|
|
* and fix this up afterwards.
|
|
|
|
*/
|
|
|
|
if (slab_is_available()) {
|
|
|
|
if (lsm_append(lsm, &lsm_names) < 0)
|
|
|
|
panic("%s - Cannot get early memory.\n", __func__);
|
|
|
|
}
|
2017-01-19 09:09:05 +08:00
|
|
|
}
|
|
|
|
|
2019-06-14 20:20:14 +08:00
|
|
|
int call_blocking_lsm_notifier(enum lsm_event event, void *data)
|
2017-05-19 20:48:53 +08:00
|
|
|
{
|
2019-06-14 20:20:14 +08:00
|
|
|
return blocking_notifier_call_chain(&blocking_lsm_notifier_chain,
|
|
|
|
event, data);
|
2017-05-19 20:48:53 +08:00
|
|
|
}
|
2019-06-14 20:20:14 +08:00
|
|
|
EXPORT_SYMBOL(call_blocking_lsm_notifier);
|
2017-05-19 20:48:53 +08:00
|
|
|
|
2019-06-14 20:20:14 +08:00
|
|
|
int register_blocking_lsm_notifier(struct notifier_block *nb)
|
2017-05-19 20:48:53 +08:00
|
|
|
{
|
2019-06-14 20:20:14 +08:00
|
|
|
return blocking_notifier_chain_register(&blocking_lsm_notifier_chain,
|
|
|
|
nb);
|
2017-05-19 20:48:53 +08:00
|
|
|
}
|
2019-06-14 20:20:14 +08:00
|
|
|
EXPORT_SYMBOL(register_blocking_lsm_notifier);
|
2017-05-19 20:48:53 +08:00
|
|
|
|
2019-06-14 20:20:14 +08:00
|
|
|
int unregister_blocking_lsm_notifier(struct notifier_block *nb)
|
2017-05-19 20:48:53 +08:00
|
|
|
{
|
2019-06-14 20:20:14 +08:00
|
|
|
return blocking_notifier_chain_unregister(&blocking_lsm_notifier_chain,
|
|
|
|
nb);
|
2017-05-19 20:48:53 +08:00
|
|
|
}
|
2019-06-14 20:20:14 +08:00
|
|
|
EXPORT_SYMBOL(unregister_blocking_lsm_notifier);
|
2017-05-19 20:48:53 +08:00
|
|
|
|
2018-11-13 01:30:56 +08:00
|
|
|
/**
|
|
|
|
* lsm_cred_alloc - allocate a composite cred blob
|
|
|
|
* @cred: the cred that needs a blob
|
|
|
|
* @gfp: allocation type
|
|
|
|
*
|
|
|
|
* Allocate the cred blob for all the modules
|
|
|
|
*
|
|
|
|
* Returns 0, or -ENOMEM if memory can't be allocated.
|
|
|
|
*/
|
|
|
|
static int lsm_cred_alloc(struct cred *cred, gfp_t gfp)
|
|
|
|
{
|
|
|
|
if (blob_sizes.lbs_cred == 0) {
|
|
|
|
cred->security = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cred->security = kzalloc(blob_sizes.lbs_cred, gfp);
|
|
|
|
if (cred->security == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lsm_early_cred - during initialization allocate a composite cred blob
|
|
|
|
* @cred: the cred that needs a blob
|
|
|
|
*
|
2019-01-18 18:15:59 +08:00
|
|
|
* Allocate the cred blob for all the modules
|
2018-11-13 01:30:56 +08:00
|
|
|
*/
|
2019-01-18 18:15:59 +08:00
|
|
|
static void __init lsm_early_cred(struct cred *cred)
|
2018-11-13 01:30:56 +08:00
|
|
|
{
|
2019-01-18 18:15:59 +08:00
|
|
|
int rc = lsm_cred_alloc(cred, GFP_KERNEL);
|
2018-11-13 01:30:56 +08:00
|
|
|
|
|
|
|
if (rc)
|
|
|
|
panic("%s: Early cred alloc failed.\n", __func__);
|
|
|
|
}
|
|
|
|
|
2018-11-13 04:02:49 +08:00
|
|
|
/**
|
|
|
|
* lsm_file_alloc - allocate a composite file blob
|
|
|
|
* @file: the file that needs a blob
|
|
|
|
*
|
|
|
|
* Allocate the file blob for all the modules
|
|
|
|
*
|
|
|
|
* Returns 0, or -ENOMEM if memory can't be allocated.
|
|
|
|
*/
|
|
|
|
static int lsm_file_alloc(struct file *file)
|
|
|
|
{
|
|
|
|
if (!lsm_file_cache) {
|
|
|
|
file->f_security = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
file->f_security = kmem_cache_zalloc(lsm_file_cache, GFP_KERNEL);
|
|
|
|
if (file->f_security == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-22 08:19:29 +08:00
|
|
|
/**
|
|
|
|
* lsm_inode_alloc - allocate a composite inode blob
|
|
|
|
* @inode: the inode that needs a blob
|
|
|
|
*
|
|
|
|
* Allocate the inode blob for all the modules
|
|
|
|
*
|
|
|
|
* Returns 0, or -ENOMEM if memory can't be allocated.
|
|
|
|
*/
|
|
|
|
int lsm_inode_alloc(struct inode *inode)
|
|
|
|
{
|
|
|
|
if (!lsm_inode_cache) {
|
|
|
|
inode->i_security = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inode->i_security = kmem_cache_zalloc(lsm_inode_cache, GFP_NOFS);
|
|
|
|
if (inode->i_security == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-22 08:19:37 +08:00
|
|
|
/**
|
|
|
|
* lsm_task_alloc - allocate a composite task blob
|
|
|
|
* @task: the task that needs a blob
|
|
|
|
*
|
|
|
|
* Allocate the task blob for all the modules
|
|
|
|
*
|
|
|
|
* Returns 0, or -ENOMEM if memory can't be allocated.
|
|
|
|
*/
|
2019-01-16 13:44:32 +08:00
|
|
|
static int lsm_task_alloc(struct task_struct *task)
|
2018-09-22 08:19:37 +08:00
|
|
|
{
|
|
|
|
if (blob_sizes.lbs_task == 0) {
|
|
|
|
task->security = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
task->security = kzalloc(blob_sizes.lbs_task, GFP_KERNEL);
|
|
|
|
if (task->security == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-21 03:55:02 +08:00
|
|
|
/**
|
|
|
|
* lsm_ipc_alloc - allocate a composite ipc blob
|
|
|
|
* @kip: the ipc that needs a blob
|
|
|
|
*
|
|
|
|
* Allocate the ipc blob for all the modules
|
|
|
|
*
|
|
|
|
* Returns 0, or -ENOMEM if memory can't be allocated.
|
|
|
|
*/
|
2019-01-16 13:44:32 +08:00
|
|
|
static int lsm_ipc_alloc(struct kern_ipc_perm *kip)
|
2018-11-21 03:55:02 +08:00
|
|
|
{
|
|
|
|
if (blob_sizes.lbs_ipc == 0) {
|
|
|
|
kip->security = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
kip->security = kzalloc(blob_sizes.lbs_ipc, GFP_KERNEL);
|
|
|
|
if (kip->security == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lsm_msg_msg_alloc - allocate a composite msg_msg blob
|
|
|
|
* @mp: the msg_msg that needs a blob
|
|
|
|
*
|
|
|
|
* Allocate the ipc blob for all the modules
|
|
|
|
*
|
|
|
|
* Returns 0, or -ENOMEM if memory can't be allocated.
|
|
|
|
*/
|
2019-01-16 13:44:32 +08:00
|
|
|
static int lsm_msg_msg_alloc(struct msg_msg *mp)
|
2018-11-21 03:55:02 +08:00
|
|
|
{
|
|
|
|
if (blob_sizes.lbs_msg_msg == 0) {
|
|
|
|
mp->security = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp->security = kzalloc(blob_sizes.lbs_msg_msg, GFP_KERNEL);
|
|
|
|
if (mp->security == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-22 08:19:37 +08:00
|
|
|
/**
|
|
|
|
* lsm_early_task - during initialization allocate a composite task blob
|
|
|
|
* @task: the task that needs a blob
|
|
|
|
*
|
2019-01-18 18:15:59 +08:00
|
|
|
* Allocate the task blob for all the modules
|
2018-09-22 08:19:37 +08:00
|
|
|
*/
|
2019-01-18 18:15:59 +08:00
|
|
|
static void __init lsm_early_task(struct task_struct *task)
|
2018-09-22 08:19:37 +08:00
|
|
|
{
|
2019-01-18 18:15:59 +08:00
|
|
|
int rc = lsm_task_alloc(task);
|
2018-09-22 08:19:37 +08:00
|
|
|
|
|
|
|
if (rc)
|
|
|
|
panic("%s: Early task alloc failed.\n", __func__);
|
|
|
|
}
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
/*
|
2015-05-03 06:11:42 +08:00
|
|
|
* Hook list operation macros.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2015-05-03 06:11:29 +08:00
|
|
|
* call_void_hook:
|
|
|
|
* This is a hook that does not return a value.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2015-05-03 06:11:29 +08:00
|
|
|
* call_int_hook:
|
|
|
|
* This is a hook that returns a value.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2015-05-03 06:11:42 +08:00
|
|
|
#define call_void_hook(FUNC, ...) \
|
|
|
|
do { \
|
|
|
|
struct security_hook_list *P; \
|
|
|
|
\
|
2018-03-29 09:28:23 +08:00
|
|
|
hlist_for_each_entry(P, &security_hook_heads.FUNC, list) \
|
2015-05-03 06:11:42 +08: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 09:28:23 +08:00
|
|
|
hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \
|
2015-05-03 06:11:42 +08:00
|
|
|
RC = P->hook.FUNC(__VA_ARGS__); \
|
|
|
|
if (RC != 0) \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} while (0); \
|
|
|
|
RC; \
|
|
|
|
})
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
/* Security operations */
|
|
|
|
|
2015-01-21 23:54:10 +08:00
|
|
|
int security_binder_set_context_mgr(struct task_struct *mgr)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(binder_set_context_mgr, 0, mgr);
|
2015-01-21 23:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_binder_transaction(struct task_struct *from,
|
|
|
|
struct task_struct *to)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(binder_transaction, 0, from, to);
|
2015-01-21 23:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_binder_transfer_binder(struct task_struct *from,
|
|
|
|
struct task_struct *to)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(binder_transfer_binder, 0, from, to);
|
2015-01-21 23:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_binder_transfer_file(struct task_struct *from,
|
|
|
|
struct task_struct *to, struct file *file)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(binder_transfer_file, 0, from, to, file);
|
2015-01-21 23:54:10 +08:00
|
|
|
}
|
|
|
|
|
2009-05-07 17:26:19 +08:00
|
|
|
int security_ptrace_access_check(struct task_struct *child, unsigned int mode)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(ptrace_access_check, 0, child, mode);
|
security: Fix setting of PF_SUPERPRIV by __capable()
Fix the setting of PF_SUPERPRIV by __capable() as it could corrupt the flags
the target process if that is not the current process and it is trying to
change its own flags in a different way at the same time.
__capable() is using neither atomic ops nor locking to protect t->flags. This
patch removes __capable() and introduces has_capability() that doesn't set
PF_SUPERPRIV on the process being queried.
This patch further splits security_ptrace() in two:
(1) security_ptrace_may_access(). This passes judgement on whether one
process may access another only (PTRACE_MODE_ATTACH for ptrace() and
PTRACE_MODE_READ for /proc), and takes a pointer to the child process.
current is the parent.
(2) security_ptrace_traceme(). This passes judgement on PTRACE_TRACEME only,
and takes only a pointer to the parent process. current is the child.
In Smack and commoncap, this uses has_capability() to determine whether
the parent will be permitted to use PTRACE_ATTACH if normal checks fail.
This does not set PF_SUPERPRIV.
Two of the instances of __capable() actually only act on current, and so have
been changed to calls to capable().
Of the places that were using __capable():
(1) The OOM killer calls __capable() thrice when weighing the killability of a
process. All of these now use has_capability().
(2) cap_ptrace() and smack_ptrace() were using __capable() to check to see
whether the parent was allowed to trace any process. As mentioned above,
these have been split. For PTRACE_ATTACH and /proc, capable() is now
used, and for PTRACE_TRACEME, has_capability() is used.
(3) cap_safe_nice() only ever saw current, so now uses capable().
(4) smack_setprocattr() rejected accesses to tasks other than current just
after calling __capable(), so the order of these two tests have been
switched and capable() is used instead.
(5) In smack_file_send_sigiotask(), we need to allow privileged processes to
receive SIGIO on files they're manipulating.
(6) In smack_task_wait(), we let a process wait for a privileged process,
whether or not the process doing the waiting is privileged.
I've tested this with the LTP SELinux and syscalls testscripts.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Acked-by: Andrew G. Morgan <morgan@kernel.org>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: James Morris <jmorris@namei.org>
2008-08-14 18:37:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_ptrace_traceme(struct task_struct *parent)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(ptrace_traceme, 0, parent);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_capget(struct task_struct *target,
|
|
|
|
kernel_cap_t *effective,
|
|
|
|
kernel_cap_t *inheritable,
|
|
|
|
kernel_cap_t *permitted)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(capget, 0, target,
|
|
|
|
effective, inheritable, permitted);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
CRED: Inaugurate COW credentials
Inaugurate copy-on-write credentials management. This uses RCU to manage the
credentials pointer in the task_struct with respect to accesses by other tasks.
A process may only modify its own credentials, and so does not need locking to
access or modify its own credentials.
A mutex (cred_replace_mutex) is added to the task_struct to control the effect
of PTRACE_ATTACHED on credential calculations, particularly with respect to
execve().
With this patch, the contents of an active credentials struct may not be
changed directly; rather a new set of credentials must be prepared, modified
and committed using something like the following sequence of events:
struct cred *new = prepare_creds();
int ret = blah(new);
if (ret < 0) {
abort_creds(new);
return ret;
}
return commit_creds(new);
There are some exceptions to this rule: the keyrings pointed to by the active
credentials may be instantiated - keyrings violate the COW rule as managing
COW keyrings is tricky, given that it is possible for a task to directly alter
the keys in a keyring in use by another task.
To help enforce this, various pointers to sets of credentials, such as those in
the task_struct, are declared const. The purpose of this is compile-time
discouragement of altering credentials through those pointers. Once a set of
credentials has been made public through one of these pointers, it may not be
modified, except under special circumstances:
(1) Its reference count may incremented and decremented.
(2) The keyrings to which it points may be modified, but not replaced.
The only safe way to modify anything else is to create a replacement and commit
using the functions described in Documentation/credentials.txt (which will be
added by a later patch).
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
This now prepares and commits credentials in various places in the
security code rather than altering the current creds directly.
(2) Temporary credential overrides.
do_coredump() and sys_faccessat() now prepare their own credentials and
temporarily override the ones currently on the acting thread, whilst
preventing interference from other threads by holding cred_replace_mutex
on the thread being dumped.
This will be replaced in a future patch by something that hands down the
credentials directly to the functions being called, rather than altering
the task's objective credentials.
(3) LSM interface.
A number of functions have been changed, added or removed:
(*) security_capset_check(), ->capset_check()
(*) security_capset_set(), ->capset_set()
Removed in favour of security_capset().
(*) security_capset(), ->capset()
New. This is passed a pointer to the new creds, a pointer to the old
creds and the proposed capability sets. It should fill in the new
creds or return an error. All pointers, barring the pointer to the
new creds, are now const.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
Changed; now returns a value, which will cause the process to be
killed if it's an error.
(*) security_task_alloc(), ->task_alloc_security()
Removed in favour of security_prepare_creds().
(*) security_cred_free(), ->cred_free()
New. Free security data attached to cred->security.
(*) security_prepare_creds(), ->cred_prepare()
New. Duplicate any security data attached to cred->security.
(*) security_commit_creds(), ->cred_commit()
New. Apply any security effects for the upcoming installation of new
security by commit_creds().
(*) security_task_post_setuid(), ->task_post_setuid()
Removed in favour of security_task_fix_setuid().
(*) security_task_fix_setuid(), ->task_fix_setuid()
Fix up the proposed new credentials for setuid(). This is used by
cap_set_fix_setuid() to implicitly adjust capabilities in line with
setuid() changes. Changes are made to the new credentials, rather
than the task itself as in security_task_post_setuid().
(*) security_task_reparent_to_init(), ->task_reparent_to_init()
Removed. Instead the task being reparented to init is referred
directly to init's credentials.
NOTE! This results in the loss of some state: SELinux's osid no
longer records the sid of the thread that forked it.
(*) security_key_alloc(), ->key_alloc()
(*) security_key_permission(), ->key_permission()
Changed. These now take cred pointers rather than task pointers to
refer to the security context.
(4) sys_capset().
This has been simplified and uses less locking. The LSM functions it
calls have been merged.
(5) reparent_to_kthreadd().
This gives the current thread the same credentials as init by simply using
commit_thread() to point that way.
(6) __sigqueue_alloc() and switch_uid()
__sigqueue_alloc() can't stop the target task from changing its creds
beneath it, so this function gets a reference to the currently applicable
user_struct which it then passes into the sigqueue struct it returns if
successful.
switch_uid() is now called from commit_creds(), and possibly should be
folded into that. commit_creds() should take care of protecting
__sigqueue_alloc().
(7) [sg]et[ug]id() and co and [sg]et_current_groups.
The set functions now all use prepare_creds(), commit_creds() and
abort_creds() to build and check a new set of credentials before applying
it.
security_task_set[ug]id() is called inside the prepared section. This
guarantees that nothing else will affect the creds until we've finished.
The calling of set_dumpable() has been moved into commit_creds().
Much of the functionality of set_user() has been moved into
commit_creds().
The get functions all simply access the data directly.
(8) security_task_prctl() and cap_task_prctl().
security_task_prctl() has been modified to return -ENOSYS if it doesn't
want to handle a function, or otherwise return the return value directly
rather than through an argument.
Additionally, cap_task_prctl() now prepares a new set of credentials, even
if it doesn't end up using it.
(9) Keyrings.
A number of changes have been made to the keyrings code:
(a) switch_uid_keyring(), copy_keys(), exit_keys() and suid_keys() have
all been dropped and built in to the credentials functions directly.
They may want separating out again later.
(b) key_alloc() and search_process_keyrings() now take a cred pointer
rather than a task pointer to specify the security context.
(c) copy_creds() gives a new thread within the same thread group a new
thread keyring if its parent had one, otherwise it discards the thread
keyring.
(d) The authorisation key now points directly to the credentials to extend
the search into rather pointing to the task that carries them.
(e) Installing thread, process or session keyrings causes a new set of
credentials to be created, even though it's not strictly necessary for
process or session keyrings (they're shared).
(10) Usermode helper.
The usermode helper code now carries a cred struct pointer in its
subprocess_info struct instead of a new session keyring pointer. This set
of credentials is derived from init_cred and installed on the new process
after it has been cloned.
call_usermodehelper_setup() allocates the new credentials and
call_usermodehelper_freeinfo() discards them if they haven't been used. A
special cred function (prepare_usermodeinfo_creds()) is provided
specifically for call_usermodehelper_setup() to call.
call_usermodehelper_setkeys() adjusts the credentials to sport the
supplied keyring as the new session keyring.
(11) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) selinux_setprocattr() no longer does its check for whether the
current ptracer can access processes with the new SID inside the lock
that covers getting the ptracer's SID. Whilst this lock ensures that
the check is done with the ptracer pinned, the result is only valid
until the lock is released, so there's no point doing it inside the
lock.
(12) is_single_threaded().
This function has been extracted from selinux_setprocattr() and put into
a file of its own in the lib/ directory as join_session_keyring() now
wants to use it too.
The code in SELinux just checked to see whether a task shared mm_structs
with other tasks (CLONE_VM), but that isn't good enough. We really want
to know if they're part of the same thread group (CLONE_THREAD).
(13) nfsd.
The NFS server daemon now has to use the COW credentials to set the
credentials it is going to use. It really needs to pass the credentials
down to the functions it calls, but it can't do that until other patches
in this series have been applied.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
int security_capset(struct cred *new, const struct cred *old,
|
|
|
|
const kernel_cap_t *effective,
|
|
|
|
const kernel_cap_t *inheritable,
|
|
|
|
const kernel_cap_t *permitted)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(capset, 0, new, old,
|
|
|
|
effective, inheritable, permitted);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2019-01-08 08:10:53 +08:00
|
|
|
int security_capable(const struct cred *cred,
|
|
|
|
struct user_namespace *ns,
|
|
|
|
int cap,
|
|
|
|
unsigned int opts)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2019-01-08 08:10:53 +08:00
|
|
|
return call_int_hook(capable, 0, cred, ns, cap, opts);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_quotactl(int cmds, int type, int id, struct super_block *sb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(quotactl, 0, cmds, type, id, sb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_quota_on(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(quota_on, 0, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2010-11-16 07:36:29 +08:00
|
|
|
int security_syslog(int type)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(syslog, 0, type);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 14:02:11 +08:00
|
|
|
int security_settime64(const struct timespec64 *ts, const struct timezone *tz)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(settime, 0, ts, tz);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
struct security_hook_list *hp;
|
|
|
|
int cap_sys_admin = 1;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The module will respond with a positive value if
|
|
|
|
* it thinks the __vm_enough_memory() call should be
|
|
|
|
* made with the cap_sys_admin set. If all of the modules
|
|
|
|
* agree that it should be set it will. If any module
|
|
|
|
* thinks it should not be set it won't.
|
|
|
|
*/
|
2018-03-29 09:28:23 +08:00
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.vm_enough_memory, list) {
|
2015-05-03 06:11:42 +08: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 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
CRED: Make execve() take advantage of copy-on-write credentials
Make execve() take advantage of copy-on-write credentials, allowing it to set
up the credentials in advance, and then commit the whole lot after the point
of no return.
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
The credential bits from struct linux_binprm are, for the most part,
replaced with a single credentials pointer (bprm->cred). This means that
all the creds can be calculated in advance and then applied at the point
of no return with no possibility of failure.
I would like to replace bprm->cap_effective with:
cap_isclear(bprm->cap_effective)
but this seems impossible due to special behaviour for processes of pid 1
(they always retain their parent's capability masks where normally they'd
be changed - see cap_bprm_set_creds()).
The following sequence of events now happens:
(a) At the start of do_execve, the current task's cred_exec_mutex is
locked to prevent PTRACE_ATTACH from obsoleting the calculation of
creds that we make.
(a) prepare_exec_creds() is then called to make a copy of the current
task's credentials and prepare it. This copy is then assigned to
bprm->cred.
This renders security_bprm_alloc() and security_bprm_free()
unnecessary, and so they've been removed.
(b) The determination of unsafe execution is now performed immediately
after (a) rather than later on in the code. The result is stored in
bprm->unsafe for future reference.
(c) prepare_binprm() is called, possibly multiple times.
(i) This applies the result of set[ug]id binaries to the new creds
attached to bprm->cred. Personality bit clearance is recorded,
but now deferred on the basis that the exec procedure may yet
fail.
(ii) This then calls the new security_bprm_set_creds(). This should
calculate the new LSM and capability credentials into *bprm->cred.
This folds together security_bprm_set() and parts of
security_bprm_apply_creds() (these two have been removed).
Anything that might fail must be done at this point.
(iii) bprm->cred_prepared is set to 1.
bprm->cred_prepared is 0 on the first pass of the security
calculations, and 1 on all subsequent passes. This allows SELinux
in (ii) to base its calculations only on the initial script and
not on the interpreter.
(d) flush_old_exec() is called to commit the task to execution. This
performs the following steps with regard to credentials:
(i) Clear pdeath_signal and set dumpable on certain circumstances that
may not be covered by commit_creds().
(ii) Clear any bits in current->personality that were deferred from
(c.i).
(e) install_exec_creds() [compute_creds() as was] is called to install the
new credentials. This performs the following steps with regard to
credentials:
(i) Calls security_bprm_committing_creds() to apply any security
requirements, such as flushing unauthorised files in SELinux, that
must be done before the credentials are changed.
This is made up of bits of security_bprm_apply_creds() and
security_bprm_post_apply_creds(), both of which have been removed.
This function is not allowed to fail; anything that might fail
must have been done in (c.ii).
(ii) Calls commit_creds() to apply the new credentials in a single
assignment (more or less). Possibly pdeath_signal and dumpable
should be part of struct creds.
(iii) Unlocks the task's cred_replace_mutex, thus allowing
PTRACE_ATTACH to take place.
(iv) Clears The bprm->cred pointer as the credentials it was holding
are now immutable.
(v) Calls security_bprm_committed_creds() to apply any security
alterations that must be done after the creds have been changed.
SELinux uses this to flush signals and signal handlers.
(f) If an error occurs before (d.i), bprm_free() will call abort_creds()
to destroy the proposed new credentials and will then unlock
cred_replace_mutex. No changes to the credentials will have been
made.
(2) LSM interface.
A number of functions have been changed, added or removed:
(*) security_bprm_alloc(), ->bprm_alloc_security()
(*) security_bprm_free(), ->bprm_free_security()
Removed in favour of preparing new credentials and modifying those.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
(*) security_bprm_post_apply_creds(), ->bprm_post_apply_creds()
Removed; split between security_bprm_set_creds(),
security_bprm_committing_creds() and security_bprm_committed_creds().
(*) security_bprm_set(), ->bprm_set_security()
Removed; folded into security_bprm_set_creds().
(*) security_bprm_set_creds(), ->bprm_set_creds()
New. The new credentials in bprm->creds should be checked and set up
as appropriate. bprm->cred_prepared is 0 on the first call, 1 on the
second and subsequent calls.
(*) security_bprm_committing_creds(), ->bprm_committing_creds()
(*) security_bprm_committed_creds(), ->bprm_committed_creds()
New. Apply the security effects of the new credentials. This
includes closing unauthorised files in SELinux. This function may not
fail. When the former is called, the creds haven't yet been applied
to the process; when the latter is called, they have.
The former may access bprm->cred, the latter may not.
(3) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) The bprm_security_struct struct has been removed in favour of using
the credentials-under-construction approach.
(c) flush_unauthorized_files() now takes a cred pointer and passes it on
to inode_has_perm(), file_has_perm() and dentry_open().
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:24 +08:00
|
|
|
int security_bprm_set_creds(struct linux_binprm *bprm)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(bprm_set_creds, 0, bprm);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
CRED: Make execve() take advantage of copy-on-write credentials
Make execve() take advantage of copy-on-write credentials, allowing it to set
up the credentials in advance, and then commit the whole lot after the point
of no return.
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
The credential bits from struct linux_binprm are, for the most part,
replaced with a single credentials pointer (bprm->cred). This means that
all the creds can be calculated in advance and then applied at the point
of no return with no possibility of failure.
I would like to replace bprm->cap_effective with:
cap_isclear(bprm->cap_effective)
but this seems impossible due to special behaviour for processes of pid 1
(they always retain their parent's capability masks where normally they'd
be changed - see cap_bprm_set_creds()).
The following sequence of events now happens:
(a) At the start of do_execve, the current task's cred_exec_mutex is
locked to prevent PTRACE_ATTACH from obsoleting the calculation of
creds that we make.
(a) prepare_exec_creds() is then called to make a copy of the current
task's credentials and prepare it. This copy is then assigned to
bprm->cred.
This renders security_bprm_alloc() and security_bprm_free()
unnecessary, and so they've been removed.
(b) The determination of unsafe execution is now performed immediately
after (a) rather than later on in the code. The result is stored in
bprm->unsafe for future reference.
(c) prepare_binprm() is called, possibly multiple times.
(i) This applies the result of set[ug]id binaries to the new creds
attached to bprm->cred. Personality bit clearance is recorded,
but now deferred on the basis that the exec procedure may yet
fail.
(ii) This then calls the new security_bprm_set_creds(). This should
calculate the new LSM and capability credentials into *bprm->cred.
This folds together security_bprm_set() and parts of
security_bprm_apply_creds() (these two have been removed).
Anything that might fail must be done at this point.
(iii) bprm->cred_prepared is set to 1.
bprm->cred_prepared is 0 on the first pass of the security
calculations, and 1 on all subsequent passes. This allows SELinux
in (ii) to base its calculations only on the initial script and
not on the interpreter.
(d) flush_old_exec() is called to commit the task to execution. This
performs the following steps with regard to credentials:
(i) Clear pdeath_signal and set dumpable on certain circumstances that
may not be covered by commit_creds().
(ii) Clear any bits in current->personality that were deferred from
(c.i).
(e) install_exec_creds() [compute_creds() as was] is called to install the
new credentials. This performs the following steps with regard to
credentials:
(i) Calls security_bprm_committing_creds() to apply any security
requirements, such as flushing unauthorised files in SELinux, that
must be done before the credentials are changed.
This is made up of bits of security_bprm_apply_creds() and
security_bprm_post_apply_creds(), both of which have been removed.
This function is not allowed to fail; anything that might fail
must have been done in (c.ii).
(ii) Calls commit_creds() to apply the new credentials in a single
assignment (more or less). Possibly pdeath_signal and dumpable
should be part of struct creds.
(iii) Unlocks the task's cred_replace_mutex, thus allowing
PTRACE_ATTACH to take place.
(iv) Clears The bprm->cred pointer as the credentials it was holding
are now immutable.
(v) Calls security_bprm_committed_creds() to apply any security
alterations that must be done after the creds have been changed.
SELinux uses this to flush signals and signal handlers.
(f) If an error occurs before (d.i), bprm_free() will call abort_creds()
to destroy the proposed new credentials and will then unlock
cred_replace_mutex. No changes to the credentials will have been
made.
(2) LSM interface.
A number of functions have been changed, added or removed:
(*) security_bprm_alloc(), ->bprm_alloc_security()
(*) security_bprm_free(), ->bprm_free_security()
Removed in favour of preparing new credentials and modifying those.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
(*) security_bprm_post_apply_creds(), ->bprm_post_apply_creds()
Removed; split between security_bprm_set_creds(),
security_bprm_committing_creds() and security_bprm_committed_creds().
(*) security_bprm_set(), ->bprm_set_security()
Removed; folded into security_bprm_set_creds().
(*) security_bprm_set_creds(), ->bprm_set_creds()
New. The new credentials in bprm->creds should be checked and set up
as appropriate. bprm->cred_prepared is 0 on the first call, 1 on the
second and subsequent calls.
(*) security_bprm_committing_creds(), ->bprm_committing_creds()
(*) security_bprm_committed_creds(), ->bprm_committed_creds()
New. Apply the security effects of the new credentials. This
includes closing unauthorised files in SELinux. This function may not
fail. When the former is called, the creds haven't yet been applied
to the process; when the latter is called, they have.
The former may access bprm->cred, the latter may not.
(3) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) The bprm_security_struct struct has been removed in favour of using
the credentials-under-construction approach.
(c) flush_unauthorized_files() now takes a cred pointer and passes it on
to inode_has_perm(), file_has_perm() and dentry_open().
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:24 +08:00
|
|
|
int security_bprm_check(struct linux_binprm *bprm)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2009-10-23 05:30:13 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
ret = call_int_hook(bprm_check_security, 0, bprm);
|
2009-10-23 05:30:13 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return ima_bprm_check(bprm);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
CRED: Make execve() take advantage of copy-on-write credentials
Make execve() take advantage of copy-on-write credentials, allowing it to set
up the credentials in advance, and then commit the whole lot after the point
of no return.
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
The credential bits from struct linux_binprm are, for the most part,
replaced with a single credentials pointer (bprm->cred). This means that
all the creds can be calculated in advance and then applied at the point
of no return with no possibility of failure.
I would like to replace bprm->cap_effective with:
cap_isclear(bprm->cap_effective)
but this seems impossible due to special behaviour for processes of pid 1
(they always retain their parent's capability masks where normally they'd
be changed - see cap_bprm_set_creds()).
The following sequence of events now happens:
(a) At the start of do_execve, the current task's cred_exec_mutex is
locked to prevent PTRACE_ATTACH from obsoleting the calculation of
creds that we make.
(a) prepare_exec_creds() is then called to make a copy of the current
task's credentials and prepare it. This copy is then assigned to
bprm->cred.
This renders security_bprm_alloc() and security_bprm_free()
unnecessary, and so they've been removed.
(b) The determination of unsafe execution is now performed immediately
after (a) rather than later on in the code. The result is stored in
bprm->unsafe for future reference.
(c) prepare_binprm() is called, possibly multiple times.
(i) This applies the result of set[ug]id binaries to the new creds
attached to bprm->cred. Personality bit clearance is recorded,
but now deferred on the basis that the exec procedure may yet
fail.
(ii) This then calls the new security_bprm_set_creds(). This should
calculate the new LSM and capability credentials into *bprm->cred.
This folds together security_bprm_set() and parts of
security_bprm_apply_creds() (these two have been removed).
Anything that might fail must be done at this point.
(iii) bprm->cred_prepared is set to 1.
bprm->cred_prepared is 0 on the first pass of the security
calculations, and 1 on all subsequent passes. This allows SELinux
in (ii) to base its calculations only on the initial script and
not on the interpreter.
(d) flush_old_exec() is called to commit the task to execution. This
performs the following steps with regard to credentials:
(i) Clear pdeath_signal and set dumpable on certain circumstances that
may not be covered by commit_creds().
(ii) Clear any bits in current->personality that were deferred from
(c.i).
(e) install_exec_creds() [compute_creds() as was] is called to install the
new credentials. This performs the following steps with regard to
credentials:
(i) Calls security_bprm_committing_creds() to apply any security
requirements, such as flushing unauthorised files in SELinux, that
must be done before the credentials are changed.
This is made up of bits of security_bprm_apply_creds() and
security_bprm_post_apply_creds(), both of which have been removed.
This function is not allowed to fail; anything that might fail
must have been done in (c.ii).
(ii) Calls commit_creds() to apply the new credentials in a single
assignment (more or less). Possibly pdeath_signal and dumpable
should be part of struct creds.
(iii) Unlocks the task's cred_replace_mutex, thus allowing
PTRACE_ATTACH to take place.
(iv) Clears The bprm->cred pointer as the credentials it was holding
are now immutable.
(v) Calls security_bprm_committed_creds() to apply any security
alterations that must be done after the creds have been changed.
SELinux uses this to flush signals and signal handlers.
(f) If an error occurs before (d.i), bprm_free() will call abort_creds()
to destroy the proposed new credentials and will then unlock
cred_replace_mutex. No changes to the credentials will have been
made.
(2) LSM interface.
A number of functions have been changed, added or removed:
(*) security_bprm_alloc(), ->bprm_alloc_security()
(*) security_bprm_free(), ->bprm_free_security()
Removed in favour of preparing new credentials and modifying those.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
(*) security_bprm_post_apply_creds(), ->bprm_post_apply_creds()
Removed; split between security_bprm_set_creds(),
security_bprm_committing_creds() and security_bprm_committed_creds().
(*) security_bprm_set(), ->bprm_set_security()
Removed; folded into security_bprm_set_creds().
(*) security_bprm_set_creds(), ->bprm_set_creds()
New. The new credentials in bprm->creds should be checked and set up
as appropriate. bprm->cred_prepared is 0 on the first call, 1 on the
second and subsequent calls.
(*) security_bprm_committing_creds(), ->bprm_committing_creds()
(*) security_bprm_committed_creds(), ->bprm_committed_creds()
New. Apply the security effects of the new credentials. This
includes closing unauthorised files in SELinux. This function may not
fail. When the former is called, the creds haven't yet been applied
to the process; when the latter is called, they have.
The former may access bprm->cred, the latter may not.
(3) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) The bprm_security_struct struct has been removed in favour of using
the credentials-under-construction approach.
(c) flush_unauthorized_files() now takes a cred pointer and passes it on
to inode_has_perm(), file_has_perm() and dentry_open().
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:24 +08:00
|
|
|
void security_bprm_committing_creds(struct linux_binprm *bprm)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(bprm_committing_creds, bprm);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
CRED: Make execve() take advantage of copy-on-write credentials
Make execve() take advantage of copy-on-write credentials, allowing it to set
up the credentials in advance, and then commit the whole lot after the point
of no return.
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
The credential bits from struct linux_binprm are, for the most part,
replaced with a single credentials pointer (bprm->cred). This means that
all the creds can be calculated in advance and then applied at the point
of no return with no possibility of failure.
I would like to replace bprm->cap_effective with:
cap_isclear(bprm->cap_effective)
but this seems impossible due to special behaviour for processes of pid 1
(they always retain their parent's capability masks where normally they'd
be changed - see cap_bprm_set_creds()).
The following sequence of events now happens:
(a) At the start of do_execve, the current task's cred_exec_mutex is
locked to prevent PTRACE_ATTACH from obsoleting the calculation of
creds that we make.
(a) prepare_exec_creds() is then called to make a copy of the current
task's credentials and prepare it. This copy is then assigned to
bprm->cred.
This renders security_bprm_alloc() and security_bprm_free()
unnecessary, and so they've been removed.
(b) The determination of unsafe execution is now performed immediately
after (a) rather than later on in the code. The result is stored in
bprm->unsafe for future reference.
(c) prepare_binprm() is called, possibly multiple times.
(i) This applies the result of set[ug]id binaries to the new creds
attached to bprm->cred. Personality bit clearance is recorded,
but now deferred on the basis that the exec procedure may yet
fail.
(ii) This then calls the new security_bprm_set_creds(). This should
calculate the new LSM and capability credentials into *bprm->cred.
This folds together security_bprm_set() and parts of
security_bprm_apply_creds() (these two have been removed).
Anything that might fail must be done at this point.
(iii) bprm->cred_prepared is set to 1.
bprm->cred_prepared is 0 on the first pass of the security
calculations, and 1 on all subsequent passes. This allows SELinux
in (ii) to base its calculations only on the initial script and
not on the interpreter.
(d) flush_old_exec() is called to commit the task to execution. This
performs the following steps with regard to credentials:
(i) Clear pdeath_signal and set dumpable on certain circumstances that
may not be covered by commit_creds().
(ii) Clear any bits in current->personality that were deferred from
(c.i).
(e) install_exec_creds() [compute_creds() as was] is called to install the
new credentials. This performs the following steps with regard to
credentials:
(i) Calls security_bprm_committing_creds() to apply any security
requirements, such as flushing unauthorised files in SELinux, that
must be done before the credentials are changed.
This is made up of bits of security_bprm_apply_creds() and
security_bprm_post_apply_creds(), both of which have been removed.
This function is not allowed to fail; anything that might fail
must have been done in (c.ii).
(ii) Calls commit_creds() to apply the new credentials in a single
assignment (more or less). Possibly pdeath_signal and dumpable
should be part of struct creds.
(iii) Unlocks the task's cred_replace_mutex, thus allowing
PTRACE_ATTACH to take place.
(iv) Clears The bprm->cred pointer as the credentials it was holding
are now immutable.
(v) Calls security_bprm_committed_creds() to apply any security
alterations that must be done after the creds have been changed.
SELinux uses this to flush signals and signal handlers.
(f) If an error occurs before (d.i), bprm_free() will call abort_creds()
to destroy the proposed new credentials and will then unlock
cred_replace_mutex. No changes to the credentials will have been
made.
(2) LSM interface.
A number of functions have been changed, added or removed:
(*) security_bprm_alloc(), ->bprm_alloc_security()
(*) security_bprm_free(), ->bprm_free_security()
Removed in favour of preparing new credentials and modifying those.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
(*) security_bprm_post_apply_creds(), ->bprm_post_apply_creds()
Removed; split between security_bprm_set_creds(),
security_bprm_committing_creds() and security_bprm_committed_creds().
(*) security_bprm_set(), ->bprm_set_security()
Removed; folded into security_bprm_set_creds().
(*) security_bprm_set_creds(), ->bprm_set_creds()
New. The new credentials in bprm->creds should be checked and set up
as appropriate. bprm->cred_prepared is 0 on the first call, 1 on the
second and subsequent calls.
(*) security_bprm_committing_creds(), ->bprm_committing_creds()
(*) security_bprm_committed_creds(), ->bprm_committed_creds()
New. Apply the security effects of the new credentials. This
includes closing unauthorised files in SELinux. This function may not
fail. When the former is called, the creds haven't yet been applied
to the process; when the latter is called, they have.
The former may access bprm->cred, the latter may not.
(3) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) The bprm_security_struct struct has been removed in favour of using
the credentials-under-construction approach.
(c) flush_unauthorized_files() now takes a cred pointer and passes it on
to inode_has_perm(), file_has_perm() and dentry_open().
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:24 +08:00
|
|
|
void security_bprm_committed_creds(struct linux_binprm *bprm)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(bprm_committed_creds, bprm);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-12-24 05:02:47 +08:00
|
|
|
int security_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc)
|
|
|
|
{
|
|
|
|
return call_int_hook(fs_context_dup, 0, fc, src_fc);
|
|
|
|
}
|
|
|
|
|
2018-11-02 07:07:24 +08:00
|
|
|
int security_fs_context_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
|
|
|
{
|
|
|
|
return call_int_hook(fs_context_parse_param, -ENOPARAM, fc, param);
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_sb_alloc(struct super_block *sb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_alloc_security, 0, sb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_sb_free(struct super_block *sb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sb_free_security, sb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-12-14 02:41:47 +08:00
|
|
|
void security_free_mnt_opts(void **mnt_opts)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2018-12-14 02:41:47 +08:00
|
|
|
if (!*mnt_opts)
|
|
|
|
return;
|
|
|
|
call_void_hook(sb_free_mnt_opts, *mnt_opts);
|
|
|
|
*mnt_opts = NULL;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2018-12-14 02:41:47 +08:00
|
|
|
EXPORT_SYMBOL(security_free_mnt_opts);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
2018-12-14 02:41:47 +08:00
|
|
|
int security_sb_eat_lsm_opts(char *options, void **mnt_opts)
|
2011-03-04 05:09:14 +08:00
|
|
|
{
|
2018-12-14 02:41:47 +08:00
|
|
|
return call_int_hook(sb_eat_lsm_opts, 0, options, mnt_opts);
|
2011-03-04 05:09:14 +08:00
|
|
|
}
|
2018-11-18 01:09:18 +08:00
|
|
|
EXPORT_SYMBOL(security_sb_eat_lsm_opts);
|
2011-03-04 05:09:14 +08:00
|
|
|
|
2018-12-02 12:06:57 +08:00
|
|
|
int security_sb_remount(struct super_block *sb,
|
2018-12-14 02:41:47 +08:00
|
|
|
void *mnt_opts)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2018-12-14 02:41:47 +08:00
|
|
|
return call_int_hook(sb_remount, 0, sb, mnt_opts);
|
2011-03-04 05:09:14 +08:00
|
|
|
}
|
2018-12-11 06:19:21 +08:00
|
|
|
EXPORT_SYMBOL(security_sb_remount);
|
2011-03-04 05:09:14 +08:00
|
|
|
|
2018-12-06 00:58:35 +08:00
|
|
|
int security_sb_kern_mount(struct super_block *sb)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2018-12-06 00:58:35 +08:00
|
|
|
return call_int_hook(sb_kern_mount, 0, sb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-07-04 07:47:13 +08:00
|
|
|
int security_sb_show_options(struct seq_file *m, struct super_block *sb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_show_options, 0, m, sb);
|
2008-07-04 07:47:13 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_sb_statfs(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_statfs, 0, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2016-03-26 02:52:53 +08:00
|
|
|
int security_sb_mount(const char *dev_name, const struct path *path,
|
2012-10-11 23:42:01 +08:00
|
|
|
const char *type, unsigned long flags, void *data)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sb_umount(struct vfsmount *mnt, int flags)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_umount, 0, mnt, flags);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2016-03-26 03:31:19 +08:00
|
|
|
int security_sb_pivotroot(const struct path *old_path, const struct path *new_path)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sb_pivotroot, 0, old_path, new_path);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2007-12-01 02:00:35 +08:00
|
|
|
int security_sb_set_mnt_opts(struct super_block *sb,
|
2018-12-14 02:41:47 +08:00
|
|
|
void *mnt_opts,
|
2013-05-23 00:50:36 +08:00
|
|
|
unsigned long kern_flags,
|
|
|
|
unsigned long *set_kern_flags)
|
2007-12-01 02:00:35 +08:00
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(sb_set_mnt_opts,
|
2018-12-14 02:41:47 +08:00
|
|
|
mnt_opts ? -EOPNOTSUPP : 0, sb,
|
|
|
|
mnt_opts, kern_flags, set_kern_flags);
|
2007-12-01 02:00:35 +08:00
|
|
|
}
|
2008-03-05 23:31:54 +08:00
|
|
|
EXPORT_SYMBOL(security_sb_set_mnt_opts);
|
2007-12-01 02:00:35 +08:00
|
|
|
|
selinux: make security_sb_clone_mnt_opts return an error on context mismatch
I had the following problem reported a while back. If you mount the
same filesystem twice using NFSv4 with different contexts, then the
second context= option is ignored. For instance:
# mount server:/export /mnt/test1
# mount server:/export /mnt/test2 -o context=system_u:object_r:tmp_t:s0
# ls -dZ /mnt/test1
drwxrwxrwt. root root system_u:object_r:nfs_t:s0 /mnt/test1
# ls -dZ /mnt/test2
drwxrwxrwt. root root system_u:object_r:nfs_t:s0 /mnt/test2
When we call into SELinux to set the context of a "cloned" superblock,
it will currently just bail out when it notices that we're reusing an
existing superblock. Since the existing superblock is already set up and
presumably in use, we can't go overwriting its context with the one from
the "original" sb. Because of this, the second context= option in this
case cannot take effect.
This patch fixes this by turning security_sb_clone_mnt_opts into an int
return operation. When it finds that the "new" superblock that it has
been handed is already set up, it checks to see whether the contexts on
the old superblock match it. If it does, then it will just return
success, otherwise it'll return -EBUSY and emit a printk to tell the
admin why the second mount failed.
Note that this patch may cause casualties. The NFSv4 code relies on
being able to walk down to an export from the pseudoroot. If you mount
filesystems that are nested within one another with different contexts,
then this patch will make those mounts fail in new and "exciting" ways.
For instance, suppose that /export is a separate filesystem on the
server:
# mount server:/ /mnt/test1
# mount salusa:/export /mnt/test2 -o context=system_u:object_r:tmp_t:s0
mount.nfs: an incorrect mount option was specified
...with the printk in the ring buffer. Because we *might* eventually
walk down to /mnt/test1/export, the mount is denied due to this patch.
The second mount needs the pseudoroot superblock, but that's already
present with the wrong context.
OTOH, if we mount these in the reverse order, then both mounts work,
because the pseudoroot superblock created when mounting /export is
discarded once that mount is done. If we then however try to walk into
that directory, the automount fails for the similar reasons:
# cd /mnt/test1/scratch/
-bash: cd: /mnt/test1/scratch: Device or resource busy
The story I've gotten from the SELinux folks that I've talked to is that
this is desirable behavior. In SELinux-land, mounting the same data
under different contexts is wrong -- there can be only one.
Cc: Steve Dickson <steved@redhat.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Acked-by: Eric Paris <eparis@redhat.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
2013-04-01 20:14:24 +08:00
|
|
|
int security_sb_clone_mnt_opts(const struct super_block *oldsb,
|
2017-06-05 23:45:04 +08:00
|
|
|
struct super_block *newsb,
|
|
|
|
unsigned long kern_flags,
|
|
|
|
unsigned long *set_kern_flags)
|
2007-12-01 02:00:35 +08:00
|
|
|
{
|
2017-06-05 23:45:04 +08:00
|
|
|
return call_int_hook(sb_clone_mnt_opts, 0, oldsb, newsb,
|
|
|
|
kern_flags, set_kern_flags);
|
2007-12-01 02:00:35 +08:00
|
|
|
}
|
2008-03-05 23:31:54 +08:00
|
|
|
EXPORT_SYMBOL(security_sb_clone_mnt_opts);
|
|
|
|
|
2018-12-15 12:42:21 +08:00
|
|
|
int security_add_mnt_opt(const char *option, const char *val, int len,
|
|
|
|
void **mnt_opts)
|
2008-03-05 23:31:54 +08:00
|
|
|
{
|
2018-12-15 12:42:21 +08:00
|
|
|
return call_int_hook(sb_add_mnt_opt, -EINVAL,
|
|
|
|
option, val, len, mnt_opts);
|
2008-03-05 23:31:54 +08:00
|
|
|
}
|
2018-12-15 12:42:21 +08:00
|
|
|
EXPORT_SYMBOL(security_add_mnt_opt);
|
2007-12-01 02:00:35 +08:00
|
|
|
|
2018-11-06 01:40:30 +08:00
|
|
|
int security_move_mount(const struct path *from_path, const struct path *to_path)
|
|
|
|
{
|
|
|
|
return call_int_hook(move_mount, 0, from_path, to_path);
|
|
|
|
}
|
|
|
|
|
fanotify, inotify, dnotify, security: add security hook for fs notifications
As of now, setting watches on filesystem objects has, at most, applied a
check for read access to the inode, and in the case of fanotify, requires
CAP_SYS_ADMIN. No specific security hook or permission check has been
provided to control the setting of watches. Using any of inotify, dnotify,
or fanotify, it is possible to observe, not only write-like operations, but
even read access to a file. Modeling the watch as being merely a read from
the file is insufficient for the needs of SELinux. This is due to the fact
that read access should not necessarily imply access to information about
when another process reads from a file. Furthermore, fanotify watches grant
more power to an application in the form of permission events. While
notification events are solely, unidirectional (i.e. they only pass
information to the receiving application), permission events are blocking.
Permission events make a request to the receiving application which will
then reply with a decision as to whether or not that action may be
completed. This causes the issue of the watching application having the
ability to exercise control over the triggering process. Without drawing a
distinction within the permission check, the ability to read would imply
the greater ability to control an application. Additionally, mount and
superblock watches apply to all files within the same mount or superblock.
Read access to one file should not necessarily imply the ability to watch
all files accessed within a given mount or superblock.
In order to solve these issues, a new LSM hook is implemented and has been
placed within the system calls for marking filesystem objects with inotify,
fanotify, and dnotify watches. These calls to the hook are placed at the
point at which the target path has been resolved and are provided with the
path struct, the mask of requested notification events, and the type of
object on which the mark is being set (inode, superblock, or mount). The
mask and obj_type have already been translated into common FS_* values
shared by the entirety of the fs notification infrastructure. The path
struct is passed rather than just the inode so that the mount is available,
particularly for mount watches. This also allows for use of the hook by
pathname-based security modules. However, since the hook is intended for
use even by inode based security modules, it is not placed under the
CONFIG_SECURITY_PATH conditional. Otherwise, the inode-based security
modules would need to enable all of the path hooks, even though they do not
use any of them.
This only provides a hook at the point of setting a watch, and presumes
that permission to set a particular watch implies the ability to receive
all notification about that object which match the mask. This is all that
is required for SELinux. If other security modules require additional hooks
or infrastructure to control delivery of notification, these can be added
by them. It does not make sense for us to propose hooks for which we have
no implementation. The understanding that all notifications received by the
requesting application are all strictly of a type for which the application
has been granted permission shows that this implementation is sufficient in
its coverage.
Security modules wishing to provide complete control over fanotify must
also implement a security_file_open hook that validates that the access
requested by the watching application is authorized. Fanotify has the issue
that it returns a file descriptor with the file mode specified during
fanotify_init() to the watching process on event. This is already covered
by the LSM security_file_open hook if the security module implements
checking of the requested file mode there. Otherwise, a watching process
can obtain escalated access to a file for which it has not been authorized.
The selinux_path_notify hook implementation works by adding five new file
permissions: watch, watch_mount, watch_sb, watch_reads, and watch_with_perm
(descriptions about which will follow), and one new filesystem permission:
watch (which is applied to superblock checks). The hook then decides which
subset of these permissions must be held by the requesting application
based on the contents of the provided mask and the obj_type. The
selinux_file_open hook already checks the requested file mode and therefore
ensures that a watching process cannot escalate its access through
fanotify.
The watch, watch_mount, and watch_sb permissions are the baseline
permissions for setting a watch on an object and each are a requirement for
any watch to be set on a file, mount, or superblock respectively. It should
be noted that having either of the other two permissions (watch_reads and
watch_with_perm) does not imply the watch, watch_mount, or watch_sb
permission. Superblock watches further require the filesystem watch
permission to the superblock. As there is no labeled object in view for
mounts, there is no specific check for mount watches beyond watch_mount to
the inode. Such a check could be added in the future, if a suitable labeled
object existed representing the mount.
The watch_reads permission is required to receive notifications from
read-exclusive events on filesystem objects. These events include accessing
a file for the purpose of reading and closing a file which has been opened
read-only. This distinction has been drawn in order to provide a direct
indication in the policy for this otherwise not obvious capability. Read
access to a file should not necessarily imply the ability to observe read
events on a file.
Finally, watch_with_perm only applies to fanotify masks since it is the
only way to set a mask which allows for the blocking, permission event.
This permission is needed for any watch which is of this type. Though
fanotify requires CAP_SYS_ADMIN, this is insufficient as it gives implicit
trust to root, which we do not do, and does not support least privilege.
Signed-off-by: Aaron Goidel <acgoide@tycho.nsa.gov>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Acked-by: Jan Kara <jack@suse.cz>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2019-08-12 23:20:00 +08:00
|
|
|
int security_path_notify(const struct path *path, u64 mask,
|
|
|
|
unsigned int obj_type)
|
|
|
|
{
|
|
|
|
return call_int_hook(path_notify, 0, path, mask, obj_type);
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_inode_alloc(struct inode *inode)
|
|
|
|
{
|
2018-09-22 08:19:29 +08:00
|
|
|
int rc = lsm_inode_alloc(inode);
|
|
|
|
|
|
|
|
if (unlikely(rc))
|
|
|
|
return rc;
|
|
|
|
rc = call_int_hook(inode_alloc_security, 0, inode);
|
|
|
|
if (unlikely(rc))
|
|
|
|
security_inode_free(inode);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void inode_free_by_rcu(struct rcu_head *head)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The rcu head is at the start of the inode blob
|
|
|
|
*/
|
|
|
|
kmem_cache_free(lsm_inode_cache, head);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_inode_free(struct inode *inode)
|
|
|
|
{
|
2011-03-10 03:13:22 +08:00
|
|
|
integrity_inode_free(inode);
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(inode_free_security, inode);
|
2018-09-22 08:19:29 +08:00
|
|
|
/*
|
|
|
|
* The inode may still be referenced in a path walk and
|
|
|
|
* a call to security_inode_permission() can be made
|
|
|
|
* after inode_free_security() is called. Ideally, the VFS
|
|
|
|
* wouldn't do this, but fixing that is a much harder
|
|
|
|
* job. For now, simply free the i_security via RCU, and
|
|
|
|
* leave the current inode->i_security pointer intact.
|
|
|
|
* The inode will be freed after the RCU grace period too.
|
|
|
|
*/
|
|
|
|
if (inode->i_security)
|
|
|
|
call_rcu((struct rcu_head *)inode->i_security,
|
|
|
|
inode_free_by_rcu);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2013-05-23 00:50:34 +08:00
|
|
|
int security_dentry_init_security(struct dentry *dentry, int mode,
|
2016-07-21 04:06:15 +08:00
|
|
|
const struct qstr *name, void **ctx,
|
2013-05-23 00:50:34 +08:00
|
|
|
u32 *ctxlen)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode,
|
|
|
|
name, ctx, ctxlen);
|
2013-05-23 00:50:34 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_dentry_init_security);
|
|
|
|
|
2016-07-13 22:44:52 +08: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 14:31:32 +08:00
|
|
|
int security_inode_init_security(struct inode *inode, struct inode *dir,
|
2011-06-07 03:29:25 +08:00
|
|
|
const struct qstr *qstr,
|
|
|
|
const initxattrs initxattrs, void *fs_data)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2011-06-16 09:19:10 +08:00
|
|
|
struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1];
|
|
|
|
struct xattr *lsm_xattr, *evm_xattr, *xattr;
|
2011-06-07 03:29:25 +08:00
|
|
|
int ret;
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2011-08-15 22:13:18 +08:00
|
|
|
return 0;
|
2011-06-07 03:29:25 +08:00
|
|
|
|
|
|
|
if (!initxattrs)
|
2015-08-24 20:22:25 +08:00
|
|
|
return call_int_hook(inode_init_security, -EOPNOTSUPP, inode,
|
|
|
|
dir, qstr, NULL, NULL, NULL);
|
2013-07-25 04:44:02 +08:00
|
|
|
memset(new_xattrs, 0, sizeof(new_xattrs));
|
2011-06-07 03:29:25 +08:00
|
|
|
lsm_xattr = new_xattrs;
|
2015-05-03 06:11:42 +08:00
|
|
|
ret = call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir, qstr,
|
2011-06-07 03:29:25 +08:00
|
|
|
&lsm_xattr->name,
|
|
|
|
&lsm_xattr->value,
|
|
|
|
&lsm_xattr->value_len);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2011-06-16 09:19:10 +08:00
|
|
|
|
|
|
|
evm_xattr = lsm_xattr + 1;
|
|
|
|
ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2011-06-07 03:29:25 +08:00
|
|
|
ret = initxattrs(inode, new_xattrs, fs_data);
|
|
|
|
out:
|
2013-07-25 04:44:02 +08:00
|
|
|
for (xattr = new_xattrs; xattr->value != NULL; xattr++)
|
2011-06-16 09:19:10 +08:00
|
|
|
kfree(xattr->value);
|
2011-06-07 03:29:25 +08:00
|
|
|
return (ret == -EOPNOTSUPP) ? 0 : ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_init_security);
|
|
|
|
|
|
|
|
int security_old_inode_init_security(struct inode *inode, struct inode *dir,
|
2013-07-25 04:44:02 +08:00
|
|
|
const struct qstr *qstr, const char **name,
|
2011-06-07 03:29:25 +08:00
|
|
|
void **value, size_t *len)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2012-01-03 20:14:29 +08:00
|
|
|
return -EOPNOTSUPP;
|
2015-08-24 20:22:25 +08:00
|
|
|
return call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir,
|
|
|
|
qstr, name, value, len);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2011-06-07 03:29:25 +08:00
|
|
|
EXPORT_SYMBOL(security_old_inode_init_security);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
2008-12-17 12:24:15 +08:00
|
|
|
#ifdef CONFIG_SECURITY_PATH
|
2016-03-26 03:21:09 +08:00
|
|
|
int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode,
|
2008-12-17 12:24:15 +08:00
|
|
|
unsigned int dev)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_mknod, 0, dir, dentry, mode, dev);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_path_mknod);
|
|
|
|
|
2016-03-26 03:21:09 +08:00
|
|
|
int security_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t mode)
|
2008-12-17 12:24:15 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_mkdir, 0, dir, dentry, mode);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
2010-12-24 22:48:35 +08:00
|
|
|
EXPORT_SYMBOL(security_path_mkdir);
|
2008-12-17 12:24:15 +08:00
|
|
|
|
2016-03-26 03:13:39 +08:00
|
|
|
int security_path_rmdir(const struct path *dir, struct dentry *dentry)
|
2008-12-17 12:24:15 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_rmdir, 0, dir, dentry);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
|
|
|
|
2016-03-26 03:13:39 +08:00
|
|
|
int security_path_unlink(const struct path *dir, struct dentry *dentry)
|
2008-12-17 12:24:15 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_unlink, 0, dir, dentry);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
2010-12-24 22:48:35 +08:00
|
|
|
EXPORT_SYMBOL(security_path_unlink);
|
2008-12-17 12:24:15 +08:00
|
|
|
|
2016-03-26 03:21:09 +08:00
|
|
|
int security_path_symlink(const struct path *dir, struct dentry *dentry,
|
2008-12-17 12:24:15 +08:00
|
|
|
const char *old_name)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_symlink, 0, dir, dentry, old_name);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
|
|
|
|
2016-03-26 03:27:45 +08:00
|
|
|
int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
|
2008-12-17 12:24:15 +08:00
|
|
|
struct dentry *new_dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
|
|
|
|
2016-03-26 03:27:45 +08: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 23:08:43 +08:00
|
|
|
unsigned int flags)
|
2008-12-17 12:24:15 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
|
|
|
|
(d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2014-04-01 23:08:43 +08:00
|
|
|
|
|
|
|
if (flags & RENAME_EXCHANGE) {
|
2015-05-03 06:11:29 +08:00
|
|
|
int err = call_int_hook(path_rename, 0, new_dir, new_dentry,
|
|
|
|
old_dir, old_dentry);
|
2014-04-01 23:08:43 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_rename, 0, old_dir, old_dentry, new_dir,
|
|
|
|
new_dentry);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
2010-12-24 22:48:35 +08:00
|
|
|
EXPORT_SYMBOL(security_path_rename);
|
2008-12-17 12:24:15 +08:00
|
|
|
|
2016-03-26 02:22:01 +08:00
|
|
|
int security_path_truncate(const struct path *path)
|
2008-12-17 12:24:15 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2008-12-17 12:24:15 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_truncate, 0, path);
|
2008-12-17 12:24:15 +08:00
|
|
|
}
|
2009-10-04 20:49:47 +08:00
|
|
|
|
2016-03-26 02:56:23 +08:00
|
|
|
int security_path_chmod(const struct path *path, umode_t mode)
|
2009-10-04 20:49:47 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2009-10-04 20:49:47 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_chmod, 0, path, mode);
|
2009-10-04 20:49:47 +08:00
|
|
|
}
|
|
|
|
|
2016-03-26 02:44:41 +08:00
|
|
|
int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
|
2009-10-04 20:49:47 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2009-10-04 20:49:47 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_chown, 0, path, uid, gid);
|
2009-10-04 20:49:47 +08:00
|
|
|
}
|
2009-10-04 20:49:48 +08:00
|
|
|
|
2016-03-26 03:28:43 +08:00
|
|
|
int security_path_chroot(const struct path *path)
|
2009-10-04 20:49:48 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(path_chroot, 0, path);
|
2009-10-04 20:49:48 +08:00
|
|
|
}
|
2008-12-17 12:24:15 +08:00
|
|
|
#endif
|
|
|
|
|
2011-07-26 13:42:34 +08:00
|
|
|
int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(dir)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_create, 0, dir, dentry, mode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2009-04-03 23:42:40 +08:00
|
|
|
EXPORT_SYMBOL_GPL(security_inode_create);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
|
|
|
int security_inode_link(struct dentry *old_dentry, struct inode *dir,
|
|
|
|
struct dentry *new_dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_unlink(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_unlink, 0, dir, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_symlink(struct inode *dir, struct dentry *dentry,
|
|
|
|
const char *old_name)
|
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(dir)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_symlink, 0, dir, dentry, old_name);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2011-07-26 13:41:39 +08:00
|
|
|
int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(dir)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_mkdir, 0, dir, dentry, mode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2009-04-03 23:42:40 +08:00
|
|
|
EXPORT_SYMBOL_GPL(security_inode_mkdir);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
|
|
|
int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_rmdir, 0, dir, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2011-07-26 13:52:52 +08:00
|
|
|
int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(dir)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_mknod, 0, dir, dentry, mode, dev);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
|
2014-04-01 23:08:43 +08:00
|
|
|
struct inode *new_dir, struct dentry *new_dentry,
|
|
|
|
unsigned int flags)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
|
|
|
|
(d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2014-04-01 23:08:43 +08:00
|
|
|
|
|
|
|
if (flags & RENAME_EXCHANGE) {
|
2015-05-03 06:11:29 +08:00
|
|
|
int err = call_int_hook(inode_rename, 0, new_dir, new_dentry,
|
2014-04-01 23:08:43 +08:00
|
|
|
old_dir, old_dentry);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_rename, 0, old_dir, old_dentry,
|
2007-10-17 14:31:32 +08:00
|
|
|
new_dir, new_dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_readlink(struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_readlink, 0, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2015-03-23 10:37:39 +08:00
|
|
|
int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
|
|
|
|
bool rcu)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-03-23 10:37:39 +08:00
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-06-28 04:26:03 +08:00
|
|
|
return call_int_hook(inode_follow_link, 0, dentry, inode, rcu);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-07-17 21:37:02 +08:00
|
|
|
int security_inode_permission(struct inode *inode, int mask)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_permission, 0, inode, mask);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
|
|
|
|
{
|
2011-05-14 00:53:38 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
ret = call_int_hook(inode_setattr, 0, dentry, attr);
|
2011-05-14 00:53:38 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return evm_inode_setattr(dentry, attr);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2008-07-01 21:01:28 +08:00
|
|
|
EXPORT_SYMBOL_GPL(security_inode_setattr);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
2015-03-09 07:28:30 +08:00
|
|
|
int security_inode_getattr(const struct path *path)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_getattr, 0, path);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 15:59:41 +08:00
|
|
|
int security_inode_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
const void *value, size_t size, int flags)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2011-03-10 03:38:26 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:42 +08:00
|
|
|
/*
|
|
|
|
* SELinux and Smack integrate the cap call,
|
|
|
|
* so assume that all LSMs supplying this call do so.
|
|
|
|
*/
|
|
|
|
ret = call_int_hook(inode_setxattr, 1, dentry, name, value, size,
|
2015-05-03 06:11:29 +08:00
|
|
|
flags);
|
2015-05-03 06:11:42 +08:00
|
|
|
|
|
|
|
if (ret == 1)
|
|
|
|
ret = cap_inode_setxattr(dentry, name, value, size, flags);
|
2011-03-11 07:54:15 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = ima_inode_setxattr(dentry, name, value, size);
|
2011-03-10 03:38:26 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return evm_inode_setxattr(dentry, name, value, size);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 15:59:41 +08:00
|
|
|
void security_inode_post_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
const void *value, size_t size, int flags)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return;
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(inode_post_setxattr, dentry, name, value, size, flags);
|
2011-03-10 03:38:26 +08:00
|
|
|
evm_inode_post_setxattr(dentry, name, value, size);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 15:59:41 +08:00
|
|
|
int security_inode_getxattr(struct dentry *dentry, const char *name)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_getxattr, 0, dentry, name);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_listxattr(struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_listxattr, 0, dentry);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 15:59:41 +08:00
|
|
|
int security_inode_removexattr(struct dentry *dentry, const char *name)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2011-03-10 03:38:26 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-03-18 06:26:22 +08:00
|
|
|
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
|
2007-10-17 14:31:32 +08:00
|
|
|
return 0;
|
2015-05-03 06:11:42 +08:00
|
|
|
/*
|
|
|
|
* SELinux and Smack integrate the cap call,
|
|
|
|
* so assume that all LSMs supplying this call do so.
|
|
|
|
*/
|
|
|
|
ret = call_int_hook(inode_removexattr, 1, dentry, name);
|
|
|
|
if (ret == 1)
|
|
|
|
ret = cap_inode_removexattr(dentry, name);
|
2011-03-11 07:54:15 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = ima_inode_removexattr(dentry, name);
|
2011-03-10 03:38:26 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return evm_inode_removexattr(dentry, name);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
Implement file posix capabilities
Implement file posix capabilities. This allows programs to be given a
subset of root's powers regardless of who runs them, without having to use
setuid and giving the binary all of root's powers.
This version works with Kaigai Kohei's userspace tools, found at
http://www.kaigai.gr.jp/index.php. For more information on how to use this
patch, Chris Friedhoff has posted a nice page at
http://www.friedhoff.org/fscaps.html.
Changelog:
Nov 27:
Incorporate fixes from Andrew Morton
(security-introduce-file-caps-tweaks and
security-introduce-file-caps-warning-fix)
Fix Kconfig dependency.
Fix change signaling behavior when file caps are not compiled in.
Nov 13:
Integrate comments from Alexey: Remove CONFIG_ ifdef from
capability.h, and use %zd for printing a size_t.
Nov 13:
Fix endianness warnings by sparse as suggested by Alexey
Dobriyan.
Nov 09:
Address warnings of unused variables at cap_bprm_set_security
when file capabilities are disabled, and simultaneously clean
up the code a little, by pulling the new code into a helper
function.
Nov 08:
For pointers to required userspace tools and how to use
them, see http://www.friedhoff.org/fscaps.html.
Nov 07:
Fix the calculation of the highest bit checked in
check_cap_sanity().
Nov 07:
Allow file caps to be enabled without CONFIG_SECURITY, since
capabilities are the default.
Hook cap_task_setscheduler when !CONFIG_SECURITY.
Move capable(TASK_KILL) to end of cap_task_kill to reduce
audit messages.
Nov 05:
Add secondary calls in selinux/hooks.c to task_setioprio and
task_setscheduler so that selinux and capabilities with file
cap support can be stacked.
Sep 05:
As Seth Arnold points out, uid checks are out of place
for capability code.
Sep 01:
Define task_setscheduler, task_setioprio, cap_task_kill, and
task_setnice to make sure a user cannot affect a process in which
they called a program with some fscaps.
One remaining question is the note under task_setscheduler: are we
ok with CAP_SYS_NICE being sufficient to confine a process to a
cpuset?
It is a semantic change, as without fsccaps, attach_task doesn't
allow CAP_SYS_NICE to override the uid equivalence check. But since
it uses security_task_setscheduler, which elsewhere is used where
CAP_SYS_NICE can be used to override the uid equivalence check,
fixing it might be tough.
task_setscheduler
note: this also controls cpuset:attach_task. Are we ok with
CAP_SYS_NICE being used to confine to a cpuset?
task_setioprio
task_setnice
sys_setpriority uses this (through set_one_prio) for another
process. Need same checks as setrlimit
Aug 21:
Updated secureexec implementation to reflect the fact that
euid and uid might be the same and nonzero, but the process
might still have elevated caps.
Aug 15:
Handle endianness of xattrs.
Enforce capability version match between kernel and disk.
Enforce that no bits beyond the known max capability are
set, else return -EPERM.
With this extra processing, it may be worth reconsidering
doing all the work at bprm_set_security rather than
d_instantiate.
Aug 10:
Always call getxattr at bprm_set_security, rather than
caching it at d_instantiate.
[morgan@kernel.org: file-caps clean up for linux/capability.h]
[bunk@kernel.org: unexport cap_inode_killpriv]
Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: James Morris <jmorris@namei.org>
Cc: Chris Wright <chrisw@sous-sol.org>
Cc: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Adrian Bunk <bunk@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-17 14:31:36 +08:00
|
|
|
int security_inode_need_killpriv(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_need_killpriv, 0, dentry);
|
Implement file posix capabilities
Implement file posix capabilities. This allows programs to be given a
subset of root's powers regardless of who runs them, without having to use
setuid and giving the binary all of root's powers.
This version works with Kaigai Kohei's userspace tools, found at
http://www.kaigai.gr.jp/index.php. For more information on how to use this
patch, Chris Friedhoff has posted a nice page at
http://www.friedhoff.org/fscaps.html.
Changelog:
Nov 27:
Incorporate fixes from Andrew Morton
(security-introduce-file-caps-tweaks and
security-introduce-file-caps-warning-fix)
Fix Kconfig dependency.
Fix change signaling behavior when file caps are not compiled in.
Nov 13:
Integrate comments from Alexey: Remove CONFIG_ ifdef from
capability.h, and use %zd for printing a size_t.
Nov 13:
Fix endianness warnings by sparse as suggested by Alexey
Dobriyan.
Nov 09:
Address warnings of unused variables at cap_bprm_set_security
when file capabilities are disabled, and simultaneously clean
up the code a little, by pulling the new code into a helper
function.
Nov 08:
For pointers to required userspace tools and how to use
them, see http://www.friedhoff.org/fscaps.html.
Nov 07:
Fix the calculation of the highest bit checked in
check_cap_sanity().
Nov 07:
Allow file caps to be enabled without CONFIG_SECURITY, since
capabilities are the default.
Hook cap_task_setscheduler when !CONFIG_SECURITY.
Move capable(TASK_KILL) to end of cap_task_kill to reduce
audit messages.
Nov 05:
Add secondary calls in selinux/hooks.c to task_setioprio and
task_setscheduler so that selinux and capabilities with file
cap support can be stacked.
Sep 05:
As Seth Arnold points out, uid checks are out of place
for capability code.
Sep 01:
Define task_setscheduler, task_setioprio, cap_task_kill, and
task_setnice to make sure a user cannot affect a process in which
they called a program with some fscaps.
One remaining question is the note under task_setscheduler: are we
ok with CAP_SYS_NICE being sufficient to confine a process to a
cpuset?
It is a semantic change, as without fsccaps, attach_task doesn't
allow CAP_SYS_NICE to override the uid equivalence check. But since
it uses security_task_setscheduler, which elsewhere is used where
CAP_SYS_NICE can be used to override the uid equivalence check,
fixing it might be tough.
task_setscheduler
note: this also controls cpuset:attach_task. Are we ok with
CAP_SYS_NICE being used to confine to a cpuset?
task_setioprio
task_setnice
sys_setpriority uses this (through set_one_prio) for another
process. Need same checks as setrlimit
Aug 21:
Updated secureexec implementation to reflect the fact that
euid and uid might be the same and nonzero, but the process
might still have elevated caps.
Aug 15:
Handle endianness of xattrs.
Enforce capability version match between kernel and disk.
Enforce that no bits beyond the known max capability are
set, else return -EPERM.
With this extra processing, it may be worth reconsidering
doing all the work at bprm_set_security rather than
d_instantiate.
Aug 10:
Always call getxattr at bprm_set_security, rather than
caching it at d_instantiate.
[morgan@kernel.org: file-caps clean up for linux/capability.h]
[bunk@kernel.org: unexport cap_inode_killpriv]
Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: James Morris <jmorris@namei.org>
Cc: Chris Wright <chrisw@sous-sol.org>
Cc: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Adrian Bunk <bunk@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-17 14:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_killpriv(struct dentry *dentry)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_killpriv, 0, dentry);
|
Implement file posix capabilities
Implement file posix capabilities. This allows programs to be given a
subset of root's powers regardless of who runs them, without having to use
setuid and giving the binary all of root's powers.
This version works with Kaigai Kohei's userspace tools, found at
http://www.kaigai.gr.jp/index.php. For more information on how to use this
patch, Chris Friedhoff has posted a nice page at
http://www.friedhoff.org/fscaps.html.
Changelog:
Nov 27:
Incorporate fixes from Andrew Morton
(security-introduce-file-caps-tweaks and
security-introduce-file-caps-warning-fix)
Fix Kconfig dependency.
Fix change signaling behavior when file caps are not compiled in.
Nov 13:
Integrate comments from Alexey: Remove CONFIG_ ifdef from
capability.h, and use %zd for printing a size_t.
Nov 13:
Fix endianness warnings by sparse as suggested by Alexey
Dobriyan.
Nov 09:
Address warnings of unused variables at cap_bprm_set_security
when file capabilities are disabled, and simultaneously clean
up the code a little, by pulling the new code into a helper
function.
Nov 08:
For pointers to required userspace tools and how to use
them, see http://www.friedhoff.org/fscaps.html.
Nov 07:
Fix the calculation of the highest bit checked in
check_cap_sanity().
Nov 07:
Allow file caps to be enabled without CONFIG_SECURITY, since
capabilities are the default.
Hook cap_task_setscheduler when !CONFIG_SECURITY.
Move capable(TASK_KILL) to end of cap_task_kill to reduce
audit messages.
Nov 05:
Add secondary calls in selinux/hooks.c to task_setioprio and
task_setscheduler so that selinux and capabilities with file
cap support can be stacked.
Sep 05:
As Seth Arnold points out, uid checks are out of place
for capability code.
Sep 01:
Define task_setscheduler, task_setioprio, cap_task_kill, and
task_setnice to make sure a user cannot affect a process in which
they called a program with some fscaps.
One remaining question is the note under task_setscheduler: are we
ok with CAP_SYS_NICE being sufficient to confine a process to a
cpuset?
It is a semantic change, as without fsccaps, attach_task doesn't
allow CAP_SYS_NICE to override the uid equivalence check. But since
it uses security_task_setscheduler, which elsewhere is used where
CAP_SYS_NICE can be used to override the uid equivalence check,
fixing it might be tough.
task_setscheduler
note: this also controls cpuset:attach_task. Are we ok with
CAP_SYS_NICE being used to confine to a cpuset?
task_setioprio
task_setnice
sys_setpriority uses this (through set_one_prio) for another
process. Need same checks as setrlimit
Aug 21:
Updated secureexec implementation to reflect the fact that
euid and uid might be the same and nonzero, but the process
might still have elevated caps.
Aug 15:
Handle endianness of xattrs.
Enforce capability version match between kernel and disk.
Enforce that no bits beyond the known max capability are
set, else return -EPERM.
With this extra processing, it may be worth reconsidering
doing all the work at bprm_set_security rather than
d_instantiate.
Aug 10:
Always call getxattr at bprm_set_security, rather than
caching it at d_instantiate.
[morgan@kernel.org: file-caps clean up for linux/capability.h]
[bunk@kernel.org: unexport cap_inode_killpriv]
Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: James Morris <jmorris@namei.org>
Cc: Chris Wright <chrisw@sous-sol.org>
Cc: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Andrew Morgan <morgan@kernel.org>
Signed-off-by: Adrian Bunk <bunk@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-17 14:31:36 +08:00
|
|
|
}
|
|
|
|
|
2015-12-25 00:09:39 +08:00
|
|
|
int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2016-06-01 08:24:15 +08:00
|
|
|
struct security_hook_list *hp;
|
|
|
|
int rc;
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2010-01-14 06:33:28 +08:00
|
|
|
return -EOPNOTSUPP;
|
2016-06-01 08:24:15 +08:00
|
|
|
/*
|
|
|
|
* Only one module will provide an attribute with a given name.
|
|
|
|
*/
|
2018-03-29 09:28:23 +08:00
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.inode_getsecurity, list) {
|
2016-06-01 08:24:15 +08:00
|
|
|
rc = hp->hook.inode_getsecurity(inode, name, buffer, alloc);
|
|
|
|
if (rc != -EOPNOTSUPP)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
return -EOPNOTSUPP;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
|
|
|
|
{
|
2016-06-01 08:24:15 +08:00
|
|
|
struct security_hook_list *hp;
|
|
|
|
int rc;
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
2010-01-14 06:33:28 +08:00
|
|
|
return -EOPNOTSUPP;
|
2016-06-01 08:24:15 +08:00
|
|
|
/*
|
|
|
|
* Only one module will provide an attribute with a given name.
|
|
|
|
*/
|
2018-03-29 09:28:23 +08:00
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) {
|
2016-06-01 08:24:15 +08:00
|
|
|
rc = hp->hook.inode_setsecurity(inode, name, value, size,
|
|
|
|
flags);
|
|
|
|
if (rc != -EOPNOTSUPP)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
return -EOPNOTSUPP;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
|
|
|
|
{
|
|
|
|
if (unlikely(IS_PRIVATE(inode)))
|
|
|
|
return 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_listsecurity, 0, inode, buffer, buffer_size);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2013-05-23 00:50:45 +08:00
|
|
|
EXPORT_SYMBOL(security_inode_listsecurity);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
2015-12-25 00:09:39 +08:00
|
|
|
void security_inode_getsecid(struct inode *inode, u32 *secid)
|
2008-03-02 03:51:09 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(inode_getsecid, inode, secid);
|
2008-03-02 03:51:09 +08:00
|
|
|
}
|
|
|
|
|
2016-07-13 23:13:56 +08: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 22:44:49 +08: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);
|
|
|
|
|
2019-02-22 22:57:16 +08:00
|
|
|
int security_kernfs_init_security(struct kernfs_node *kn_dir,
|
|
|
|
struct kernfs_node *kn)
|
|
|
|
{
|
|
|
|
return call_int_hook(kernfs_init_security, 0, kn_dir, kn);
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_file_permission(struct file *file, int mask)
|
|
|
|
{
|
2009-12-18 10:24:34 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
ret = call_int_hook(file_permission, 0, file, mask);
|
2009-12-18 10:24:34 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return fsnotify_perm(file, mask);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_alloc(struct file *file)
|
|
|
|
{
|
2018-11-13 04:02:49 +08:00
|
|
|
int rc = lsm_file_alloc(file);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
rc = call_int_hook(file_alloc_security, 0, file);
|
|
|
|
if (unlikely(rc))
|
|
|
|
security_file_free(file);
|
|
|
|
return rc;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_file_free(struct file *file)
|
|
|
|
{
|
2018-11-13 04:02:49 +08:00
|
|
|
void *blob;
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(file_free_security, file);
|
2018-11-13 04:02:49 +08:00
|
|
|
|
|
|
|
blob = file->f_security;
|
|
|
|
if (blob) {
|
|
|
|
file->f_security = NULL;
|
|
|
|
kmem_cache_free(lsm_file_cache, blob);
|
|
|
|
}
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_ioctl, 0, file, cmd, arg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2012-05-31 07:58:30 +08:00
|
|
|
static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2012-05-31 05:11:23 +08:00
|
|
|
/*
|
2012-05-31 07:58:30 +08:00
|
|
|
* Does we have PROT_READ and does the application expect
|
|
|
|
* it to imply PROT_EXEC? If not, nothing to talk about...
|
2012-05-31 05:11:23 +08:00
|
|
|
*/
|
2012-05-31 07:58:30 +08:00
|
|
|
if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ)
|
|
|
|
return prot;
|
2012-05-31 05:11:23 +08:00
|
|
|
if (!(current->personality & READ_IMPLIES_EXEC))
|
2012-05-31 07:58:30 +08:00
|
|
|
return prot;
|
|
|
|
/*
|
|
|
|
* if that's an anonymous mapping, let it.
|
|
|
|
*/
|
|
|
|
if (!file)
|
|
|
|
return prot | PROT_EXEC;
|
|
|
|
/*
|
|
|
|
* ditto if it's not on noexec mount, except that on !MMU we need
|
2015-01-14 17:42:32 +08:00
|
|
|
* NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
|
2012-05-31 07:58:30 +08:00
|
|
|
*/
|
2015-06-30 03:42:03 +08:00
|
|
|
if (!path_noexec(&file->f_path)) {
|
2012-05-31 05:11:23 +08:00
|
|
|
#ifndef CONFIG_MMU
|
2015-01-14 17:42:32 +08:00
|
|
|
if (file->f_op->mmap_capabilities) {
|
|
|
|
unsigned caps = file->f_op->mmap_capabilities(file);
|
|
|
|
if (!(caps & NOMMU_MAP_EXEC))
|
|
|
|
return prot;
|
|
|
|
}
|
2012-05-31 05:11:23 +08:00
|
|
|
#endif
|
2012-05-31 07:58:30 +08:00
|
|
|
return prot | PROT_EXEC;
|
2012-05-31 05:11:23 +08:00
|
|
|
}
|
2012-05-31 07:58:30 +08:00
|
|
|
/* anything on noexec mount won't get PROT_EXEC */
|
|
|
|
return prot;
|
|
|
|
}
|
|
|
|
|
|
|
|
int security_mmap_file(struct file *file, unsigned long prot,
|
|
|
|
unsigned long flags)
|
|
|
|
{
|
|
|
|
int ret;
|
2015-05-03 06:11:29 +08:00
|
|
|
ret = call_int_hook(mmap_file, 0, file, prot,
|
2012-05-31 07:58:30 +08:00
|
|
|
mmap_prot(file, prot), flags);
|
2009-10-23 05:30:13 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return ima_file_mmap(file, prot);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2012-05-31 01:30:51 +08:00
|
|
|
int security_mmap_addr(unsigned long addr)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(mmap_addr, 0, addr);
|
2012-05-31 01:30:51 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
|
|
|
|
unsigned long prot)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_mprotect, 0, vma, reqprot, prot);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_lock(struct file *file, unsigned int cmd)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_lock, 0, file, cmd);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_fcntl, 0, file, cmd, arg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2014-08-22 23:27:32 +08:00
|
|
|
void security_file_set_fowner(struct file *file)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(file_set_fowner, file);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_send_sigiotask(struct task_struct *tsk,
|
|
|
|
struct fown_struct *fown, int sig)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_send_sigiotask, 0, tsk, fown, sig);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_file_receive(struct file *file)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(file_receive, 0, file);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-07-11 01:25:29 +08:00
|
|
|
int security_file_open(struct file *file)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2009-12-18 10:24:34 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-07-11 02:13:18 +08:00
|
|
|
ret = call_int_hook(file_open, 0, file);
|
2009-12-18 10:24:34 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return fsnotify_perm(file, MAY_OPEN);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2017-03-24 19:46:33 +08:00
|
|
|
int security_task_alloc(struct task_struct *task, unsigned long clone_flags)
|
|
|
|
{
|
2018-09-22 08:19:37 +08:00
|
|
|
int rc = lsm_task_alloc(task);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
rc = call_int_hook(task_alloc, 0, task, clone_flags);
|
|
|
|
if (unlikely(rc))
|
|
|
|
security_task_free(task);
|
|
|
|
return rc;
|
2017-03-24 19:46:33 +08:00
|
|
|
}
|
|
|
|
|
2011-12-22 04:17:03 +08:00
|
|
|
void security_task_free(struct task_struct *task)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(task_free, task);
|
2018-09-22 08:19:37 +08:00
|
|
|
|
|
|
|
kfree(task->security);
|
|
|
|
task->security = NULL;
|
2011-12-22 04:17:03 +08:00
|
|
|
}
|
|
|
|
|
KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]
Add a keyctl to install a process's session keyring onto its parent. This
replaces the parent's session keyring. Because the COW credential code does
not permit one process to change another process's credentials directly, the
change is deferred until userspace next starts executing again. Normally this
will be after a wait*() syscall.
To support this, three new security hooks have been provided:
cred_alloc_blank() to allocate unset security creds, cred_transfer() to fill in
the blank security creds and key_session_to_parent() - which asks the LSM if
the process may replace its parent's session keyring.
The replacement may only happen if the process has the same ownership details
as its parent, and the process has LINK permission on the session keyring, and
the session keyring is owned by the process, and the LSM permits it.
Note that this requires alteration to each architecture's notify_resume path.
This has been done for all arches barring blackfin, m68k* and xtensa, all of
which need assembly alteration to support TIF_NOTIFY_RESUME. This allows the
replacement to be performed at the point the parent process resumes userspace
execution.
This allows the userspace AFS pioctl emulation to fully emulate newpag() and
the VIOCSETTOK and VIOCSETTOK2 pioctls, all of which require the ability to
alter the parent process's PAG membership. However, since kAFS doesn't use
PAGs per se, but rather dumps the keys into the session keyring, the session
keyring of the parent must be replaced if, for example, VIOCSETTOK is passed
the newpag flag.
This can be tested with the following program:
#include <stdio.h>
#include <stdlib.h>
#include <keyutils.h>
#define KEYCTL_SESSION_TO_PARENT 18
#define OSERROR(X, S) do { if ((long)(X) == -1) { perror(S); exit(1); } } while(0)
int main(int argc, char **argv)
{
key_serial_t keyring, key;
long ret;
keyring = keyctl_join_session_keyring(argv[1]);
OSERROR(keyring, "keyctl_join_session_keyring");
key = add_key("user", "a", "b", 1, keyring);
OSERROR(key, "add_key");
ret = keyctl(KEYCTL_SESSION_TO_PARENT);
OSERROR(ret, "KEYCTL_SESSION_TO_PARENT");
return 0;
}
Compiled and linked with -lkeyutils, you should see something like:
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
355907932 --alswrv 4043 -1 \_ keyring: _uid.4043
[dhowells@andromeda ~]$ /tmp/newpag
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
1055658746 --alswrv 4043 4043 \_ user: a
[dhowells@andromeda ~]$ /tmp/newpag hello
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: hello
340417692 --alswrv 4043 4043 \_ user: a
Where the test program creates a new session keyring, sticks a user key named
'a' into it and then installs it on its parent.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
2009-09-02 16:14:21 +08:00
|
|
|
int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
|
|
|
|
{
|
2018-11-13 01:30:56 +08:00
|
|
|
int rc = lsm_cred_alloc(cred, gfp);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = call_int_hook(cred_alloc_blank, 0, cred, gfp);
|
2018-11-13 04:02:49 +08:00
|
|
|
if (unlikely(rc))
|
2018-11-13 01:30:56 +08:00
|
|
|
security_cred_free(cred);
|
|
|
|
return rc;
|
KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]
Add a keyctl to install a process's session keyring onto its parent. This
replaces the parent's session keyring. Because the COW credential code does
not permit one process to change another process's credentials directly, the
change is deferred until userspace next starts executing again. Normally this
will be after a wait*() syscall.
To support this, three new security hooks have been provided:
cred_alloc_blank() to allocate unset security creds, cred_transfer() to fill in
the blank security creds and key_session_to_parent() - which asks the LSM if
the process may replace its parent's session keyring.
The replacement may only happen if the process has the same ownership details
as its parent, and the process has LINK permission on the session keyring, and
the session keyring is owned by the process, and the LSM permits it.
Note that this requires alteration to each architecture's notify_resume path.
This has been done for all arches barring blackfin, m68k* and xtensa, all of
which need assembly alteration to support TIF_NOTIFY_RESUME. This allows the
replacement to be performed at the point the parent process resumes userspace
execution.
This allows the userspace AFS pioctl emulation to fully emulate newpag() and
the VIOCSETTOK and VIOCSETTOK2 pioctls, all of which require the ability to
alter the parent process's PAG membership. However, since kAFS doesn't use
PAGs per se, but rather dumps the keys into the session keyring, the session
keyring of the parent must be replaced if, for example, VIOCSETTOK is passed
the newpag flag.
This can be tested with the following program:
#include <stdio.h>
#include <stdlib.h>
#include <keyutils.h>
#define KEYCTL_SESSION_TO_PARENT 18
#define OSERROR(X, S) do { if ((long)(X) == -1) { perror(S); exit(1); } } while(0)
int main(int argc, char **argv)
{
key_serial_t keyring, key;
long ret;
keyring = keyctl_join_session_keyring(argv[1]);
OSERROR(keyring, "keyctl_join_session_keyring");
key = add_key("user", "a", "b", 1, keyring);
OSERROR(key, "add_key");
ret = keyctl(KEYCTL_SESSION_TO_PARENT);
OSERROR(ret, "KEYCTL_SESSION_TO_PARENT");
return 0;
}
Compiled and linked with -lkeyutils, you should see something like:
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
355907932 --alswrv 4043 -1 \_ keyring: _uid.4043
[dhowells@andromeda ~]$ /tmp/newpag
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
1055658746 --alswrv 4043 4043 \_ user: a
[dhowells@andromeda ~]$ /tmp/newpag hello
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: hello
340417692 --alswrv 4043 4043 \_ user: a
Where the test program creates a new session keyring, sticks a user key named
'a' into it and then installs it on its parent.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
2009-09-02 16:14:21 +08:00
|
|
|
}
|
|
|
|
|
CRED: Inaugurate COW credentials
Inaugurate copy-on-write credentials management. This uses RCU to manage the
credentials pointer in the task_struct with respect to accesses by other tasks.
A process may only modify its own credentials, and so does not need locking to
access or modify its own credentials.
A mutex (cred_replace_mutex) is added to the task_struct to control the effect
of PTRACE_ATTACHED on credential calculations, particularly with respect to
execve().
With this patch, the contents of an active credentials struct may not be
changed directly; rather a new set of credentials must be prepared, modified
and committed using something like the following sequence of events:
struct cred *new = prepare_creds();
int ret = blah(new);
if (ret < 0) {
abort_creds(new);
return ret;
}
return commit_creds(new);
There are some exceptions to this rule: the keyrings pointed to by the active
credentials may be instantiated - keyrings violate the COW rule as managing
COW keyrings is tricky, given that it is possible for a task to directly alter
the keys in a keyring in use by another task.
To help enforce this, various pointers to sets of credentials, such as those in
the task_struct, are declared const. The purpose of this is compile-time
discouragement of altering credentials through those pointers. Once a set of
credentials has been made public through one of these pointers, it may not be
modified, except under special circumstances:
(1) Its reference count may incremented and decremented.
(2) The keyrings to which it points may be modified, but not replaced.
The only safe way to modify anything else is to create a replacement and commit
using the functions described in Documentation/credentials.txt (which will be
added by a later patch).
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
This now prepares and commits credentials in various places in the
security code rather than altering the current creds directly.
(2) Temporary credential overrides.
do_coredump() and sys_faccessat() now prepare their own credentials and
temporarily override the ones currently on the acting thread, whilst
preventing interference from other threads by holding cred_replace_mutex
on the thread being dumped.
This will be replaced in a future patch by something that hands down the
credentials directly to the functions being called, rather than altering
the task's objective credentials.
(3) LSM interface.
A number of functions have been changed, added or removed:
(*) security_capset_check(), ->capset_check()
(*) security_capset_set(), ->capset_set()
Removed in favour of security_capset().
(*) security_capset(), ->capset()
New. This is passed a pointer to the new creds, a pointer to the old
creds and the proposed capability sets. It should fill in the new
creds or return an error. All pointers, barring the pointer to the
new creds, are now const.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
Changed; now returns a value, which will cause the process to be
killed if it's an error.
(*) security_task_alloc(), ->task_alloc_security()
Removed in favour of security_prepare_creds().
(*) security_cred_free(), ->cred_free()
New. Free security data attached to cred->security.
(*) security_prepare_creds(), ->cred_prepare()
New. Duplicate any security data attached to cred->security.
(*) security_commit_creds(), ->cred_commit()
New. Apply any security effects for the upcoming installation of new
security by commit_creds().
(*) security_task_post_setuid(), ->task_post_setuid()
Removed in favour of security_task_fix_setuid().
(*) security_task_fix_setuid(), ->task_fix_setuid()
Fix up the proposed new credentials for setuid(). This is used by
cap_set_fix_setuid() to implicitly adjust capabilities in line with
setuid() changes. Changes are made to the new credentials, rather
than the task itself as in security_task_post_setuid().
(*) security_task_reparent_to_init(), ->task_reparent_to_init()
Removed. Instead the task being reparented to init is referred
directly to init's credentials.
NOTE! This results in the loss of some state: SELinux's osid no
longer records the sid of the thread that forked it.
(*) security_key_alloc(), ->key_alloc()
(*) security_key_permission(), ->key_permission()
Changed. These now take cred pointers rather than task pointers to
refer to the security context.
(4) sys_capset().
This has been simplified and uses less locking. The LSM functions it
calls have been merged.
(5) reparent_to_kthreadd().
This gives the current thread the same credentials as init by simply using
commit_thread() to point that way.
(6) __sigqueue_alloc() and switch_uid()
__sigqueue_alloc() can't stop the target task from changing its creds
beneath it, so this function gets a reference to the currently applicable
user_struct which it then passes into the sigqueue struct it returns if
successful.
switch_uid() is now called from commit_creds(), and possibly should be
folded into that. commit_creds() should take care of protecting
__sigqueue_alloc().
(7) [sg]et[ug]id() and co and [sg]et_current_groups.
The set functions now all use prepare_creds(), commit_creds() and
abort_creds() to build and check a new set of credentials before applying
it.
security_task_set[ug]id() is called inside the prepared section. This
guarantees that nothing else will affect the creds until we've finished.
The calling of set_dumpable() has been moved into commit_creds().
Much of the functionality of set_user() has been moved into
commit_creds().
The get functions all simply access the data directly.
(8) security_task_prctl() and cap_task_prctl().
security_task_prctl() has been modified to return -ENOSYS if it doesn't
want to handle a function, or otherwise return the return value directly
rather than through an argument.
Additionally, cap_task_prctl() now prepares a new set of credentials, even
if it doesn't end up using it.
(9) Keyrings.
A number of changes have been made to the keyrings code:
(a) switch_uid_keyring(), copy_keys(), exit_keys() and suid_keys() have
all been dropped and built in to the credentials functions directly.
They may want separating out again later.
(b) key_alloc() and search_process_keyrings() now take a cred pointer
rather than a task pointer to specify the security context.
(c) copy_creds() gives a new thread within the same thread group a new
thread keyring if its parent had one, otherwise it discards the thread
keyring.
(d) The authorisation key now points directly to the credentials to extend
the search into rather pointing to the task that carries them.
(e) Installing thread, process or session keyrings causes a new set of
credentials to be created, even though it's not strictly necessary for
process or session keyrings (they're shared).
(10) Usermode helper.
The usermode helper code now carries a cred struct pointer in its
subprocess_info struct instead of a new session keyring pointer. This set
of credentials is derived from init_cred and installed on the new process
after it has been cloned.
call_usermodehelper_setup() allocates the new credentials and
call_usermodehelper_freeinfo() discards them if they haven't been used. A
special cred function (prepare_usermodeinfo_creds()) is provided
specifically for call_usermodehelper_setup() to call.
call_usermodehelper_setkeys() adjusts the credentials to sport the
supplied keyring as the new session keyring.
(11) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) selinux_setprocattr() no longer does its check for whether the
current ptracer can access processes with the new SID inside the lock
that covers getting the ptracer's SID. Whilst this lock ensures that
the check is done with the ptracer pinned, the result is only valid
until the lock is released, so there's no point doing it inside the
lock.
(12) is_single_threaded().
This function has been extracted from selinux_setprocattr() and put into
a file of its own in the lib/ directory as join_session_keyring() now
wants to use it too.
The code in SELinux just checked to see whether a task shared mm_structs
with other tasks (CLONE_VM), but that isn't good enough. We really want
to know if they're part of the same thread group (CLONE_THREAD).
(13) nfsd.
The NFS server daemon now has to use the COW credentials to set the
credentials it is going to use. It really needs to pass the credentials
down to the functions it calls, but it can't do that until other patches
in this series have been applied.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
void security_cred_free(struct cred *cred)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2019-01-17 07:41:11 +08:00
|
|
|
/*
|
|
|
|
* There is a failure case in prepare_creds() that
|
|
|
|
* may result in a call here with ->security being NULL.
|
|
|
|
*/
|
|
|
|
if (unlikely(cred->security == NULL))
|
|
|
|
return;
|
|
|
|
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(cred_free, cred);
|
2018-11-13 01:30:56 +08:00
|
|
|
|
|
|
|
kfree(cred->security);
|
|
|
|
cred->security = NULL;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
CRED: Inaugurate COW credentials
Inaugurate copy-on-write credentials management. This uses RCU to manage the
credentials pointer in the task_struct with respect to accesses by other tasks.
A process may only modify its own credentials, and so does not need locking to
access or modify its own credentials.
A mutex (cred_replace_mutex) is added to the task_struct to control the effect
of PTRACE_ATTACHED on credential calculations, particularly with respect to
execve().
With this patch, the contents of an active credentials struct may not be
changed directly; rather a new set of credentials must be prepared, modified
and committed using something like the following sequence of events:
struct cred *new = prepare_creds();
int ret = blah(new);
if (ret < 0) {
abort_creds(new);
return ret;
}
return commit_creds(new);
There are some exceptions to this rule: the keyrings pointed to by the active
credentials may be instantiated - keyrings violate the COW rule as managing
COW keyrings is tricky, given that it is possible for a task to directly alter
the keys in a keyring in use by another task.
To help enforce this, various pointers to sets of credentials, such as those in
the task_struct, are declared const. The purpose of this is compile-time
discouragement of altering credentials through those pointers. Once a set of
credentials has been made public through one of these pointers, it may not be
modified, except under special circumstances:
(1) Its reference count may incremented and decremented.
(2) The keyrings to which it points may be modified, but not replaced.
The only safe way to modify anything else is to create a replacement and commit
using the functions described in Documentation/credentials.txt (which will be
added by a later patch).
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
This now prepares and commits credentials in various places in the
security code rather than altering the current creds directly.
(2) Temporary credential overrides.
do_coredump() and sys_faccessat() now prepare their own credentials and
temporarily override the ones currently on the acting thread, whilst
preventing interference from other threads by holding cred_replace_mutex
on the thread being dumped.
This will be replaced in a future patch by something that hands down the
credentials directly to the functions being called, rather than altering
the task's objective credentials.
(3) LSM interface.
A number of functions have been changed, added or removed:
(*) security_capset_check(), ->capset_check()
(*) security_capset_set(), ->capset_set()
Removed in favour of security_capset().
(*) security_capset(), ->capset()
New. This is passed a pointer to the new creds, a pointer to the old
creds and the proposed capability sets. It should fill in the new
creds or return an error. All pointers, barring the pointer to the
new creds, are now const.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
Changed; now returns a value, which will cause the process to be
killed if it's an error.
(*) security_task_alloc(), ->task_alloc_security()
Removed in favour of security_prepare_creds().
(*) security_cred_free(), ->cred_free()
New. Free security data attached to cred->security.
(*) security_prepare_creds(), ->cred_prepare()
New. Duplicate any security data attached to cred->security.
(*) security_commit_creds(), ->cred_commit()
New. Apply any security effects for the upcoming installation of new
security by commit_creds().
(*) security_task_post_setuid(), ->task_post_setuid()
Removed in favour of security_task_fix_setuid().
(*) security_task_fix_setuid(), ->task_fix_setuid()
Fix up the proposed new credentials for setuid(). This is used by
cap_set_fix_setuid() to implicitly adjust capabilities in line with
setuid() changes. Changes are made to the new credentials, rather
than the task itself as in security_task_post_setuid().
(*) security_task_reparent_to_init(), ->task_reparent_to_init()
Removed. Instead the task being reparented to init is referred
directly to init's credentials.
NOTE! This results in the loss of some state: SELinux's osid no
longer records the sid of the thread that forked it.
(*) security_key_alloc(), ->key_alloc()
(*) security_key_permission(), ->key_permission()
Changed. These now take cred pointers rather than task pointers to
refer to the security context.
(4) sys_capset().
This has been simplified and uses less locking. The LSM functions it
calls have been merged.
(5) reparent_to_kthreadd().
This gives the current thread the same credentials as init by simply using
commit_thread() to point that way.
(6) __sigqueue_alloc() and switch_uid()
__sigqueue_alloc() can't stop the target task from changing its creds
beneath it, so this function gets a reference to the currently applicable
user_struct which it then passes into the sigqueue struct it returns if
successful.
switch_uid() is now called from commit_creds(), and possibly should be
folded into that. commit_creds() should take care of protecting
__sigqueue_alloc().
(7) [sg]et[ug]id() and co and [sg]et_current_groups.
The set functions now all use prepare_creds(), commit_creds() and
abort_creds() to build and check a new set of credentials before applying
it.
security_task_set[ug]id() is called inside the prepared section. This
guarantees that nothing else will affect the creds until we've finished.
The calling of set_dumpable() has been moved into commit_creds().
Much of the functionality of set_user() has been moved into
commit_creds().
The get functions all simply access the data directly.
(8) security_task_prctl() and cap_task_prctl().
security_task_prctl() has been modified to return -ENOSYS if it doesn't
want to handle a function, or otherwise return the return value directly
rather than through an argument.
Additionally, cap_task_prctl() now prepares a new set of credentials, even
if it doesn't end up using it.
(9) Keyrings.
A number of changes have been made to the keyrings code:
(a) switch_uid_keyring(), copy_keys(), exit_keys() and suid_keys() have
all been dropped and built in to the credentials functions directly.
They may want separating out again later.
(b) key_alloc() and search_process_keyrings() now take a cred pointer
rather than a task pointer to specify the security context.
(c) copy_creds() gives a new thread within the same thread group a new
thread keyring if its parent had one, otherwise it discards the thread
keyring.
(d) The authorisation key now points directly to the credentials to extend
the search into rather pointing to the task that carries them.
(e) Installing thread, process or session keyrings causes a new set of
credentials to be created, even though it's not strictly necessary for
process or session keyrings (they're shared).
(10) Usermode helper.
The usermode helper code now carries a cred struct pointer in its
subprocess_info struct instead of a new session keyring pointer. This set
of credentials is derived from init_cred and installed on the new process
after it has been cloned.
call_usermodehelper_setup() allocates the new credentials and
call_usermodehelper_freeinfo() discards them if they haven't been used. A
special cred function (prepare_usermodeinfo_creds()) is provided
specifically for call_usermodehelper_setup() to call.
call_usermodehelper_setkeys() adjusts the credentials to sport the
supplied keyring as the new session keyring.
(11) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) selinux_setprocattr() no longer does its check for whether the
current ptracer can access processes with the new SID inside the lock
that covers getting the ptracer's SID. Whilst this lock ensures that
the check is done with the ptracer pinned, the result is only valid
until the lock is released, so there's no point doing it inside the
lock.
(12) is_single_threaded().
This function has been extracted from selinux_setprocattr() and put into
a file of its own in the lib/ directory as join_session_keyring() now
wants to use it too.
The code in SELinux just checked to see whether a task shared mm_structs
with other tasks (CLONE_VM), but that isn't good enough. We really want
to know if they're part of the same thread group (CLONE_THREAD).
(13) nfsd.
The NFS server daemon now has to use the COW credentials to set the
credentials it is going to use. It really needs to pass the credentials
down to the functions it calls, but it can't do that until other patches
in this series have been applied.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2018-11-13 01:30:56 +08:00
|
|
|
int rc = lsm_cred_alloc(new, gfp);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = call_int_hook(cred_prepare, 0, new, old, gfp);
|
2018-11-13 04:02:49 +08:00
|
|
|
if (unlikely(rc))
|
2018-11-13 01:30:56 +08:00
|
|
|
security_cred_free(new);
|
|
|
|
return rc;
|
CRED: Inaugurate COW credentials
Inaugurate copy-on-write credentials management. This uses RCU to manage the
credentials pointer in the task_struct with respect to accesses by other tasks.
A process may only modify its own credentials, and so does not need locking to
access or modify its own credentials.
A mutex (cred_replace_mutex) is added to the task_struct to control the effect
of PTRACE_ATTACHED on credential calculations, particularly with respect to
execve().
With this patch, the contents of an active credentials struct may not be
changed directly; rather a new set of credentials must be prepared, modified
and committed using something like the following sequence of events:
struct cred *new = prepare_creds();
int ret = blah(new);
if (ret < 0) {
abort_creds(new);
return ret;
}
return commit_creds(new);
There are some exceptions to this rule: the keyrings pointed to by the active
credentials may be instantiated - keyrings violate the COW rule as managing
COW keyrings is tricky, given that it is possible for a task to directly alter
the keys in a keyring in use by another task.
To help enforce this, various pointers to sets of credentials, such as those in
the task_struct, are declared const. The purpose of this is compile-time
discouragement of altering credentials through those pointers. Once a set of
credentials has been made public through one of these pointers, it may not be
modified, except under special circumstances:
(1) Its reference count may incremented and decremented.
(2) The keyrings to which it points may be modified, but not replaced.
The only safe way to modify anything else is to create a replacement and commit
using the functions described in Documentation/credentials.txt (which will be
added by a later patch).
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
This now prepares and commits credentials in various places in the
security code rather than altering the current creds directly.
(2) Temporary credential overrides.
do_coredump() and sys_faccessat() now prepare their own credentials and
temporarily override the ones currently on the acting thread, whilst
preventing interference from other threads by holding cred_replace_mutex
on the thread being dumped.
This will be replaced in a future patch by something that hands down the
credentials directly to the functions being called, rather than altering
the task's objective credentials.
(3) LSM interface.
A number of functions have been changed, added or removed:
(*) security_capset_check(), ->capset_check()
(*) security_capset_set(), ->capset_set()
Removed in favour of security_capset().
(*) security_capset(), ->capset()
New. This is passed a pointer to the new creds, a pointer to the old
creds and the proposed capability sets. It should fill in the new
creds or return an error. All pointers, barring the pointer to the
new creds, are now const.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
Changed; now returns a value, which will cause the process to be
killed if it's an error.
(*) security_task_alloc(), ->task_alloc_security()
Removed in favour of security_prepare_creds().
(*) security_cred_free(), ->cred_free()
New. Free security data attached to cred->security.
(*) security_prepare_creds(), ->cred_prepare()
New. Duplicate any security data attached to cred->security.
(*) security_commit_creds(), ->cred_commit()
New. Apply any security effects for the upcoming installation of new
security by commit_creds().
(*) security_task_post_setuid(), ->task_post_setuid()
Removed in favour of security_task_fix_setuid().
(*) security_task_fix_setuid(), ->task_fix_setuid()
Fix up the proposed new credentials for setuid(). This is used by
cap_set_fix_setuid() to implicitly adjust capabilities in line with
setuid() changes. Changes are made to the new credentials, rather
than the task itself as in security_task_post_setuid().
(*) security_task_reparent_to_init(), ->task_reparent_to_init()
Removed. Instead the task being reparented to init is referred
directly to init's credentials.
NOTE! This results in the loss of some state: SELinux's osid no
longer records the sid of the thread that forked it.
(*) security_key_alloc(), ->key_alloc()
(*) security_key_permission(), ->key_permission()
Changed. These now take cred pointers rather than task pointers to
refer to the security context.
(4) sys_capset().
This has been simplified and uses less locking. The LSM functions it
calls have been merged.
(5) reparent_to_kthreadd().
This gives the current thread the same credentials as init by simply using
commit_thread() to point that way.
(6) __sigqueue_alloc() and switch_uid()
__sigqueue_alloc() can't stop the target task from changing its creds
beneath it, so this function gets a reference to the currently applicable
user_struct which it then passes into the sigqueue struct it returns if
successful.
switch_uid() is now called from commit_creds(), and possibly should be
folded into that. commit_creds() should take care of protecting
__sigqueue_alloc().
(7) [sg]et[ug]id() and co and [sg]et_current_groups.
The set functions now all use prepare_creds(), commit_creds() and
abort_creds() to build and check a new set of credentials before applying
it.
security_task_set[ug]id() is called inside the prepared section. This
guarantees that nothing else will affect the creds until we've finished.
The calling of set_dumpable() has been moved into commit_creds().
Much of the functionality of set_user() has been moved into
commit_creds().
The get functions all simply access the data directly.
(8) security_task_prctl() and cap_task_prctl().
security_task_prctl() has been modified to return -ENOSYS if it doesn't
want to handle a function, or otherwise return the return value directly
rather than through an argument.
Additionally, cap_task_prctl() now prepares a new set of credentials, even
if it doesn't end up using it.
(9) Keyrings.
A number of changes have been made to the keyrings code:
(a) switch_uid_keyring(), copy_keys(), exit_keys() and suid_keys() have
all been dropped and built in to the credentials functions directly.
They may want separating out again later.
(b) key_alloc() and search_process_keyrings() now take a cred pointer
rather than a task pointer to specify the security context.
(c) copy_creds() gives a new thread within the same thread group a new
thread keyring if its parent had one, otherwise it discards the thread
keyring.
(d) The authorisation key now points directly to the credentials to extend
the search into rather pointing to the task that carries them.
(e) Installing thread, process or session keyrings causes a new set of
credentials to be created, even though it's not strictly necessary for
process or session keyrings (they're shared).
(10) Usermode helper.
The usermode helper code now carries a cred struct pointer in its
subprocess_info struct instead of a new session keyring pointer. This set
of credentials is derived from init_cred and installed on the new process
after it has been cloned.
call_usermodehelper_setup() allocates the new credentials and
call_usermodehelper_freeinfo() discards them if they haven't been used. A
special cred function (prepare_usermodeinfo_creds()) is provided
specifically for call_usermodehelper_setup() to call.
call_usermodehelper_setkeys() adjusts the credentials to sport the
supplied keyring as the new session keyring.
(11) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) selinux_setprocattr() no longer does its check for whether the
current ptracer can access processes with the new SID inside the lock
that covers getting the ptracer's SID. Whilst this lock ensures that
the check is done with the ptracer pinned, the result is only valid
until the lock is released, so there's no point doing it inside the
lock.
(12) is_single_threaded().
This function has been extracted from selinux_setprocattr() and put into
a file of its own in the lib/ directory as join_session_keyring() now
wants to use it too.
The code in SELinux just checked to see whether a task shared mm_structs
with other tasks (CLONE_VM), but that isn't good enough. We really want
to know if they're part of the same thread group (CLONE_THREAD).
(13) nfsd.
The NFS server daemon now has to use the COW credentials to set the
credentials it is going to use. It really needs to pass the credentials
down to the functions it calls, but it can't do that until other patches
in this series have been applied.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
}
|
|
|
|
|
KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]
Add a keyctl to install a process's session keyring onto its parent. This
replaces the parent's session keyring. Because the COW credential code does
not permit one process to change another process's credentials directly, the
change is deferred until userspace next starts executing again. Normally this
will be after a wait*() syscall.
To support this, three new security hooks have been provided:
cred_alloc_blank() to allocate unset security creds, cred_transfer() to fill in
the blank security creds and key_session_to_parent() - which asks the LSM if
the process may replace its parent's session keyring.
The replacement may only happen if the process has the same ownership details
as its parent, and the process has LINK permission on the session keyring, and
the session keyring is owned by the process, and the LSM permits it.
Note that this requires alteration to each architecture's notify_resume path.
This has been done for all arches barring blackfin, m68k* and xtensa, all of
which need assembly alteration to support TIF_NOTIFY_RESUME. This allows the
replacement to be performed at the point the parent process resumes userspace
execution.
This allows the userspace AFS pioctl emulation to fully emulate newpag() and
the VIOCSETTOK and VIOCSETTOK2 pioctls, all of which require the ability to
alter the parent process's PAG membership. However, since kAFS doesn't use
PAGs per se, but rather dumps the keys into the session keyring, the session
keyring of the parent must be replaced if, for example, VIOCSETTOK is passed
the newpag flag.
This can be tested with the following program:
#include <stdio.h>
#include <stdlib.h>
#include <keyutils.h>
#define KEYCTL_SESSION_TO_PARENT 18
#define OSERROR(X, S) do { if ((long)(X) == -1) { perror(S); exit(1); } } while(0)
int main(int argc, char **argv)
{
key_serial_t keyring, key;
long ret;
keyring = keyctl_join_session_keyring(argv[1]);
OSERROR(keyring, "keyctl_join_session_keyring");
key = add_key("user", "a", "b", 1, keyring);
OSERROR(key, "add_key");
ret = keyctl(KEYCTL_SESSION_TO_PARENT);
OSERROR(ret, "KEYCTL_SESSION_TO_PARENT");
return 0;
}
Compiled and linked with -lkeyutils, you should see something like:
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
355907932 --alswrv 4043 -1 \_ keyring: _uid.4043
[dhowells@andromeda ~]$ /tmp/newpag
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
1055658746 --alswrv 4043 4043 \_ user: a
[dhowells@andromeda ~]$ /tmp/newpag hello
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: hello
340417692 --alswrv 4043 4043 \_ user: a
Where the test program creates a new session keyring, sticks a user key named
'a' into it and then installs it on its parent.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
2009-09-02 16:14:21 +08:00
|
|
|
void security_transfer_creds(struct cred *new, const struct cred *old)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(cred_transfer, new, old);
|
KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]
Add a keyctl to install a process's session keyring onto its parent. This
replaces the parent's session keyring. Because the COW credential code does
not permit one process to change another process's credentials directly, the
change is deferred until userspace next starts executing again. Normally this
will be after a wait*() syscall.
To support this, three new security hooks have been provided:
cred_alloc_blank() to allocate unset security creds, cred_transfer() to fill in
the blank security creds and key_session_to_parent() - which asks the LSM if
the process may replace its parent's session keyring.
The replacement may only happen if the process has the same ownership details
as its parent, and the process has LINK permission on the session keyring, and
the session keyring is owned by the process, and the LSM permits it.
Note that this requires alteration to each architecture's notify_resume path.
This has been done for all arches barring blackfin, m68k* and xtensa, all of
which need assembly alteration to support TIF_NOTIFY_RESUME. This allows the
replacement to be performed at the point the parent process resumes userspace
execution.
This allows the userspace AFS pioctl emulation to fully emulate newpag() and
the VIOCSETTOK and VIOCSETTOK2 pioctls, all of which require the ability to
alter the parent process's PAG membership. However, since kAFS doesn't use
PAGs per se, but rather dumps the keys into the session keyring, the session
keyring of the parent must be replaced if, for example, VIOCSETTOK is passed
the newpag flag.
This can be tested with the following program:
#include <stdio.h>
#include <stdlib.h>
#include <keyutils.h>
#define KEYCTL_SESSION_TO_PARENT 18
#define OSERROR(X, S) do { if ((long)(X) == -1) { perror(S); exit(1); } } while(0)
int main(int argc, char **argv)
{
key_serial_t keyring, key;
long ret;
keyring = keyctl_join_session_keyring(argv[1]);
OSERROR(keyring, "keyctl_join_session_keyring");
key = add_key("user", "a", "b", 1, keyring);
OSERROR(key, "add_key");
ret = keyctl(KEYCTL_SESSION_TO_PARENT);
OSERROR(ret, "KEYCTL_SESSION_TO_PARENT");
return 0;
}
Compiled and linked with -lkeyutils, you should see something like:
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
355907932 --alswrv 4043 -1 \_ keyring: _uid.4043
[dhowells@andromeda ~]$ /tmp/newpag
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
1055658746 --alswrv 4043 4043 \_ user: a
[dhowells@andromeda ~]$ /tmp/newpag hello
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: hello
340417692 --alswrv 4043 4043 \_ user: a
Where the test program creates a new session keyring, sticks a user key named
'a' into it and then installs it on its parent.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
2009-09-02 16:14:21 +08:00
|
|
|
}
|
|
|
|
|
2018-01-09 05:36:19 +08: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 07:39:28 +08:00
|
|
|
int security_kernel_act_as(struct cred *new, u32 secid)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(kernel_act_as, 0, new, secid);
|
2008-11-14 07:39:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_kernel_create_files_as(struct cred *new, struct inode *inode)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(kernel_create_files_as, 0, new, inode);
|
2008-11-14 07:39:28 +08:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:35:32 +08:00
|
|
|
int security_kernel_module_request(char *kmod_name)
|
2009-08-13 21:44:57 +08:00
|
|
|
{
|
integrity: prevent deadlock during digsig verification.
This patch aimed to prevent deadlock during digsig verification.The point
of issue - user space utility modprobe and/or it's dependencies (ld-*.so,
libz.so.*, libc-*.so and /lib/modules/ files) that could be used for
kernel modules load during digsig verification and could be signed by
digsig in the same time.
First at all, look at crypto_alloc_tfm() work algorithm:
crypto_alloc_tfm() will first attempt to locate an already loaded
algorithm. If that fails and the kernel supports dynamically loadable
modules, it will then attempt to load a module of the same name or alias.
If that fails it will send a query to any loaded crypto manager to
construct an algorithm on the fly.
We have situation, when public_key_verify_signature() in case of RSA
algorithm use alg_name to store internal information in order to construct
an algorithm on the fly, but crypto_larval_lookup() will try to use
alg_name in order to load kernel module with same name.
1) we can't do anything with crypto module work, since it designed to work
exactly in this way;
2) we can't globally filter module requests for modprobe, since it
designed to work with any requests.
In this patch, I propose add an exception for "crypto-pkcs1pad(rsa,*)"
module requests only in case of enabled integrity asymmetric keys support.
Since we don't have any real "crypto-pkcs1pad(rsa,*)" kernel modules for
sure, we are safe to fail such module request from crypto_larval_lookup().
In this way we prevent modprobe execution during digsig verification and
avoid possible deadlock if modprobe and/or it's dependencies also signed
with digsig.
Requested "crypto-pkcs1pad(rsa,*)" kernel module name formed by:
1) "pkcs1pad(rsa,%s)" in public_key_verify_signature();
2) "crypto-%s" / "crypto-%s-all" in crypto_larval_lookup().
"crypto-pkcs1pad(rsa," part of request is a constant and unique and could
be used as filter.
Signed-off-by: Mikhail Kurinnoi <viewizard@viewizard.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
include/linux/integrity.h | 13 +++++++++++++
security/integrity/digsig_asymmetric.c | 23 +++++++++++++++++++++++
security/security.c | 7 ++++++-
3 files changed, 42 insertions(+), 1 deletion(-)
2018-06-27 21:33:42 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = call_int_hook(kernel_module_request, 0, kmod_name);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return integrity_kernel_module_request(kmod_name);
|
2009-08-13 21:44:57 +08:00
|
|
|
}
|
|
|
|
|
2016-01-31 11:23:26 +08:00
|
|
|
int security_kernel_read_file(struct file *file, enum kernel_read_file_id id)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = call_int_hook(kernel_read_file, 0, file, id);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return ima_read_file(file, id);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(security_kernel_read_file);
|
|
|
|
|
2016-01-24 23:07:32 +08:00
|
|
|
int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
|
|
|
|
enum kernel_read_file_id id)
|
2015-12-29 05:02:29 +08:00
|
|
|
{
|
2016-01-15 06:57:47 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = call_int_hook(kernel_post_read_file, 0, file, buf, size, id);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return ima_post_read_file(file, buf, size, id);
|
2015-12-29 05:02:29 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(security_kernel_post_read_file);
|
|
|
|
|
2018-07-14 02:05:56 +08:00
|
|
|
int security_kernel_load_data(enum kernel_load_data_id id)
|
|
|
|
{
|
2018-07-14 02:05:58 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = call_int_hook(kernel_load_data, 0, id);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return ima_load_data(id);
|
2018-07-14 02:05:56 +08:00
|
|
|
}
|
2018-07-18 04:23:37 +08:00
|
|
|
EXPORT_SYMBOL_GPL(security_kernel_load_data);
|
2018-07-14 02:05:56 +08:00
|
|
|
|
CRED: Inaugurate COW credentials
Inaugurate copy-on-write credentials management. This uses RCU to manage the
credentials pointer in the task_struct with respect to accesses by other tasks.
A process may only modify its own credentials, and so does not need locking to
access or modify its own credentials.
A mutex (cred_replace_mutex) is added to the task_struct to control the effect
of PTRACE_ATTACHED on credential calculations, particularly with respect to
execve().
With this patch, the contents of an active credentials struct may not be
changed directly; rather a new set of credentials must be prepared, modified
and committed using something like the following sequence of events:
struct cred *new = prepare_creds();
int ret = blah(new);
if (ret < 0) {
abort_creds(new);
return ret;
}
return commit_creds(new);
There are some exceptions to this rule: the keyrings pointed to by the active
credentials may be instantiated - keyrings violate the COW rule as managing
COW keyrings is tricky, given that it is possible for a task to directly alter
the keys in a keyring in use by another task.
To help enforce this, various pointers to sets of credentials, such as those in
the task_struct, are declared const. The purpose of this is compile-time
discouragement of altering credentials through those pointers. Once a set of
credentials has been made public through one of these pointers, it may not be
modified, except under special circumstances:
(1) Its reference count may incremented and decremented.
(2) The keyrings to which it points may be modified, but not replaced.
The only safe way to modify anything else is to create a replacement and commit
using the functions described in Documentation/credentials.txt (which will be
added by a later patch).
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
This now prepares and commits credentials in various places in the
security code rather than altering the current creds directly.
(2) Temporary credential overrides.
do_coredump() and sys_faccessat() now prepare their own credentials and
temporarily override the ones currently on the acting thread, whilst
preventing interference from other threads by holding cred_replace_mutex
on the thread being dumped.
This will be replaced in a future patch by something that hands down the
credentials directly to the functions being called, rather than altering
the task's objective credentials.
(3) LSM interface.
A number of functions have been changed, added or removed:
(*) security_capset_check(), ->capset_check()
(*) security_capset_set(), ->capset_set()
Removed in favour of security_capset().
(*) security_capset(), ->capset()
New. This is passed a pointer to the new creds, a pointer to the old
creds and the proposed capability sets. It should fill in the new
creds or return an error. All pointers, barring the pointer to the
new creds, are now const.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
Changed; now returns a value, which will cause the process to be
killed if it's an error.
(*) security_task_alloc(), ->task_alloc_security()
Removed in favour of security_prepare_creds().
(*) security_cred_free(), ->cred_free()
New. Free security data attached to cred->security.
(*) security_prepare_creds(), ->cred_prepare()
New. Duplicate any security data attached to cred->security.
(*) security_commit_creds(), ->cred_commit()
New. Apply any security effects for the upcoming installation of new
security by commit_creds().
(*) security_task_post_setuid(), ->task_post_setuid()
Removed in favour of security_task_fix_setuid().
(*) security_task_fix_setuid(), ->task_fix_setuid()
Fix up the proposed new credentials for setuid(). This is used by
cap_set_fix_setuid() to implicitly adjust capabilities in line with
setuid() changes. Changes are made to the new credentials, rather
than the task itself as in security_task_post_setuid().
(*) security_task_reparent_to_init(), ->task_reparent_to_init()
Removed. Instead the task being reparented to init is referred
directly to init's credentials.
NOTE! This results in the loss of some state: SELinux's osid no
longer records the sid of the thread that forked it.
(*) security_key_alloc(), ->key_alloc()
(*) security_key_permission(), ->key_permission()
Changed. These now take cred pointers rather than task pointers to
refer to the security context.
(4) sys_capset().
This has been simplified and uses less locking. The LSM functions it
calls have been merged.
(5) reparent_to_kthreadd().
This gives the current thread the same credentials as init by simply using
commit_thread() to point that way.
(6) __sigqueue_alloc() and switch_uid()
__sigqueue_alloc() can't stop the target task from changing its creds
beneath it, so this function gets a reference to the currently applicable
user_struct which it then passes into the sigqueue struct it returns if
successful.
switch_uid() is now called from commit_creds(), and possibly should be
folded into that. commit_creds() should take care of protecting
__sigqueue_alloc().
(7) [sg]et[ug]id() and co and [sg]et_current_groups.
The set functions now all use prepare_creds(), commit_creds() and
abort_creds() to build and check a new set of credentials before applying
it.
security_task_set[ug]id() is called inside the prepared section. This
guarantees that nothing else will affect the creds until we've finished.
The calling of set_dumpable() has been moved into commit_creds().
Much of the functionality of set_user() has been moved into
commit_creds().
The get functions all simply access the data directly.
(8) security_task_prctl() and cap_task_prctl().
security_task_prctl() has been modified to return -ENOSYS if it doesn't
want to handle a function, or otherwise return the return value directly
rather than through an argument.
Additionally, cap_task_prctl() now prepares a new set of credentials, even
if it doesn't end up using it.
(9) Keyrings.
A number of changes have been made to the keyrings code:
(a) switch_uid_keyring(), copy_keys(), exit_keys() and suid_keys() have
all been dropped and built in to the credentials functions directly.
They may want separating out again later.
(b) key_alloc() and search_process_keyrings() now take a cred pointer
rather than a task pointer to specify the security context.
(c) copy_creds() gives a new thread within the same thread group a new
thread keyring if its parent had one, otherwise it discards the thread
keyring.
(d) The authorisation key now points directly to the credentials to extend
the search into rather pointing to the task that carries them.
(e) Installing thread, process or session keyrings causes a new set of
credentials to be created, even though it's not strictly necessary for
process or session keyrings (they're shared).
(10) Usermode helper.
The usermode helper code now carries a cred struct pointer in its
subprocess_info struct instead of a new session keyring pointer. This set
of credentials is derived from init_cred and installed on the new process
after it has been cloned.
call_usermodehelper_setup() allocates the new credentials and
call_usermodehelper_freeinfo() discards them if they haven't been used. A
special cred function (prepare_usermodeinfo_creds()) is provided
specifically for call_usermodehelper_setup() to call.
call_usermodehelper_setkeys() adjusts the credentials to sport the
supplied keyring as the new session keyring.
(11) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) selinux_setprocattr() no longer does its check for whether the
current ptracer can access processes with the new SID inside the lock
that covers getting the ptracer's SID. Whilst this lock ensures that
the check is done with the ptracer pinned, the result is only valid
until the lock is released, so there's no point doing it inside the
lock.
(12) is_single_threaded().
This function has been extracted from selinux_setprocattr() and put into
a file of its own in the lib/ directory as join_session_keyring() now
wants to use it too.
The code in SELinux just checked to see whether a task shared mm_structs
with other tasks (CLONE_VM), but that isn't good enough. We really want
to know if they're part of the same thread group (CLONE_THREAD).
(13) nfsd.
The NFS server daemon now has to use the COW credentials to set the
credentials it is going to use. It really needs to pass the credentials
down to the functions it calls, but it can't do that until other patches
in this series have been applied.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
int security_task_fix_setuid(struct cred *new, const struct cred *old,
|
|
|
|
int flags)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_fix_setuid, 0, new, old, flags);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_setpgid(struct task_struct *p, pid_t pgid)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_setpgid, 0, p, pgid);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getpgid(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_getpgid, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getsid(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_getsid, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_task_getsecid(struct task_struct *p, u32 *secid)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
*secid = 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(task_getsecid, p, secid);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_task_getsecid);
|
|
|
|
|
|
|
|
int security_task_setnice(struct task_struct *p, int nice)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_setnice, 0, p, nice);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_setioprio(struct task_struct *p, int ioprio)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_setioprio, 0, p, ioprio);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getioprio(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_getioprio, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
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 20:57:00 +08: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-27 00:41:16 +08:00
|
|
|
int security_task_setrlimit(struct task_struct *p, unsigned int resource,
|
|
|
|
struct rlimit *new_rlim)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_setrlimit, 0, p, resource, new_rlim);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2010-10-15 03:21:18 +08:00
|
|
|
int security_task_setscheduler(struct task_struct *p)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_setscheduler, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_getscheduler(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_getscheduler, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_movememory(struct task_struct *p)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(task_movememory, 0, p);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-09-25 17:27:20 +08:00
|
|
|
int security_task_kill(struct task_struct *p, struct kernel_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-09 00:40:01 +08:00
|
|
|
int sig, const struct cred *cred)
|
2007-10-17 14:31:32 +08: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-09 00:40:01 +08:00
|
|
|
return call_int_hook(task_kill, 0, p, info, sig, cred);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
|
CRED: Inaugurate COW credentials
Inaugurate copy-on-write credentials management. This uses RCU to manage the
credentials pointer in the task_struct with respect to accesses by other tasks.
A process may only modify its own credentials, and so does not need locking to
access or modify its own credentials.
A mutex (cred_replace_mutex) is added to the task_struct to control the effect
of PTRACE_ATTACHED on credential calculations, particularly with respect to
execve().
With this patch, the contents of an active credentials struct may not be
changed directly; rather a new set of credentials must be prepared, modified
and committed using something like the following sequence of events:
struct cred *new = prepare_creds();
int ret = blah(new);
if (ret < 0) {
abort_creds(new);
return ret;
}
return commit_creds(new);
There are some exceptions to this rule: the keyrings pointed to by the active
credentials may be instantiated - keyrings violate the COW rule as managing
COW keyrings is tricky, given that it is possible for a task to directly alter
the keys in a keyring in use by another task.
To help enforce this, various pointers to sets of credentials, such as those in
the task_struct, are declared const. The purpose of this is compile-time
discouragement of altering credentials through those pointers. Once a set of
credentials has been made public through one of these pointers, it may not be
modified, except under special circumstances:
(1) Its reference count may incremented and decremented.
(2) The keyrings to which it points may be modified, but not replaced.
The only safe way to modify anything else is to create a replacement and commit
using the functions described in Documentation/credentials.txt (which will be
added by a later patch).
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
This now prepares and commits credentials in various places in the
security code rather than altering the current creds directly.
(2) Temporary credential overrides.
do_coredump() and sys_faccessat() now prepare their own credentials and
temporarily override the ones currently on the acting thread, whilst
preventing interference from other threads by holding cred_replace_mutex
on the thread being dumped.
This will be replaced in a future patch by something that hands down the
credentials directly to the functions being called, rather than altering
the task's objective credentials.
(3) LSM interface.
A number of functions have been changed, added or removed:
(*) security_capset_check(), ->capset_check()
(*) security_capset_set(), ->capset_set()
Removed in favour of security_capset().
(*) security_capset(), ->capset()
New. This is passed a pointer to the new creds, a pointer to the old
creds and the proposed capability sets. It should fill in the new
creds or return an error. All pointers, barring the pointer to the
new creds, are now const.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
Changed; now returns a value, which will cause the process to be
killed if it's an error.
(*) security_task_alloc(), ->task_alloc_security()
Removed in favour of security_prepare_creds().
(*) security_cred_free(), ->cred_free()
New. Free security data attached to cred->security.
(*) security_prepare_creds(), ->cred_prepare()
New. Duplicate any security data attached to cred->security.
(*) security_commit_creds(), ->cred_commit()
New. Apply any security effects for the upcoming installation of new
security by commit_creds().
(*) security_task_post_setuid(), ->task_post_setuid()
Removed in favour of security_task_fix_setuid().
(*) security_task_fix_setuid(), ->task_fix_setuid()
Fix up the proposed new credentials for setuid(). This is used by
cap_set_fix_setuid() to implicitly adjust capabilities in line with
setuid() changes. Changes are made to the new credentials, rather
than the task itself as in security_task_post_setuid().
(*) security_task_reparent_to_init(), ->task_reparent_to_init()
Removed. Instead the task being reparented to init is referred
directly to init's credentials.
NOTE! This results in the loss of some state: SELinux's osid no
longer records the sid of the thread that forked it.
(*) security_key_alloc(), ->key_alloc()
(*) security_key_permission(), ->key_permission()
Changed. These now take cred pointers rather than task pointers to
refer to the security context.
(4) sys_capset().
This has been simplified and uses less locking. The LSM functions it
calls have been merged.
(5) reparent_to_kthreadd().
This gives the current thread the same credentials as init by simply using
commit_thread() to point that way.
(6) __sigqueue_alloc() and switch_uid()
__sigqueue_alloc() can't stop the target task from changing its creds
beneath it, so this function gets a reference to the currently applicable
user_struct which it then passes into the sigqueue struct it returns if
successful.
switch_uid() is now called from commit_creds(), and possibly should be
folded into that. commit_creds() should take care of protecting
__sigqueue_alloc().
(7) [sg]et[ug]id() and co and [sg]et_current_groups.
The set functions now all use prepare_creds(), commit_creds() and
abort_creds() to build and check a new set of credentials before applying
it.
security_task_set[ug]id() is called inside the prepared section. This
guarantees that nothing else will affect the creds until we've finished.
The calling of set_dumpable() has been moved into commit_creds().
Much of the functionality of set_user() has been moved into
commit_creds().
The get functions all simply access the data directly.
(8) security_task_prctl() and cap_task_prctl().
security_task_prctl() has been modified to return -ENOSYS if it doesn't
want to handle a function, or otherwise return the return value directly
rather than through an argument.
Additionally, cap_task_prctl() now prepares a new set of credentials, even
if it doesn't end up using it.
(9) Keyrings.
A number of changes have been made to the keyrings code:
(a) switch_uid_keyring(), copy_keys(), exit_keys() and suid_keys() have
all been dropped and built in to the credentials functions directly.
They may want separating out again later.
(b) key_alloc() and search_process_keyrings() now take a cred pointer
rather than a task pointer to specify the security context.
(c) copy_creds() gives a new thread within the same thread group a new
thread keyring if its parent had one, otherwise it discards the thread
keyring.
(d) The authorisation key now points directly to the credentials to extend
the search into rather pointing to the task that carries them.
(e) Installing thread, process or session keyrings causes a new set of
credentials to be created, even though it's not strictly necessary for
process or session keyrings (they're shared).
(10) Usermode helper.
The usermode helper code now carries a cred struct pointer in its
subprocess_info struct instead of a new session keyring pointer. This set
of credentials is derived from init_cred and installed on the new process
after it has been cloned.
call_usermodehelper_setup() allocates the new credentials and
call_usermodehelper_freeinfo() discards them if they haven't been used. A
special cred function (prepare_usermodeinfo_creds()) is provided
specifically for call_usermodehelper_setup() to call.
call_usermodehelper_setkeys() adjusts the credentials to sport the
supplied keyring as the new session keyring.
(11) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) selinux_setprocattr() no longer does its check for whether the
current ptracer can access processes with the new SID inside the lock
that covers getting the ptracer's SID. Whilst this lock ensures that
the check is done with the ptracer pinned, the result is only valid
until the lock is released, so there's no point doing it inside the
lock.
(12) is_single_threaded().
This function has been extracted from selinux_setprocattr() and put into
a file of its own in the lib/ directory as join_session_keyring() now
wants to use it too.
The code in SELinux just checked to see whether a task shared mm_structs
with other tasks (CLONE_VM), but that isn't good enough. We really want
to know if they're part of the same thread group (CLONE_THREAD).
(13) nfsd.
The NFS server daemon now has to use the COW credentials to set the
credentials it is going to use. It really needs to pass the credentials
down to the functions it calls, but it can't do that until other patches
in this series have been applied.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
unsigned long arg4, unsigned long arg5)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
int thisrc;
|
|
|
|
int rc = -ENOSYS;
|
|
|
|
struct security_hook_list *hp;
|
|
|
|
|
2018-03-29 09:28:23 +08:00
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.task_prctl, list) {
|
2015-05-03 06:11:42 +08: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 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_task_to_inode(struct task_struct *p, struct inode *inode)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(task_to_inode, p, inode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(ipc_permission, 0, ipcp, flag);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-03-02 03:51:09 +08:00
|
|
|
void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
*secid = 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(ipc_getsecid, ipcp, secid);
|
2008-03-02 03:51:09 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_msg_msg_alloc(struct msg_msg *msg)
|
|
|
|
{
|
2018-11-21 03:55:02 +08:00
|
|
|
int rc = lsm_msg_msg_alloc(msg);
|
|
|
|
|
|
|
|
if (unlikely(rc))
|
|
|
|
return rc;
|
|
|
|
rc = call_int_hook(msg_msg_alloc_security, 0, msg);
|
|
|
|
if (unlikely(rc))
|
|
|
|
security_msg_msg_free(msg);
|
|
|
|
return rc;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_msg_msg_free(struct msg_msg *msg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(msg_msg_free_security, msg);
|
2018-11-21 03:55:02 +08:00
|
|
|
kfree(msg->security);
|
|
|
|
msg->security = NULL;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:22:26 +08:00
|
|
|
int security_msg_queue_alloc(struct kern_ipc_perm *msq)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2018-11-21 03:55:02 +08:00
|
|
|
int rc = lsm_ipc_alloc(msq);
|
|
|
|
|
|
|
|
if (unlikely(rc))
|
|
|
|
return rc;
|
|
|
|
rc = call_int_hook(msg_queue_alloc_security, 0, msq);
|
|
|
|
if (unlikely(rc))
|
|
|
|
security_msg_queue_free(msq);
|
|
|
|
return rc;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:22:26 +08:00
|
|
|
void security_msg_queue_free(struct kern_ipc_perm *msq)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(msg_queue_free_security, msq);
|
2018-11-21 03:55:02 +08:00
|
|
|
kfree(msq->security);
|
|
|
|
msq->security = NULL;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:22:26 +08:00
|
|
|
int security_msg_queue_associate(struct kern_ipc_perm *msq, int msqflg)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(msg_queue_associate, 0, msq, msqflg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:22:26 +08:00
|
|
|
int security_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(msg_queue_msgctl, 0, msq, cmd);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:22:26 +08:00
|
|
|
int security_msg_queue_msgsnd(struct kern_ipc_perm *msq,
|
2007-10-17 14:31:32 +08:00
|
|
|
struct msg_msg *msg, int msqflg)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(msg_queue_msgsnd, 0, msq, msg, msqflg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:22:26 +08:00
|
|
|
int security_msg_queue_msgrcv(struct kern_ipc_perm *msq, struct msg_msg *msg,
|
2007-10-17 14:31:32 +08:00
|
|
|
struct task_struct *target, long type, int mode)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:08:27 +08:00
|
|
|
int security_shm_alloc(struct kern_ipc_perm *shp)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2018-11-21 03:55:02 +08:00
|
|
|
int rc = lsm_ipc_alloc(shp);
|
|
|
|
|
|
|
|
if (unlikely(rc))
|
|
|
|
return rc;
|
|
|
|
rc = call_int_hook(shm_alloc_security, 0, shp);
|
|
|
|
if (unlikely(rc))
|
|
|
|
security_shm_free(shp);
|
|
|
|
return rc;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:08:27 +08:00
|
|
|
void security_shm_free(struct kern_ipc_perm *shp)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(shm_free_security, shp);
|
2018-11-21 03:55:02 +08:00
|
|
|
kfree(shp->security);
|
|
|
|
shp->security = NULL;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:08:27 +08:00
|
|
|
int security_shm_associate(struct kern_ipc_perm *shp, int shmflg)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(shm_associate, 0, shp, shmflg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:08:27 +08:00
|
|
|
int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(shm_shmctl, 0, shp, cmd);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:08:27 +08:00
|
|
|
int security_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr, int shmflg)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 09:52:43 +08:00
|
|
|
int security_sem_alloc(struct kern_ipc_perm *sma)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2018-11-21 03:55:02 +08:00
|
|
|
int rc = lsm_ipc_alloc(sma);
|
|
|
|
|
|
|
|
if (unlikely(rc))
|
|
|
|
return rc;
|
|
|
|
rc = call_int_hook(sem_alloc_security, 0, sma);
|
|
|
|
if (unlikely(rc))
|
|
|
|
security_sem_free(sma);
|
|
|
|
return rc;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 09:52:43 +08:00
|
|
|
void security_sem_free(struct kern_ipc_perm *sma)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sem_free_security, sma);
|
2018-11-21 03:55:02 +08:00
|
|
|
kfree(sma->security);
|
|
|
|
sma->security = NULL;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 09:52:43 +08:00
|
|
|
int security_sem_associate(struct kern_ipc_perm *sma, int semflg)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sem_associate, 0, sma, semflg);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 09:52:43 +08:00
|
|
|
int security_sem_semctl(struct kern_ipc_perm *sma, int cmd)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sem_semctl, 0, sma, cmd);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 09:52:43 +08:00
|
|
|
int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops,
|
2007-10-17 14:31:32 +08:00
|
|
|
unsigned nsops, int alter)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sem_semop, 0, sma, sops, nsops, alter);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_d_instantiate(struct dentry *dentry, struct inode *inode)
|
|
|
|
{
|
|
|
|
if (unlikely(inode && IS_PRIVATE(inode)))
|
|
|
|
return;
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(d_instantiate, dentry, inode);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_d_instantiate);
|
|
|
|
|
2018-09-22 08:16:59 +08:00
|
|
|
int security_getprocattr(struct task_struct *p, const char *lsm, char *name,
|
|
|
|
char **value)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2018-09-22 08:16:59 +08:00
|
|
|
struct security_hook_list *hp;
|
|
|
|
|
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.getprocattr, list) {
|
|
|
|
if (lsm != NULL && strcmp(lsm, hp->lsm))
|
|
|
|
continue;
|
|
|
|
return hp->hook.getprocattr(p, name, value);
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 08:16:59 +08:00
|
|
|
int security_setprocattr(const char *lsm, const char *name, void *value,
|
|
|
|
size_t size)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2018-09-22 08:16:59 +08:00
|
|
|
struct security_hook_list *hp;
|
|
|
|
|
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.setprocattr, list) {
|
|
|
|
if (lsm != NULL && strcmp(lsm, hp->lsm))
|
|
|
|
continue;
|
|
|
|
return hp->hook.setprocattr(name, value, size);
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_netlink_send(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(netlink_send, 0, sk, skb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2013-05-23 00:50:35 +08:00
|
|
|
int security_ismaclabel(const char *name)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(ismaclabel, 0, name);
|
2013-05-23 00:50:35 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_ismaclabel);
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(secid_to_secctx, -EOPNOTSUPP, secid, secdata,
|
|
|
|
seclen);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secid_to_secctx);
|
|
|
|
|
2008-04-30 03:52:51 +08:00
|
|
|
int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
|
2008-01-16 07:47:35 +08:00
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
*secid = 0;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid);
|
2008-01-16 07:47:35 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secctx_to_secid);
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
void security_release_secctx(char *secdata, u32 seclen)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(release_secctx, secdata, seclen);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_release_secctx);
|
|
|
|
|
2015-12-25 00:09:40 +08:00
|
|
|
void security_inode_invalidate_secctx(struct inode *inode)
|
|
|
|
{
|
|
|
|
call_void_hook(inode_invalidate_secctx, inode);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_invalidate_secctx);
|
|
|
|
|
2009-09-04 02:25:57 +08:00
|
|
|
int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen);
|
2009-09-04 02:25:57 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_notifysecctx);
|
|
|
|
|
|
|
|
int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen);
|
2009-09-04 02:25:57 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_setsecctx);
|
|
|
|
|
|
|
|
int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen);
|
2009-09-04 02:25:57 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inode_getsecctx);
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
#ifdef CONFIG_SECURITY_NETWORK
|
|
|
|
|
2011-01-06 07:38:53 +08:00
|
|
|
int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(unix_stream_connect, 0, sock, other, newsk);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_unix_stream_connect);
|
|
|
|
|
|
|
|
int security_unix_may_send(struct socket *sock, struct socket *other)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(unix_may_send, 0, sock, other);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_unix_may_send);
|
|
|
|
|
|
|
|
int security_socket_create(int family, int type, int protocol, int kern)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_create, 0, family, type, protocol, kern);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_post_create(struct socket *sock, int family,
|
|
|
|
int type, int protocol, int kern)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_post_create, 0, sock, family, type,
|
2007-10-17 14:31:32 +08:00
|
|
|
protocol, kern);
|
|
|
|
}
|
|
|
|
|
2018-05-04 22:28:19 +08: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 14:31:32 +08:00
|
|
|
int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_bind, 0, sock, address, addrlen);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_connect, 0, sock, address, addrlen);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_listen(struct socket *sock, int backlog)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_listen, 0, sock, backlog);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_accept(struct socket *sock, struct socket *newsock)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_accept, 0, sock, newsock);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_sendmsg, 0, sock, msg, size);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
|
|
|
|
int size, int flags)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_recvmsg, 0, sock, msg, size, flags);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getsockname(struct socket *sock)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_getsockname, 0, sock);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getpeername(struct socket *sock)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_getpeername, 0, sock);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getsockopt(struct socket *sock, int level, int optname)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_getsockopt, 0, sock, level, optname);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_setsockopt(struct socket *sock, int level, int optname)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_setsockopt, 0, sock, level, optname);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_shutdown(struct socket *sock, int how)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_shutdown, 0, sock, how);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(socket_sock_rcv_skb, 0, sk, skb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sock_rcv_skb);
|
|
|
|
|
|
|
|
int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
|
|
|
|
int __user *optlen, unsigned len)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock,
|
|
|
|
optval, optlen, len);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
|
|
|
|
{
|
2015-08-24 20:22:25 +08:00
|
|
|
return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock,
|
|
|
|
skb, secid);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_socket_getpeersec_dgram);
|
|
|
|
|
|
|
|
int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(sk_alloc_security, 0, sk, family, priority);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_sk_free(struct sock *sk)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sk_free_security, sk);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_sk_clone(const struct sock *sk, struct sock *newsk)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sk_clone_security, sk, newsk);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2011-10-07 17:40:59 +08:00
|
|
|
EXPORT_SYMBOL(security_sk_clone);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
|
|
|
void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sk_getsecid, sk, &fl->flowi_secid);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sk_classify_flow);
|
|
|
|
|
|
|
|
void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(req_classify_flow, req, fl);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_req_classify_flow);
|
|
|
|
|
|
|
|
void security_sock_graft(struct sock *sk, struct socket *parent)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(sock_graft, sk, parent);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_sock_graft);
|
|
|
|
|
|
|
|
int security_inet_conn_request(struct sock *sk,
|
|
|
|
struct sk_buff *skb, struct request_sock *req)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(inet_conn_request, 0, sk, skb, req);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_inet_conn_request);
|
|
|
|
|
|
|
|
void security_inet_csk_clone(struct sock *newsk,
|
|
|
|
const struct request_sock *req)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(inet_csk_clone, newsk, req);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_inet_conn_established(struct sock *sk,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(inet_conn_established, sk, skb);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
2018-02-14 04:53:21 +08:00
|
|
|
EXPORT_SYMBOL(security_inet_conn_established);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
2010-10-14 04:24:41 +08:00
|
|
|
int security_secmark_relabel_packet(u32 secid)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(secmark_relabel_packet, 0, secid);
|
2010-10-14 04:24:41 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secmark_relabel_packet);
|
|
|
|
|
|
|
|
void security_secmark_refcount_inc(void)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(secmark_refcount_inc);
|
2010-10-14 04:24:41 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secmark_refcount_inc);
|
|
|
|
|
|
|
|
void security_secmark_refcount_dec(void)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(secmark_refcount_dec);
|
2010-10-14 04:24:41 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_secmark_refcount_dec);
|
|
|
|
|
2013-01-14 15:12:19 +08:00
|
|
|
int security_tun_dev_alloc_security(void **security)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(tun_dev_alloc_security, 0, security);
|
2013-01-14 15:12:19 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_alloc_security);
|
|
|
|
|
|
|
|
void security_tun_dev_free_security(void *security)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(tun_dev_free_security, security);
|
2013-01-14 15:12:19 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_free_security);
|
|
|
|
|
2009-08-29 06:12:43 +08:00
|
|
|
int security_tun_dev_create(void)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(tun_dev_create, 0);
|
2009-08-29 06:12:43 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_create);
|
|
|
|
|
2013-01-14 15:12:19 +08:00
|
|
|
int security_tun_dev_attach_queue(void *security)
|
2009-08-29 06:12:43 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(tun_dev_attach_queue, 0, security);
|
2009-08-29 06:12:43 +08:00
|
|
|
}
|
2013-01-14 15:12:19 +08:00
|
|
|
EXPORT_SYMBOL(security_tun_dev_attach_queue);
|
2009-08-29 06:12:43 +08:00
|
|
|
|
2013-01-14 15:12:19 +08:00
|
|
|
int security_tun_dev_attach(struct sock *sk, void *security)
|
2009-08-29 06:12:43 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(tun_dev_attach, 0, sk, security);
|
2009-08-29 06:12:43 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_attach);
|
|
|
|
|
2013-01-14 15:12:19 +08:00
|
|
|
int security_tun_dev_open(void *security)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(tun_dev_open, 0, security);
|
2013-01-14 15:12:19 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_tun_dev_open);
|
|
|
|
|
2018-02-14 04:53:21 +08: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 14:31:32 +08: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 20:48:52 +08: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 20:48:54 +08: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 20:48:52 +08: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 14:31:32 +08:00
|
|
|
#ifdef CONFIG_SECURITY_NETWORK_XFRM
|
|
|
|
|
2014-03-07 19:44:19 +08:00
|
|
|
int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
|
|
|
|
struct xfrm_user_sec_ctx *sec_ctx,
|
|
|
|
gfp_t gfp)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_policy_alloc_security, 0, ctxp, sec_ctx, gfp);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_xfrm_policy_alloc);
|
|
|
|
|
2008-04-13 10:07:52 +08:00
|
|
|
int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
|
|
|
|
struct xfrm_sec_ctx **new_ctxp)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-13 10:07:52 +08:00
|
|
|
void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(xfrm_policy_free_security, ctx);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_xfrm_policy_free);
|
|
|
|
|
2008-04-13 10:07:52 +08:00
|
|
|
int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_policy_delete_security, 0, ctx);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 05:38:38 +08:00
|
|
|
int security_xfrm_state_alloc(struct xfrm_state *x,
|
|
|
|
struct xfrm_user_sec_ctx *sec_ctx)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_xfrm_state_alloc);
|
|
|
|
|
|
|
|
int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
|
|
|
|
struct xfrm_sec_ctx *polsec, u32 secid)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_xfrm_state_delete(struct xfrm_state *x)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_state_delete_security, 0, x);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_xfrm_state_delete);
|
|
|
|
|
|
|
|
void security_xfrm_state_free(struct xfrm_state *x)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(xfrm_state_free_security, x);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-13 10:07:52 +08:00
|
|
|
int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid, dir);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
|
2011-02-23 10:13:15 +08:00
|
|
|
struct xfrm_policy *xp,
|
|
|
|
const struct flowi *fl)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
struct security_hook_list *hp;
|
|
|
|
int rc = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since this function is expected to return 0 or 1, the judgment
|
|
|
|
* becomes difficult if multiple LSMs supply this call. Fortunately,
|
|
|
|
* we can use the first LSM's judgment because currently only SELinux
|
|
|
|
* supplies this call.
|
|
|
|
*
|
|
|
|
* For speed optimization, we explicitly break the loop rather than
|
|
|
|
* using the macro
|
|
|
|
*/
|
2018-03-29 09:28:23 +08:00
|
|
|
hlist_for_each_entry(hp, &security_hook_heads.xfrm_state_pol_flow_match,
|
2015-05-03 06:11:42 +08:00
|
|
|
list) {
|
|
|
|
rc = hp->hook.xfrm_state_pol_flow_match(x, xp, fl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(xfrm_decode_session, 0, skb, secid, 1);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
int rc = call_int_hook(xfrm_decode_session, 0, skb, &fl->flowi_secid,
|
|
|
|
0);
|
2007-10-17 14:31:32 +08:00
|
|
|
|
|
|
|
BUG_ON(rc);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_skb_classify_flow);
|
|
|
|
|
|
|
|
#endif /* CONFIG_SECURITY_NETWORK_XFRM */
|
|
|
|
|
|
|
|
#ifdef CONFIG_KEYS
|
|
|
|
|
CRED: Inaugurate COW credentials
Inaugurate copy-on-write credentials management. This uses RCU to manage the
credentials pointer in the task_struct with respect to accesses by other tasks.
A process may only modify its own credentials, and so does not need locking to
access or modify its own credentials.
A mutex (cred_replace_mutex) is added to the task_struct to control the effect
of PTRACE_ATTACHED on credential calculations, particularly with respect to
execve().
With this patch, the contents of an active credentials struct may not be
changed directly; rather a new set of credentials must be prepared, modified
and committed using something like the following sequence of events:
struct cred *new = prepare_creds();
int ret = blah(new);
if (ret < 0) {
abort_creds(new);
return ret;
}
return commit_creds(new);
There are some exceptions to this rule: the keyrings pointed to by the active
credentials may be instantiated - keyrings violate the COW rule as managing
COW keyrings is tricky, given that it is possible for a task to directly alter
the keys in a keyring in use by another task.
To help enforce this, various pointers to sets of credentials, such as those in
the task_struct, are declared const. The purpose of this is compile-time
discouragement of altering credentials through those pointers. Once a set of
credentials has been made public through one of these pointers, it may not be
modified, except under special circumstances:
(1) Its reference count may incremented and decremented.
(2) The keyrings to which it points may be modified, but not replaced.
The only safe way to modify anything else is to create a replacement and commit
using the functions described in Documentation/credentials.txt (which will be
added by a later patch).
This patch and the preceding patches have been tested with the LTP SELinux
testsuite.
This patch makes several logical sets of alteration:
(1) execve().
This now prepares and commits credentials in various places in the
security code rather than altering the current creds directly.
(2) Temporary credential overrides.
do_coredump() and sys_faccessat() now prepare their own credentials and
temporarily override the ones currently on the acting thread, whilst
preventing interference from other threads by holding cred_replace_mutex
on the thread being dumped.
This will be replaced in a future patch by something that hands down the
credentials directly to the functions being called, rather than altering
the task's objective credentials.
(3) LSM interface.
A number of functions have been changed, added or removed:
(*) security_capset_check(), ->capset_check()
(*) security_capset_set(), ->capset_set()
Removed in favour of security_capset().
(*) security_capset(), ->capset()
New. This is passed a pointer to the new creds, a pointer to the old
creds and the proposed capability sets. It should fill in the new
creds or return an error. All pointers, barring the pointer to the
new creds, are now const.
(*) security_bprm_apply_creds(), ->bprm_apply_creds()
Changed; now returns a value, which will cause the process to be
killed if it's an error.
(*) security_task_alloc(), ->task_alloc_security()
Removed in favour of security_prepare_creds().
(*) security_cred_free(), ->cred_free()
New. Free security data attached to cred->security.
(*) security_prepare_creds(), ->cred_prepare()
New. Duplicate any security data attached to cred->security.
(*) security_commit_creds(), ->cred_commit()
New. Apply any security effects for the upcoming installation of new
security by commit_creds().
(*) security_task_post_setuid(), ->task_post_setuid()
Removed in favour of security_task_fix_setuid().
(*) security_task_fix_setuid(), ->task_fix_setuid()
Fix up the proposed new credentials for setuid(). This is used by
cap_set_fix_setuid() to implicitly adjust capabilities in line with
setuid() changes. Changes are made to the new credentials, rather
than the task itself as in security_task_post_setuid().
(*) security_task_reparent_to_init(), ->task_reparent_to_init()
Removed. Instead the task being reparented to init is referred
directly to init's credentials.
NOTE! This results in the loss of some state: SELinux's osid no
longer records the sid of the thread that forked it.
(*) security_key_alloc(), ->key_alloc()
(*) security_key_permission(), ->key_permission()
Changed. These now take cred pointers rather than task pointers to
refer to the security context.
(4) sys_capset().
This has been simplified and uses less locking. The LSM functions it
calls have been merged.
(5) reparent_to_kthreadd().
This gives the current thread the same credentials as init by simply using
commit_thread() to point that way.
(6) __sigqueue_alloc() and switch_uid()
__sigqueue_alloc() can't stop the target task from changing its creds
beneath it, so this function gets a reference to the currently applicable
user_struct which it then passes into the sigqueue struct it returns if
successful.
switch_uid() is now called from commit_creds(), and possibly should be
folded into that. commit_creds() should take care of protecting
__sigqueue_alloc().
(7) [sg]et[ug]id() and co and [sg]et_current_groups.
The set functions now all use prepare_creds(), commit_creds() and
abort_creds() to build and check a new set of credentials before applying
it.
security_task_set[ug]id() is called inside the prepared section. This
guarantees that nothing else will affect the creds until we've finished.
The calling of set_dumpable() has been moved into commit_creds().
Much of the functionality of set_user() has been moved into
commit_creds().
The get functions all simply access the data directly.
(8) security_task_prctl() and cap_task_prctl().
security_task_prctl() has been modified to return -ENOSYS if it doesn't
want to handle a function, or otherwise return the return value directly
rather than through an argument.
Additionally, cap_task_prctl() now prepares a new set of credentials, even
if it doesn't end up using it.
(9) Keyrings.
A number of changes have been made to the keyrings code:
(a) switch_uid_keyring(), copy_keys(), exit_keys() and suid_keys() have
all been dropped and built in to the credentials functions directly.
They may want separating out again later.
(b) key_alloc() and search_process_keyrings() now take a cred pointer
rather than a task pointer to specify the security context.
(c) copy_creds() gives a new thread within the same thread group a new
thread keyring if its parent had one, otherwise it discards the thread
keyring.
(d) The authorisation key now points directly to the credentials to extend
the search into rather pointing to the task that carries them.
(e) Installing thread, process or session keyrings causes a new set of
credentials to be created, even though it's not strictly necessary for
process or session keyrings (they're shared).
(10) Usermode helper.
The usermode helper code now carries a cred struct pointer in its
subprocess_info struct instead of a new session keyring pointer. This set
of credentials is derived from init_cred and installed on the new process
after it has been cloned.
call_usermodehelper_setup() allocates the new credentials and
call_usermodehelper_freeinfo() discards them if they haven't been used. A
special cred function (prepare_usermodeinfo_creds()) is provided
specifically for call_usermodehelper_setup() to call.
call_usermodehelper_setkeys() adjusts the credentials to sport the
supplied keyring as the new session keyring.
(11) SELinux.
SELinux has a number of changes, in addition to those to support the LSM
interface changes mentioned above:
(a) selinux_setprocattr() no longer does its check for whether the
current ptracer can access processes with the new SID inside the lock
that covers getting the ptracer's SID. Whilst this lock ensures that
the check is done with the ptracer pinned, the result is only valid
until the lock is released, so there's no point doing it inside the
lock.
(12) is_single_threaded().
This function has been extracted from selinux_setprocattr() and put into
a file of its own in the lib/ directory as join_session_keyring() now
wants to use it too.
The code in SELinux just checked to see whether a task shared mm_structs
with other tasks (CLONE_VM), but that isn't good enough. We really want
to know if they're part of the same thread group (CLONE_THREAD).
(13) nfsd.
The NFS server daemon now has to use the COW credentials to set the
credentials it is going to use. It really needs to pass the credentials
down to the functions it calls, but it can't do that until other patches
in this series have been applied.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
int security_key_alloc(struct key *key, const struct cred *cred,
|
|
|
|
unsigned long flags)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(key_alloc, 0, key, cred, flags);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_key_free(struct key *key)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(key_free, key);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_key_permission(key_ref_t key_ref,
|
2014-03-15 01:44:49 +08:00
|
|
|
const struct cred *cred, unsigned perm)
|
2007-10-17 14:31:32 +08:00
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(key_permission, 0, key_ref, cred, perm);
|
2007-10-17 14:31:32 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 16:01:26 +08:00
|
|
|
int security_key_getsecurity(struct key *key, char **_buffer)
|
|
|
|
{
|
2015-05-03 06:11:42 +08:00
|
|
|
*_buffer = NULL;
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(key_getsecurity, 0, key, _buffer);
|
2008-04-29 16:01:26 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:31:32 +08:00
|
|
|
#endif /* CONFIG_KEYS */
|
2008-03-02 04:00:05 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIT
|
|
|
|
|
|
|
|
int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(audit_rule_init, 0, field, op, rulestr, lsmrule);
|
2008-03-02 04:00:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int security_audit_rule_known(struct audit_krule *krule)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
return call_int_hook(audit_rule_known, 0, krule);
|
2008-03-02 04:00:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void security_audit_rule_free(void *lsmrule)
|
|
|
|
{
|
2015-05-03 06:11:29 +08:00
|
|
|
call_void_hook(audit_rule_free, lsmrule);
|
2008-03-02 04:00:05 +08:00
|
|
|
}
|
|
|
|
|
2019-02-01 00:52:11 +08:00
|
|
|
int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule)
|
2008-03-02 04:00:05 +08:00
|
|
|
{
|
2019-02-01 00:52:11 +08:00
|
|
|
return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule);
|
2008-03-02 04:00:05 +08:00
|
|
|
}
|
2015-05-03 06:11:42 +08:00
|
|
|
#endif /* CONFIG_AUDIT */
|
2017-10-19 04:00:24 +08: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 */
|
2019-08-20 08:17:38 +08:00
|
|
|
|
|
|
|
int security_locked_down(enum lockdown_reason what)
|
|
|
|
{
|
|
|
|
return call_int_hook(locked_down, 0, what);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(security_locked_down);
|