Skip to contentSkip to conversation

Link nfct and helper modules with `-z lazy`

PATCH Applied Kevin Cernekee 2 participants 2 messages Sep 11, 2016 – Sep 22, 2016 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Link nfct and helper modules with `-z lazy`

Some distributions, such as Gentoo and Chrome OS, try to link all programs with -z now as a security hardening measure. This breaks nfct, because nfct cannot satisfy all of the helper modules' symbols. Therefore nfct implicitly depends on lazy binding.

Have autoconf probe the linker to see if -z lazy works, and if so, use it to link nfct and the helpers.

conntrackd itself is unaffected, and should still work with -z now.

---

Note that the autoconf script is GPLv3. But I've seen it used in other projects, and it seemed like a nicer solution than re-inventing the wheel.

 configure.ac             |  3 ++
 m4/ax_check_link_flag.m4 | 74 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/Makefile.am          |  2 +-
 src/helpers/Makefile.am  | 39 +++++++++++++------------
 4 files changed, 99 insertions(+), 19 deletions(-)
 create mode 100644 m4/ax_check_link_flag.m4
configure.ac +3 -0
index e2223d7555a5..6141220c0e6a 100644
@@ -118,6 +118,9 @@ dnl AC_CHECK_HEADERS([netinet/in.h stdlib.h])
 dnl AC_C_CONST
 dnl AC_C_INLINE
 
+# Let nfct use dlopen() on helper libraries without resolving all symbols.
+AX_CHECK_LINK_FLAG([-Wl,-z,lazy], [AC_SUBST([LAZY_LDFLAGS], [-Wl,-z,lazy])])
+
 # Checks for library functions.
 dnl AC_FUNC_MALLOC
 dnl AC_FUNC_VPRINTF
m4/ax_check_link_flag.m4 new file +74 -0

74 lines not on this page · raw message

src/Makefile.am +1 -1
index 607f19161857..144c52c48c64 100644
@@ -35,7 +35,7 @@ if HAVE_CTHELPER
 nfct_LDADD += ${LIBNETFILTER_CTHELPER_LIBS}
 endif
 
-nfct_LDFLAGS = -export-dynamic
+nfct_LDFLAGS = -export-dynamic @LAZY_LDFLAGS@
 
 conntrackd_SOURCES = alarm.c main.c run.c hash.c queue.c rbtree.c \
 		    local.c log.c mcast.c udp.c netlink.c vector.c \
src/helpers/Makefile.am +21 -18
index 51f4887ccced..05801bc7f703 100644
@@ -10,38 +10,41 @@ pkglib_LTLIBRARIES = ct_helper_amanda.la \
 		     ct_helper_sane.la	\
 		     ct_helper_ssdp.la
 
+HELPER_LDFLAGS = -avoid-version -module $(LIBNETFILTER_CONNTRACK_LIBS) @LAZY_LDFLAGS@
+HELPER_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_CONNTRACK_CFLAGS)
+
 ct_helper_amanda_la_SOURCES = amanda.c
-ct_helper_amanda_la_LDFLAGS = -avoid-version -module $(LIBNETFILTER_CONNTRACK_LIBS)
-ct_helper_amanda_la_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_CONNTRACK_CFLAGS)
+ct_helper_amanda_la_LDFLAGS = $(HELPER_LDFLAGS)
+ct_helper_amanda_la_CFLAGS = $(HELPER_CFLAGS)
 
 ct_helper_dhcpv6_la_SOURCES = dhcpv6.c
-ct_helper_dhcpv6_la_LDFLAGS = -avoid-version -module $(LIBNETFILTER_CONNTRACK_LIBS)
-ct_helper_dhcpv6_la_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_CONNTRACK_CFLAGS)
+ct_helper_dhcpv6_la_LDFLAGS = $(HELPER_LDFLAGS)
+ct_helper_dhcpv6_la_CFLAGS = $(HELPER_CFLAGS)
 
 ct_helper_ftp_la_SOURCES = ftp.c
-ct_helper_ftp_la_LDFLAGS = -avoid-version -module $(LIBNETFILTER_CONNTRACK_LIBS)
-ct_helper_ftp_la_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_CONNTRACK_CFLAGS)
+ct_helper_ftp_la_LDFLAGS = $(HELPER_LDFLAGS)
+ct_helper_ftp_la_CFLAGS = $(HELPER_CFLAGS)
 
 ct_helper_mdns_la_SOURCES = mdns.c
-ct_helper_mdns_la_LDFLAGS = -avoid-version -module $(LIBNETFILTER_CONNTRACK_LIBS)
-ct_helper_mdns_la_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_CONNTRACK_CFLAGS)
+ct_helper_mdns_la_LDFLAGS = $(HELPER_LDFLAGS)
+ct_helper_mdns_la_CFLAGS = $(HELPER_CFLAGS)
 
 ct_helper_rpc_la_SOURCES = rpc.c
-ct_helper_rpc_la_LDFLAGS = -avoid-version -module $(LIBNETFILTER_CONNTRACK_LIBS)
-ct_helper_rpc_la_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_CONNTRACK_CFLAGS)
+ct_helper_rpc_la_LDFLAGS = $(HELPER_LDFLAGS)
+ct_helper_rpc_la_CFLAGS = $(HELPER_CFLAGS)
 
 ct_helper_tftp_la_SOURCES = tftp.c
-ct_helper_tftp_la_LDFLAGS = -avoid-version -module $(LIBNETFILTER_CONNTRACK_LIBS)
-ct_helper_tftp_la_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_CONNTRACK_CFLAGS)
+ct_helper_tftp_la_LDFLAGS = $(HELPER_LDFLAGS)
+ct_helper_tftp_la_CFLAGS = $(HELPER_CFLAGS)
 
 ct_helper_tns_la_SOURCES = tns.c
-ct_helper_tns_la_LDFLAGS = -avoid-version -module $(LIBNETFILTER_CONNTRACK_LIBS)
-ct_helper_tns_la_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_CONNTRACK_CFLAGS)
+ct_helper_tns_la_LDFLAGS = $(HELPER_LDFLAGS)
+ct_helper_tns_la_CFLAGS = $(HELPER_CFLAGS)
 
 ct_helper_sane_la_SOURCES = sane.c
-ct_helper_sane_la_LDFLAGS = -avoid-version -module $(LIBNETFILTER_CONNTRACK_LIBS)
-ct_helper_sane_la_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_CONNTRACK_CFLAGS)
+ct_helper_sane_la_LDFLAGS = $(HELPER_LDFLAGS)
+ct_helper_sane_la_CFLAGS = $(HELPER_CFLAGS)
 
 ct_helper_ssdp_la_SOURCES = ssdp.c
-ct_helper_ssdp_la_LDFLAGS = -avoid-version -module $(LIBNETFILTER_CONNTRACK_LIBS)
-ct_helper_ssdp_la_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_CONNTRACK_CFLAGS)
+ct_helper_ssdp_la_LDFLAGS = $(HELPER_LDFLAGS)
+ct_helper_ssdp_la_CFLAGS = $(HELPER_CFLAGS)
Signature · 1 line
2.8.0.rc3.226.g39d4020
maintainer Applied
#1 lore raw
Quoted 9 lines · Kevin Cernekee

Some distributions, such as Gentoo and Chrome OS, try to link all programs with -z now as a security hardening measure. This breaks nfct, because nfct cannot satisfy all of the helper modules' symbols. Therefore nfct implicitly depends on lazy binding.

Have autoconf probe the linker to see if -z lazy works, and if so, use it to link nfct and the helpers.

conntrackd itself is unaffected, and should still work with -z now.

Applied, thanks for your patience.