Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 391899 - sys-devel/binutils-2.22: static bins segfault after __libc_csu_init on hardened
Summary: sys-devel/binutils-2.22: static bins segfault after __libc_csu_init on hardened
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: The Gentoo Linux Hardened Team
URL:
Whiteboard:
Keywords:
: 391939 393327 (view as bug list)
Depends on: 393321
Blocks:
  Show dependency tree
 
Reported: 2011-11-25 20:49 UTC by Bertrand Jacquin
Modified: 2016-07-04 03:21 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (emerge--info.txt,11.09 KB, text/plain)
2011-11-25 20:50 UTC, Bertrand Jacquin
Details
binutils-2.22-initfini-pie.patch (XX_all_binutils-2.22-initfini-pie.patch,1.26 KB, patch)
2011-12-02 14:28 UTC, iGentoo
Details | Diff
Add support for crtbeginTS.o (binutils-2.22-initfini-crtbeginTS.patch,1.65 KB, patch)
2011-12-05 21:23 UTC, Magnus Granberg
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bertrand Jacquin 2011-11-25 20:49:11 UTC
If I try to compile that small program staticaly :

$ cat conftest.c 
int
main ()
{

  ;
  return 0;
}

$ x86_64-pc-linux-gnu-gcc -march=core2 -O2 -pipe -fomit-frame-pointer -mtune=core2  -D_GNU_SOURCE -g -ggdb -static  conftest.c

It segfault :

$ ./a.out 
Segmentation fault

A backtrace :

$ gdb ./a.out 
...
(gdb) r
Starting program: /var/tmp/a.out 

Program received signal SIGSEGV, Segmentation fault.
0xffffffffffffffff in ?? ()
(gdb) bt
#0  0xffffffffffffffff in ?? ()
#1  0x0000000000400c8c in __libc_csu_init ()
#2  0x0000000000400699 in __libc_start_main ()
#3  0x0000000000400409 in _start ()

If I compile it as shared, all is fine :


$ x86_64-pc-linux-gnu-gcc -march=core2 -O2 -pipe -fomit-frame-pointer -mtune=core2  -D_GNU_SOURCE -g -ggdb conftest.c
$ ./a.out 

Attached a emerge --info

Is a objdump -d necessary ?

Reproducible: Always
Comment 1 Bertrand Jacquin 2011-11-25 20:50:14 UTC
Created attachment 293761 [details]
emerge --info
Comment 2 iGentoo 2011-11-26 08:36:54 UTC
*** Bug 391939 has been marked as a duplicate of this bug. ***
Comment 3 Magnus Granberg gentoo-dev 2011-11-27 13:10:45 UTC
Looks like binutils-2.22 make the linking fail some way so the static bin don't work.
Comment 4 Magnus Granberg gentoo-dev 2011-12-01 20:11:14 UTC
Looks like binutils 2.22 don't like the pie/static hybrid crtbeginTS.o
Something get wrong. On older binutils it was working fine.
Mike do you have any hint where to look in the binutils code for it?
Comment 5 iGentoo 2011-12-02 14:28:16 UTC
Created attachment 294519 [details, diff]
binutils-2.22-initfini-pie.patch
Comment 6 Magnus Granberg gentoo-dev 2011-12-02 16:08:20 UTC
(In reply to comment #5)
> Created attachment 294519 [details, diff] [details, diff]
> binutils-2.22-initfini-pie.patch

Tested and it works, thank you
Mike can we include it in next patch bump?
Comment 7 SpanKY gentoo-dev 2011-12-02 20:10:22 UTC
if we look at ld/scripttempl/elf.sc, i'm a bit uneasy by our crt handling.  aren't we already missing handling later on in the file ?

...
CTOR=".ctors        ${CONSTRUCTING-0} :
...
    KEEP (*crtbegin.o(.ctors))
    KEEP (*crtbegin?.o(.ctors))
...
    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
    KEEP (*(SORT(.ctors.*)))
    KEEP (*(.ctors))
...
DTOR=".dtors        ${CONSTRUCTING-0} :
...
    KEEP (*crtbegin.o(.dtors))
    KEEP (*crtbegin?.o(.dtors))
    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
    KEEP (*(SORT(.dtors.*)))
...
Comment 9 iGentoo 2011-12-02 22:28:56 UTC
Like this...?

@@ -264,6 +264,7 @@ CTOR=".ctors        ${CONSTRUCTING-0} :
 
     KEEP (*crtbegin.o(.ctors))
     KEEP (*crtbegin?.o(.ctors))
+    KEEP (*crtbeginTS.o(.ctors))
 
     /* We don't want to include the .ctor section from
        the crtend.o file until after the sorted ctors.
@@ -280,6 +281,7 @@ DTOR=".dtors        ${CONSTRUCTING-0} :
     ${CONSTRUCTING+${DTOR_START}}
     KEEP (*crtbegin.o(.dtors))
     KEEP (*crtbegin?.o(.dtors))
+    KEEP (*crtbeginTS.o(.dtors))
     KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
     KEEP (*(SORT(.dtors.*)))
     KEEP (*(.dtors))
Comment 10 SpanKY gentoo-dev 2011-12-02 22:50:30 UTC
that would be my guess ... but i'd like it if some hardened peeps did some testing before we commit that :)
Comment 11 Anthony Basile gentoo-dev 2011-12-03 13:51:52 UTC
(In reply to comment #10)
> that would be my guess ... but i'd like it if some hardened peeps did some
> testing before we commit that :)

I tested applying the patch in comments 5 and 9 and it resolves the issue.
Comment 12 Magnus Granberg gentoo-dev 2011-12-03 13:53:11 UTC
Works fine here to.
Comment 13 SpanKY gentoo-dev 2011-12-03 16:59:14 UTC
someone should post a patch i can actually d/l and apply ;)
Comment 14 Magnus Granberg gentoo-dev 2011-12-05 21:23:09 UTC
Created attachment 294895 [details, diff]
Add support for crtbeginTS.o

Add support for the crtbeginTS.o from hardened gcc.
Comment 15 SpanKY gentoo-dev 2011-12-05 21:33:57 UTC
Comment on attachment 294895 [details, diff]
Add support for crtbeginTS.o

i think you've got a copy & paste typo here; i'll fix it up when i commit:
     KEEP (*crtbegin?.o(.dtors))
+    KEEP (*crtbeginTS.o(.ctors))

pretty sure that should be .dtors
Comment 16 SpanKY gentoo-dev 2011-12-05 21:41:41 UTC
queued in the 2.22 patchset.  i'll bump once i go through open bugs to make sure there are no other pending things to include.
Comment 17 Magnus Granberg gentoo-dev 2011-12-11 21:59:16 UTC
*** Bug 393327 has been marked as a duplicate of this bug. ***
Comment 18 SpanKY gentoo-dev 2016-07-04 03:21:07 UTC
FYI i'm dropping this patch starting with 2.26.1 since it's been in gcc long enough.  i'll prob drop it from older binutils too, just not do an explicit patchset push for it.