From patchwork Tue Sep 25 00:18:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10613137 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A15AD17D2 for ; Tue, 25 Sep 2018 00:25:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E52729F00 for ; Tue, 25 Sep 2018 00:25:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C58429FB6; Tue, 25 Sep 2018 00:25:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 284E829F53 for ; Tue, 25 Sep 2018 00:25:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728328AbeIYGaN (ORCPT ); Tue, 25 Sep 2018 02:30:13 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:33214 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728153AbeIYGaK (ORCPT ); Tue, 25 Sep 2018 02:30:10 -0400 Received: by mail-pf1-f193.google.com with SMTP id d4-v6so9940356pfn.0 for ; Mon, 24 Sep 2018 17:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=na71TelZGQ6m9GWmFesTEQd4UFPGStcPcyELJo/B8RM=; b=WT0YX7zWHH6WAFUpHrLCf6WlHBYsAnIO+a8HgEj8X2cHErLyMHE4+4lURbnqC9RSWP OAI/QXRK7mPFoG6493qlcbXboTjzJt9RnSjNs6ynisvoaqJDem5XEBsJFacRmRblesy5 zO8Y4O737dUtgCyCSBjo26tzCLDAdhdaVZOI4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=na71TelZGQ6m9GWmFesTEQd4UFPGStcPcyELJo/B8RM=; b=CQWrcMviTBfvOpuT4Z8dw8YILbvGgSK3Y5nGyry0bavaW+KEcZnwEUMKOrUs8Je9X2 bWYFx5KX2YzbBqlVzHgllSJHRWj7HyBCnd5s9HGCtQquzo7WqyvIk4OS/EHQ6pDnl60W hA9g7iZfFzV7/DsRCNmaVeAH0gcRixIdIUOo6kcftpXvFTl33KIG075btuNMGKrrYtyc pEFQtFCwC+ltsWFvaHzksoraBKtwWtGg3dzG+bxbo0AcpHhbUTmL0hF/wYfRgeDrcK5L HsejcrikPiAJ2IXtCTtK4FhBEmTxxGO0McnIFcKlfOSXbc69aSGCb4upwDC7d/upZcSD kyXQ== X-Gm-Message-State: ABuFfoj9KH8GtiGNngw16EJBzqBt+JlyzosNfF7MuaHdZ9TQaZGhIGhN 7ghqxbizB4pm3PamISyngOHl9w== X-Google-Smtp-Source: ACcGV63fiF8Usp5VDSHevpjSdzhvKONFzj5aTYfHcBlazhkjuEJWBw3JJudQ4OVRL0TAURsxjxz1Aw== X-Received: by 2002:a65:608b:: with SMTP id t11-v6mr936718pgu.259.1537835121914; Mon, 24 Sep 2018 17:25:21 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id v190-v6sm547521pgb.16.2018.09.24.17.25.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Sep 2018 17:25:20 -0700 (PDT) From: Kees Cook To: James Morris Cc: Kees Cook , Casey Schaufler , John Johansen , Tetsuo Handa , Paul Moore , Stephen Smalley , "Schaufler, Casey" , LSM , Jonathan Corbet , linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH security-next v3 20/29] LSM: Refactor "security=" in terms of enable/disable Date: Mon, 24 Sep 2018 17:18:23 -0700 Message-Id: <20180925001832.18322-21-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180925001832.18322-1-keescook@chromium.org> References: <20180925001832.18322-1-keescook@chromium.org> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP For what are marked as the Legacy Major LSMs, make them effectively exclusive when selected on the "security=" boot parameter, to handle the future case of when a previously major LSMs become non-exclusive (e.g. when TOMOYO starts blob-sharing). Signed-off-by: Kees Cook --- security/security.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/security/security.c b/security/security.c index e325fcc41f00..a98549b334af 100644 --- a/security/security.c +++ b/security/security.c @@ -103,14 +103,6 @@ static bool __init lsm_allowed(struct lsm_info *lsm) if (!is_enabled(lsm)) return false; - /* Skip major-specific checks if not a major LSM. */ - if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0) - return true; - - /* Disabled if this LSM isn't the chosen one. */ - if (strcmp(lsm->name, chosen_major_lsm) != 0) - return false; - return true; } @@ -188,8 +180,24 @@ static void __init prepare_lsm_enable(void) parse_lsm_enable(chosen_lsm_enable, set_enabled, true); parse_lsm_enable(chosen_lsm_disable, set_enabled, false); + /* Process "security=", if given. */ if (!chosen_major_lsm) chosen_major_lsm = CONFIG_DEFAULT_SECURITY; + if (chosen_major_lsm) { + struct lsm_info *lsm; + + /* + * To match the original "security=" behavior, this + * explicitly does NOT fallback to another Legacy Major + * if the selected one was separately disabled: disable + * all non-matching Legacy Major LSMs. + */ + for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { + if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) && + strcmp(lsm->name, chosen_major_lsm) != 0) + set_enabled(lsm, false); + } + } } /**