[Bug binutils/22829] objcopy/strip: PT_GNU_RELRO is removed when it's not placed before read-only section

2018-02-13 Thread cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=22829

--- Comment #10 from cvs-commit at gcc dot gnu.org  ---
The master branch has been updated by Alan Modra :

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f2731e0c374e5323ce4cdae2bcc7b7fe22da1a6f

commit f2731e0c374e5323ce4cdae2bcc7b7fe22da1a6f
Author: Alan Modra 
Date:   Mon Feb 12 13:06:07 2018 +1030

PR22829, objcopy/strip removes PT_GNU_RELRO from lld binaries

lld lays out the relro segment differently to GNU ld, not bothering to
include the first few bytes of .got.plt and padding out to a page at
the end of the segment.  This patch teaches binutils to recognize the
different (and somewhat inferior) layout as valid.

bfd/
PR 22829
* elf.c (assign_file_positions_for_non_load_sections): Rewrite
PT_GNU_RELRO setup.
ld/
* testsuite/ld-x86-64/pr14207.d: Adjust relro p_filesz.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug binutils/22829] objcopy/strip: PT_GNU_RELRO is removed when it's not placed before read-only section

2018-02-12 Thread ngg at tresorit dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=22829

--- Comment #9 from NGG  ---
The second patch works in all the cases I've tried, thanks!

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug binutils/22829] objcopy/strip: PT_GNU_RELRO is removed when it's not placed before read-only section

2018-02-12 Thread amodra at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=22829

Alan Modra  changed:

   What|Removed |Added

  Attachment #10808|0   |1
is obsolete||

--- Comment #8 from Alan Modra  ---
Created attachment 10810
  --> https://sourceware.org/bugzilla/attachment.cgi?id=10810&action=edit
a better fix

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug binutils/22829] objcopy/strip: PT_GNU_RELRO is removed when it's not placed before read-only section

2018-02-12 Thread amodra at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=22829

Alan Modra  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 CC|amodra at gmail dot com|
   Assignee|unassigned at sourceware dot org   |amodra at gmail dot com
   Severity|enhancement |normal

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug binutils/22829] objcopy/strip: PT_GNU_RELRO is removed when it's not placed before read-only section

2018-02-11 Thread ngg at tresorit dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=22829

--- Comment #7 from NGG  ---
Thank you for the quick response and patch proposal.

Sorry for overreacting. I assigned it to critical due to its possible security
implications and because of the wide range of products it might affect. I
should have either written this at my initial description or leave it at normal
and let you decide its severity.

Your patch seems to work in my case, I've tried it with a few examples with all
of ld.bfd, ld.gold, ld.lld.

Although it is strange that for example on my sample input the
Type   Offset   VirtAddr   PhysAddr   FileSiz  MemSiz  
Flg Align
GNU_RELRO  0x003000 0x00203000 0x00203000 0x0001a0 0x001000
R   0x1
becomes (after stripping)
GNU_RELRO  0x003000 0x00203000 0x00203000 0x001000 0x001000
R   0x1

The whole file is smaller than 0x4000 so p_filesz cannot be correct.
It's working because the glibc dynamic linker only checks p_vaddr, p_memsz
(https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/dl-load.c;hb=7bb087bd7bfe3616c4c0974a3f7352b593353ea5#l1095)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug binutils/22829] objcopy/strip: PT_GNU_RELRO is removed when it's not placed before read-only section

2018-02-11 Thread amodra at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=22829

--- Comment #6 from Alan Modra  ---
Created attachment 10808
  --> https://sourceware.org/bugzilla/attachment.cgi?id=10808&action=edit
prospective patch

The importance fields are for use by binutils maintainers.  They are not for
users to flag how important the bug is to them.  You selected "critical" which
is quite obviously wrong from the point of view of the binutils project, and
perhaps I overreacted by marking your bug all the way down to "enhancement".

What you don't know is that I'd already investigated the problem to the point
of writing a fix, which would have worked but runs foul of what looks to be a
lld bug.  Why is lld putting p_memsz of the relro header larger than p_filsz? 
So I looked and found https://reviews.llvm.org/D28267.  Apparently lld doesn't
try to align the end of the relro segment.  That has the unfortunate effect of
wasting space where it matters for targets with limited addressing, whereas
wasting space at the begining of the relro segment doesn't matter for such
targets (you have to waste space somewhere), reinforcing my opinion that lld is
a toy linker.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug binutils/22829] objcopy/strip: PT_GNU_RELRO is removed when it's not placed before read-only section

2018-02-11 Thread ngg at tresorit dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=22829

--- Comment #5 from NGG  ---
This is not an enhancement request, it is clearly a bug.
The ELF header is perfectly valid the way lld creates it, and strip reduces its
security.

This is why Chromium on Android switched to elfutils strip (see
https://chromium-review.googlesource.com/c/chromium/src/+/644908)
It also affects my project where I want to separate debug symbols after linking
and I also want to use lld's thin-lto optimizations.
Also embedded and source-based Linux distros will not be able to support lld
without either fixing this or switching to an alternative.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug binutils/22829] objcopy/strip: PT_GNU_RELRO is removed when it's not placed before read-only section

2018-02-11 Thread hjl.tools at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=22829

H.J. Lu  changed:

   What|Removed |Added

Summary|objcopy/strip: PT_GNU_RELRO |objcopy/strip: PT_GNU_RELRO
   |is removed when it's not at |is removed when it's not
   |the beginning of a PT_LOAD  |placed before read-only
   |area|section

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils