aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2018-03-08 20:35:20 -0600
committerEric Sandeen <sandeen@redhat.com>2018-03-08 20:35:20 -0600
commit1b0adc71229ba8611b06abc2bffa03babba5157d (patch)
treeeeb51d705966ef5c7a304c97050256b594e59150
parentffe5df5574f3655ab30a1cedacb3c7cb37b3f7a6 (diff)
downloadxfsprogs-dev-1b0adc71229ba8611b06abc2bffa03babba5157d.tar.gz
misc: enable retpolines across all xfsprogs utilities
Detect and enable retpolines for all code, to mitigate Spectre v2 (branch target injection) on x86. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
-rw-r--r--configure.ac1
-rw-r--r--include/builddefs.in7
-rw-r--r--m4/package_libcdev.m422
3 files changed, 30 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 3a0ab184af..b0d26016dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -206,6 +206,7 @@ if test "$have_threadsan" = "yes" && test "$have_addrsan" = "yes"; then
AC_MSG_WARN([ADDRSAN and THREADSAN are not known to work together.])
fi
+AC_PACKAGE_CHECK_RETPOLINE
AC_CHECK_SIZEOF([long])
AC_CHECK_SIZEOF([char *])
AC_TYPE_UMODE_T
diff --git a/include/builddefs.in b/include/builddefs.in
index df76b2c161..fe05dc376c 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -176,6 +176,13 @@ endif
SANITIZER_CFLAGS += @addrsan_cflags@ @threadsan_cflags@ @ubsan_cflags@
SANITIZER_LDFLAGS += @addrsan_ldflags@ @threadsan_ldflags@ @ubsan_ldflags@
+# Enable retpolines if available
+HAVE_RETPOLINE = @have_retpoline@
+ifeq ($(HAVE_RETPOLINE),yes)
+OPTIMIZER += @retpoline_cflags@
+LOADERFLAGS += @retpoline_ldflags@
+endif
+
GCFLAGS = $(DEBUG) \
-DVERSION=\"$(PKG_VERSION)\" -DLOCALEDIR=\"$(PKG_LOCALE_DIR)\" \
-DPACKAGE=\"$(PKG_NAME)\" -I$(TOPDIR)/include -I$(TOPDIR)/libxfs
diff --git a/m4/package_libcdev.m4 b/m4/package_libcdev.m4
index 9258c271fd..5a7baa1e53 100644
--- a/m4/package_libcdev.m4
+++ b/m4/package_libcdev.m4
@@ -420,3 +420,25 @@ AC_DEFUN([AC_HAVE_HDIO_GETGEO],
AC_MSG_RESULT(no))
AC_SUBST(have_hdio_getgeo)
])
+
+AC_DEFUN([AC_PACKAGE_CHECK_RETPOLINE],
+ [ AC_MSG_CHECKING([if C compiler supports retpoline])
+ OLD_CFLAGS="$CFLAGS"
+ OLD_LDFLAGS="$LDFLAGS"
+ RETPOLINE_FLAGS="-mindirect-branch=thunk"
+ CFLAGS="$CFLAGS $RETPOLINE_FLAGS"
+ LDFLAGS="$LDFLAGS $RETPOLINE_FLAGS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
+ [AC_MSG_RESULT([yes])]
+ [retpoline_cflags=$RETPOLINE_FLAGS]
+ [retpoline_ldflags=$RETPOLINE_FLAGS],
+ [AC_MSG_RESULT([no])])
+ if test -n "$retpoline_cflags"; then
+ have_retpoline=yes
+ fi
+ CFLAGS="${OLD_CFLAGS}"
+ LDFLAGS="${OLD_LDFLAGS}"
+ AC_SUBST(have_retpoline)
+ AC_SUBST(retpoline_cflags)
+ AC_SUBST(retpoline_ldflags)
+ ])