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] [thread-next>] [day] [month] [year] [list]
Message-ID: <ae88354f68254b0ab17b67eb8696fa52@AcuMS.aculab.com>
Date:   Fri, 18 Feb 2022 22:37:14 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Andrew Cooper' <Andrew.Cooper3@...rix.com>,
        Peter Zijlstra <peterz@...radead.org>,
        "x86@...nel.org" <x86@...nel.org>,
        "joao@...rdrivepizza.com" <joao@...rdrivepizza.com>,
        "hjl.tools@...il.com" <hjl.tools@...il.com>,
        "jpoimboe@...hat.com" <jpoimboe@...hat.com>
CC:     "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "ndesaulniers@...gle.com" <ndesaulniers@...gle.com>,
        "keescook@...omium.org" <keescook@...omium.org>,
        "samitolvanen@...gle.com" <samitolvanen@...gle.com>,
        "mark.rutland@....com" <mark.rutland@....com>,
        "alyssa.milburn@...el.com" <alyssa.milburn@...el.com>
Subject: RE: [PATCH 05/29] x86: Base IBT bits

From: Andrew Cooper
> Sent: 18 February 2022 21:24
> 
> On 18/02/2022 21:11, David Laight wrote:
> > From: Andrew Cooper
> >> Sent: 18 February 2022 20:50
> >>
> >> On 18/02/2022 16:49, Peter Zijlstra wrote:
> >>> +/*
> >>> + * A bit convoluted, but matches both endbr32 and endbr64 without
> >>> + * having either as literal in the text.
> >>> + */
> >>> +static inline bool is_endbr(const void *addr)
> >>> +{
> >>> +	unsigned int val = ~*(unsigned int *)addr;
> >>> +	val |= 0x01000000U;
> >>> +	return val == ~0xfa1e0ff3;
> >>> +}
> >> At this point, I feel I've earned an "I told you so". :)
> >>
> >> Clang 13 sees straight through the trickery and generates:
> >>
> >> is_endbr:                               # @is_endbr
> >>         movl    $-16777217, %eax                # imm = 0xFEFFFFFF
> >>         andl    (%rdi), %eax
> >>         cmpl    $-98693133, %eax                # imm = 0xFA1E0FF3
> >>         sete    %al
> >>         retq
> > I think it is enough to add:
> > 	asm("", "=r" (val));
> > somewhere in the middle.
> 
> (First, you mean "+r" not "=r"),

I always double check....

> but no - the problem isn't val.  It's
> `~0xfa1e0ff3` which the compiler is free to transform in several unsafe way.

Actually you could do (modulo stupid errors):
	val = (*(unsigned int *)addr & ~0x01000000) ^ 0xff3;
	asm("", "+r" (val));
	return val ^ 0xfa1e0000;
which should be zero for endbra and non-zero overwise.
Shame the compiler will probably never use the flags from the final xor.
Converting to bool just adds code!
(I hate bool)

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