[lld] r290986 - ELF: Round p_memsz of the PT_GNU_RELRO program header up to the page size.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 27 13:09:12 PST 2017


On Fri, Jan 27, 2017 at 1:01 PM, Ed Maste <emaste at freebsd.org> wrote:

> On 27 January 2017 at 13:36, Rafael Avila de Espindola
> <rafael.espindola at gmail.com> wrote:
> >
> > Can you expand a bit on how this crashes? The first section after
> > PT_GNU_RELRO is also aligned to MaxPageSize:
>
> But the end of the final PT_LOAD is not aligned to MaxPageSize.
>
> I don't have the exact details (they were relayed to me over IRC), but
> this isn't an allocation from LLD, it's e.g. a malloc() from the
> application. It might be that it requires multiple threads, with
> simultaneous dlopen() and malloc().
>
> The problem here is that the PT_GNU_RELRO covered up to 15 pages
> beyond the final PT_LOAD, with MaxPageSize=64K and 4K pages. So rtld
> maps the final PT_LOAD and then after relocation applies mprotect to
> pages that were never mapped by rtld.
>

So the bug is caused by an executable with .data.rel.ro but no .bss (or .
bss.rel.ro)? I see. So it sounds like we need to round to Target->PageSize
instead of Config->MaxPageSize. Here's a reproducer:

$ cat foo.s
.section .data.rel.ro,"aw",%progbits
.byte 1
$ llvm-mc -filetype=obj -triple=aarch64-linux-gnu -o foo.o foo.s
$ ld.lld -o foo foo.o
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x20000
$ llvm-readobj -program-headers foo

File: foo
Format: ELF64-aarch64-little
Arch: aarch64
AddressSize: 64bit
LoadName:
ProgramHeaders [
  ProgramHeader {
    Type: PT_PHDR (0x6)
    Offset: 0x40
    VirtualAddress: 0x10040
    PhysicalAddress: 0x10040
    FileSize: 336
    MemSize: 336
    Flags [ (0x4)
      PF_R (0x4)
    ]
    Alignment: 8
  }
  ProgramHeader {
    Type: PT_LOAD (0x1)
    Offset: 0x0
    VirtualAddress: 0x10000
    PhysicalAddress: 0x10000
    FileSize: 400
    MemSize: 400
    Flags [ (0x4)
      PF_R (0x4)
    ]
    Alignment: 65536
  }
  ProgramHeader {
    Type: PT_LOAD (0x1)
    Offset: 0x10000
    VirtualAddress: 0x20000
    PhysicalAddress: 0x20000
    FileSize: 1
    MemSize: 1
    Flags [ (0x6)
      PF_R (0x4)
      PF_W (0x2)
    ]
    Alignment: 65536
  }
  ProgramHeader {
    Type: PT_GNU_RELRO (0x6474E552)
    Offset: 0x10000
    VirtualAddress: 0x20000
    PhysicalAddress: 0x20000
    FileSize: 1
    MemSize: 65536
    Flags [ (0x4)
      PF_R (0x4)
    ]
    Alignment: 1
  }
  ProgramHeader {
    Type: PT_GNU_STACK (0x6474E551)
    Offset: 0x0
    VirtualAddress: 0x0
    PhysicalAddress: 0x0
    FileSize: 0
    MemSize: 0
    Flags [ (0x6)
      PF_R (0x4)
      PF_W (0x2)
    ]
    Alignment: 0
  }
]


Thanks,
-- 
-- 
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170127/2072ae2a/attachment.html>


More information about the llvm-commits mailing list