Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2177CC433E1 for ; Thu, 14 May 2020 22:32:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F27AA20709 for ; Thu, 14 May 2020 22:32:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="Mfe3z4m0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728663AbgENWcn (ORCPT ); Thu, 14 May 2020 18:32:43 -0400 Received: from sonic309-27.consmr.mail.ne1.yahoo.com ([66.163.184.153]:43379 "EHLO sonic309-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728525AbgENWcm (ORCPT ); Thu, 14 May 2020 18:32:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1589495562; bh=CXLrghL2246zzEWsu94Kcqk12JO7Gj9mpePZWe08Rd4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Mfe3z4m0S5X90LWsM9JYvl4r1nieCtCpWxZET/SY1EQHKxlIRIawTYFE4ame5aWYPkDWYG+cZtb3koTjZUR2NcX63bFmgELiTHNPI+AWamnvxRIF0Ji5vYtAPs87SA19IJkRkrC77gYXtneuoQKNuBhpJe/MGUD8PUqkTffWZTX5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R1 ocmV0C77yzUZ7v_DWDh0qjQYseWy4eMEw6m5z0HHfih9.J3MUOP6A9tCvjEy1Y71Z_7YYXBM4jIf AikrSUlq0j8I5xEwUmLQTPprORLN4PAMO9wu9S3M.ZQj52YdFQnbMQi8gbKwQsdywXi0WxbYggMp kIRgMpvUhhPe.uz6KY66Uv_Dbfc13pjPfT.JqqDykBCvU5_ySJEcUOlhF3TPvV55NnhyZh1vOzQS 7c3AIqp8YTeXSznGPWl5rzdv85.3kgVA69ffbCVeRJJsc9Zs3r2JI.LJICTcZZ3zCeL8uoAJVjMJ KvdGtw_r6S1ZtELvJ91Zfhcjfi37ygKLWZJ4nUGn7pQr660HLwUmBo5bf3Z5ZmNXCDHQ61xBr3xV mfFHNs9xNE1jBs.ppsGEEhUEzaYa6Nb2gJ1On2xgM66y2oFFn9AbsgkHIyJ9OHFtuwDa62Tbv9eN pwV1ANvoJI566CpLBL9PbvOIRbmBFxM85hMx2dwBJ0FhJDDvf006cQ7HK0PaorAMgUbv.xUnHVQu i8kP5BH17Wyg1ZoqusQDz8mvJ8b_ukcaCsdfmRnDlLhZ9tcNWIehgZij92C8- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ne1.yahoo.com with HTTP; Thu, 14 May 2020 22:32:42 +0000 Received: by smtp405.mail.bf1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID a21fe4c302c24d17582575c2e3e82ae3; Thu, 14 May 2020 22:32: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, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov, linux-audit@redhat.com Subject: [PATCH v17 19/23] LSM: Verify LSM display sanity in binder Date: Thu, 14 May 2020 15:11:38 -0700 Message-Id: <20200514221142.11857-20-casey@schaufler-ca.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200514221142.11857-1-casey@schaufler-ca.com> References: <20200514221142.11857-1-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: Verify that the tasks on the ends of a binder transaction use the same "display" security module. This prevents confusion of security "contexts". Reviewed-by: Kees Cook Acked-by: Stephen Smalley Signed-off-by: Casey Schaufler --- security/security.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/security/security.c b/security/security.c index d082ef0673d0..677a9f409dc2 100644 --- a/security/security.c +++ b/security/security.c @@ -788,9 +788,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_display = lsm_task_display(from); + int to_display = lsm_task_display(to); + + /* + * If the display 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_display == LSMBLOB_INVALID) + from_display = 0; + if (to_display == LSMBLOB_INVALID) + to_display = 0; + if (from_display != to_display) + return -EINVAL; + return call_int_hook(binder_transaction, 0, from, to); } -- 2.24.1