linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] riscv/purgatory: Do not use fortified string functions
@ 2023-06-01 16:00 Kees Cook
  2023-06-01 17:34 ` Conor Dooley
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Kees Cook @ 2023-06-01 16:00 UTC (permalink / raw)
  To: Paul Walmsley
  Cc: Kees Cook, Thorsten Leemhuis, Joan Bruguera Micó,
	Palmer Dabbelt, Albert Ou, Masahiro Yamada, Conor Dooley,
	Nick Desaulniers, Alyssa Ross, Heiko Stuebner,
	Gustavo A. R. Silva, linux-riscv, Andrew Jones, linux-kernel,
	linux-hardening

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.

Reported-by: Thorsten Leemhuis <linux@leemhuis.info>
Closes: https://lore.kernel.org/lkml/175578ec-9dec-7a9c-8d3a-43f24ff86b92@leemhuis.info/
Bisected-by: "Joan Bruguera Micó" <joanbrugueram@gmail.com>
Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Conor Dooley <conor.dooley@microchip.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Alyssa Ross <hi@alyssa.is>
Cc: Heiko Stuebner <heiko.stuebner@vrull.eu>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-riscv@lists.infradead.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
v2: - only limit fortify for sha256 (conor)
v1: https://lore.kernel.org/lkml/20230531003404.never.167-kees@kernel.org
---
 arch/riscv/purgatory/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/purgatory/Makefile b/arch/riscv/purgatory/Makefile
index 5730797a6b40..8c73360c42bb 100644
--- a/arch/riscv/purgatory/Makefile
+++ b/arch/riscv/purgatory/Makefile
@@ -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
 
-- 
2.34.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] riscv/purgatory: Do not use fortified string functions
  2023-06-01 16:00 [PATCH v2] riscv/purgatory: Do not use fortified string functions Kees Cook
@ 2023-06-01 17:34 ` Conor Dooley
  2023-06-01 18:27 ` Kees Cook
  2023-06-01 20:20 ` patchwork-bot+linux-riscv
  2 siblings, 0 replies; 7+ messages in thread
From: Conor Dooley @ 2023-06-01 17:34 UTC (permalink / raw)
  To: Kees Cook
  Cc: Paul Walmsley, Thorsten Leemhuis, Joan Bruguera Micó,
	Palmer Dabbelt, Albert Ou, Masahiro Yamada, Conor Dooley,
	Nick Desaulniers, Alyssa Ross, Heiko Stuebner,
	Gustavo A. R. Silva, linux-riscv, Andrew Jones, linux-kernel,
	linux-hardening


[-- Attachment #1.1: Type: text/plain, Size: 1214 bytes --]

On Thu, Jun 01, 2023 at 09:00:28AM -0700, Kees Cook 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];
> };
> 
> 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.
> 
> Reported-by: Thorsten Leemhuis <linux@leemhuis.info>
> Closes: https://lore.kernel.org/lkml/175578ec-9dec-7a9c-8d3a-43f24ff86b92@leemhuis.info/
> Bisected-by: "Joan Bruguera Micó" <joanbrugueram@gmail.com>
> Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")
> Cc: Paul Walmsley <paul.walmsley@sifive.com>
> Cc: Palmer Dabbelt <palmer@dabbelt.com>
> Cc: Albert Ou <aou@eecs.berkeley.edu>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: Conor Dooley <conor.dooley@microchip.com>

Reviewed-by: Conor Dooley <conor.dooley@microchip.com>

Thanks for the quick update Kees,
Conor.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] riscv/purgatory: Do not use fortified string functions
  2023-06-01 16:00 [PATCH v2] riscv/purgatory: Do not use fortified string functions Kees Cook
  2023-06-01 17:34 ` Conor Dooley
@ 2023-06-01 18:27 ` Kees Cook
  2023-06-01 20:17   ` Palmer Dabbelt
  2023-06-01 20:20 ` patchwork-bot+linux-riscv
  2 siblings, 1 reply; 7+ messages in thread
From: Kees Cook @ 2023-06-01 18:27 UTC (permalink / raw)
  To: keescook, paul.walmsley
  Cc: ndesaulniers, linux-kernel, gustavoars, linux, heiko.stuebner,
	linux-hardening, aou, linux-riscv, joanbrugueram, masahiroy,
	conor.dooley, ajones, hi, palmer

On Thu, 1 Jun 2023 09:00:28 -0700, Kees Cook 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];
> };
> 
> [...]

Applied to for-next/hardening, thanks!

