x86/purgatory: Do not use fortified string functions
PATCH 1/1 x86/purgatory: Do not use fortified string functions
With the addition of -fstrict-flex-arrays=3, struct sha256_state's trailing array is no longer ignored by CONFIG_FORTIFY_SOURCE:
struct sha256_state {
u32 state[SHA256_DIGEST_SIZE / 4];
u64 count;
u8 buf[SHA256_BLOCK_SIZE];
};This means that the memcpy() calls with "buf" as a destination in sha256.c's code will attempt to perform run-time bounds checking, which could lead to calling missing functions, specifically a potential WARN_ONCE, which isn't callable from purgatory.
--- arch/x86/purgatory/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/purgatory/Makefile +1 -1
@@ -12,7 +12,7 @@ $(obj)/string.o: $(srctree)/arch/x86/boot/compressed/string.c FORCE $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE $(call if_changed_rule,cc_o_c) -CFLAGS_sha256.o := -D__DISABLE_EXPORTS +CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY # When linking purgatory.ro with -r unresolved symbols are not checked, # also link a purgatory.chk binary without -r to check for unresolved symbols.
Signature · 1 line
2.34.1
Kees, thx for looking into this.
Joan, thx for bisecting. I should have done this earlier myself...
Quoted 9 lines · Kees Cook
With the addition of -fstrict-flex-arrays=3, struct sha256_state's trailing array is no longer ignored by
CONFIG_FORTIFY_SOURCE:struct sha256_state { u32 state[SHA256_DIGEST_SIZE / 4]; u64 count; u8 buf[SHA256_BLOCK_SIZE]; };
Quoted 7 lines
This means that the
memcpy()calls with "buf" as a destination in sha256.c's code will attempt to perform run-time bounds checking, which could lead to calling missing functions, specifically a potentialWARN_ONCE, which isn't callable from purgatory.
Did a test build and booted it in a Vm, everything seems fine. So thx again and feel free to add:
Ciao, Thorsten
Quoted 14 lines · Kees Cook
With the addition of -fstrict-flex-arrays=3, struct sha256_state's trailing array is no longer ignored by
CONFIG_FORTIFY_SOURCE:struct sha256_state { u32 state[SHA256_DIGEST_SIZE / 4]; u64 count; u8 buf[SHA256_BLOCK_SIZE]; };This means that the
memcpy()calls with "buf" as a destination in sha256.c's code will attempt to perform run-time bounds checking, which could lead to calling missing functions, specifically a potentialWARN_ONCE, which isn't callable from purgatory.
Quoted 6 lines
Reported-by Thorsten Leemhuis <[email protected]>Bisected-by "Joan Bruguera Micó" <[email protected]>Fixes df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>
Hi Folks,
The -fstrict-flex-arrays=3 commit isn't upstream yet, right? That makes it a _bit_ wonky for us to carry this on the x86 side since among other things, the Fixes commit doesn't exist. I'd be fine if this goes up along with the -fstrict-flex-arrays=3 code, so:
We could also pick it up from the x86 side, but I think that would need a _bit_ of a different commit message to allude to it being to prepare for the _future_ setting of -fstrict-flex-arrays=3 and having no practical benefits now.
Let me know if you don't want to send this up with the -fstrict-flex-arrays=3 set.
Quoted 22 lines · Dave Hansen
Quoted 14 lines · Kees Cook
With the addition of -fstrict-flex-arrays=3, struct sha256_state's trailing array is no longer ignored by
CONFIG_FORTIFY_SOURCE:struct sha256_state { u32 state[SHA256_DIGEST_SIZE / 4]; u64 count; u8 buf[SHA256_BLOCK_SIZE]; };This means that the
memcpy()calls with "buf" as a destination in sha256.c's code will attempt to perform run-time bounds checking, which could lead to calling missing functions, specifically a potentialWARN_ONCE, which isn't callable from purgatory.Quoted 6 lines
Reported-by Thorsten Leemhuis <[email protected]>Bisected-by "Joan Bruguera Micó" <[email protected]>Fixes df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>
Quoted 3 lines
Hi Folks,
The -fstrict-flex-arrays=3 commit isn't upstream yet, right? That makes
Correct.
Quoted 5 lines
it a _bit_ wonky for us to carry this on the x86 side since among other things, the Fixes commit doesn't exist. I'd be fine if this goes up along with the -fstrict-flex-arrays=3 code, so:
Acked-by Dave Hansen <[email protected]>
That would be perfect; thank you! I've added it to my tree.
Signature · 1 line
Kees Cook
Kees Cook
AppliedQuoted 10 lines · Kees Cook
With the addition of -fstrict-flex-arrays=3, struct sha256_state's trailing array is no longer ignored by
CONFIG_FORTIFY_SOURCE:struct sha256_state { u32 state[SHA256_DIGEST_SIZE / 4]; u64 count; u8 buf[SHA256_BLOCK_SIZE]; };[...]
Applied to for-next/hardening, thanks!
[1/1] x86/purgatory: Do not use fortified string functions
https://git.kernel.org/kees/c/f6ab7fc96a53
Signature · 1 line
Kees Cook