From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Subject: [PATCH security-next v4 30/32] capability: Initialize as LSM_ORDER_FIRST Date: Mon, 1 Oct 2018 17:55:03 -0700 Message-ID: <20181002005505.6112-31-keescook@chromium.org> References: <20181002005505.6112-1-keescook@chromium.org> Return-path: In-Reply-To: <20181002005505.6112-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org 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 List-Id: linux-arch.vger.kernel.org This converts capabilities to use the new LSM_ORDER_FIRST position. Signed-off-by: Kees Cook Reviewed-by: Casey Schaufler --- include/linux/lsm_hooks.h | 2 -- security/commoncap.c | 9 ++++++++- security/security.c | 9 ++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 62bc230826e0..36e7a716fdfe 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2092,6 +2092,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..c928eb3fe784 100644 --- a/security/commoncap.c +++ b/security/commoncap.c @@ -1366,10 +1366,17 @@ 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) = { + .name = "capability", + .order = LSM_ORDER_FIRST, + .init = capability_init, +}; + #endif /* CONFIG_SECURITY */ diff --git a/security/security.c b/security/security.c index dac379518e60..813dab3b5b97 100644 --- a/security/security.c +++ b/security/security.c @@ -62,6 +62,10 @@ static __initdata bool debug; 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; @@ -306,11 +310,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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-f65.google.com ([209.85.166.65]:42879 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727281AbeJBHf4 (ORCPT ); Tue, 2 Oct 2018 03:35:56 -0400 Received: by mail-io1-f65.google.com with SMTP id n18-v6so241962ioa.9 for ; Mon, 01 Oct 2018 17:55:27 -0700 (PDT) From: Kees Cook Subject: [PATCH security-next v4 30/32] capability: Initialize as LSM_ORDER_FIRST Date: Mon, 1 Oct 2018 17:55:03 -0700 Message-ID: <20181002005505.6112-31-keescook@chromium.org> In-Reply-To: <20181002005505.6112-1-keescook@chromium.org> References: <20181002005505.6112-1-keescook@chromium.org> Sender: linux-arch-owner@vger.kernel.org List-ID: 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 Message-ID: <20181002005503.LAliDgA8Cto-4w94pAbxHCZu1_d2ekDqdb4o3qI2oQE@z> This converts capabilities to use the new LSM_ORDER_FIRST position. Signed-off-by: Kees Cook Reviewed-by: Casey Schaufler --- include/linux/lsm_hooks.h | 2 -- security/commoncap.c | 9 ++++++++- security/security.c | 9 ++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 62bc230826e0..36e7a716fdfe 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2092,6 +2092,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..c928eb3fe784 100644 --- a/security/commoncap.c +++ b/security/commoncap.c @@ -1366,10 +1366,17 @@ 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) = { + .name = "capability", + .order = LSM_ORDER_FIRST, + .init = capability_init, +}; + #endif /* CONFIG_SECURITY */ diff --git a/security/security.c b/security/security.c index dac379518e60..813dab3b5b97 100644 --- a/security/security.c +++ b/security/security.c @@ -62,6 +62,10 @@ static __initdata bool debug; 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; @@ -306,11 +310,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