Re: Fwd: Segfaulting with Ubuntu

Felix von Leitner <[email protected]>
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
> That worked!  What exactly causes this issue? Certainly not a buffer
> overflow in dietlibc?

I added a workaround to the Makefile.

The issue is this: Ubuntu adds -fstack-protector to the gcc default
flags, without telling anyone.  On x86_64, this emits code like this:

   b:   64 48 8b 04 25 28 00    mov    %fs:0x28,%rax
  12:   00 00 
  14:   48 89 45 f8             mov    %rax,-0x8(%rbp)

at the beginning of each function, and

  24:   48 8b 55 f8             mov    -0x8(%rbp),%rdx
  28:   64 48 33 14 25 28 00    xor    %fs:0x28,%rdx
  2f:   00 00 
  31:   74 05                   je     38 <foo+0x38>
  33:   e8 00 00 00 00          callq  38 <foo+0x38>
                        34: R_X86_64_PC32       __stack_chk_fail+0xfffffffffffffffc

at the end of each function.  Now, %fs is not initialized, and accessing
%fs:0x28 segfaults.  The libc startup code is expected to set this up,
so that that memory can be accessed and there is a random value at that
address.  Now, since Ubuntu enables the stack protector globally, the
function in dietlibc that sets up %fs and %fs:0x28 is ALSO compiled with
this extra code, and the first part accesses %fs:0x28 before the
function has a chance to set it up, causing a segfault.

If you ask me, the Ubuntu people deserve a kick in the nuts for this.

I added a workaround to the cvs Makefile.

Please note that dietlibc does not support -fstack-protector on all
platforms, because I do not have access to all platforms.  So you might
still get segfaults on non-x86 platforms.  If you do, please contact me
so we can add stack-protector support for your platform.

Felix
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.