All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] security: don't treat structure as an array of struct hlist_head
@ 2022-04-07 17:59 Bill Wendling
  2022-04-12 17:26 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Bill Wendling @ 2022-04-07 17:59 UTC (permalink / raw)
  To: Kees Cook, James Morris, Serge E. Hallyn, linux-hardening,
	linux-kernel, linux-security-module
  Cc: Bill Wendling

The initialization of "security_hook_heads" is done by casting it to
another structure pointer type, and treating it as an array of "struct
hlist_head" objects. This requires an exception be made in "randstruct",
because otherwise it will emit an error, reducing the effectiveness of
the hardening technique.

Instead of using a cast, initialize the individual struct hlist_head
elements in security_hook_heads explicitly. This removes the need for
the cast and randstruct exception.

Signed-off-by: Bill Wendling <morbo@google.com>
Cc: Kees Cook <keescook@chromium.org>
---
 scripts/gcc-plugins/randomize_layout_plugin.c | 2 --
 security/security.c                           | 9 ++++-----
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
index 334741a31d0a..c2ec81b68505 100644
--- a/scripts/gcc-plugins/randomize_layout_plugin.c
+++ b/scripts/gcc-plugins/randomize_layout_plugin.c
@@ -52,8 +52,6 @@ static const struct whitelist_entry whitelist[] = {
 	{ "net/unix/af_unix.c", "unix_skb_parms", "char" },
 	/* big_key payload.data struct splashing */
 	{ "security/keys/big_key.c", "path", "void *" },
-	/* walk struct security_hook_heads as an array of struct hlist_head */
-	{ "security/security.c", "hlist_head", "security_hook_heads" },
 	{ }
 };
 
diff --git a/security/security.c b/security/security.c
index b7cf5cbfdc67..37a9eeb901e0 100644
--- a/security/security.c
+++ b/security/security.c
@@ -365,13 +365,12 @@ static void __init ordered_lsm_init(void)
 
 int __init early_security_init(void)
 {
-	int i;
-	struct hlist_head *list = (struct hlist_head *) &security_hook_heads;
 	struct lsm_info *lsm;
 
-	for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head);
-	     i++)
-		INIT_HLIST_HEAD(&list[i]);
+#define LSM_HOOK(RET, DEFAULT, NAME, ...) \
+	INIT_HLIST_HEAD(&security_hook_heads.NAME);
+#include "linux/lsm_hook_defs.h"
+#undef LSM_HOOK
 
 	for (lsm = __start_early_lsm_info; lsm < __end_early_lsm_info; lsm++) {
 		if (!lsm->enabled)
-- 
2.35.1.1178.g4f1659d476-goog


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

* Re: [PATCH] security: don't treat structure as an array of struct hlist_head
  2022-04-07 17:59 [PATCH] security: don't treat structure as an array of struct hlist_head Bill Wendling
@ 2022-04-12 17:26 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2022-04-12 17:26 UTC (permalink / raw)
  To: Bill Wendling
  Cc: James Morris, Serge E. Hallyn, linux-hardening, linux-kernel,
	linux-security-module

On Thu, Apr 07, 2022 at 10:59:30AM -0700, Bill Wendling wrote:
> The initialization of "security_hook_heads" is done by casting it to
> another structure pointer type, and treating it as an array of "struct
> hlist_head" objects. This requires an exception be made in "randstruct",
> because otherwise it will emit an error, reducing the effectiveness of
> the hardening technique.
> 
> Instead of using a cast, initialize the individual struct hlist_head
> elements in security_hook_heads explicitly. This removes the need for
> the cast and randstruct exception.
> 
> Signed-off-by: Bill Wendling <morbo@google.com>
> Cc: Kees Cook <keescook@chromium.org>

Ah! Yes, thanks. This is a good solution for this. I'd rather not have
any exceptions in the randstruct plugin. :) I'll take this via the
hardening tree unless anyone objects.

-Kees

-- 
Kees Cook

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

end of thread, other threads:[~2022-04-12 17:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 17:59 [PATCH] security: don't treat structure as an array of struct hlist_head Bill Wendling
2022-04-12 17:26 ` Kees Cook

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.