From patchwork Mon Apr 18 14:59:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12816788 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 6D042C43217 for ; Mon, 18 Apr 2022 15:41:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345603AbiDRPoN (ORCPT ); Mon, 18 Apr 2022 11:44:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345944AbiDRPnJ (ORCPT ); Mon, 18 Apr 2022 11:43:09 -0400 Received: from sonic317-38.consmr.mail.ne1.yahoo.com (sonic317-38.consmr.mail.ne1.yahoo.com [66.163.184.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05FDA6446 for ; Mon, 18 Apr 2022 08:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1650294577; bh=4/A9RMlo2VDUS+eJ3c9f9QVdqHvAgQb0ICSOChfHCEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=A/UEjKhdKa7Fyvn5/Z2KDs//KFmWCJAvubbqPcG+G/zBCHBGhcfJPB3pXknWA3X8vX+QanDZAbX4FWVvgbJwYUkJoTe7009em1mY1omsOcoc1amS4xsap7kfAGP6uSuJ12i1tfD4/YcN4X1pufMB0DL2EX8Ptnue72WAxztyl5fbbmkjMFbCSqWYNzwrTBvOzUspWF5la2Rf/jAE/jpBwYSGEPg4yOPqrUfA0z6TqzEwC23JSMuj7CKN5Z/F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yseaG6lRp9FUaev6br5Hvrjnu5Y3wdYcwBzA7NIE3Hgh cYXzVK3N19VYjyQnksUaAJqR2nt_8EwEKIVKKuOvIHSaHLbBDFmsMbFz6bN8HzW_HyIkFYkSx69u AOvkQCEpN610eQC5pCDrnPNXi96N9zykVXETHDXxy75MyOF8K4L90pwp1tfX35.4k.T2Nba6Nv7m hKBqT6O3HNTgbse_wFptoLAXWjerQ8_rybPMlXXSYL8XUfzs5WHYsId1mUrbPFkzHtyQ2CZc0jLo f6WjevgSgf4pg6KSfvGl8NtorNOeleV_4l4FBmIbJAFQsXpnIZGEACDVSZk98v4dshU9vS3gywje WDlSXd8S7KIuayZrlpI58HYLNMiQ4Jp90dn1tOL61_u3O3qnRoD4WVZQe5Ot70uXC.8zPH9kbJl6 uzrc4QpenbL.dnU9JE_g5mT.h5OL8sT52x6Ynf9BYUyDq.oamSLubARm1t_E5nHEfcFF_NshF3TZ q3uxc4zD1OQlveR9tlzM7d.9pwQwBstSOzN2e1IyH6vqEaGFZKUQPu9gc.e9C16FBFLEJwWsTorZ kN4UoiqRF.DWypXsEm5P_utsPIm4AYDg34jXQ48wxaVibfhJlv02oKhvZIkt0DUtZ1uv_9AIUOmG DuAKFAhTebecTD3tgy9C0YNZNjrBY3zVLoVycYJ2s6lIIn9R.j17rKjpsULgPvBl5Nd3BHmQt4vc 6wGE5A4vrc0wN5lGvIpcqahFsucmekmVCcAvD4YZ9aY3EAM0S1.h_wIH5.09m.O5elbW3gZX.5ut dFBJFSracrEWpjVHjIGj0xpkA1o4mmVsOMjrjq6LzH07yc.IsMJAHwrNcTQ-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Mon, 18 Apr 2022 15:09:37 +0000 Received: by hermes--canary-production-ne1-c7c4f6977-9gvrn (VZM Hermes SMTP Server) with ESMTPA ID d63a51ac54c25c4b8dfd633eacacc622; Mon, 18 Apr 2022 15:09:36 +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 v35 20/29] binder: Pass LSM identifier for confirmation Date: Mon, 18 Apr 2022 07:59:36 -0700 Message-Id: <20220418145945.38797-21-casey@schaufler-ca.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220418145945.38797-1-casey@schaufler-ca.com> References: <20220418145945.38797-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 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