05 May, 2018

1 commit

  • The migitation control is simpler to implement in architecture code as it
    avoids the extra function call to check the mode. Aside of that having an
    explicit seccomp enabled mode in the architecture mitigations would require
    even more workarounds.

    Move it into architecture code and provide a weak function in the seccomp
    code. Remove the 'which' argument as this allows the architecture to decide
    which mitigations are relevant for seccomp.

    Signed-off-by: Thomas Gleixner

    Thomas Gleixner
     

03 May, 2018

2 commits

  • Adjust arch_prctl_get/set_spec_ctrl() to operate on tasks other than
    current.

    This is needed both for /proc/$pid/status queries and for seccomp (since
    thread-syncing can trigger seccomp in non-current threads).

    Signed-off-by: Kees Cook
    Signed-off-by: Thomas Gleixner

    Kees Cook
     
  • Add two new prctls to control aspects of speculation related vulnerabilites
    and their mitigations to provide finer grained control over performance
    impacting mitigations.

    PR_GET_SPECULATION_CTRL returns the state of the speculation misfeature
    which is selected with arg2 of prctl(2). The return value uses bit 0-2 with
    the following meaning:

    Bit Define Description
    0 PR_SPEC_PRCTL Mitigation can be controlled per task by
    PR_SET_SPECULATION_CTRL
    1 PR_SPEC_ENABLE The speculation feature is enabled, mitigation is
    disabled
    2 PR_SPEC_DISABLE The speculation feature is disabled, mitigation is
    enabled

    If all bits are 0 the CPU is not affected by the speculation misfeature.

    If PR_SPEC_PRCTL is set, then the per task control of the mitigation is
    available. If not set, prctl(PR_SET_SPECULATION_CTRL) for the speculation
    misfeature will fail.

    PR_SET_SPECULATION_CTRL allows to control the speculation misfeature, which
    is selected by arg2 of prctl(2) per task. arg3 is used to hand in the
    control value, i.e. either PR_SPEC_ENABLE or PR_SPEC_DISABLE.

    The common return values are:

    EINVAL prctl is not implemented by the architecture or the unused prctl()
    arguments are not 0
    ENODEV arg2 is selecting a not supported speculation misfeature

    PR_SET_SPECULATION_CTRL has these additional return values:

    ERANGE arg3 is incorrect, i.e. it's not either PR_SPEC_ENABLE or PR_SPEC_DISABLE
    ENXIO prctl control of the selected speculation misfeature is disabled

    The first supported controlable speculation misfeature is
    PR_SPEC_STORE_BYPASS. Add the define so this can be shared between
    architectures.

    Based on an initial patch from Tim Chen and mostly rewritten.

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Ingo Molnar
    Reviewed-by: Konrad Rzeszutek Wilk

    Thomas Gleixner
     

17 Feb, 2018

