Skip to contentSkip to conversation

x86/asm/entry/64: Fix MSR_IA32_SYSENTER_CS MSR value

PATCH In review Borislav Petkov 3 participants 7 messages Apr 3, 2015 x86

lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

PATCH 1/1 x86/asm/entry/64: Fix MSR_IA32_SYSENTER_CS MSR value

From: Borislav Petkov <[email protected]>

Commit

d56fe4bf5f3c ("x86/asm/entry/64: Always set up SYSENTER MSRs")

missed to add "ULL" to the 0 and wrmsrl_safe() complains:

arch/x86/kernel/cpu/common.c: In function ‘syscall_init’:
arch/x86/kernel/cpu/common.c:1226:2: warning: right shift count >= width of type

    wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0);

Fix it.

Cc Denys Vlasenko <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Kees Cook <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Will Drewry <[email protected]>
Cc Ingo Molnar <[email protected]>
---
 arch/x86/kernel/cpu/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/common.c +1 -1
index bb6633a87a19..2c249b57e4b5 100644
@@ -1223,7 +1223,7 @@ void syscall_init(void)
 	wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
 #else
 	wrmsrl(MSR_CSTAR, ignore_sysret);
-	wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0);
+	wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0ULL);
 	wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
 	wrmsrl_safe(MSR_IA32_SYSENTER_EIP, 0ULL);
 #endif
Signature · 1 line
2.3.3
author maintainer
#1 lore raw
Quoted 35 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

Commit

d56fe4bf5f3c ("x86/asm/entry/64: Always set up SYSENTER MSRs")

missed to add "ULL" to the 0 and wrmsrl_safe() complains:

arch/x86/kernel/cpu/common.c: In function ‘syscall_init’:
arch/x86/kernel/cpu/common.c:1226:2: warning: right shift count >= width of type

    wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0);

Fix it.

Cc Denys Vlasenko <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Kees Cook <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Will Drewry <[email protected]>
Cc Ingo Molnar <[email protected]>
---
 arch/x86/kernel/cpu/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/common.c +0 -0
index bb6633a87a19..2c249b57e4b5 100644

arch/x86/kernel/cpu/common.c void syscall_init(void) · line 1226

Quoted 5 lines
arch/x86/kernel/cpu/common.c +1 -1
@@ -1223,7 +1223,7 @@ void syscall_init(void)
 	wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
 #else
 	wrmsrl(MSR_CSTAR, ignore_sysret);
-	wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0);
+	wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0ULL);

Btw, we probably should define an invalid segment

#define GDT_ENTRY_INVALID_SEGMENT 0ULL

and use that value instead of the naked 0.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#2 lore raw
Quoted 44 lines · Borislav Petkov
Quoted 35 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

Commit

d56fe4bf5f3c ("x86/asm/entry/64: Always set up SYSENTER MSRs")

missed to add "ULL" to the 0 and wrmsrl_safe() complains:

arch/x86/kernel/cpu/common.c: In function ‘syscall_init’:
arch/x86/kernel/cpu/common.c:1226:2: warning: right shift count >= width of type

    wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0);

Fix it.

Cc Denys Vlasenko <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Kees Cook <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Will Drewry <[email protected]>
Cc Ingo Molnar <[email protected]>
---
 arch/x86/kernel/cpu/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/common.c +0 -0
index bb6633a87a19..2c249b57e4b5 100644

arch/x86/kernel/cpu/common.c void syscall_init(void) · line 1226

Quoted 5 lines
arch/x86/kernel/cpu/common.c +1 -1
@@ -1223,7 +1223,7 @@ void syscall_init(void)
 	wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
 #else
 	wrmsrl(MSR_CSTAR, ignore_sysret);
-	wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0);
+	wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0ULL);

Btw, we probably should define an invalid segment

Quoted 3 lines

#define GDT_ENTRY_INVALID_SEGMENT 0ULL

and use that value instead of the naked 0.

Why? Segment selectors aren't "long long", they are in fact "short" (16-bit ints).

The "ULL" is used here in wrmsrl not because it's a segment, but because wrmsrl expects a u64 parameter.

We can probably add a cast in its definition...

author maintainer
#3 lore raw
Quoted 7 lines · Denys Vlasenko

Why? Segment selectors aren't "long long", they are in fact "short" (16-bit ints).

The "ULL" is used here in wrmsrl not because it's a segment, but because wrmsrl expects a u64 parameter.

We can probably add a cast in its definition...

Yeah, I meant to not use the naked 0. Cast should be fine.

Let me do a patch.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
author maintainer
#4 lore raw

PATCH 1/1 x86/asm/entry/64: Use a define for an invalid segment

