-
Notifications
You must be signed in to change notification settings - Fork 148
add SMAP helpers #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add SMAP helpers #566
Conversation
This PR adds helpers for SMAP. SMAP is a security feature that can be used to detect accidental access to user memory by the kernel.
josephlr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice addition.
Do we think adding example usage in the docs would make sense? Up to you.
| { | ||
| let was_enabled = self.is_enabled(); | ||
|
|
||
| self.disable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to disable SMAP again if it was already disabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional. I assume that running stac unnecessarily will be faster than branching, but I did not actually test this.
| /// Disable SMAP access checks by setting [`RFlags::ALIGNMENT_CHECK`] using | ||
| /// the `stac` instruction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here (and in disable), we should explain what happens if SMAP is already disabled (or enabled respectively) when this function is called.
I think it's a no-op, but we should say so.
src/instructions/smap.rs
Outdated
| /// function does not check CR4 because doing so is much slower than just | ||
| /// checking the AC flag. | ||
| #[inline] | ||
| pub fn is_enabled(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the methods on Smap take it by value? It don't really matter, but for a zero-sized Copy type, I usually have them passed by value.
I would like to do this, but I think any example of these methods would also need to show Rust code accessing user memory and that's a can of worms I don't want to open. |
This PR adds helpers for SMAP. SMAP is a security feature that can be used to detect accidental access to user memory by the kernel.
Closes #562
Cc @ChocolateLoverRaj