Bounds checking with Intel MPX

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?

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.

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.

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

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.

3 Likes

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.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.