Skip to content

Commit cdab10b

Browse files
committed
Merge tag 'selinux-pr-20211101' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull selinux updates from Paul Moore: - Add LSM/SELinux/Smack controls and auditing for io-uring. As usual, the individual commit descriptions have more detail, but we were basically missing two things which we're adding here: + establishment of a proper audit context so that auditing of io-uring ops works similarly to how it does for syscalls (with some io-uring additions because io-uring ops are *not* syscalls) + additional LSM hooks to enable access control points for some of the more unusual io-uring features, e.g. credential overrides. The additional audit callouts and LSM hooks were done in conjunction with the io-uring folks, based on conversations and RFC patches earlier in the year. - Fixup the binder credential handling so that the proper credentials are used in the LSM hooks; the commit description and the code comment which is removed in these patches are helpful to understand the background and why this is the proper fix. - Enable SELinux genfscon policy support for securityfs, allowing improved SELinux filesystem labeling for other subsystems which make use of securityfs, e.g. IMA. * tag 'selinux-pr-20211101' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: security: Return xattr name from security_dentry_init_security() selinux: fix a sock regression in selinux_ip_postroute_compat() binder: use cred instead of task for getsecid binder: use cred instead of task for selinux checks binder: use euid from cred instead of using task LSM: Avoid warnings about potentially unused hook variables selinux: fix all of the W=1 build warnings selinux: make better use of the nf_hook_state passed to the NF hooks selinux: fix race condition when computing ocontext SIDs selinux: remove unneeded ipv6 hook wrappers selinux: remove the SELinux lockdown implementation selinux: enable genfscon labeling for securityfs Smack: Brutalist io_uring support selinux: add support for the io_uring access controls lsm,io_uring: add LSM hooks to io_uring io_uring: convert io_uring to the secure anon inode interface fs: add anon_inode_getfile_secure() similar to anon_inode_getfd_secure() audit: add filtering for io_uring records audit,io_uring,io-wq: add some basic audit support to io_uring audit: prepare audit_context for use in calling contexts beyond syscalls
2 parents 6fedc28 + 15bf323 commit cdab10b

28 files changed

+884
-421
lines changed

