Git Product home page Git Product logo

arm-software / speculation-barrier Goto Github PK

View Code? Open in Web Editor NEW
44.0 12.0 15.0 12 KB

This project provides a header file which contains wrapper macros for the __builtin_load_no_speculate builtin function defined at https://www.arm.com/security-update This builtin function defines a speculation barrier, which can be used to limit the conditions under which a value which has been loaded can be used under speculative execution.

License: Boost Software License 1.0

C 20.94% Objective-C 79.06%

speculation-barrier's Introduction

Speculation Barrier

This header file implements a set of wrapper macros for the __builtin_load_no_speculate builtin function detailed at https://www.arm.com/security-update. This builtin function defines a speculation barrier, which can be used to limit the conditions under which a value which has been loaded can be used under speculative execution.

The header file provided here allows a migration path to using the builtin function for users who are unable to immediately upgrade to a compiler which supports the builtin. Arm recommends using an upgraded compiler where possible to ensure the most comprehensive support for the mitigation provided by the builtin function.

Use

This header file can be included in a project as any other C header would be. For full details on usage of the builtin function please see https://www.arm.com/security-update.

This header provides three wrapper macros, which correspond to using the __builtin_load_no_speculate builtin function with three, four and five arguments respectively.

  load_no_speculate (__ptr, __low, __high)
  load_no_speculate_fail (__ptr, __low, __high, __failval)
  load_no_speculate_cmp (__ptr, __low, __high, __failval, __cmpptr)

As an example, consider this function, also given as an example at https://www.arm.com/security-update.

int array[N]; 
int foo (unsigned n) 
{ 
  int tmp; 
  if (n < N) 
    tmp = array[n] 
  else 
    tmp = FAIL; 

  return tmp; 
}

This can result in a speculative return of the value at array[n], even if n >= N. To mitigate against this, we can use the wrapper macros defined in this header:

#include "speculation_barrier.h"

int foo (unsigned n) 
{ 
  int *lower = array;
  int *ptr = array + n; 
  int *upper = array + N; 
  return load_no_speculate_fail (ptr, lower, upper, FAIL);
}

This will ensure that speculative execution can only continue using a value stored within the array or with FAIL.

Supported Environments

This header provides a migration path to using the builtin function for the AArch64 execution state of Armv8-A, and for the A32 (Arm) and T32 (Thumb) execution states of Armv7-A and Armv8-A.

Support for other architectures is currently only provided when using a compiler which provides the predefine __HAVE_LOAD_NO_SPECULATE, indicating compiler support for the __builtin_load_no_speculate builtin function.

Compatibility

This header has been tested with Arm Compiler 6 versions 6.5 and above, GCC versions 4.8 and above, including GCC 7 with prototype support for the compiler builtin function, and with an LLVM/Clang development toolchain (version 6.0.0).

Testing

A set of testcases are provided in tests.c. These test the abstract machine semantics of the provided wrapper macros. The expected behaviour of running the test program is for no output to be printed. Any output indicates a failure to implement the required abstract machine semantics of the builtin.

Note that the testcases provided do not check whether speculative execution has been inhibited.

License

This project is licensed under the Boost Software License 1.0 (SPDX-License-Identifier: BSL-1.0). See the LICENSE.md file for details.

Contributing

Contributions to this project are welcome under the Boost Software License 1.0 (SPDX-License-Identifier: BSL-1.0).

Arm does not foresee this project requiring a high volume of contributions, but welcomes contributions adding support for other architectures, further testcases, and bug-fixes.

Further details

For further details on use of the __builtin_load_no_speculate compiler builtin, please refer to https://www.arm.com/security-update.

speculation-barrier's People

Contributors

jforissier avatar jgreenhalgh-arm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

speculation-barrier's Issues

In-band error indication

Your API uses a __failval argument as the value to return upon failure, which means that a caller cannot distinguish between a bound check failure, and a successful check followed by a load returning the same value as __failval. If the caller cannot sacrify a value to represent failures in this way, then they must make a second call with a different __failval value in case the first one fails.

The API could use another style, by taking a pointer to a buffer in which to write the loaded value, and returning a boolean.

Barrier is Starting

I am having a problem when I try to host the barrier server on my windows device. When I try to connect to it on my Linux device it gets stuck on the message that barrier is starting. If I host the server on linux it works fine. But it dose not work when I try to host the server on windows. BTW your software is great and It is also a life saver.

Undefined behavior in pointer arithmetic

In your example

  int *lower = array;
  int *ptr = array + n; 
  int *upper = array + N; 

the expression array + n triggers undefined behavior precisely in the case where n is out of bounds (I am assuming that array is not part of a larger allocated memory block). A possible consequence would be for an optimizing C compiler to completely remove the bound checks, thus creating a security problem far worse than the one you are trying to mitigate.

A possible solution would be to compare integers rather than pointers. Pointers can be cast to uintptr_t. The C standard guarantees that no loss of information occurs (the integer can be converted back to an equal pointer), but does not relate operations on uintptr_t and the pointers they represent (in particular, it does not promise that a successful bound check on uintptr_t means a successful bound check on the pointers). However, it does state that conversions between pointers and integers are intended to be consistent with the addressing structure of the execution environment, which, on ARM, means that the bound check can be performed on the integers.

Note that this problem affects the interface of the API (both __builtin_load_no_speculate and the wrappers).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.