Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp604413imu; Mon, 26 Nov 2018 15:40:37 -0800 (PST) X-Google-Smtp-Source: AJdET5eIYpY6Av1U4/Xu3DFpvRbL9mEcukEBRo3IlIgtKBt3CiqFBoTsiEth8qJezQ/LC2vohLjq X-Received: by 2002:a62:2606:: with SMTP id m6mr29656693pfm.133.1543275637415; Mon, 26 Nov 2018 15:40:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543275637; cv=none; d=google.com; s=arc-20160816; b=lcstAHR2iBS89xAQ+nEMC3daGYellpzdZzFTvh3fYf/WOYKveHWePvQGWaBiZQmViW wilZVtsYVX8deBmnf/Pm32oDm8TQdQs9+AV/RrbvhLhHTkyiD1QFe6ZbaIOujyiO1RFU aLkMHBlzU8X0tcxaPBPqzFdR3wyVpN2pLlWflUuzGDOEQycAbFUbfLv5GTgHkyL5DLr1 nwx7qzHNnloStsnk4qDO7VHO4QsNYal3Z0YaIENjVvnkifl5MlMfBGRiffgWMSzGsKy4 FBCCUwO7t5fmextKvL5kbz1WeY0raDuT16w9i6DxRzg7+1LAmpX4Jbk19raQFWHLdqM0 oI2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=jV11Dho+W8jm+OTKCjoUEiJ1PzwrfCLcMmvEuAbflbk=; b=BDD9Ajsjv17MJc+CORuxzwxKEPhrbyAjTSsXx2CFR3BbOmsw9C84XddgZQCHliOIF9 3yyytGdCHk0Ps+TBo0YRnx81frnvWf+K8pI0nhFS6/Jb0su83To28qN6LRFzi+TDLwdv wTkhybiorH/NywlCPgxqo1MlSxlq0aZNBXlaY6N+2PYc6K6XvOVgNvlOYtDa4tW9uz6t 1ZFIaXuIVv4sVtiUMT4s+jlk39q3xAiYJiDreas/8Rc11npQu9m/0VwmlAIIQ7HONdrg SQoamO7f3eR6l5E7q94fTwwyMv1zj/L1Baz2Q9OAyR4bQJ/a1yMLsMhzwJF8ZEAdLtaU 3zRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=Q4nK2J9K; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si1814405pgl.122.2018.11.26.15.40.21; Mon, 26 Nov 2018 15:40:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=Q4nK2J9K; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727867AbeK0KeR (ORCPT + 99 others); Tue, 27 Nov 2018 05:34:17 -0500 Received: from sonic315-27.consmr.mail.ne1.yahoo.com ([66.163.190.153]:44812 "EHLO sonic315-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727667AbeK0KeR (ORCPT ); Tue, 27 Nov 2018 05:34:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1543275507; bh=jV11Dho+W8jm+OTKCjoUEiJ1PzwrfCLcMmvEuAbflbk=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=Q4nK2J9KPexbdiAxFNCpJbLhYux6mtOzZBYhpYerRgCIT4T9lcs3efTtp+3xx2F4Y/ZLc1kWXFmP4f6hnfo52WVlGsHnUMEZmj1mlOiTJPkDKX2YH41ubKpc+I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fxF4IGPF.U5oIXwMuJ47nrGTcmXihQt5sMWam3kz XRGHRtgKo61T13xvkiAvfO_R_7vgydFDTLSjHydf3K6.J6U030QysttTRc47UJzULA.yo7YoUUHV Yv7u9lwbThpYEYLF7CplCTBN9vUBWkwvd6OJCCCVK0bNCGxaiwoQVwco4W3IKpnokZv578EvJckM agJsyJyuVD5vZhXmGHCIZ7Hahh_Lc7zgOGUM3atgw4tsDb4ef4yGu10ZoLMwVlEcfmc7LkOpCUjX LJgAC6oAvYv4M.a8chUUMf4Rl.xOPfWqNpBP.Fw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.ne1.yahoo.com with HTTP; Mon, 26 Nov 2018 23:38:27 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.105]) ([67.169.65.224]) by smtp417.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 453e085596c4061cfe71d166fcd08f8b; Mon, 26 Nov 2018 23:38:23 +0000 (UTC) Subject: [PATCH v5 15/38] LSM: Split LSM preparation from initialization To: James Morris , LSM , LKLM , SE Linux Cc: John Johansen , Kees Cook , Tetsuo Handa , Paul Moore , "linux-fsdevel@vger.kernel.org" , Stephen Smalley , Alexey Dobriyan , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , Salvatore Mesoraca References: <50db058a-7dde-441b-a7f9-f6837fe8b69f@schaufler-ca.com> From: Casey Schaufler Message-ID: Date: Mon, 26 Nov 2018 15:38:20 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <50db058a-7dde-441b-a7f9-f6837fe8b69f@schaufler-ca.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since we already have to do a pass through the LSMs to figure out if exclusive LSMs should be disabled after the first one is seen as enabled, this splits the logic up a bit more cleanly. Now we do a full "prepare" pass through the LSMs (which also allows for later use by the blob-sharing code), before starting the LSM initialization pass. Signed-off-by: Kees Cook --- security/security.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/security/security.c b/security/security.c index df71b54c1ba4..3fac0ff39944 100644 --- a/security/security.c +++ b/security/security.c @@ -139,22 +139,28 @@ static bool __init lsm_allowed(struct lsm_info *lsm) return true; } -/* Check if LSM should be initialized. */ -static void __init maybe_initialize_lsm(struct lsm_info *lsm) +/* Prepare LSM for initialization. */ +static void __init prepare_lsm(struct lsm_info *lsm) { int enabled = lsm_allowed(lsm); /* Record enablement (to handle any following exclusive LSMs). */ set_enabled(lsm, enabled); - /* If selected, initialize the LSM. */ + /* If enabled, do pre-initialization work. */ if (enabled) { - int ret; - if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) { exclusive = lsm; init_debug("exclusive chosen: %s\n", lsm->name); } + } +} + +/* Initialize a given LSM, if it is enabled. */ +static void __init initialize_lsm(struct lsm_info *lsm) +{ + if (is_enabled(lsm)) { + int ret; init_debug("initializing %s\n", lsm->name); ret = lsm->init(); @@ -240,7 +246,10 @@ static void __init ordered_lsm_init(void) ordered_lsm_parse(builtin_lsm_order, "builtin"); for (lsm = ordered_lsms; *lsm; lsm++) - maybe_initialize_lsm(*lsm); + prepare_lsm(*lsm); + + for (lsm = ordered_lsms; *lsm; lsm++) + initialize_lsm(*lsm); kfree(ordered_lsms); } -- 2.14.5