All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] misc: enable retpolines across all xfsprogs utilities
@ 2018-02-22  2:16 Darrick J. Wong
  2018-02-22 15:09 ` Christoph Hellwig
  0 siblings, 1 reply; 6+ messages in thread
From: Darrick J. Wong @ 2018-02-22  2:16 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

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>
---
 configure.ac          |    1 +
 include/builddefs.in  |    7 +++++++
 m4/package_libcdev.m4 |   22 ++++++++++++++++++++++
 3 files changed, 30 insertions(+)

diff --git a/configure.ac b/configure.ac
index d068ba0..2104219 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 df76b2c..fe05dc3 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 9258c27..5a7baa1 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)
+  ])

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] misc: enable retpolines across all xfsprogs utilities
  2018-02-22  2:16 [PATCH] misc: enable retpolines across all xfsprogs utilities Darrick J. Wong
@ 2018-02-22 15:09 ` Christoph Hellwig
  2018-02-22 15:31   ` Eric Sandeen
  0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2018-02-22 15:09 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Eric Sandeen, xfs

On Wed, Feb 21, 2018 at 06:16:25PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Detect and enable retpolines for all code, to mitigate Spectre v2
> (branch target injection) on x86.

The mechanics look ok, but why do we really care for xfsprogs?
fs utilities seem like a lesser target and should just be covered
by hopefully sane compiler defaults, shouldn't they?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] misc: enable retpolines across all xfsprogs utilities
  2018-02-22 15:09 ` Christoph Hellwig
@ 2018-02-22 15:31   ` Eric Sandeen
  2018-02-22 17:15     ` Darrick J. Wong
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Sandeen @ 2018-02-22 15:31 UTC (permalink / raw)
  To: Christoph Hellwig, Darrick J. Wong; +Cc: xfs

On 2/22/18 9:09 AM, Christoph Hellwig wrote:
> On Wed, Feb 21, 2018 at 06:16:25PM -0800, Darrick J. Wong wrote:
>> From: Darrick J. Wong <darrick.wong@oracle.com>
>>
>> Detect and enable retpolines for all code, to mitigate Spectre v2
>> (branch target injection) on x86.
> 
> The mechanics look ok, but why do we really care for xfsprogs?
> fs utilities seem like a lesser target and should just be covered
> by hopefully sane compiler defaults, shouldn't they?
> 

That's my feeling as well - does manually fixing one utility out of
hundreds on the system help anything? Shouldn't this be done via toolchain
or distro-package-build defaults?

-Eric

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] misc: enable retpolines across all xfsprogs utilities
  2018-02-22 15:31   ` Eric Sandeen
@ 2018-02-22 17:15     ` Darrick J. Wong
  2018-02-22 21:10       ` Matthias Schniedermeyer
  0 siblings, 1 reply; 6+ messages in thread
From: Darrick J. Wong @ 2018-02-22 17:15 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Christoph Hellwig, xfs

On Thu, Feb 22, 2018 at 09:31:41AM -0600, Eric Sandeen wrote:
> On 2/22/18 9:09 AM, Christoph Hellwig wrote:
> > On Wed, Feb 21, 2018 at 06:16:25PM -0800, Darrick J. Wong wrote:
> >> From: Darrick J. Wong <darrick.wong@oracle.com>
> >>
> >> Detect and enable retpolines for all code, to mitigate Spectre v2
> >> (branch target injection) on x86.
> > 
> > The mechanics look ok, but why do we really care for xfsprogs?
> > fs utilities seem like a lesser target and should just be covered

They're a smaller target than the kernel, for sure, but the scary part
about spectre is that unprivileged programs running on the same core as
a privileged xfs_repair can then use branch predictor poisoning to cause
problems with the xfs_repair.

> > by hopefully sane compiler defaults, shouldn't they?

I would have thought so, but look at the gcc manpage:

-mindirect-branch=choice
	Convert indirect call and jump with choice.  The default is
	keep, which keeps indirect call and jump unmodified.  thunk

Unmodified, as in don't provide spectre mitigations...

	converts indirect call and jump to call and return thunk.
	thunk-inline converts indirect call and jump to inlined call and
	return thunk.  thunk-extern converts indirect call and jump to
	external call and return thunk provided in a separate object
	file.  You can control this behavior for a specific function by
	using the function attribute "indirect_branch".

	Note that -mcmodel=large is incompatible with
	-mindirect-branch=thunk nor -mindirect-branch=thunk-extern since
	the thunk function may not be reachable in large code model.

So, gcc defaults to unprotected.

> That's my feeling as well - does manually fixing one utility out of
> hundreds on the system help anything? Shouldn't this be done via toolchain
> or distro-package-build defaults?

Maybe they will someday, but right now:

$ dpkg-buildflags --get CFLAGS
-g -O2 -fdebug-prefix-map=/home/djwong=. -fstack-protector-strong -Wformat -Werror=format-security

It's not clear to me if Debian plans to adopt the per-platform spectre
mitigations distro-wide or just for specific packages, or what?  So far
it looks like Ubuntu is only doing it for their browser packages.  libc
hasn't been rebuilt, which limits the effectiveness of turning it on for
xfsprogs, but otoh we could still protect the bits we control.

--D

> -Eric
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] misc: enable retpolines across all xfsprogs utilities
  2018-02-22 17:15     ` Darrick J. Wong
