Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1544829
| Path | csiph.com!news.mixmin.net!aioe.org!news.servidellagleba.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | Andy Lutomirski <luto@amacapital.net> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] selftests/x86: Add a selftest for SYSRET to noncanonical addresses |
| Date | Tue, 20 Dec 2016 00:40:01 +0100 |
| Message-ID | <sQfHb-605-29@gated-at.bofh.it> (permalink) |
| References | <sQbDz-3xO-19@gated-at.bofh.it> <sQfHb-605-25@gated-at.bofh.it> |
| X-Original-To | "Kirill A. Shutemov" <kirill@shutemov.name> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=mdYSdy2+rJ2HllxvDUeHY/Q0wQZSDBcIUrOITpV9SYw=; b=TLTu58iN5AubZJ5fzZTNHKl6QkaVAaRCaUtuU2mReyILt9WgZdOokGQrFMUIp5d32c g/h7NC5Mt8qkpvAsfY9VRy0i5jY27THrqrrvRRvDNaMWwxhEQVOeKZA/VpqqB81EOdV+ blhnjdsM/Mv2FtJZy/v3y877fv247nIGQ/XbCldX/HSrfQAWeeE4gMJFV08huAwYOl8W ep04gjUQ0iIrpQGilNtzYs1N7CIgKDhJ7EzOsjhbQZuiuq/SuPflKL2+QHijAQSlbzYn /MLHZZWxrJmf/AVU0BqljAZhLXT1Bpa2DYCQquxGask0Wgf1xFtKl+VhFfch+wkKyx9T WZzw== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=mdYSdy2+rJ2HllxvDUeHY/Q0wQZSDBcIUrOITpV9SYw=; b=gay9rrqvDiLmmiKl5knGNV56PMGMacWTaN9oKenT/FrfZdltvNT7JbAqTyqSDoILDi 9TSAoj8GTwrRVqAGuKz3WgUd1IVkjmpPA0gb0dbuG3hDxFESFBrjOLi2K0EFVz4BMM9T h+jo/UW1Ksy+j86vy00ubLbf78MfvuJ5w24MM6Uff0sORWEMgM2GJeAxrn0QBQ1r2BUK t6XrrCQ1WrKWQz6A0aHUMlttR46SlLPshOUQpHSdybiMsqX9FFWSSv0YH2zjx+yqf+36 2Bz12bYaAMlI6MN2HyoZ2VUvRf9uHJvm/gDJqQaKflW3kE6q3TaUoj2XTqYhACpXMslq ehVA== |
| X-Gm-Message-State | AIkVDXJXkms8kZ/Z8c+dCirSsXtWGCFSkAzuxHv6yYXWJ58KY4mxkIIRdofoJsOl7NHyn9cnxCuPrmYeqTFaJQKu |
| X-Received | by 10.31.131.208 with SMTP id f199mr6962005vkd.154.1482190685510; Mon, 19 Dec 2016 15:38:05 -0800 (PST) |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 78 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Andy Lutomirski <luto@kernel.org>, X86 ML <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> |
| X-Original-Date | Mon, 19 Dec 2016 15:37:45 -0800 |
| X-Original-Message-ID | <CALCETrVpnH4YDVQTM2vb6iELrr439xn-GZqO4exZ9PHdbYROGw@mail.gmail.com> |
| X-Original-References | <cfaa34f39f8a339965336c64c229f818c72e4c52.1482174742.git.luto@kernel.org> <20161219233033.GB24180@node.shutemov.name> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1544829 |
Show key headers only | View raw
On Mon, Dec 19, 2016 at 3:30 PM, Kirill A. Shutemov
<kirill@shutemov.name> wrote:
> On Mon, Dec 19, 2016 at 11:12:42AM -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.
>>
>> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
>> Signed-off-by: Andy Lutomirski <luto@kernel.org>
>
> Thanks a lot.
>
> That's what I've got with 5-level paging:
[...]
Looks good.
>> + err(1, "mremap to 0x%p", new_address);
>
> "0x" is redundant for %p.
>
>> + } else {
>> + printf("[OK]\tmremap to 0x%p failed\n", new_address);
>
> Ditto.
Will fix.
>> + test_sigreturn_to((1UL<<i));
>
> Redundant parenthesis?
Indeed.
>
>> +
>> + clearhandler(SIGUSR1);
>> +
>> + sethandler(SIGSEGV, sigsegv_for_fallthrough, 0);
>> +
>> + /* This should execute on all kernels. */
>> + test_syscall_fallthrough_to((1UL << 47) - PAGE_SIZE);
>> +
>> + /* Make sure that we didn't screw up the mremap logic. */
>> + test_syscall_fallthrough_to((1UL << 47) - 2*PAGE_SIZE);
>> +
>> + /* These are the interesting cases. */
>> + for (int i = 47; i < 64; i++)
>> + test_syscall_fallthrough_to((1UL<<i));
>
> Ditto.
>
> Also, "(1UL << i) - PAGE_SIZE" is interesting too. TASK_SIZE for 5-level
> paging would be (1UL << 56) - PAGE_SIZE. I would be better to catch both
> corner cases.
There's not much scope for error, though -- (1UL << 56) - PAGE_SIZE
isn't really any different from any other address. I all add it, but
I'm not sure I see any way that the kernel could plausible get it
wrong. I guess it's comforting to see the boundary, though.
--Andy
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH] selftests/x86: Add a selftest for SYSRET to noncanonical addresses Andy Lutomirski <luto@kernel.org> - 2016-12-19 20:20 +0100
Re: [PATCH] selftests/x86: Add a selftest for SYSRET to noncanonical addresses "Kirill A. Shutemov" <kirill@shutemov.name> - 2016-12-20 00:40 +0100
Re: [PATCH] selftests/x86: Add a selftest for SYSRET to noncanonical addresses Andy Lutomirski <luto@amacapital.net> - 2016-12-20 00:40 +0100
csiph-web