From patchwork Mon Dec 16 22:36:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 11296151 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C09ED17F0 for ; Mon, 16 Dec 2019 22:38:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9535321739 for ; Mon, 16 Dec 2019 22:38:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="Cop19Ag/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727861AbfLPWiL (ORCPT ); Mon, 16 Dec 2019 17:38:11 -0500 Received: from sonic311-30.consmr.mail.ne1.yahoo.com ([66.163.188.211]:41547 "EHLO sonic311-30.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727826AbfLPWiK (ORCPT ); Mon, 16 Dec 2019 17:38:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1576535889; bh=Vw5PzqK2k4wespl9dNFvI58s/wyRhq2FOJ5+UO2Nnnc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Cop19Ag//8shdZoCgAW0iUzWlaTbp6MtTtXujp2lE82A0zzDj1C/PmfuG3AvlcqY2uHNtGWLr6VOocskgw0Xi2HFERW2PHA4NZSLrlG57/WHtH0GiAM1sK7BzEhIHvHX7hjSRyAR3pDVCaYo1qOKZVItiXY/Cltz0h0yAW3QcDn1qMCOZmAmVIr7FrB8Ug3X1sRghUwY4GvNqy+Ls2iPLhhyTiIzPig7yxmyUtDqMTYHIcbSdMuFBiYni9qyYxRh1OAqNHo4h/sBm4gD/ll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ThU0HBojZjYuRfnD3IZW.qG_M9ELd6JZztf3oNaJxOprf2v2UcvJH UvlPWIKqoruzuc8R6L.0gBxpWFzuSukGXyghzlkbuzfY0UGn.DLpvJ_PJ.J5Ce.LrnDpIRkKjUTM t1VKjlew_ZVzfK_3.XCKbvGsdq_qeBHA1_X1voLei0jv4QpxOto.1V5XCGTpm3GErTgBEekpelM8 CY3CvOh9J_XUspJb98iJGyCXtYpZ14k4Z4eQXXNVUDssAmo3WR2siR2_qn8kgpRfq6VIyeblzPCX _UmFWosj5r1eE50hEowXrbPXT5YxdLl5ZMnnRTJzFh3vapfmOIN36k7GojdLotSglu23D0t5rDxd 5zRZdlZPX0kle56VK714.sOVZvs1gt.DFNjA.OdJo7DWzzw4zefMcv8RqrDcC3UC5WvYwC8HrM4h ZdkaoG5B6tw9WT_ZGR1bMmJ0iCAIPOhZO8Y2NcZ9jWrejJX2k3EQUwxUZm8._b.Kg2dkz Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Mon, 16 Dec 2019 22:38:09 +0000 Received: by smtp424.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 19a4a615975b36081bc636e8892a49d8; Mon, 16 Dec 2019 22:38:08 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH v12 20/25] LSM: Verify LSM display sanity in binder Date: Mon, 16 Dec 2019 14:36:16 -0800 Message-Id: <20191216223621.5127-21-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191216223621.5127-1-casey@schaufler-ca.com> References: <20191216223621.5127-1-casey@schaufler-ca.com> MIME-Version: 1.0 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". Signed-off-by: Casey Schaufler Acked-by: Stephen Smalley --- security/security.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/security/security.c b/security/security.c index 963641acf9dc..bca092dd4f00 100644 --- a/security/security.c +++ b/security/security.c @@ -738,9 +738,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); }