From 11d9eed6ce4b481b5745972fe4d080e788c0c112 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Tue, 24 Aug 2021 16:12:18 +0200 Subject: [PATCH] Link libp11-kit so that it cannot unload libp11-kit installs a pthread_atfork() callback to count forks. If the library gets unloaded, a stale pointer is called on the next fork(), leading to a crash. This fix adds -z nodelete linker flag so that libp11-kit cannot be unloaded. Unfortunately, that only fixes the problem for GNU ld. More additionnal flags will be required for other linkers. --- configure.ac | 13 +++++++++++++ p11-kit/Makefile.am | 1 + 2 files changed, 14 insertions(+) diff --git a/configure.ac b/configure.ac index 6fdf1f27a..6f2c19878 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,19 @@ LT_INIT([dlopen disable-static]) dnl Check if -Wl,--version-script is supported by the linker gl_LD_VERSION_SCRIPT +# -------------------------------------------------------------------- +# Check for -z nodelete link flag + +SAVE_LDFLAGS="$LDFLAGS" +LDFLAGS="$LDFLAGS -Wl,-z -Wl,nodelete" +AC_MSG_CHECKING([whether linker understands -z nodelete]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], + [LDFLAGS_Z_NODELETE="-Wl,-z -Wl,nodelete"; has_option=yes], + [LDFLAGS_Z_NODELETE=""; has_option=no]) +AC_MSG_RESULT($has_option) +LDFLAGS="$SAVE_LDFLAGS" +AC_SUBST(LDFLAGS_Z_NODELETE) + dnl Checks for programs. AC_PROG_CC AC_PROG_CPP diff --git a/p11-kit/Makefile.am b/p11-kit/Makefile.am index 0ed41883f..7fe7a6cbf 100644 --- a/p11-kit/Makefile.am +++ b/p11-kit/Makefile.am @@ -87,6 +87,7 @@ COMMON_LIBS = \ libp11_kit_la_CFLAGS = $(COMMON_CFLAGS) libp11_kit_la_LDFLAGS = \ + $(LDFLAGS_Z_NODELETE) \ -no-undefined \ -version-info $(P11KIT_LT_RELEASE)