This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC][PATCH] AArch64: use movz/movk instead of literal pools in start.S
- From: Szabolcs Nagy <szabolcs dot nagy at arm dot com>
- To: Andrew Pinski <pinskia at gmail dot com>, wangboshi <wangboshi at huawei dot com>
- Cc: nd at arm dot com, GNU C Library <libc-alpha at sourceware dot org>
- Date: Mon, 11 Sep 2017 10:24:50 +0100
- Subject: Re: [RFC][PATCH] AArch64: use movz/movk instead of literal pools in start.S
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Szabolcs dot Nagy at arm dot com;
- Nodisclaimer: True
- References: <e65025af-5168-c999-bfc1-7ac614314836@huawei.com> <CA+=Sn1n7edmzjTSDatyY1tfi3Lz70m3XjeXfgKbgDt_GCZE2NQ@mail.gmail.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
On 11/09/17 10:09, Andrew Pinski wrote:
> On Thu, Sep 7, 2017 at 12:33 AM, wangboshi <wangboshi@huawei.com> wrote:
>> eXecute-Only Memory (XOM) is a protection mechanism against some ROP
>> attacks. XOM sets the code as executable and unreadable, so the access to
>> any data, like literal pools, in the code section causes the fault with XOM.
>> The compiler can disable literal pools for C source files, but not for
>> assembly files, so I use movz/movk instead of literal pools in start.S for
>> XOM.
>>
>> I add MOVL macro with movz/movk instructions like movl pseudo-instruction in
>> armasm, and use the macro instead of literal pools.
>
> I have a few comments about the overall design:
> I don't know if this is a good idea, can the kernel override XOM anyways?
> That is if you do write(N, &main, 1024);
> That will write the main function out to the file?
i think the change makes sense even without xom, maybe
a better rationale is needed in the commit message.
(i don't know what the kernel does with the write, with
a non-readable page i'd expect the write to fail just
like on PROT_NONE pages: EFAULT).
>> +/* Load an immediate into R.
>> + Note R is a register number and not a register name. */
>> +#ifdef __LP64__
>> +# define MOVL(n, name) \
>> + movz PTR_REG(n), #:abs_g3:name; \
>> + movk PTR_REG(n), #:abs_g2_nc:name; \
>> + movk PTR_REG(n), #:abs_g1_nc:name; \
>> + movk PTR_REG(n), #:abs_g0_nc:name;
>> +#else
>> +# define MOVL(n, name) \
>> + movz PTR_REG(n), #:abs_g1:name; \
>> + movk PTR_REG(n), #:abs_g0_nc:name;
>> +#endif
>
> Since PTR_REG is defined only based on __LP64__ already why don't you just do:
i think either is fine (the meaning of PTR_REG should
be obvious since it is used all over the place)
> #ifdef __LP64__
> # define MOVL(n, name) \
> movz x##n, #:abs_g3:name; \
> movk x##n, #:abs_g2_nc:name; \
> movk x##n, #:abs_g1_nc:name; \
> movk x##n, #:abs_g0_nc:name;
> #else
> # define MOVL(n, name) \
> movz w##n, #:abs_g1:name; \
> movk w##n, #:abs_g0_nc:name;
> #endif