Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp121594oof; Mon, 24 Sep 2018 17:19:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV60+FpK7gXRY5g5TfkQqlz1pxFGk++YedEemZzZeFOAjRRUrRotz4xyyiVvM74GPS60EJj52 X-Received: by 2002:a65:5c46:: with SMTP id v6-v6mr900066pgr.21.1537834789291; Mon, 24 Sep 2018 17:19:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537834789; cv=none; d=google.com; s=arc-20160816; b=CvgFLvTnbgvdsoGmS7PF1dJjYkJR1GYX+xWk6dn+XLk7mxcU+sfPAwQh55L++O5UBN 14mdInw01EYmYAROkezs8yxyNiQbchf0e06r5ZVpg/XO3i0VbGdjgeq85lYvhQfR6haq S/3JQpraEfhYlJ51EEM6g7EZg1UJqR+I9L5pDkEREkKOVsVQyVrihCzkM/sZuFKo02mN PV34F9lo65aZfcCiWWL8K4ArylrSU6we+kOkVIwUSKrY4/LZE7gSm/JlkJOFxG/qkN5Y 3vVMzUd+nxpKaBpgvWOk3I3V4yWuoEqm7CQun1h7zif/xCB3KkQJFikZQcE666eFIrBi 0IWg== 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=FC/QKfEJBIYGajENgFeOjr6c8O9WQvcgfsZ6DqAb1iY=; b=V5NLGYk1TV2GyIGMguo3UnplSNVeOp7kjCLQ6ioKvJ7iSC5o0DqVX5GmMToOlPcbZo OzD2rSLYr1AJyuaY6Xg0RW8xeQRj3tkvpLgpSwnlR7Lo6WoXGMFsjTLyT1/2od+OCY60 bwn1SyWIU6NikiZzyHkszx3r532phUgyYSbBiuDjTQ7XCeZsqw6TqPZY8j7YXvUeHU5C NZFBZ3PBuhJeAXk82XoUrM5i3qmKMabUIZH8KokWlSlA3p3Vt3xCLepG8EBZ02zBjGu+ eSS8NFaq6TpM4thBSjNImIzJCFUeH3Yf6+QeK4YRuXgVICLacnSfmDWUm+NVu+Hrdkzh Q47A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=j40WdLdy; 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 o123-v6si730044pfd.36.2018.09.24.17.19.34; Mon, 24 Sep 2018 17:19:49 -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=j40WdLdy; 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 S1728849AbeIYGYD (ORCPT + 99 others); Tue, 25 Sep 2018 02:24:03 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36712 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728850AbeIYGXn (ORCPT ); Tue, 25 Sep 2018 02:23:43 -0400 Received: by mail-pg1-f196.google.com with SMTP id d1-v6so10118371pgo.3 for ; Mon, 24 Sep 2018 17:18:57 -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=FC/QKfEJBIYGajENgFeOjr6c8O9WQvcgfsZ6DqAb1iY=; b=j40WdLdyIbYENYwIgFmEWOcifIjaAw3581c2wJaONAih3gdzAeKVhQgA+Bvqc2OX20 jKeeiiqKlVVGo8An0aCZmJhCN+/At8m4VHwgn0lUvvdJ+EGOvVFTOSwI3nTXgCdrgiTl FEq0mmGCl1eLkJ5DYIwwtWnSe3WTyYlbUfI7k= 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=FC/QKfEJBIYGajENgFeOjr6c8O9WQvcgfsZ6DqAb1iY=; b=sc7n/uIZ0J44HeGpLmwwDJfef3umk7FgCa0F+mqTSbp2PMkjOW7hn+Q+vjtY5bQHN8 TEs08mhPBwee7HFh4RH8Qgp/PFRB7wxQ6/g2cLb+TsCnj1MCMiWo5mny0mdouCX4yoWk /qISJpYzo1gk5SfvA2S2uwG5FzW5leJpGW0UX/a58Wt1TuxOomZvtYY4z+Hi9GGa0pMd Sem7q24JbOTmdybSeg9XwWhq9lii0LuqsWi6gCajZ8N5OhOQKogc2xJkz/W0Rjeq+gd/ flt+5qdjyBf0MnTSsOXjBclck9kOInCuDREflqEIVayAc24pJKBR+TOvebIsHGMDCRq2 01hA== X-Gm-Message-State: ABuFfoiEaWUAJXK3+qhkJ47P8xEjFc+QH75Td27Npwkd3huebrqQbpD7 OpZaGPdbWdI+zBe9nXa+Aq30bw== X-Received: by 2002:a62:69c9:: with SMTP id e192-v6mr981027pfc.35.1537834737132; Mon, 24 Sep 2018 17:18:57 -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 b73-v6sm661299pfj.93.2018.09.24.17.18.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Sep 2018 17:18:48 -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 27/29] capability: Initialize as LSM_ORDER_FIRST Date: Mon, 24 Sep 2018 17:18:30 -0700 Message-Id: <20180925001832.18322-28-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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This converts capabilities to use the new LSM_ORDER_FIRST position. Signed-off-by: Kees Cook --- include/linux/lsm_hooks.h | 2 -- security/commoncap.c | 8 +++++++- security/security.c | 9 ++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index b38902ea0be5..950042fb2385 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2098,6 +2098,4 @@ static inline void security_delete_hooks(struct security_hook_list *hooks, #define __lsm_ro_after_init __ro_after_init #endif /* CONFIG_SECURITY_WRITABLE_HOOKS */ -extern void __init capability_add_hooks(void); - #endif /* ! __LINUX_LSM_HOOKS_H */ diff --git a/security/commoncap.c b/security/commoncap.c index 2e489d6a3ac8..7a6abaec65de 100644 --- a/security/commoncap.c +++ b/security/commoncap.c @@ -1366,10 +1366,16 @@ struct security_hook_list capability_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(vm_enough_memory, cap_vm_enough_memory), }; -void __init capability_add_hooks(void) +static int __init capability_init(void) { security_add_hooks(capability_hooks, ARRAY_SIZE(capability_hooks), "capability"); + return 0; } +DEFINE_LSM(capability) + .order = LSM_ORDER_FIRST, + .init = capability_init, +END_LSM; + #endif /* CONFIG_SECURITY */ diff --git a/security/security.c b/security/security.c index 8b93afa75e3c..ade74b90b73c 100644 --- a/security/security.c +++ b/security/security.c @@ -62,6 +62,10 @@ static bool debug __initdata; static bool __init is_enabled(struct lsm_info *lsm) { + /* LSM_ORDER_FIRST is always enabled. */ + if (lsm->order == LSM_ORDER_FIRST) + return true; + if (WARN_ON(!lsm->enabled)) return false; @@ -314,11 +318,6 @@ int __init security_init(void) /* Figure out which LSMs are enabled and disabled. */ prepare_lsm_enable(); - /* - * Load minor LSMs, with the capability module always first. - */ - capability_add_hooks(); - /* Load LSMs in specified order. */ prepare_lsm_order(); ordered_lsm_init(); -- 2.17.1