[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210513200807.15910-21-casey@schaufler-ca.com>
Date: Thu, 13 May 2021 13:08:02 -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,
sds@...ho.nsa.gov, linux-kernel@...r.kernel.org
Subject: [PATCH v26 20/25] LSM: Verify LSM display sanity in binder
Verify that the tasks on the ends of a binder transaction
use the same "interface_lsm" security module. This prevents
confusion of security "contexts".
Reviewed-by: Kees Cook <keescook@...omium.org>
Reviewed-by: John Johansen <john.johansen@...onical.com>
Acked-by: Stephen Smalley <sds@...ho.nsa.gov>
Acked-by: Paul Moore <paul@...l-moore.com>
Signed-off-by: Casey Schaufler <casey@...aufler-ca.com>
---
security/security.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/security/security.c b/security/security.c
index 1e441c3491b5..d1e9a54e22b4 100644
--- a/security/security.c
+++ b/security/security.c
@@ -857,9 +857,38 @@ int security_binder_set_context_mgr(struct task_struct *mgr)
return call_int_hook(binder_set_context_mgr, 0, mgr);
}
+/**
+ * security_binder_transaction - Binder driver transaction check
+ * @from: source of the transaction
+ * @to: destination of the transaction
+ *
+ * Verify that the tasks have the same LSM "display", then
+ * call the security module hooks.
+ *
+ * Returns -EINVAL if the displays don't match, or the
+ * result of the security module checks.
+ */
int security_binder_transaction(struct task_struct *from,
struct task_struct *to)
{
+ int from_ilsm = lsm_task_ilsm(from);
+ int to_ilsm = lsm_task_ilsm(to);
+
+ /*
+ * If the ilsm is LSMBLOB_INVALID the first module that has
+ * an entry is used. This will be in the 0 slot.
+ *
+ * This is currently only required if the server has requested
+ * peer contexts, but it would be unwieldly to have too much of
+ * the binder driver detail here.
+ */
+ if (from_ilsm == LSMBLOB_INVALID)
+ from_ilsm = 0;
+ if (to_ilsm == LSMBLOB_INVALID)
+ to_ilsm = 0;
+ if (from_ilsm != to_ilsm)
+ return -EINVAL;
+
return call_int_hook(binder_transaction, 0, from, to);
}
--
2.29.2
Powered by blists - more mailing lists