riscv/purgatory: Do not use fortified string functions
PATCH 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.
--- arch/riscv/purgatory/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/riscv/purgatory/Makefile +3 -3
@@ -31,9 +31,9 @@ $(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_string.o := -D__DISABLE_EXPORTS -CFLAGS_ctype.o := -D__DISABLE_EXPORTS +CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY +CFLAGS_string.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY +CFLAGS_ctype.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 · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Hey Kees,
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 15 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]>Cc Nick Desaulniers <[email protected]>Cc Alyssa Ross <[email protected]>Cc Heiko Stuebner <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>
Perhaps this is indicative of other issues in RISC-V land, but allmodconfig complains about this patch:
../lib/string.c:17: warning: "__NO_FORTIFY" redefined ../lib/string.c:17:9: warning: preprocessor token __NO_FORTIFY redefined
Quoted 29 lines
--- arch/riscv/purgatory/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/riscv/purgatory/Makefile +3
-3@@ -31,9 +31,9 @@ $(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_string.o := -D__DISABLE_EXPORTS -CFLAGS_ctype.o := -D__DISABLE_EXPORTS +CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY +CFLAGS_string.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY +CFLAGS_ctype.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 · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 33 lines · Conor Dooley
Hey Kees,
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 15 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]>Cc Nick Desaulniers <[email protected]>Cc Alyssa Ross <[email protected]>Cc Heiko Stuebner <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>
Quoted 5 lines
Perhaps this is indicative of other issues in RISC-V land, but allmodconfig complains about this patch:
../lib/string.c:17: warning: "__NO_FORTIFY" redefined../lib/string.c:17:9: warning: preprocessor token__NO_FORTIFYredefined
Argh, thanks. My compile test clearly failed. I'll fix this up.
-Kees
Quoted 30 lines
Quoted 30 lines
--- arch/riscv/purgatory/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/riscv/purgatory/Makefile +3
-3@@ -31,9 +31,9 @@ $(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_string.o := -D__DISABLE_EXPORTS -CFLAGS_ctype.o := -D__DISABLE_EXPORTS +CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY +CFLAGS_string.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY +CFLAGS_ctype.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 · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Signature · 1 line
Kees Cook