Quoted 1 line · Borislav Petkov

Let me do a patch.

---
From: Borislav Petkov <[email protected]>
Date: Fri, 3 Apr 2015 14:22:00 +0200
Subject: [PATCH] x86/asm/entry/64: Use a define for an invalid segment
selector

... instead of a naked number, for better readability.

---
 arch/x86/include/asm/segment.h | 2 ++
 arch/x86/kernel/cpu/common.c   | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/include/asm/segment.h +2 -0
index d394899e055c..5a9856eb12ba 100644
@@ -39,6 +39,8 @@
 /* ... GDT has it cleared */
 #define SEGMENT_GDT		0x0
 
+#define GDT_ENTRY_INVALID_SEG	0
+
 #ifdef CONFIG_X86_32
 /*
  * The layout of the per-CPU GDT under Linux:
arch/x86/kernel/cpu/common.c +1 -1
index 2c249b57e4b5..a62cf04dac8a 100644
@@ -1223,7 +1223,7 @@ void syscall_init(void)
 	wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
 #else
 	wrmsrl(MSR_CSTAR, ignore_sysret);
-	wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0ULL);
+	wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)GDT_ENTRY_INVALID_SEG);
 	wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
 	wrmsrl_safe(MSR_IA32_SYSENTER_EIP, 0ULL);
 #endif
Signature · 8 lines
2.3.3

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#5 lore raw
In reply to Borislav Petkov
x86/asm/entry/64: Fix MSR_IA32_SYSENTER_CS MSR value
Commit-ID:  7c74d5b7b7b63fc279ed446ebd78de20d81f2824
Gitweb:     http://git.kernel.org/tip/7c74d5b7b7b63fc279ed446ebd78de20d81f2824
Author:     Borislav Petkov <[email protected]>
AuthorDate: Fri, 3 Apr 2015 11:42:10 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 15:29:12 +0200

x86/asm/entry/64: Fix MSR_IA32_SYSENTER_CS MSR value

Commit:

d56fe4bf5f3c ("x86/asm/entry/64: Always set up SYSENTER MSRs")

missed to add "ULL" to the 0 and wrmsrl_safe() complains:

arch/x86/kernel/cpu/common.c: In function ‘syscall_init’:
arch/x86/kernel/cpu/common.c:1226:2: warning: right shift count >= width of type wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0);

Fix it.

Cc Alexei Starovoitov <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Kees Cook <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Will Drewry <[email protected]>
---
 arch/x86/kernel/cpu/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/common.c +1 -1
index a383d53..d56d307 100644
@@ -1184,7 +1184,7 @@ void syscall_init(void)
 	wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
 #else
 	wrmsrl(MSR_CSTAR, ignore_sysret);
-	wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0);
+	wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0ULL);
 	wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
 	wrmsrl_safe(MSR_IA32_SYSENTER_EIP, 0ULL);
 #endif
#6 lore raw

[tip:x86/asm] x86/asm/entry/64: Use a define for an invalid segment selector

In reply to Borislav Petkov
x86/asm/entry/64: Use a define for an invalid segment selector
Commit-ID:  6b51311c976593fb7311322b1647a912cd456ec4
Gitweb:     http://git.kernel.org/tip/6b51311c976593fb7311322b1647a912cd456ec4
Author:     Borislav Petkov <[email protected]>
AuthorDate: Fri, 3 Apr 2015 14:25:28 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 15:29:13 +0200

x86/asm/entry/64: Use a define for an invalid segment selector

... instead of a naked number, for better readability.

Cc Alexei Starovoitov <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Kees Cook <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Will Drewry <[email protected]>
---
 arch/x86/include/asm/segment.h | 2 ++
 arch/x86/kernel/cpu/common.c   | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/include/asm/segment.h +2 -0
index d394899..5a9856e 100644
@@ -39,6 +39,8 @@
 /* ... GDT has it cleared */
 #define SEGMENT_GDT		0x0
 
+#define GDT_ENTRY_INVALID_SEG	0
+
 #ifdef CONFIG_X86_32
 /*
  * The layout of the per-CPU GDT under Linux:
arch/x86/kernel/cpu/common.c +1 -1
index d56d307..3f70538 100644
@@ -1184,7 +1184,7 @@ void syscall_init(void)
 	wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
 #else
 	wrmsrl(MSR_CSTAR, ignore_sysret);
-	wrmsrl_safe(MSR_IA32_SYSENTER_CS, 0ULL);
+	wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)GDT_ENTRY_INVALID_SEG);
 	wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
 	wrmsrl_safe(MSR_IA32_SYSENTER_EIP, 0ULL);
 #endif