lkml.org 
[lkml]   [2014]   [Sep]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] x86 : Ensure X86_FLAGS_NT is cleared on syscall entry
On 09/25/2014 12:42 PM, Anish Bhatt wrote:
> The MSR_SYSCALL_MASK, which is responsible for clearing specific EFLAGS on
> syscall entry, should also clear the nested task (NT) flag to be safe from
> userspace injection. Without this fix the application segmentation
> faults on syscall return because of the changed meaning of the IRET
> instruction.
>
> Further details can be seen here https://bugs.winehq.org/show_bug.cgi?id=33275
>
> Signed-off-by: Anish Bhatt <anish@chelsio.com>
> Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
> ---
> 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 e4ab2b4..3126558 100644
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -1184,7 +1184,7 @@ void syscall_init(void)
> /* Flags to clear on syscall */
> wrmsrl(MSR_SYSCALL_MASK,
> X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|
> - X86_EFLAGS_IOPL|X86_EFLAGS_AC);
> + X86_EFLAGS_IOPL|X86_EFLAGS_AC|X86_EFLAGS_NT);

Something's weird here, and at the very least the changelog is
insufficiently informative.

The Intel SDM says:

If the NT flag is set and the processor is in IA-32e mode, the IRET
instruction causes a general protection exception.

Presumably interrupt delivery clears NT. I haven't spotted where that's
documented yet.

sysret doesn't appear to care about NT at all.

So: the test code doesn't appear to do anything interesting *unless* it
goes through syscall followed by the iret exit path. Then it receives
#GP on return, which turns into a signal.

On the premise that the slow and fast return paths ought to be
indistinguishable from userspace, I think we should fix this. But I
want to understand it better first.

Also, 32-bit may need more care here.

--Andy


\
 
 \ /
  Last update: 2014-09-29 20:21    [W:0.110 / U:1.544 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site