2015-04-03 09:44:15

by Borislav Petkov

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Borislav Petkov <[email protected]>
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(-)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index bb6633a87a19..2c249b57e4b5 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -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
--
2.3.3


2015-04-03 11:22:33

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH] x86/asm/entry/64: Fix MSR_IA32_SYSENTER_CS MSR value

On Fri, Apr 03, 2015 at 11:42:10AM +0200, Borislav Petkov wrote:
> 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.
>
> Signed-off-by: Borislav Petkov <[email protected]>
> 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(-)
>
> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> index bb6633a87a19..2c249b57e4b5 100644
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -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.

--
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.
--

2015-04-03 11:52:09

by Denys Vlasenko

[permalink] [raw]
Subject: Re: [PATCH] x86/asm/entry/64: Fix MSR_IA32_SYSENTER_CS MSR value

On 04/03/2015 01:20 PM, Borislav Petkov wrote:
> On Fri, Apr 03, 2015 at 11:42:10AM +0200, Borislav Petkov wrote:
>> 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.
>>
>> Signed-off-by: Borislav Petkov <[email protected]>
>> 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(-)
>>
>> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
>> index bb6633a87a19..2c249b57e4b5 100644
>> --- a/arch/x86/kernel/cpu/common.c
>> +++ b/arch/x86/kernel/cpu/common.c
>> @@ -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.

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

2015-04-03 12:07:22

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH] x86/asm/entry/64: Fix MSR_IA32_SYSENTER_CS MSR value

On Fri, Apr 03, 2015 at 01:52:00PM +0200, Denys Vlasenko wrote:
> 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.

--
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.
--

2015-04-03 12:27:32

by Borislav Petkov

[permalink] [raw]
Subject: [PATCH] x86/asm/entry/64: Use a define for an invalid segment

On Fri, Apr 03, 2015 at 02:05:17PM +0200, Borislav Petkov wrote:
> 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.

Signed-off-by: Borislav Petkov <[email protected]>
---
arch/x86/include/asm/segment.h | 2 ++
arch/x86/kernel/cpu/common.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
index d394899e055c..5a9856eb12ba 100644
--- a/arch/x86/include/asm/segment.h
+++ b/arch/x86/include/asm/segment.h
@@ -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:
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 2c249b57e4b5..a62cf04dac8a 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -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
--
2.3.3

--
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.
--

Subject: [tip:x86/asm] 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.

Signed-off-by: Borislav Petkov <[email protected]>
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]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/kernel/cpu/common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index a383d53..d56d307 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -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

Subject: [tip:x86/asm] 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.

Signed-off-by: Borislav Petkov <[email protected]>
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]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/include/asm/segment.h | 2 ++
arch/x86/kernel/cpu/common.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
index d394899..5a9856e 100644
--- a/arch/x86/include/asm/segment.h
+++ b/arch/x86/include/asm/segment.h
@@ -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:
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index d56d307..3f70538 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -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