riscv/purgatory: Do not use fortified string functions
PATCH v2 1/1 riscv/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.
---
v2: - only limit fortify for sha256 (conor)
v1: https://lore.kernel.org/lkml/[email protected]
--- arch/riscv/purgatory/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/purgatory/Makefile +1 -1
@@ -31,7 +31,7 @@ $(obj)/strncmp.o: $(srctree)/arch/riscv/lib/strncmp.S 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 CFLAGS_string.o := -D__DISABLE_EXPORTS CFLAGS_ctype.o := -D__DISABLE_EXPORTS
Signature · 1 line
2.34.1
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 9 lines
Reported-by Thorsten Leemhuis <[email protected]>Bisected-by "Joan Bruguera Micó" <[email protected]>Fixes df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")Cc Paul Walmsley <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Albert Ou <[email protected]>Cc Masahiro Yamada <[email protected]>Cc Conor Dooley <[email protected]>
Thanks for the quick update Kees,
Conor.
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] riscv/purgatory: Do not use fortified string functions
https://git.kernel.org/kees/c/ca2ca08f479d
Signature · 7 lines
Kees Cook _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Palmer Dabbelt
maintainerQuoted 10 lines · On Thu, 01 Jun 2023 11:27:03 PDT (-0700), [email protected] wrote:
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 6 lines
Quoted 1 line
[...]
Applied to for-next/hardening, thanks!
[1/1] riscv/purgatory: Do not use fortified string functions
https://git.kernel.org/kees/c/ca2ca08f479d
Sorry, I'd just applied this to riscv/fixes as well. I can drop it if you want? I was going to send a PR tomorrow, just LMK.
Quoted 13 lines · Palmer Dabbelt
Quoted 12 lines · On Thu, 01 Jun 2023 11:27:03 PDT (-0700), [email protected] wrote:
Quoted 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]; };[...]
Quoted 7 lines
Quoted 4 lines
Applied to for-next/hardening, thanks!
[1/1] riscv/purgatory: Do not use fortified string functions
https://git.kernel.org/kees/c/ca2ca08f479dSorry, I'd just applied this to riscv/fixes as well. I can drop it if you want? I was going to send a PR tomorrow, just LMK.
I'm fine either way. I was carrying each arch's fix just since it was related to the -fstrict-flex-arrays=3 patch in the hardening tree.
Signature · 1 line
Kees Cook
Quoted 16 lines · On Thu, 01 Jun 2023 13:31:33 PDT (-0700), [email protected] wrote:
Quoted 15 lines · Palmer Dabbelt
Quoted 14 lines · On Thu, 01 Jun 2023 11:27:03 PDT (-0700), [email protected] wrote:
Quoted 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!
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
[1/1] riscv/purgatory: Do not use fortified string functions
https://git.kernel.org/kees/c/ca2ca08f479dSorry, I'd just applied this to riscv/fixes as well. I can drop it if you want? I was going to send a PR tomorrow, just LMK.
I'm fine either way. I was carrying each arch's fix just since it was related to the -fstrict-flex-arrays=3 patch in the hardening tree.
Works for me, I'll drop it.
The bots will probably get confussed and it was briefly visible to linux-next, so there might be a bit of spam.
This patch was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <[email protected]>:
Quoted 10 lines · On Thu, 1 Jun 2023 09:00:28 -0700 you wrote:
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]; };[...]
Here is the summary with links:
- [v2] riscv/purgatory: Do not use fortified string functions
https://git.kernel.org/riscv/c/0f84097ab015
You are awesome, thank you!
Signature · 9 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv