[PATCH v37 21/33] binder: Pass LSM identifier for confirmation
From: Casey Schaufler
Date: Mon Jun 27 2022 - 21:10:42 EST
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@xxxxxxxxxxxxxxxx>
---
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 8ae1a624cd37..f2a0faf6d9c6 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -3107,6 +3107,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,
@@ -4552,6 +4553,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 8dc0bccf8513..7233bfdb72db 100644
--- a/drivers/android/binder_internal.h
+++ b/drivers/android/binder_internal.h
@@ -550,6 +550,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.36.1