Skip to contentSkip to conversation

s390/speculation: Use statically initialized const for instructions

PATCH Applied Kees Cook 2 participants 2 messages Jun 16, 2021 – Jun 22, 2021 s390

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 s390/speculation: Use statically initialized const for instructions

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.

---
 arch/s390/kernel/nospec-branch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kernel/nospec-branch.c +2 -1
index 2c5c3756644b..250e4dbf653c 100644
@@ -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];
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 11 lines · Kees Cook

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.

---
 arch/s390/kernel/nospec-branch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied, thanks!