All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Andy Lutomirski <luto@kernel.org>
Cc: x86@kernel.org, Borislav Petkov <bp@alien8.de>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Subject: Re: [PATCH v2] selftests/x86: Add a selftest for SYSRET to noncanonical addresses
Date: Tue, 3 Jan 2017 18:11:55 +0300	[thread overview]
Message-ID: <20170103151155.GA17319@node.shutemov.name> (raw)
In-Reply-To: <e70bd9a3f90657ba47b755100a20475d038fa26b.1482808435.git.luto@kernel.org>

On Mon, Dec 26, 2016 at 07:20:50PM -0800, Andy Lutomirski wrote:
> SYSRET to a noncanonical address will blow up on Intel CPUs.  Linux
> needs to prevent this from happening in two major cases, and the
> criteria will become more complicated when support for larger virtual
> address spaces is added.
> 
> A fast-path SYSCALL will fallthrough to the following instruction
> using SYSRET without any particular checking.  To prevent fallthrough
> to a noncanonical address, Linux prevents the highest canonical page
> from being mapped.  This test case checks a variety of possible maximum
> addresses to make sure that either we can't map code there or that
> SYSCALL fallthrough works.
> 
> A slow-path system call can return anywhere.  Linux needs to make sure
> that, if the return address is non-canonical, it won't use SYSRET.
> This test cases causes sigreturn() to return to a variety of addresses
> (with RCX == RIP) and makes sure that nothing explodes.
> 
> Some of this code comes from Kirill Shutemov.
> 
> Changes from v1:
>  - Get rid of some extra parentheses.
>  - Test more corner cases.
>  - Get rid of some duplicate '0x' printout.
> 
> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> Signed-off-by: Andy Lutomirski <luto@kernel.org>

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

Output with 5-level paging enabled:

[RUN]   sigreturn to 0x800000000000
[OK]    Got SIGSEGV at RIP=0x800000000000
[RUN]   sigreturn to 0x1000000000000
[OK]    Got SIGSEGV at RIP=0x1000000000000
[RUN]   sigreturn to 0x2000000000000
[OK]    Got SIGSEGV at RIP=0x2000000000000
[RUN]   sigreturn to 0x4000000000000
[OK]    Got SIGSEGV at RIP=0x4000000000000
[RUN]   sigreturn to 0x8000000000000
[OK]    Got SIGSEGV at RIP=0x8000000000000
[RUN]   sigreturn to 0x10000000000000
[OK]    Got SIGSEGV at RIP=0x10000000000000
[RUN]   sigreturn to 0x20000000000000
[OK]    Got SIGSEGV at RIP=0x20000000000000
[RUN]   sigreturn to 0x40000000000000
[OK]    Got SIGSEGV at RIP=0x40000000000000
[RUN]   sigreturn to 0x80000000000000
[OK]    Got SIGSEGV at RIP=0x80000000000000
[RUN]   sigreturn to 0x100000000000000
[OK]    Got SIGSEGV at RIP=0x100000000000000
[RUN]   sigreturn to 0x200000000000000
[OK]    Got SIGSEGV at RIP=0x200000000000000
[RUN]   sigreturn to 0x400000000000000
[OK]    Got SIGSEGV at RIP=0x400000000000000
[RUN]   sigreturn to 0x800000000000000
[OK]    Got SIGSEGV at RIP=0x800000000000000
[RUN]   sigreturn to 0x1000000000000000
[OK]    Got SIGSEGV at RIP=0x1000000000000000
[RUN]   sigreturn to 0x2000000000000000
[OK]    Got SIGSEGV at RIP=0x2000000000000000
[RUN]   sigreturn to 0x4000000000000000
[OK]    Got SIGSEGV at RIP=0x4000000000000000
[RUN]   sigreturn to 0x8000000000000000
[OK]    Got SIGSEGV at RIP=0x8000000000000000
[RUN]   Trying a SYSCALL that falls through to 0x7fffffffe000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x7ffffffff000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x800000000000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0xfffffffff000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x1000000000000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x1fffffffff000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x2000000000000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x3fffffffff000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x4000000000000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x7fffffffff000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x8000000000000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0xffffffffff000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x10000000000000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x1ffffffffff000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x20000000000000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x3ffffffffff000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x40000000000000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x7ffffffffff000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x80000000000000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0xfffffffffff000
[OK]    We survived
[RUN]   Trying a SYSCALL that falls through to 0x100000000000000
[OK]    mremap to 0xfffffffffff000 failed
[RUN]   Trying a SYSCALL that falls through to 0x1fffffffffff000
[OK]    mremap to 0x1ffffffffffe000 failed
[RUN]   Trying a SYSCALL that falls through to 0x200000000000000
[OK]    mremap to 0x1fffffffffff000 failed
[RUN]   Trying a SYSCALL that falls through to 0x3fffffffffff000
[OK]    mremap to 0x3ffffffffffe000 failed
[RUN]   Trying a SYSCALL that falls through to 0x400000000000000
[OK]    mremap to 0x3fffffffffff000 failed
[RUN]   Trying a SYSCALL that falls through to 0x7fffffffffff000
[OK]    mremap to 0x7ffffffffffe000 failed
[RUN]   Trying a SYSCALL that falls through to 0x800000000000000
[OK]    mremap to 0x7fffffffffff000 failed
[RUN]   Trying a SYSCALL that falls through to 0xffffffffffff000
[OK]    mremap to 0xfffffffffffe000 failed
[RUN]   Trying a SYSCALL that falls through to 0x1000000000000000
[OK]    mremap to 0xffffffffffff000 failed
[RUN]   Trying a SYSCALL that falls through to 0x1ffffffffffff000
[OK]    mremap to 0x1fffffffffffe000 failed
[RUN]   Trying a SYSCALL that falls through to 0x2000000000000000
[OK]    mremap to 0x1ffffffffffff000 failed
[RUN]   Trying a SYSCALL that falls through to 0x3ffffffffffff000
[OK]    mremap to 0x3fffffffffffe000 failed
[RUN]   Trying a SYSCALL that falls through to 0x4000000000000000
[OK]    mremap to 0x3ffffffffffff000 failed
[RUN]   Trying a SYSCALL that falls through to 0x7ffffffffffff000
[OK]    mremap to 0x7fffffffffffe000 failed
[RUN]   Trying a SYSCALL that falls through to 0x8000000000000000
[OK]    mremap to 0x7ffffffffffff000 failed

-- 
 Kirill A. Shutemov

  reply	other threads:[~2017-01-03 15:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-27  3:20 [PATCH v2] selftests/x86: Add a selftest for SYSRET to noncanonical addresses Andy Lutomirski
2017-01-03 15:11 ` Kirill A. Shutemov [this message]
2017-01-05 15:07 ` [tip:x86/asm] " tip-bot for Andy Lutomirski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170103151155.GA17319@node.shutemov.name \
    --to=kirill@shutemov.name \
    --cc=bp@alien8.de \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.