linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] s390/speculation: Use statically initialized const for instructions
@ 2021-06-16 20:18 Kees Cook
  2021-06-22 14:16 ` Vasily Gorbik
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2021-06-16 20:18 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Kees Cook, Vasily Gorbik, Christian Borntraeger, Sven Schnelle,
	linux-kernel, linux-s390, linux-hardening

In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memcpy(), memmove(), and memset(), avoid
confusing the checks when using a static const source.

Move the static const array into a variable so the compiler can perform
appropriate bounds checking.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 arch/s390/kernel/nospec-branch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/s390/kernel/nospec-branch.c b/arch/s390/kernel/nospec-branch.c
index 2c5c3756644b..250e4dbf653c 100644
--- a/arch/s390/kernel/nospec-branch.c
+++ b/arch/s390/kernel/nospec-branch.c
@@ -99,6 +99,7 @@ early_param("spectre_v2", spectre_v2_setup_early);
 static void __init_or_module __nospec_revert(s32 *start, s32 *end)
 {
 	enum { BRCL_EXPOLINE, BRASL_EXPOLINE } type;
+	static const u8 branch[] = { 0x47, 0x00, 0x07, 0x00 };
 	u8 *instr, *thunk, *br;
 	u8 insnbuf[6];
 	s32 *epo;
@@ -128,7 +129,7 @@ static void __init_or_module __nospec_revert(s32 *start, s32 *end)
 		if ((br[0] & 0xbf) != 0x07 || (br[1] & 0xf0) != 0xf0)
 			continue;
 
-		memcpy(insnbuf + 2, (char[]) { 0x47, 0x00, 0x07, 0x00 }, 4);
+		memcpy(insnbuf + 2, branch, sizeof(branch));
 		switch (type) {
 		case BRCL_EXPOLINE:
 			insnbuf[0] = br[0];
-- 
2.25.1


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

* Re: [PATCH] s390/speculation: Use statically initialized const for instructions
  2021-06-16 20:18 [PATCH] s390/speculation: Use statically initialized const for instructions Kees Cook
@ 2021-06-22 14:16 ` Vasily Gorbik
  0 siblings, 0 replies; 2+ messages in thread
From: Vasily Gorbik @ 2021-06-22 14:16 UTC (permalink / raw)
  To: Kees Cook
  Cc: Heiko Carstens, Christian Borntraeger, Sven Schnelle,
	linux-kernel, linux-s390, linux-hardening

On Wed, Jun 16, 2021 at 01:18:23PM -0700, Kees Cook wrote:
> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memcpy(), memmove(), and memset(), avoid
> confusing the checks when using a static const source.
> 
> Move the static const array into a variable so the compiler can perform
> appropriate bounds checking.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  arch/s390/kernel/nospec-branch.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Applied, thanks!

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

end of thread, other threads:[~2021-06-22 14:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-16 20:18 [PATCH] s390/speculation: Use statically initialized const for instructions Kees Cook
2021-06-22 14:16 ` Vasily Gorbik

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).