All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Moved module init-functions into the module.
@ 2017-06-22  6:55 ` Steve Kemp
  0 siblings, 0 replies; 6+ messages in thread
From: Steve Kemp @ 2017-06-22  6:55 UTC (permalink / raw)
  To: linux-security-module


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.

Signed-off-by: Steve Kemp <steve@steve.fi>

---
 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..3d61010a 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;
 }
 
+late_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..1475acd 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;
 }
+
+late_initcall(yama_add_hooks);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] Moved module init-functions into the module.
@ 2017-06-22  6:55 ` Steve Kemp
  0 siblings, 0 replies; 6+ messages in thread
From: Steve Kemp @ 2017-06-22  6:55 UTC (permalink / raw)
  To: linux-security-module
  Cc: linux-kernel, Kees Cook, James Morris, Serge E. Hallyn


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.

Signed-off-by: Steve Kemp <steve@steve.fi>

---
 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..3d61010a 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;
 }
 
+late_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..1475acd 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;
 }
+
+late_initcall(yama_add_hooks);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] Moved module init-functions into the module.
  2017-06-22  6:55 ` Steve Kemp
@ 2017-06-22  8:02   ` Ethan Zhao
  -1 siblings, 0 replies; 6+ messages in thread
From: Ethan Zhao @ 2017-06-22  8:02 UTC (permalink / raw)
  To: linux-security-module

Steve,
      Seems you moved the initialization of security module to
late_initcall stage, that is not right.

      Functions defined with late_initcall() macro will be done pretty
late than  security_init().

      For security modules, you should use security_initcall() macro to define
the init functions.

Reviewed-by:  Ethan Zhao <ethan.zhao@oracle.com>




On Thu, Jun 22, 2017 at 2:55 PM, Steve Kemp <steve@steve.fi> 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.
>
> Signed-off-by: Steve Kemp <steve@steve.fi>
>
> ---
>  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..3d61010a 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;
>  }
>
> +late_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..1475acd 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;
>  }
> +
> +late_initcall(yama_add_hooks);
> --
> 2.1.4
>
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Moved module init-functions into the module.
@ 2017-06-22  8:02   ` Ethan Zhao
  0 siblings, 0 replies; 6+ messages in thread
From: Ethan Zhao @ 2017-06-22  8:02 UTC (permalink / raw)
  To: Steve Kemp
  Cc: linux-security-module, LKML, Kees Cook, James Morris,
	Serge E. Hallyn

Steve,
      Seems you moved the initialization of security module to
late_initcall stage, that is not right.

      Functions defined with late_initcall() macro will be done pretty
late than  security_init().

      For security modules, you should use security_initcall() macro to define
the init functions.

Reviewed-by:  Ethan Zhao <ethan.zhao@oracle.com>




On Thu, Jun 22, 2017 at 2:55 PM, Steve Kemp <steve@steve.fi> 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.
>
> Signed-off-by: Steve Kemp <steve@steve.fi>
>
> ---
>  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..3d61010a 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;
>  }
>
> +late_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..1475acd 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;
>  }
> +
> +late_initcall(yama_add_hooks);
> --
> 2.1.4
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Moved module init-functions into the module.
  2017-06-22  8:02   ` Ethan Zhao
@ 2017-06-22  8:09     ` Steve Kemp
  -1 siblings, 0 replies; 6+ messages in thread
From: Steve Kemp @ 2017-06-22  8:09 UTC (permalink / raw)
  To: linux-security-module

On Thu Jun 22, 2017 at 16:02:30 +0800, Ethan Zhao wrote:

>       Seems you moved the initialization of security module to
> late_initcall stage, that is not right.

  Thanks for the feedback.

>       For security modules, you should use security_initcall() macro to define
> the init functions.

  Literally just a change like this?

  -late_initcall(yama_add_hooks);
  +security_initcall(yama_add_hooks);

  I'll submit v2 with that shortly, thanks.

Steve
-- 
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Moved module init-functions into the module.
@ 2017-06-22  8:09     ` Steve Kemp
  0 siblings, 0 replies; 6+ messages in thread
From: Steve Kemp @ 2017-06-22  8:09 UTC (permalink / raw)
  To: Ethan Zhao
  Cc: Steve Kemp, linux-security-module, LKML, Kees Cook, James Morris,
	Serge E. Hallyn

On Thu Jun 22, 2017 at 16:02:30 +0800, Ethan Zhao wrote:

>       Seems you moved the initialization of security module to
> late_initcall stage, that is not right.

  Thanks for the feedback.

>       For security modules, you should use security_initcall() macro to define
> the init functions.

  Literally just a change like this?

  -late_initcall(yama_add_hooks);
  +security_initcall(yama_add_hooks);

  I'll submit v2 with that shortly, thanks.

Steve
-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-06-22  8:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-22  6:55 [PATCH] Moved module init-functions into the module Steve Kemp
2017-06-22  6:55 ` Steve Kemp
2017-06-22  8:02 ` Ethan Zhao
2017-06-22  8:02   ` Ethan Zhao
2017-06-22  8:09   ` Steve Kemp
2017-06-22  8:09     ` Steve Kemp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.