All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fortify: Adjust KUnit test for modular build
@ 2022-09-13 17:31 Kees Cook
  2022-09-13 22:05 ` Nathan Chancellor
  2022-09-14 10:13 ` David Gow
  0 siblings, 2 replies; 4+ messages in thread
From: Kees Cook @ 2022-09-13 17:31 UTC (permalink / raw)
  To: linux-hardening; +Cc: Kees Cook, Nathan Chancellor, David Gow, linux-kernel

A much better "unknown size" string pointer is available directly from
struct test, so use that instead of a global that isn't shared with
modules.

Reported-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/lkml/YyCOHOchVuE/E7vS@dev-arch.thelio-3990X
Fixes: 875bfd5276f3 ("fortify: Add KUnit test for FORTIFY_SOURCE internals")
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Whoops! Thanks Nathan! :) This fixes it for your reproducer.
---
 lib/fortify_kunit.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/fortify_kunit.c b/lib/fortify_kunit.c
index 99bc0ea60d27..409af07f340a 100644
--- a/lib/fortify_kunit.c
+++ b/lib/fortify_kunit.c
@@ -17,7 +17,6 @@
 
 #include <kunit/test.h>
 #include <linux/string.h>
-#include <linux/init.h>
 
 static const char array_of_10[] = "this is 10";
 static const char *ptr_of_11 = "this is 11!";
@@ -31,7 +30,7 @@ static void known_sizes_test(struct kunit *test)
 
 	KUNIT_EXPECT_EQ(test, __compiletime_strlen(array_unknown), SIZE_MAX);
 	/* Externally defined and dynamically sized string pointer: */
-	KUNIT_EXPECT_EQ(test, __compiletime_strlen(saved_command_line), SIZE_MAX);
+	KUNIT_EXPECT_EQ(test, __compiletime_strlen(test->name), SIZE_MAX);
 }
 
 /* This is volatile so the optimizer can't perform DCE below. */
-- 
2.34.1


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

* Re: [PATCH] fortify: Adjust KUnit test for modular build
  2022-09-13 17:31 [PATCH] fortify: Adjust KUnit test for modular build Kees Cook
@ 2022-09-13 22:05 ` Nathan Chancellor
  2022-09-14 10:13 ` David Gow
  1 sibling, 0 replies; 4+ messages in thread
From: Nathan Chancellor @ 2022-09-13 22:05 UTC (permalink / raw)
  To: Kees Cook; +Cc: linux-hardening, David Gow, linux-kernel

On Tue, Sep 13, 2022 at 10:31:36AM -0700, Kees Cook wrote:
> A much better "unknown size" string pointer is available directly from
> struct test, so use that instead of a global that isn't shared with
> modules.
> 
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Link: https://lore.kernel.org/lkml/YyCOHOchVuE/E7vS@dev-arch.thelio-3990X
> Fixes: 875bfd5276f3 ("fortify: Add KUnit test for FORTIFY_SOURCE internals")
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> Whoops! Thanks Nathan! :) This fixes it for your reproducer.

Confirmed :)

Build-tested-by: Nathan Chancellor <nathan@kernel.org>

Thanks for the quick fix!

> ---
>  lib/fortify_kunit.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/lib/fortify_kunit.c b/lib/fortify_kunit.c
> index 99bc0ea60d27..409af07f340a 100644
> --- a/lib/fortify_kunit.c
> +++ b/lib/fortify_kunit.c
> @@ -17,7 +17,6 @@
>  
>  #include <kunit/test.h>
>  #include <linux/string.h>
> -#include <linux/init.h>
>  
>  static const char array_of_10[] = "this is 10";
>  static const char *ptr_of_11 = "this is 11!";
> @@ -31,7 +30,7 @@ static void known_sizes_test(struct kunit *test)
>  
>  	KUNIT_EXPECT_EQ(test, __compiletime_strlen(array_unknown), SIZE_MAX);
>  	/* Externally defined and dynamically sized string pointer: */
> -	KUNIT_EXPECT_EQ(test, __compiletime_strlen(saved_command_line), SIZE_MAX);
> +	KUNIT_EXPECT_EQ(test, __compiletime_strlen(test->name), SIZE_MAX);
>  }
>  
>  /* This is volatile so the optimizer can't perform DCE below. */
> -- 
> 2.34.1
> 

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

