linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/smap: Fix the smap_save() asm
@ 2020-09-15 20:55 Andy Lutomirski
  2020-09-15 21:24 ` Nick Desaulniers
  2020-09-16  7:28 ` peterz
  0 siblings, 2 replies; 11+ messages in thread
From: Andy Lutomirski @ 2020-09-15 20:55 UTC (permalink / raw)
  To: x86
  Cc: LKML, Bill Wendling, Nick Desaulniers, Greg Thelen,
	John Sperbeck, Andy Lutomirski, stable

The old smap_save() code was:

  pushf
  pop %0

with %0 defined by an "=rm" constraint.  This is fine if the
compiler picked the register option, but it was incorrect with an
%rsp-relative memory operand.  With some intentional abuse, I can
get both gcc and clang to generate code along these lines:

  pushfq
  popq 0x8(%rsp)
  mov 0x8(%rsp),%rax

which is incorrect and will not work as intended.

Fix it by removing the memory option.  This issue is exacerbated by
a clang optimization bug:

  https://bugs.llvm.org/show_bug.cgi?id=47530

Fixes: e74deb11931f ("x86/uaccess: Introduce user_access_{save,restore}()")
Cc: stable@vger.kernel.org
Reported-by: Bill Wendling <morbo@google.com> # I think
Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 arch/x86/include/asm/smap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
index 8b58d6975d5d..be6d675ae3ac 100644
--- a/arch/x86/include/asm/smap.h
+++ b/arch/x86/include/asm/smap.h
@@ -61,7 +61,7 @@ static __always_inline unsigned long smap_save(void)
 		      ALTERNATIVE("jmp 1f", "", X86_FEATURE_SMAP)
 		      "pushf; pop %0; " __ASM_CLAC "\n\t"
 		      "1:"
-		      : "=rm" (flags) : : "memory", "cc");
+		      : "=r" (flags) : : "memory", "cc");
 
 	return flags;
 }
-- 
2.26.2


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

end of thread, other threads:[~2020-09-17 19:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-15 20:55 [PATCH] x86/smap: Fix the smap_save() asm Andy Lutomirski
2020-09-15 21:24 ` Nick Desaulniers
2020-09-15 21:31   ` Bill Wendling
2020-09-15 23:11   ` Andy Lutomirski
     [not found]     ` <7233f4cf-5b1d-0fca-0880-f1cf2e6e765b@citrix.com>
2020-09-15 23:43       ` Bill Wendling
2020-09-16  8:26       ` Borislav Petkov
     [not found]         ` <be498e49-b467-e04c-d833-372f7d83cb1f@citrix.com>
2020-09-17  6:04           ` Borislav Petkov
     [not found]             ` <ec617df229514fbaa9897683ac88dfda@AcuMS.aculab.com>
2020-09-17 11:57               ` Borislav Petkov
     [not found]                 ` <823af5fadd464c48ade635498d07ba4e@AcuMS.aculab.com>
2020-09-17 14:39                   ` Borislav Petkov
2020-09-17 16:32                     ` Andy Lutomirski
2020-09-16  7:28 ` peterz

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