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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 10 Mar 2015 20:35:40 -0700
From:	Andy Lutomirski <luto@...capital.net>
To:	Ingo Molnar <mingo@...nel.org>
Cc:	Denys Vlasenko <dvlasenk@...hat.com>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Steven Rostedt <rostedt@...dmis.org>,
	Borislav Petkov <bp@...en8.de>,
	"H. Peter Anvin" <hpa@...or.com>, Oleg Nesterov <oleg@...hat.com>,
	Frederic Weisbecker <fweisbec@...il.com>,
	Alexei Starovoitov <ast@...mgrid.com>,
	Will Drewry <wad@...omium.org>,
	Kees Cook <keescook@...omium.org>, X86 ML <x86@...nel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] x86: entry_32.S: change ESPFIX test to not touch PT_OLDSS(%esp)

On Tue, Mar 10, 2015 at 12:57 AM, Ingo Molnar <mingo@...nel.org> wrote:
>
> * Denys Vlasenko <dvlasenk@...hat.com> wrote:
>
>> Old code was trying to avoid having three branch insns,
>> but instead it has a chain of six insns where each insn
>> depends on previos one.
>>
>> And it was touching PT_OLDSS(%esp) unconditionally, even when it may
>> contain bogus data. Elsewhere we have to jump thru hoops
>> just to make sure here PT_OLDSS(%esp) is at least in a valid page.
>>
>> All this just to have one branch instead of three?
>>
>> The new code simply checks each condition.
>> All three checks can run in parallel on an out-of-order CPU.
>> Most of the time, none of branches will be taken.
>>
>> Comparison of object code:
>>     Old:
>>      1e6:   8b 44 24 38             mov    0x38(%esp),%eax
>>      1ea:   8a 64 24 40             mov    0x40(%esp),%ah
>>      1ee:   8a 44 24 34             mov    0x34(%esp),%al
>>      1f2:   25 03 04 02 00          and    $0x20403,%eax
>>      1f7:   3d 03 04 00 00          cmp    $0x403,%eax
>>      1fc:   74 0f                   je     20d <ldt_ss>
>>     New:
>>      1e6:   f6 44 24 3a 02          testb  $0x2,0x3a(%esp)
>>      1eb:   75 0e                   jne    1fb <restore_nocheck>
>>      1ed:   f6 44 24 34 03          testb  $0x3,0x34(%esp)
>>      1f2:   74 07                   je     1fb <restore_nocheck>
>>      1f4:   f6 44 24 40 04          testb  $0x4,0x40(%esp)
>>      1f9:   75 0f                   jne    20a <ldt_ss>
>
> Please do some benchmarking of this: a tight loop of getpid or getppid
> syscalls ought to be enough to be able to time this accurately.

Before you benchmark, I think you should reorder it: check CS, then
OLDSS, then EFLAGS.  The case where CS & 3 == 0, OLDSS & 4 == 4, and
EFLAGS & VM == VM should be *extremely* rare.

I'm going to hold off on resending my sp0/sp1/ss cleanups until we
resolve this -- if it turns out that your code is the same or faster
and therefore gets merged, then I think that all the -8 crap can just
be deleted instead of being fixed.

--Andy

>
> Thanks,
>
>         Ingo



-- 
Andy Lutomirski
AMA Capital Management, LLC
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