fortify: Adjust KUnit test for modular build
PATCH 1/1 fortify: Adjust KUnit test for modular build
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.
---
Whoops! Thanks Nathan! :) This fixes it for your reproducer.
--- lib/fortify_kunit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/fortify_kunit.c +1 -2
@@ -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. */
Signature · 1 line
2.34.1
Quoted 11 lines · Kees Cook
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 <[email protected]>Fixes 875bfd5276f3 ("fortify: Add KUnit test for FORTIFY_SOURCE internals")Signed-off-by Kees Cook <[email protected]>---
Whoops! Thanks Nathan! :) This fixes it for your reproducer.
Confirmed :)
Thanks for the quick fix!
Quoted 28 lines
--- lib/fortify_kunit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)lib/fortify_kunit.c +1
-2@@ -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. */ Signature · 1 line
2.34.1
Quoted 5 lines · Kees Cook
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.
Quoted 7 lines
Reported-by Nathan Chancellor <[email protected]>Fixes 875bfd5276f3 ("fortify: Add KUnit test for FORTIFY_SOURCE internals")Signed-off-by Kees Cook <[email protected]>---
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.
Cheers
-- David
Quoted 28 lines
--- lib/fortify_kunit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)lib/fortify_kunit.c +1
-3@@ -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
Quoted 14 lines · David Gow
Quoted 5 lines · Kees Cook
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.
Quoted 7 lines
Reported-by Nathan Chancellor <[email protected]>Fixes 875bfd5276f3 ("fortify: Add KUnit test for FORTIFY_SOURCE internals")Signed-off-by Kees Cook <[email protected]>---
Whoops! Thanks Nathan! :) This fixes it for your reproducer.
Quoted 4 lines
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, buttest->nameis 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.
Quoted 1 line
Reviewed-by David Gow <[email protected]>
Thanks!
-Kees
Signature · 1 line
Kees Cook