@ 2018-02-22 21:10       ` Matthias Schniedermeyer
  2018-02-22 23:57         ` Dave Chinner
  0 siblings, 1 reply; 6+ messages in thread
From: Matthias Schniedermeyer @ 2018-02-22 21:10 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Eric Sandeen, Christoph Hellwig, xfs

On 22.02.2018 09:15, Darrick J. Wong wrote:
> On Thu, Feb 22, 2018 at 09:31:41AM -0600, Eric Sandeen wrote:
> > On 2/22/18 9:09 AM, Christoph Hellwig wrote:
> > > On Wed, Feb 21, 2018 at 06:16:25PM -0800, Darrick J. Wong wrote:
> > >> From: Darrick J. Wong <darrick.wong@oracle.com>
> > >>
> > >> Detect and enable retpolines for all code, to mitigate Spectre v2
> > >> (branch target injection) on x86.
> > > 
> > > The mechanics look ok, but why do we really care for xfsprogs?
> > > fs utilities seem like a lesser target and should just be covered
> 
> They're a smaller target than the kernel, for sure, but the scary part
> about spectre is that unprivileged programs running on the same core as
> a privileged xfs_repair can then use branch predictor poisoning to cause
> problems with the xfs_repair.

Spectre & Meltdown are information disclosure vulnerabilities IOW "Read 
Only".
The other process CAN NOT interfere with xfs_repair.

I would speculate that the most it can get, is information about parts 
of the filesystem that are inaccsessible to an unprivileged process by 
spying on xfs_repair.
I don't know how xfs_repair works, especially how xfs_repair handles 
storing data in memory. But for xfs_repair to be a good target, it 
would have to store relevant data in a deterministic fashion and for 
some length of time. At least enough to justify writing an extraction 
program for it.

I would say the 'good old' xfs_repair case isn't really a good target, 
but the online-scrubbing-case sure sounds to be a different beast.

In the past you couldn't, for a given point in time, really expect a 
xfs_repair process to be running, but with online-scrubbing that game 
changes.





-- 

Matthias

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] misc: enable retpolines across all xfsprogs utilities
  2018-02-22 21:10       ` Matthias Schniedermeyer
@ 2018-02-22 23:57         ` Dave Chinner
  0 siblings, 0 replies; 6+ messages in thread
From: Dave Chinner @ 2018-02-22 23:57 UTC (permalink / raw)
  To: Matthias Schniedermeyer
  Cc: Darrick J. Wong, Eric Sandeen, Christoph Hellwig, xfs

On Thu, Feb 22, 2018 at 10:10:24PM +0100, Matthias Schniedermeyer wrote:
> On 22.02.2018 09:15, Darrick J. Wong wrote:
> > They're a smaller target than the kernel, for sure, but the scary part
> > about spectre is that unprivileged programs running on the same core as
> > a privileged xfs_repair can then use branch predictor poisoning to cause
> > problems with the xfs_repair.
> 
> Spectre & Meltdown are information disclosure vulnerabilities IOW "Read 
> Only".
> The other process CAN NOT interfere with xfs_repair.

Yup, that's enough to leak private information. e.g. encryption keys
stored in extended attributes...

> I would speculate that the most it can get, is information about parts 
> of the filesystem that are inaccsessible to an unprivileged process by 
> spying on xfs_repair.
> I don't know how xfs_repair works, especially how xfs_repair handles 
> storing data in memory. But for xfs_repair to be a good target, it 
> would have to store relevant data in a deterministic fashion and for 
> some length of time. At least enough to justify writing an extraction 
> program for it.

Oh, yeah, we've got this whopping great big buffer cache that can
cache all the metadata it reads from disk in memory while repair
does it's validation work. It's a pretty big target from that
perspective. That's made even worse if you consider a large
filesystem that takes days for xfs_repair to completely check....

> I would say the 'good old' xfs_repair case isn't really a good target, 
> but the online-scrubbing-case sure sounds to be a different beast.

Scrubbing is done in the kernel, with metadata cached in kernel
memory, so it's already protected by whatever kernel mitigations are
in place.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-02-22 23:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-22  2:16 [PATCH] misc: enable retpolines across all xfsprogs utilities Darrick J. Wong
2018-02-22 15:09 ` Christoph Hellwig
2018-02-22 15:31   ` Eric Sandeen
2018-02-22 17:15     ` Darrick J. Wong
2018-02-22 21:10       ` Matthias Schniedermeyer
2018-02-22 23:57         ` Dave Chinner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.