From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753476AbdFVQyi (ORCPT ); Thu, 22 Jun 2017 12:54:38 -0400 Received: from nm27-vm5.bullet.mail.ne1.yahoo.com ([98.138.91.249]:39983 "EHLO nm27-vm5.bullet.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752123AbdFVQyh (ORCPT ); Thu, 22 Jun 2017 12:54:37 -0400 X-Yahoo-Newman-Id: 397373.49608.bm@smtp222.mail.ne1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 0zRIrDoVM1moK8ubmBuomNKjUYsy0bPLZlASbeqXam7ZANJ jFjA1yHRn7xa3.ovbb0TwOoI7k3q1PrBSHjP6HbiZVzVp0J1CPxjfD52ze7g n_0zX670y4PxM9tceuVg2XfsB4TBF2pYNse.asEHwNF87vfhmL83Mh65XsXM gqxcxnkcK4wCPd.7t16cuyrqv1cdcpWY1ltJJfE3dJr4Uv6XZFDoffM8uGVw swotxlbLzCXEkQ5zNYQvQXadpLitLz28vtOcwSkqJfxvIO_8nh3.DyPSaicO Hiog7wG1pDBVqVnZYdLc3CmUdMCTLKG95tjQ.ja3a9qpW3nypPWV1J8mHA9t XyjDlxYo7IkHs_hFm_bJcLoqbOLHpGImf96DhT66B.RnS1uecuUaiA.Eo67K IyKQy1obUc_kOVlV7YVhIDhOeTCFxI1oDHimOKdhbJNHvAIOMxLSKjPap_ZG ROILClJUAcenLYIV5XVkWYXujG4uEMvFAPg2QPihOpXpY4DdyDFTlU__xTrN wwq0fo5vuXuyO3LOhLlCLg1rzyptYdzuMav1EC7DvYRrpu1_4q3gxKuxA.y5 4rX0- X-Yahoo-SMTP: OIJXglSswBDfgLtXluJ6wiAYv6_cnw-- Subject: Re: [PATCH v2] Moved module init-functions into the module. To: Steve Kemp , linux-security-module@vger.kernel.org Cc: LKML , Kees Cook , James Morris , "Serge E. Hallyn" References: <20170622084507.GA4025@steve.org.uk> From: Casey Schaufler Message-ID: <589cbc78-2256-2334-e907-2e440f99b612@schaufler-ca.com> Date: Thu, 22 Jun 2017 09:54:33 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20170622084507.GA4025@steve.org.uk> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/22/2017 1:45 AM, Steve Kemp wrote: > This commit moves the call to initialize the LSM modules inline > into the LSM-files themselves. > > This removes the need to hunt around for the setup, which was > something that bit me when I wrote my own (unrelated) LSM. > > Keeping LSM code in one place, including the setup of the > hooks seems like a sane choice. The module initialization code belongs in the module. The LSM infrastructure should have an absolute minimum of module specific information. I would rather see the "minor" modules (yama, loadpin) changed to use the module registration scheme used by the "major" modules, but that will require a mechanism to ensure module ordering, and we don't have that yet. No, don't do this. > > This patch has been updated to use `security_init`, as per > feedback from Ethan Zhao. This should ensure that the > LSM init is called "early". > > Signed-off-by: Steve Kemp > --- > include/linux/lsm_hooks.h | 10 ---------- > security/loadpin/loadpin.c | 5 ++++- > security/security.c | 2 -- > security/yama/yama_lsm.c | 5 ++++- > 4 files changed, 8 insertions(+), 14 deletions(-) > > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > index 080f34e..a6dbdc7 100644 > --- a/include/linux/lsm_hooks.h > +++ b/include/linux/lsm_hooks.h > @@ -1936,15 +1936,5 @@ static inline void security_delete_hooks(struct security_hook_list *hooks, > > extern int __init security_module_enable(const char *module); > extern void __init capability_add_hooks(void); > -#ifdef CONFIG_SECURITY_YAMA > -extern void __init yama_add_hooks(void); > -#else > -static inline void __init yama_add_hooks(void) { } > -#endif > -#ifdef CONFIG_SECURITY_LOADPIN > -void __init loadpin_add_hooks(void); > -#else > -static inline void loadpin_add_hooks(void) { }; > -#endif > > #endif /* ! __LINUX_LSM_HOOKS_H */ > diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c > index dbe6efd..127eb5ca 100644 > --- a/security/loadpin/loadpin.c > +++ b/security/loadpin/loadpin.c > @@ -179,12 +179,15 @@ static struct security_hook_list loadpin_hooks[] __lsm_ro_after_init = { > LSM_HOOK_INIT(kernel_read_file, loadpin_read_file), > }; > > -void __init loadpin_add_hooks(void) > +static int __init loadpin_add_hooks(void) > { > pr_info("ready to pin (currently %sabled)", enabled ? "en" : "dis"); > security_add_hooks(loadpin_hooks, ARRAY_SIZE(loadpin_hooks), "loadpin"); > + return 0; > } > > +security_initcall(loadpin_add_hooks); > + > /* Should not be mutable after boot, so not listed in sysfs (perm == 0). */ > module_param(enabled, int, 0); > MODULE_PARM_DESC(enabled, "Pin module/firmware loading (default: true)"); > diff --git a/security/security.c b/security/security.c > index b9fea39..110b85b 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -67,8 +67,6 @@ int __init security_init(void) > * Load minor LSMs, with the capability module always first. > */ > capability_add_hooks(); > - yama_add_hooks(); > - loadpin_add_hooks(); > > /* > * Load all the remaining security modules. > diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c > index 8298e09..e3c1d10 100644 > --- a/security/yama/yama_lsm.c > +++ b/security/yama/yama_lsm.c > @@ -482,9 +482,12 @@ static void __init yama_init_sysctl(void) > static inline void yama_init_sysctl(void) { } > #endif /* CONFIG_SYSCTL */ > > -void __init yama_add_hooks(void) > +static int __init yama_add_hooks(void) > { > pr_info("Yama: becoming mindful.\n"); > security_add_hooks(yama_hooks, ARRAY_SIZE(yama_hooks), "yama"); > yama_init_sysctl(); > + return 0; > } > + > +security_initcall(yama_add_hooks);