* Re: [PATCH] fortify: Adjust KUnit test for modular build
  2022-09-13 17:31 [PATCH] fortify: Adjust KUnit test for modular build Kees Cook
  2022-09-13 22:05 ` Nathan Chancellor
@ 2022-09-14 10:13 ` David Gow
  2022-09-14 13:59   ` Kees Cook
  1 sibling, 1 reply; 4+ messages in thread
From: David Gow @ 2022-09-14 10:13 UTC (permalink / raw)
  To: Kees Cook; +Cc: linux-hardening, Nathan Chancellor, Linux Kernel Mailing List

On Wed, Sep 14, 2022 at 1:31 AM Kees Cook <keescook@chromium.org> wrote:
>
> A much better "unknown size" string pointer is available directly from
> struct test, so use that instead of a global that isn't shared with
> modules.
>
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Link: https://lore.kernel.org/lkml/YyCOHOchVuE/E7vS@dev-arch.thelio-3990X
> Fixes: 875bfd5276f3 ("fortify: Add KUnit test for FORTIFY_SOURCE internals")
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> Whoops! Thanks Nathan! :) This fixes it for your reproducer.

Ah, this is better than saved_command_line, IMO. I don't think it'd
necessarily be a _disaster_ to just introduce a new dynamically-sized
string here, which would be more explicit, but test->name is at least
obviously related to this file anyway.

Reviewed-by: David Gow <davidgow@google.com>

Cheers
-- David

> ---
>  lib/fortify_kunit.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/lib/fortify_kunit.c b/lib/fortify_kunit.c
> index 99bc0ea60d27..409af07f340a 100644
> --- a/lib/fortify_kunit.c
> +++ b/lib/fortify_kunit.c
> @@ -17,7 +17,6 @@
>
>  #include <kunit/test.h>
>  #include <linux/string.h>
> -#include <linux/init.h>
>
>  static const char array_of_10[] = "this is 10";
>  static const char *ptr_of_11 = "this is 11!";
> @@ -31,7 +30,7 @@ static void known_sizes_test(struct kunit *test)
>
>         KUNIT_EXPECT_EQ(test, __compiletime_strlen(array_unknown), SIZE_MAX);
>         /* Externally defined and dynamically sized string pointer: */
> -       KUNIT_EXPECT_EQ(test, __compiletime_strlen(saved_command_line), SIZE_MAX);
> +       KUNIT_EXPECT_EQ(test, __compiletime_strlen(test->name), SIZE_MAX);
>  }
>
>  /* This is volatile so the optimizer can't perform DCE below. */
> --
> 2.34.1
>

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

* Re: [PATCH] fortify: Adjust KUnit test for modular build
  2022-09-14 10:13 ` David Gow
@ 2022-09-14 13:59   ` Kees Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2022-09-14 13:59 UTC (permalink / raw)
  To: David Gow; +Cc: linux-hardening, Nathan Chancellor, Linux Kernel Mailing List

On Wed, Sep 14, 2022 at 06:13:59PM +0800, David Gow wrote:
> On Wed, Sep 14, 2022 at 1:31 AM Kees Cook <keescook@chromium.org> wrote:
> >
> > A much better "unknown size" string pointer is available directly from
> > struct test, so use that instead of a global that isn't shared with
> > modules.
> >
> > Reported-by: Nathan Chancellor <nathan@kernel.org>
> > Link: https://lore.kernel.org/lkml/YyCOHOchVuE/E7vS@dev-arch.thelio-3990X
> > Fixes: 875bfd5276f3 ("fortify: Add KUnit test for FORTIFY_SOURCE internals")
> > Cc: linux-hardening@vger.kernel.org
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > ---
> > Whoops! Thanks Nathan! :) This fixes it for your reproducer.
> 
> Ah, this is better than saved_command_line, IMO. I don't think it'd
> necessarily be a _disaster_ to just introduce a new dynamically-sized
> string here, which would be more explicit, but test->name is at least
> obviously related to this file anyway.

Yeah, and I'm trying to explicitly use a string that the compiler won't
immediately be able to see through, so best to get it from an external
source.

> Reviewed-by: David Gow <davidgow@google.com>

Thanks!

-Kees

-- 
Kees Cook

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

end of thread, other threads:[~2022-09-14 13:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13 17:31 [PATCH] fortify: Adjust KUnit test for modular build Kees Cook
2022-09-13 22:05 ` Nathan Chancellor
2022-09-14 10:13 ` David Gow
2022-09-14 13:59   ` 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.