lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CALCETrVpnH4YDVQTM2vb6iELrr439xn-GZqO4exZ9PHdbYROGw@mail.gmail.com>
Date:   Mon, 19 Dec 2016 15:37:45 -0800
From:   Andy Lutomirski <luto@...capital.net>
To:     "Kirill A. Shutemov" <kirill@...temov.name>
Cc:     Andy Lutomirski <luto@...nel.org>, X86 ML <x86@...nel.org>,
        Borislav Petkov <bp@...en8.de>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
Subject: Re: [PATCH] selftests/x86: Add a selftest for SYSRET to noncanonical addresses

On Mon, Dec 19, 2016 at 3:30 PM, Kirill A. Shutemov
<kirill@...temov.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@...ux.intel.com>
>> Signed-off-by: Andy Lutomirski <luto@...nel.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