<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 27, 2017 at 1:01 PM, Ed Maste <span dir="ltr"><<a href="mailto:emaste@freebsd.org" target="_blank">emaste@freebsd.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 27 January 2017 at 13:36, Rafael Avila de Espindola<br>
<span class="gmail-"><<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br>
><br>
> Can you expand a bit on how this crashes? The first section after<br>
> PT_GNU_RELRO is also aligned to MaxPageSize:<br>
<br>
</span>But the end of the final PT_LOAD is not aligned to MaxPageSize.<br>
<br>
I don't have the exact details (they were relayed to me over IRC), but<br>
this isn't an allocation from LLD, it's e.g. a malloc() from the<br>
application. It might be that it requires multiple threads, with<br>
simultaneous dlopen() and malloc().<br>
<br>
The problem here is that the PT_GNU_RELRO covered up to 15 pages<br>
beyond the final PT_LOAD, with MaxPageSize=64K and 4K pages. So rtld<br>
maps the final PT_LOAD and then after relocation applies mprotect to<br>
pages that were never mapped by rtld.<br>
</blockquote></div><br>So the bug is caused by an executable with .<a href="http://data.rel.ro">data.rel.ro</a> but no .bss (or .<a href="http://bss.rel.ro">bss.rel.ro</a>)? I see. So it sounds like we need to round to Target->PageSize instead of Config->MaxPageSize. Here's a reproducer:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">$ cat foo.s</div><div class="gmail_extra">.section .<a href="http://data.rel.ro">data.rel.ro</a>,"aw",%progbits</div><div class="gmail_extra">.byte 1</div><div class="gmail_extra">$ llvm-mc -filetype=obj -triple=aarch64-linux-gnu -o foo.o foo.s<br></div><div class="gmail_extra">$ ld.lld -o foo foo.o</div><div class="gmail_extra">ld.lld: warning: cannot find entry symbol _start; defaulting to 0x20000</div><div class="gmail_extra">$ llvm-readobj -program-headers foo </div><div class="gmail_extra"><br></div><div class="gmail_extra">File: foo</div><div class="gmail_extra">Format: ELF64-aarch64-little</div><div class="gmail_extra">Arch: aarch64</div><div class="gmail_extra">AddressSize: 64bit</div><div class="gmail_extra">LoadName: </div><div class="gmail_extra">ProgramHeaders [</div><div class="gmail_extra">  ProgramHeader {</div><div class="gmail_extra">    Type: PT_PHDR (0x6)</div><div class="gmail_extra">    Offset: 0x40</div><div class="gmail_extra">    VirtualAddress: 0x10040</div><div class="gmail_extra">    PhysicalAddress: 0x10040</div><div class="gmail_extra">    FileSize: 336</div><div class="gmail_extra">    MemSize: 336</div><div class="gmail_extra">    Flags [ (0x4)</div><div class="gmail_extra">      PF_R (0x4)</div><div class="gmail_extra">    ]</div><div class="gmail_extra">    Alignment: 8</div><div class="gmail_extra">  }</div><div class="gmail_extra">  ProgramHeader {</div><div class="gmail_extra">    Type: PT_LOAD (0x1)</div><div class="gmail_extra">    Offset: 0x0</div><div class="gmail_extra">    VirtualAddress: 0x10000</div><div class="gmail_extra">    PhysicalAddress: 0x10000</div><div class="gmail_extra">    FileSize: 400</div><div class="gmail_extra">    MemSize: 400</div><div class="gmail_extra">    Flags [ (0x4)</div><div class="gmail_extra">      PF_R (0x4)</div><div class="gmail_extra">    ]</div><div class="gmail_extra">    Alignment: 65536</div><div class="gmail_extra">  }</div><div class="gmail_extra">  ProgramHeader {</div><div class="gmail_extra">    Type: PT_LOAD (0x1)</div><div class="gmail_extra">    Offset: 0x10000</div><div class="gmail_extra">    VirtualAddress: 0x20000</div><div class="gmail_extra">    PhysicalAddress: 0x20000</div><div class="gmail_extra">    FileSize: 1</div><div class="gmail_extra">    MemSize: 1</div><div class="gmail_extra">    Flags [ (0x6)</div><div class="gmail_extra">      PF_R (0x4)</div><div class="gmail_extra">      PF_W (0x2)</div><div class="gmail_extra">    ]</div><div class="gmail_extra">    Alignment: 65536</div><div class="gmail_extra">  }</div><div class="gmail_extra">  ProgramHeader {</div><div class="gmail_extra">    Type: PT_GNU_RELRO (0x6474E552)</div><div class="gmail_extra">    Offset: 0x10000</div><div class="gmail_extra">    VirtualAddress: 0x20000</div><div class="gmail_extra">    PhysicalAddress: 0x20000</div><div class="gmail_extra">    FileSize: 1</div><div class="gmail_extra">    MemSize: 65536</div><div class="gmail_extra">    Flags [ (0x4)</div><div class="gmail_extra">      PF_R (0x4)</div><div class="gmail_extra">    ]</div><div class="gmail_extra">    Alignment: 1</div><div class="gmail_extra">  }</div><div class="gmail_extra">  ProgramHeader {</div><div class="gmail_extra">    Type: PT_GNU_STACK (0x6474E551)</div><div class="gmail_extra">    Offset: 0x0</div><div class="gmail_extra">    VirtualAddress: 0x0</div><div class="gmail_extra">    PhysicalAddress: 0x0</div><div class="gmail_extra">    FileSize: 0</div><div class="gmail_extra">    MemSize: 0</div><div class="gmail_extra">    Flags [ (0x6)</div><div class="gmail_extra">      PF_R (0x4)</div><div class="gmail_extra">      PF_W (0x2)</div><div class="gmail_extra">    ]</div><div class="gmail_extra">    Alignment: 0</div><div class="gmail_extra">  }</div><div class="gmail_extra">]</div><div><br></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks,<br>-- <br><div class="gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>
</div></div>