[1/1] riscv/purgatory: Do not use fortified string functions
      https://git.kernel.org/kees/c/ca2ca08f479d

-- 
Kees Cook


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] riscv/purgatory: Do not use fortified string functions
  2023-06-01 18:27 ` Kees Cook
@ 2023-06-01 20:17   ` Palmer Dabbelt
  2023-06-01 20:31     ` Kees Cook
  0 siblings, 1 reply; 7+ messages in thread
From: Palmer Dabbelt @ 2023-06-01 20:17 UTC (permalink / raw)
  To: keescook
  Cc: keescook, Paul Walmsley, ndesaulniers, linux-kernel, gustavoars,
	linux, heiko.stuebner, linux-hardening, aou, linux-riscv,
	joanbrugueram, masahiroy, Conor Dooley, ajones, hi

On Thu, 01 Jun 2023 11:27:03 PDT (-0700), keescook@chromium.org wrote:
> On Thu, 1 Jun 2023 09:00:28 -0700, Kees Cook 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];
>> };
>>
>> [...]
>
> 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.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] riscv/purgatory: Do not use fortified string functions
  2023-06-01 16:00 [PATCH v2] riscv/purgatory: Do not use fortified string functions Kees Cook
  2023-06-01 17:34 ` Conor Dooley
  2023-06-01 18:27 ` Kees Cook
@ 2023-06-01 20:20 ` patchwork-bot+linux-riscv
  2 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+linux-riscv @ 2023-06-01 20:20 UTC (permalink / raw)
  To: Kees Cook
  Cc: linux-riscv, paul.walmsley, linux, joanbrugueram, palmer, aou,
	masahiroy, conor.dooley, ndesaulniers, hi, heiko.stuebner,
	gustavoars, ajones, linux-kernel, linux-hardening

Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] riscv/purgatory: Do not use fortified string functions
  2023-06-01 20:17   ` Palmer Dabbelt
@ 2023-06-01 20:31     ` Kees Cook
  2023-06-01 21:04       ` Palmer Dabbelt
  0 siblings, 1 reply; 7+ messages in thread
From: Kees Cook @ 2023-06-01 20:31 UTC (permalink / raw)
  To: Palmer Dabbelt
  Cc: Paul Walmsley, ndesaulniers, linux-kernel, gustavoars, linux,
	heiko.stuebner, linux-hardening, aou, linux-riscv, joanbrugueram,
	masahiroy, Conor Dooley, ajones, hi

On Thu, Jun 01, 2023 at 01:17:03PM -0700, Palmer Dabbelt wrote:
> On Thu, 01 Jun 2023 11:27:03 PDT (-0700), keescook@chromium.org wrote:
> > On Thu, 1 Jun 2023 09:00:28 -0700, Kees Cook 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];
> > > };
> > > 
> > > [...]
> > 
> > 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.

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.

-- 
Kees Cook

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] riscv/purgatory: Do not use fortified string functions
  2023-06-01 20:31     ` Kees Cook
@ 2023-06-01 21:04       ` Palmer Dabbelt
  0 siblings, 0 replies; 7+ messages in thread
From: Palmer Dabbelt @ 2023-06-01 21:04 UTC (permalink / raw)
  To: keescook
  Cc: Paul Walmsley, ndesaulniers, linux-kernel, gustavoars, linux,
	heiko.stuebner, linux-hardening, aou, linux-riscv, joanbrugueram,
	masahiroy, Conor Dooley, ajones, hi

On Thu, 01 Jun 2023 13:31:33 PDT (-0700), keescook@chromium.org wrote:
> On Thu, Jun 01, 2023 at 01:17:03PM -0700, Palmer Dabbelt wrote:
>> On Thu, 01 Jun 2023 11:27:03 PDT (-0700), keescook@chromium.org wrote:
>> > On Thu, 1 Jun 2023 09:00:28 -0700, Kees Cook 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];
>> > > };
>> > >
>> > > [...]
>> >
>> > 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.
>
> 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.

Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>

The bots will probably get confussed and it was briefly visible to 
linux-next, so there might be a bit of spam.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-06-01 21:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 16:00 [PATCH v2] riscv/purgatory: Do not use fortified string functions Kees Cook
2023-06-01 17:34 ` Conor Dooley
2023-06-01 18:27 ` Kees Cook
2023-06-01 20:17   ` Palmer Dabbelt
2023-06-01 20:31     ` Kees Cook
2023-06-01 21:04       ` Palmer Dabbelt
2023-06-01 20:20 ` patchwork-bot+linux-riscv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).