From patchwork Tue Jun 28 00:55:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12897469 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5ED65CCA47B for ; Tue, 28 Jun 2022 01:10:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241727AbiF1BKj (ORCPT ); Mon, 27 Jun 2022 21:10:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241375AbiF1BKh (ORCPT ); Mon, 27 Jun 2022 21:10:37 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com (sonic304-28.consmr.mail.ne1.yahoo.com [66.163.191.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B8A122BDC for ; Mon, 27 Jun 2022 18:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656378634; bh=d2AZFBkxP9+t+hI8o1br7sFS1euNhHyUWMYU7J/f0uI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=U8Xg/bdHp7SZgXnt8iiNX/e+8Yt/0XUO0uZSS7vKUeSTW65BsJhCQgxf9lOKtwEreJ4zMVlncm2q1Cwl8j5otvLWFiO7akAoecXhLN81TNw83ppamJ/6q1IiGxPaHWN73mjoGbsCzdywU+yg2f/mZJuj/wdHp+msnjUID5HC2TBqmenG11IECwofQGOedPawH/OtrNn4akCwmhMHe3kbrHcr+o5IRShWOCWhIjx3WhlGkNn89yJk4EvgOlVR9PZcQdy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qj0YOpZUkR8hDriWLunKoa1l_tZfAP6VXd 3Jy1XMsIKYA0TWvULApi5N5e.431FQV1NK74QzHNvao2F.UGJoSlR10UP.LL1XjxfZ_10OzbIhdq FOKgCWOdmvn7MZWYlkYTpqTiMxig2qMbYR2u8xdYbt1SuKrg8tEXhT7p1nmfZwsRQ6vFg6S7oyjw 7PUucnWEnu52FNopY3uAGstu7aC3zEDXp7S4bB0UfuWVei1_kdpnXvhQB1RqtTmuugX7aEiD.xDw kmvRnJ_FRcrvgs3lykt5mmUlh56jgiml3f5p8PmI1fujo8laP0q6vsLlPmjI.cvmqe6PBarz7JBh TNfA2WnK5abn889WBEgj4APcw0EelCyi2rL6iozx3vLW.jWEGc3HTe.cE6asIivEwk1o.1QxMIjZ LXtWEcHNk.ZDG1qfd8zYMmNX8af1XM5XBlg0_IUxOA2Og_ZxE0In7HfN.Ooz7nIdtkNUj.DQmteg q3FIL4d9sFhbBXGCOBOl7UjQuvdL46Z6Xq9NO7mH.jnolOFlbDh0FzN.iS2KwhIuBoQExl42stEY jhJeOd2XCs8QxarZepemrkYplyXBSy4J7x_NPxyhsp3.0_Mq4V5DF0_qTuCLedByNTmjfom0Y1GQ 92sbzdelCasWG5svhaljNrThQUXMHRlhJslG_eRE2sU1MOHcENdM8tlvMljkSmRhHzLyhYYC6rOU mAQmi05S8hSLv7RxAtxgOs5QIgpU8eqgQ1kxPrvvz_2Ol01_s.VCHtxe8Kid0B9tegjtSoSQJXiQ mmxp2KWd_qFtLBlXUPpX7wnAGBiYGs9Jdd0E41BHdAaaS X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 28 Jun 2022 01:10:34 +0000 Received: by hermes--canary-production-gq1-677bd878b7-wc7mq (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID e584f9a769c6d1ee8a468863bbdfebe6; Tue, 28 Jun 2022 01:10:30 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, linux-audit@redhat.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v37 21/33] binder: Pass LSM identifier for confirmation Date: Mon, 27 Jun 2022 17:55:59 -0700 Message-Id: <20220628005611.13106-22-casey@schaufler-ca.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628005611.13106-1-casey@schaufler-ca.com> References: <20220628005611.13106-1-casey@schaufler-ca.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org 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 --- 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