Skip to content

Commit

Permalink
lib/test_stackinit: Fix static initializer test
Browse files Browse the repository at this point in the history
commit f9398f1 upstream.

The static initializer test got accidentally converted to a dynamic
initializer. Fix this and retain the giant padding hole without using
an aligned struct member.

Fixes: 50ceaa9 ("lib: Introduce test_stackinit module")
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20210723221933.3431999-2-keescook@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
kees authored and gregkh committed Sep 18, 2021
1 parent e9d9530 commit f9cb67a
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/test_stackinit.c
Expand Up @@ -67,10 +67,10 @@ static bool range_contains(char *haystack_start, size_t haystack_size,
#define INIT_STRUCT_none /**/
#define INIT_STRUCT_zero = { }
#define INIT_STRUCT_static_partial = { .two = 0, }
#define INIT_STRUCT_static_all = { .one = arg->one, \
.two = arg->two, \
.three = arg->three, \
.four = arg->four, \
#define INIT_STRUCT_static_all = { .one = 0, \
.two = 0, \
.three = 0, \
.four = 0, \
}
#define INIT_STRUCT_dynamic_partial = { .two = arg->two, }
#define INIT_STRUCT_dynamic_all = { .one = arg->one, \
Expand All @@ -84,8 +84,7 @@ static bool range_contains(char *haystack_start, size_t haystack_size,
var.one = 0; \
var.two = 0; \
var.three = 0; \
memset(&var.four, 0, \
sizeof(var.four))
var.four = 0

/*
* @name: unique string name for the test
Expand Down Expand Up @@ -210,18 +209,13 @@ struct test_small_hole {
unsigned long four;
};

/* Try to trigger unhandled padding in a structure. */
struct test_aligned {
u32 internal1;
u64 internal2;
} __aligned(64);

/* Trigger unhandled padding in a structure. */
struct test_big_hole {
u8 one;
u8 two;
u8 three;
/* 61 byte padding hole here. */
struct test_aligned four;
u8 four __aligned(64);
} __aligned(64);

struct test_trailing_hole {
Expand Down

0 comments on commit f9cb67a

Please sign in to comment.