Ticket #105 (closed enhancement: fixed)

Opened 2 years ago

Last modified 1 month ago

build with -fstack-protector by default

Reported by: lennart Assigned to: lennart
Priority: minor Milestone: Avahi 0.6.18
Component: build-system Version:
Keywords: Cc: tedp

Description

Some distributions enable -fstack-protector globally (such as Ubuntu), others don't (such as Debian).

It makes sense to enable this feature explicitly for Avahi, since we are a networked service and we don't do anything particularly problematic which would be incompatible with it.

Needs some autoconf magic, of course, since it is only available in gcc 4.1 and some patched versions of gcc 3.x.

Also build everything as a PIE/PIC to make address space randomization actually work.

Attachments

gcc_stack_protect.m4 (3.1 kB) - added by tedp on 04/15/07 14:14:43.
Better autoconf macros
avahi-ssp-libc-check.patch (2.8 kB) - added by tedp on 04/17/07 15:04:17.
Tests for buggy stack-smashing protection

Change History

02/15/07 08:25:12 changed by tedp

Here are some macros that might help out: http://bugs.debian.org/cgi-bin/bugreport.cgi/gcc_stack_protect.m4?bug=366094;msg=17;att=3

You're not meant to have to add -lssp to the LDFLAGS manually, but I've found I had to on a few occasions. I think Lennart suggested putting -lssp in LIBS instead of LDFLAGS.

04/12/07 23:29:02 changed by lennart

(In [1411]) add gcc stack protector m4 to svn. unfortunately we cannot enable it (yet), because it breaks our build in avahi-glib, due to some unknonwn reason. tedp, help me! (re #105)

04/12/07 23:29:43 changed by lennart

  • status changed from new to assigned.
  • milestone set to Avahi 0.6.18.

04/12/07 23:29:55 changed by lennart

  • component changed from avahi-core to build-system.

04/13/07 01:17:02 changed by tedp

  • cc set to tedp.

04/15/07 09:55:15 changed by tedp

If you add -Wl,-z,defs to LDFLAGS (please do!) it will detect unresolved symbols in avahi-common:

.libs/libavahi_common_la-domain.o: In function `avahi_service_name_split':
/tmp/avahi-trunk/avahi-common/domain.c:575: undefined reference to `__stack_chk_fail_local'

This turns out to be a bug in glibc (fixed in glibc 2.5 by Ulrich Drepper, 2006-07-28). I have played around trying to create a test case, but no luck yet.

-fstack-protector works fine with glibc 2.5, or with '-lssp' if ssp support is not included in libc. Debian 4.0 is currently broken in this way (as of libc6 2.3.6.ds1-13), so it would be nice to have a configure test to work around an affected libc.

Yes, the '-lssp' should be added to LIBS not LDFLAGS in the autoconf macro (although that might be unnecessary since ssp has been folded into libc).

If anyone wants to have a go at creating an autoconf test for this problem, it would be great.

04/15/07 12:53:24 changed by tedp

For the benefit of search engines, without -Wl,-z,defs in the linker options you'll get an error message more like this when something tries to link with the library:

/usr/bin/ld: .libs/glib-watch-test: hidden symbol `__stack_chk_fail_local' in /usr/lib/gcc/i486-linux-gnu/4.1.2/libssp_nonshared.a(libssp_nonshared_la-ssp-local.o) is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output

04/15/07 14:14:43 changed by tedp

  • attachment gcc_stack_protect.m4 added.

Better autoconf macros

04/17/07 15:04:17 changed by tedp

  • attachment avahi-ssp-libc-check.patch added.

Tests for buggy stack-smashing protection

04/18/07 22:40:00 changed by lennart

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [1440]) Yes, I suck. This commit contains two totally unrelated changes and I really should commit them seperately, but I am ignoring my own rules, and do it in a single commit. I suck. I really do. I am sorry. Please don't try this at home. And please don't tell your children!

* Show properly that avahi-autoipd is not built if libdaemon is missing (Closes #133)

* Enable stack-smashing protection if available and wokring. Patch from tedp. (Closes #105)