drivers/android/binder.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,7 @@ static int binder_translate_binder(struct flat_binder_object *fp,
20562056
ret = -EINVAL;
20572057
goto done;
20582058
}
2059-
if (security_binder_transfer_binder(proc->tsk, target_proc->tsk)) {
2059+
if (security_binder_transfer_binder(proc->cred, target_proc->cred)) {
20602060
ret = -EPERM;
20612061
goto done;
20622062
}
@@ -2102,7 +2102,7 @@ static int binder_translate_handle(struct flat_binder_object *fp,
21022102
proc->pid, thread->pid, fp->handle);
21032103
return -EINVAL;
21042104
}
2105-
if (security_binder_transfer_binder(proc->tsk, target_proc->tsk)) {
2105+
if (security_binder_transfer_binder(proc->cred, target_proc->cred)) {
21062106
ret = -EPERM;
21072107
goto done;
21082108
}
@@ -2190,7 +2190,7 @@ static int binder_translate_fd(u32 fd, binder_size_t fd_offset,
21902190
ret = -EBADF;
21912191
goto err_fget;
21922192
}
2193-
ret = security_binder_transfer_file(proc->tsk, target_proc->tsk, file);
2193+
ret = security_binder_transfer_file(proc->cred, target_proc->cred, file);
21942194
if (ret < 0) {
21952195
ret = -EPERM;
21962196
goto err_security;
@@ -2595,8 +2595,8 @@ static void binder_transaction(struct binder_proc *proc,
25952595
return_error_line = __LINE__;
25962596
goto err_invalid_target_handle;
25972597
}
2598-
if (security_binder_transaction(proc->tsk,
2599-
target_proc->tsk) < 0) {
2598+
if (security_binder_transaction(proc->cred,
2599+
target_proc->cred) < 0) {
26002600
return_error = BR_FAILED_REPLY;
26012601
return_error_param = -EPERM;
26022602
return_error_line = __LINE__;
@@ -2711,7 +2711,7 @@ static void binder_transaction(struct binder_proc *proc,
27112711
t->from = thread;
27122712
else
27132713
t->from = NULL;
2714-
t->sender_euid = task_euid(proc->tsk);
2714+
t->sender_euid = proc->cred->euid;
27152715
t->to_proc = target_proc;
27162716
t->to_thread = target_thread;
27172717
t->code = tr->code;
@@ -2722,16 +2722,7 @@ static void binder_transaction(struct binder_proc *proc,
27222722
u32 secid;
27232723
size_t added_size;
27242724

2725-
/*
2726-
* Arguably this should be the task's subjective LSM secid but
2727-
* we can't reliably access the subjective creds of a task
2728-
* other than our own so we must use the objective creds, which
2729-
* are safe to access. The downside is that if a task is
2730-
* temporarily overriding it's creds it will not be reflected
2731-
* here; however, it isn't clear that binder would handle that
2732-
* case well anyway.
2733-
*/
2734-
security_task_getsecid_obj(proc->tsk, &secid);
2725+
security_cred_getsecid(proc->cred, &secid);
27352726
ret = security_secid_to_secctx(secid, &secctx, &secctx_sz);
27362727
if (ret) {
27372728
return_error = BR_FAILED_REPLY;
@@ -4353,6 +4344,7 @@ static void binder_free_proc(struct binder_proc *proc)
43534344
}
43544345
binder_alloc_deferred_release(&proc->alloc);
43554346
put_task_struct(proc->tsk);
4347+
put_cred(proc->cred);
43564348
binder_stats_deleted(BINDER_STAT_PROC);
43574349
kfree(proc);
43584350
}
@@ -4564,7 +4556,7 @@ static int binder_ioctl_set_ctx_mgr(struct file *filp,
45644556
ret = -EBUSY;
45654557
goto out;
45664558
}
4567-
ret = security_binder_set_context_mgr(proc->tsk);
4559+
ret = security_binder_set_context_mgr(proc->cred);
45684560
if (ret < 0)
45694561
goto out;
45704562
if (uid_valid(context->binder_context_mgr_uid)) {
@@ -5055,6 +5047,7 @@ static int binder_open(struct inode *nodp, struct file *filp)
50555047
spin_lock_init(&proc->outer_lock);
50565048
get_task_struct(current->group_leader);
50575049
proc->tsk = current->group_leader;
5050+
proc->cred = get_cred(filp->f_cred);
50585051
INIT_LIST_HEAD(&proc->todo);
50595052
init_waitqueue_head(&proc->freeze_wait);
50605053
proc->default_priority = task_nice(current);

drivers/android/binder_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ struct binder_ref {
364364
* (invariant after initialized)
365365
* @tsk task_struct for group_leader of process
366366
* (invariant after initialized)
367+
* @cred struct cred associated with the `struct file`
368+
* in binder_open()
369+
* (invariant after initialized)
367370
* @deferred_work_node: element for binder_deferred_list
368371
* (protected by binder_deferred_lock)
369372
* @deferred_work: bitmap of deferred work to perform
@@ -426,6 +429,7 @@ struct binder_proc {
426429
struct list_head waiting_threads;
427430
int pid;
428431
struct task_struct *tsk;
432+
const struct cred *cred;
429433
struct hlist_node deferred_work_node;
430434
int deferred_work;
431435
int outstanding_txns;

fs/anon_inodes.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,35 @@ struct file *anon_inode_getfile(const char *name,
148148
}
149149
EXPORT_SYMBOL_GPL(anon_inode_getfile);
150150

151+
/**
152+
* anon_inode_getfile_secure - Like anon_inode_getfile(), but creates a new
153+
* !S_PRIVATE anon inode rather than reuse the
154+
* singleton anon inode and calls the
155+
* inode_init_security_anon() LSM hook. This
156+
* allows for both the inode to have its own
157+
* security context and for the LSM to enforce
158+
* policy on the inode's creation.
159+
*
160+
* @name: [in] name of the "class" of the new file
161+
* @fops: [in] file operations for the new file
162+
* @priv: [in] private data for the new file (will be file's private_data)
163+
* @flags: [in] flags
164+
* @context_inode:
165+
* [in] the logical relationship with the new inode (optional)
166+
*
167+
* The LSM may use @context_inode in inode_init_security_anon(), but a
168+
* reference to it is not held. Returns the newly created file* or an error
169+
* pointer. See the anon_inode_getfile() documentation for more information.
170+
*/
171+
struct file *anon_inode_getfile_secure(const char *name,
172+
const struct file_operations *fops,
173+
void *priv, int flags,
174+
const struct inode *context_inode)
175+
{
176+
return __anon_inode_getfile(name, fops, priv, flags,
177+
context_inode, true);
178+
}
179+
151180
static int __anon_inode_getfd(const char *name,
152181
const struct file_operations *fops,
153182
void *priv, int flags,

fs/ceph/xattr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ int ceph_security_init_secctx(struct dentry *dentry, umode_t mode,
13111311
int err;
13121312

13131313
err = security_dentry_init_security(dentry, mode, &dentry->d_name,
1314-
&as_ctx->sec_ctx,
1314+
&name, &as_ctx->sec_ctx,
13151315
&as_ctx->sec_ctxlen);
13161316
if (err < 0) {
13171317
WARN_ON_ONCE(err != -EOPNOTSUPP);
@@ -1335,7 +1335,6 @@ int ceph_security_init_secctx(struct dentry *dentry, umode_t mode,
13351335
* It only supports single security module and only selinux has
13361336
* dentry_init_security hook.
13371337
*/
1338-
name = XATTR_NAME_SELINUX;
13391338
name_len = strlen(name);
13401339
err = ceph_pagelist_reserve(pagelist,
13411340
4 * 2 + name_len + as_ctx->sec_ctxlen);

fs/io-wq.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/rculist_nulls.h>
1515
#include <linux/cpu.h>
1616
#include <linux/tracehook.h>
17+
#include <linux/audit.h>
1718
#include <uapi/linux/io_uring.h>
1819

1920
#include "io-wq.h"
@@ -593,6 +594,8 @@ static int io_wqe_worker(void *data)
593594
snprintf(buf, sizeof(buf), "iou-wrk-%d", wq->task->pid);
594595
set_task_comm(current, buf);
595596

597+
audit_alloc_kernel(current);
598+
596599
while (!test_bit(IO_WQ_BIT_EXIT, &wq->state)) {
597600
long ret;
598601

@@ -631,6 +634,7 @@ static int io_wqe_worker(void *data)
631634
io_worker_handle_work(worker);
632635
}
633636

637+
audit_free(current);
634638
io_worker_exit(worker);
635639
return 0;
636640
}

0 commit comments

Comments
 (0)