Bounds checking with Intel MPX


#1

I just discovered this intel extension and was curious about it’s application in Rust. Since rust has very little raw pointer access, maybe it could be used for array access or as an extra precaution in unsafe code?

Here’s some more documentation:

Linux docs

Explanation with security and performance analysis

There’s a bit of discussion from a few years ago on /r/rust here. In particular there’s the concern about llvm signal handling. Has anything changed since then?


#2

Things like slice lengths might be able to be offloaded to the range registers, but unfortunately, MPX bounds checks will always result in a #BR exception on failure, so they can’t be handled nicely.


#3

You can just install a signal handler/exception handler and handle as desired (the simplest solution is to simulate a branch).

I guess the problem is whether using MPX is actually faster and whether someone is going to implement it.


#4

If you have to go through the OS (for the signal handler), definitely not.


#5

That would impose overhead on the out of bounds case, but I don’t think we really care too much about how fast you can panic. The more important thing to look at is the performance of in bounds access.


#6

Are you suggesting MPX is only used for e.g. slice::index but not for slice::get? I don’t think that’s going to give any significant performance gains since you’ll need to convert between representations often.