Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2218835imm; Thu, 20 Sep 2018 09:30:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYUZFarou8Ckb5JgD9nMjAjTa3A0vP0SdLGMhytcDQyngQIMCx3VbFNjpQ48JIAtXLVbdvY X-Received: by 2002:a63:5b63:: with SMTP id l35-v6mr37825249pgm.50.1537461040907; Thu, 20 Sep 2018 09:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537461040; cv=none; d=google.com; s=arc-20160816; b=wt3WUFKnF8OOJE2l7XMgnSE7ua+F1t4/uShyN4d8bsUvf+F7DxiZMI5RvTldFr0OzQ 3YEuge8LwJ5d0uXqzt/sujA91XxExlaRhGCmAVNKFXXdbQaB6QDSI+SYz15lYrkZ5u6K 9JhHcuYNHE6xwTDThvgk8r6h5JXjiSim2tLWNdHeFoOx9K4QNnqW2C5QazOzrYJkFtRM J0b9vQ9jst3i4sUhEpm7Jn6EHl4yrjx87De/ZlgkCfK0B33Fq9MA0mqDRPKY5AjNUHDv 819+YAGI5hP28Yfpgs17KJlrh4E7EcDgHL4rmTBzQy8KtOhOY5areR6PWLJNGnTtpn+X uv9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=NyWMd8rVkpihbr4KDxBE72JP3/jiqTkQ3QerKHyyizk=; b=uN9sHAP1QHJJslnn3D3jeBh2Z4COiZH0zKodQkkt0tPRuMXcsUqTkI6WBt3YEeLLdA O9IPBrlCUkYwAVMKZfrGRZozooKUnP+JHUuqyoRSRCsKpn5DJMCvr8Ai0GFXjZCIXC4P /4KB7cUN0rRF11MUam7K4ZKLLaEgnpN4MDC+acZf62hO16Ryh+Z0Elxu9OLWZEgbTXLA ogVy1XaeEB4QDH9p3hXeE/MkRWhDfRbw0bAQROiVzCDsRwEEFj4Q1u1dil7hysc649HR aWySCcyFM1S4Ce7BA1du/XzEG+nwewhXIKNq+8IKxzogh5o7QrPY37J7NW8Eq+W29oTi 0iGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ahZIpUG0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11-v6si24176909plg.453.2018.09.20.09.30.24; Thu, 20 Sep 2018 09:30:40 -0700 (PDT) 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=@chromium.org header.s=google header.b=ahZIpUG0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387874AbeITWN7 (ORCPT + 99 others); Thu, 20 Sep 2018 18:13:59 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:37321 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387809AbeITWN5 (ORCPT ); Thu, 20 Sep 2018 18:13:57 -0400 Received: by mail-pf1-f193.google.com with SMTP id h69-v6so4624991pfd.4 for ; Thu, 20 Sep 2018 09:29:40 -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=NyWMd8rVkpihbr4KDxBE72JP3/jiqTkQ3QerKHyyizk=; b=ahZIpUG0/YIgUgOjo2yfsN1C80IDhpbgbwdaDUX61WMGT+3KWeBpvoiYiDREs2lCB7 vy3usl9Y7vVuitETM7OnvmrNczgIUxmTaQB16iac/kJQDTOotMAHtNJL1+ZMqof1qm+V vwls64q1Ri/gH1PS899TUpkFzQl7igHNAH52Q= 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=NyWMd8rVkpihbr4KDxBE72JP3/jiqTkQ3QerKHyyizk=; b=phUOxYSpNPyUgjOtjWsKDKNiaWioEBnLyThOQhwHHADbD3D7iisOLH5ij0KqS9cXkb QgFP+alyWFrppXKqB9XDJGuSb8L9zQ4IB6jO1ernpvUiqWfcW7Wux08z/FJLjpkRmnME bp6YfOUt756o3e15pfsMShjqpqVmesgxrhwKehekor2+bQaH40+uGqOB5foTOMx8ODrI 9ZoFsyqRbbsgRdkHlWp0EQ1DMaNquYb8DwrLErOsIHU4OwtDXzDgvsZtX56WKpz3HUaF 7UEFHRJ6cOY2n75xkP1rCLE7VMjFwNb0b+3AK5jMxn9PqQLt37dlOa6pGfA/uTQLfWAp 7J2A== X-Gm-Message-State: APzg51BYzHC1hMnejFryW3XJ3Q2axS4zrgUd23Wc+GBKWs/DELa3HJm/ Vc7OBkFtKi2DESd4GTudPP4WiA== X-Received: by 2002:a63:3dc6:: with SMTP id k189-v6mr37518264pga.191.1537460980226; Thu, 20 Sep 2018 09:29:40 -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 k64-v6sm36455796pfg.141.2018.09.20.09.29.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 09:29:39 -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 v2 25/26] LSM: Separate idea of "major" LSM from "exclusive" LSM Date: Thu, 20 Sep 2018 09:23:37 -0700 Message-Id: <20180920162338.21060-26-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920162338.21060-1-keescook@chromium.org> References: <20180920162338.21060-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to both support old "security=" Legacy Major LSM selection, and handling real exclusivity, this creates LSM_FLAG_EXCLUSIVE and updates the selection logic to handle them. Signed-off-by: Kees Cook --- include/linux/lsm_hooks.h | 1 + security/apparmor/lsm.c | 2 +- security/security.c | 12 ++++++++++++ security/selinux/hooks.c | 2 +- security/smack/smack_lsm.c | 2 +- security/tomoyo/tomoyo.c | 2 +- 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 8e843eaacffb..7d9c94d31279 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2040,6 +2040,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count, char *lsm); #define LSM_FLAG_LEGACY_MAJOR (1 << 0) +#define LSM_FLAG_EXCLUSIVE (2 << 0) enum lsm_order { LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 5399c2f03536..d68bc931d388 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1601,7 +1601,7 @@ static int __init apparmor_init(void) } DEFINE_LSM(apparmor) - .flags = LSM_FLAG_LEGACY_MAJOR, + .flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE, .enabled = &apparmor_enabled, .init = apparmor_init, END_LSM; diff --git a/security/security.c b/security/security.c index a40e938db1b0..f076fdc6b451 100644 --- a/security/security.c +++ b/security/security.c @@ -49,6 +49,7 @@ static __initconst const char * const builtin_lsm_order = CONFIG_LSM_ORDER; /* Ordered list of LSMs to initialize. */ static __initdata struct lsm_info **ordered_lsms; +static __initdata struct lsm_info *exclusive; static bool debug __initdata; #define init_debug(...) \ @@ -181,6 +182,12 @@ static bool __init lsm_allowed(struct lsm_info *lsm) if (lsm->enabled && !*lsm->enabled) return false; + /* Not allowed if another exclusive LSM already initialized. */ + if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && exclusive) { + init_debug("exclusive disabled: %s\n", lsm->name); + return false; + } + return true; } @@ -196,6 +203,11 @@ static void __init maybe_initialize_lsm(struct lsm_info *lsm) if (enabled) { int ret; + if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) { + exclusive = lsm; + init_debug("exclusive: %s\n", lsm->name); + } + init_debug("initializing %s\n", lsm->name); ret = lsm->init(); WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 409a9252aeb6..5461d54fcd99 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -7193,7 +7193,7 @@ void selinux_complete_init(void) /* SELinux requires early initialization in order to label all processes and objects when they are created. */ DEFINE_LSM(selinux) - .flags = LSM_FLAG_LEGACY_MAJOR, + .flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE, .enabled = &selinux_enabled, .init = selinux_init, END_LSM; diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index e79fad43a8e3..e46c1ea8cf84 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4880,6 +4880,6 @@ static __init int smack_init(void) * all processes and objects when they are created. */ DEFINE_LSM(smack) - .flags = LSM_FLAG_LEGACY_MAJOR, + .flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE, .init = smack_init, END_LSM; diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c index 39bb994ebe09..cc39eb8df61a 100644 --- a/security/tomoyo/tomoyo.c +++ b/security/tomoyo/tomoyo.c @@ -549,6 +549,6 @@ static int __init tomoyo_init(void) } DEFINE_LSM(tomoyo) - .flags = LSM_FLAG_LEGACY_MAJOR, + .flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE, .init = tomoyo_init, END_LSM; -- 2.17.1