3 commits

  • The nospec.h header expects the per-architecture header file
    to optionally define array_index_mask_nospec(). Include
    that dependency to prevent inadvertent fallback to the default
    array_index_mask_nospec() implementation.

    The default implementation may not provide a full mitigation
    on architectures that perform data value speculation.

    Reported-by: Christian Borntraeger
    Signed-off-by: Dan Williams
    Cc: Andy Lutomirski
    Cc: Arjan van de Ven
    Cc: Borislav Petkov
    Cc: Dave Hansen
    Cc: David Woodhouse
    Cc: Greg Kroah-Hartman
    Cc: Josh Poimboeuf
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Will Deacon
    Cc: linux-arch@vger.kernel.org
    Link: http://lkml.kernel.org/r/151881605404.17395.1341935530792574707.stgit@dwillia2-desk3.amr.corp.intel.com
    Signed-off-by: Ingo Molnar

    Dan Williams
     
  • The last expression in a statement expression need not be a bare
    variable, quoting gcc docs

    The last thing in the compound statement should be an expression
    followed by a semicolon; the value of this subexpression serves as the
    value of the entire construct.

    and we already use that in e.g. the min/max macros which end with a
    ternary expression.

    This way, we can allow index to have const-qualified type, which will in
    some cases avoid the need for introducing a local copy of index of
    non-const qualified type. That, in turn, can prevent readers not
    familiar with the internals of array_index_nospec from wondering about
    the seemingly redundant extra variable, and I think that's worthwhile
    considering how confusing the whole _nospec business is.

    The expression _i&_mask has type unsigned long (since that is the type
    of _mask, and the BUILD_BUG_ONs guarantee that _i will get promoted to
    that), so in order not to change the type of the whole expression, add
    a cast back to typeof(_i).

    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Dan Williams
    Acked-by: Linus Torvalds
    Cc: Andy Lutomirski
    Cc: Arjan van de Ven
    Cc: Borislav Petkov
    Cc: Dave Hansen
    Cc: David Woodhouse
    Cc: Greg Kroah-Hartman
    Cc: Josh Poimboeuf
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Will Deacon
    Cc: linux-arch@vger.kernel.org
    Cc: stable@vger.kernel.org
    Link: http://lkml.kernel.org/r/151881604837.17395.10812767547837568328.stgit@dwillia2-desk3.amr.corp.intel.com
    Signed-off-by: Ingo Molnar

    Rasmus Villemoes
     
  • There are multiple problems with the dynamic sanity checking in
    array_index_nospec_mask_check():

    * It causes unnecessary overhead in the 32-bit case since integer sized
    @index values will no longer cause the check to be compiled away like
    in the 64-bit case.

    * In the 32-bit case it may trigger with user controllable input when
    the expectation is that should only trigger during development of new
    kernel enabling.

    * The macro reuses the input parameter in multiple locations which is
    broken if someone passes an expression like 'index++' to
    array_index_nospec().

    Reported-by: Linus Torvalds
    Signed-off-by: Dan Williams
    Cc: Andy Lutomirski
    Cc: Arjan van de Ven
    Cc: Borislav Petkov
    Cc: Dave Hansen
    Cc: David Woodhouse
    Cc: Greg Kroah-Hartman
    Cc: Josh Poimboeuf
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Will Deacon
    Cc: linux-arch@vger.kernel.org
    Link: http://lkml.kernel.org/r/151881604278.17395.6605847763178076520.stgit@dwillia2-desk3.amr.corp.intel.com
    Signed-off-by: Ingo Molnar

    Dan Williams
     

15 Feb, 2018

1 commit

  • For architectures providing their own implementation of
    array_index_mask_nospec() in asm/barrier.h, attempting to use WARN_ONCE() to
    complain about out-of-range parameters using WARN_ON() results in a mess
    of mutually-dependent include files.

    Rather than unpick the dependencies, simply have the core code in nospec.h
    perform the checking for us.

    Signed-off-by: Will Deacon
    Acked-by: Thomas Gleixner
    Cc: Dan Williams
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Link: http://lkml.kernel.org/r/1517840166-15399-1-git-send-email-will.deacon@arm.com
    Signed-off-by: Ingo Molnar

    Will Deacon
     

31 Jan, 2018

1 commit

  • array_index_nospec() is proposed as a generic mechanism to mitigate
    against Spectre-variant-1 attacks, i.e. an attack that bypasses boundary
    checks via speculative execution. The array_index_nospec()
    implementation is expected to be safe for current generation CPUs across
    multiple architectures (ARM, x86).

    Based on an original implementation by Linus Torvalds, tweaked to remove
    speculative flows by Alexei Starovoitov, and tweaked again by Linus to
    introduce an x86 assembly implementation for the mask generation.

    Co-developed-by: Linus Torvalds
    Co-developed-by: Alexei Starovoitov
    Suggested-by: Cyril Novikov
    Signed-off-by: Dan Williams
    Signed-off-by: Thomas Gleixner
    Cc: linux-arch@vger.kernel.org
    Cc: kernel-hardening@lists.openwall.com
    Cc: Peter Zijlstra
    Cc: Catalin Marinas
    Cc: Will Deacon
    Cc: Russell King
    Cc: gregkh@linuxfoundation.org
    Cc: torvalds@linux-foundation.org
    Cc: alan@linux.intel.com
    Link: https://lkml.kernel.org/r/151727414229.33451.18411580953862676575.stgit@dwillia2-desk3.amr.corp.intel.com

    Dan Williams