[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220407212230.12893-21-casey@schaufler-ca.com>
Date: Thu, 7 Apr 2022 14:22:21 -0700
From: Casey Schaufler <casey@...aufler-ca.com>
To: casey.schaufler@...el.com, jmorris@...ei.org,
linux-security-module@...r.kernel.org, selinux@...r.kernel.org
Cc: casey@...aufler-ca.com, linux-audit@...hat.com,
keescook@...omium.org, john.johansen@...onical.com,
penguin-kernel@...ove.sakura.ne.jp, paul@...l-moore.com,
stephen.smalley.work@...il.com, linux-kernel@...r.kernel.org
Subject: [PATCH v34 20/29] binder: Pass LSM identifier for confirmation
Send an identifier for the security module interface_lsm
along with the security context. This allows the receiver
to verify that the receiver and the sender agree on which
security module's context is being used. If they don't
agree the message is rejected.
Signed-off-by: Casey Schaufler <casey@...aufler-ca.com>
---
drivers/android/binder.c | 21 +++++++++++++++++++++
drivers/android/binder_internal.h | 1 +
2 files changed, 22 insertions(+)
diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index b0b0c132a247..259f5e38e6ba 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -3024,6 +3024,7 @@ static void binder_transaction(struct binder_proc *proc,
ALIGN(extra_buffers_size, sizeof(void *)) -
ALIGN(lsmctx.len, sizeof(u64));
+ t->security_interface = lsm_task_ilsm(current);
t->security_ctx = (uintptr_t)t->buffer->user_data + buf_offset;
err = binder_alloc_copy_to_buffer(&target_proc->alloc,
t->buffer, buf_offset,
@@ -4453,6 +4454,26 @@ static int binder_thread_read(struct binder_proc *proc,
tr.secctx = t->security_ctx;
if (t->security_ctx) {
+ int to_ilsm = lsm_task_ilsm(current);
+ int from_ilsm = t->security_interface;
+
+ if (to_ilsm == LSMBLOB_INVALID)
+ to_ilsm = 0;
+ if (from_ilsm == LSMBLOB_INVALID)
+ from_ilsm = 0;
+ /*
+ * The sender provided a security context from
+ * a different security module than the one this
+ * process wants to report if these don't match.
+ */
+ if (from_ilsm != to_ilsm) {
+ if (t_from)
+ binder_thread_dec_tmpref(t_from);
+
+ binder_cleanup_transaction(t, "security context mismatch",
+ BR_FAILED_REPLY);
+ return -EINVAL;
+ }
cmd = BR_TRANSACTION_SEC_CTX;
trsize = sizeof(tr);
}
diff --git a/drivers/android/binder_internal.h b/drivers/android/binder_internal.h
index d6b6b8cb7346..e3a0718ce17c 100644
--- a/drivers/android/binder_internal.h
+++ b/drivers/android/binder_internal.h
@@ -545,6 +545,7 @@ struct binder_transaction {
long saved_priority;
kuid_t sender_euid;
struct list_head fd_fixups;
+ int security_interface;
binder_uintptr_t security_ctx;
/**
* @lock: protects @from, @to_proc, and @to_thread
--
2.35.1
Powered by blists - more mailing lists