Skip to content

Conversation

@Freax13
Copy link
Member

@Freax13 Freax13 commented Nov 15, 2025

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

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.
@Freax13 Freax13 requested a review from phil-opp November 15, 2025 07:34
Copy link
Contributor

@josephlr josephlr left a 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();
Copy link
Contributor

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?

Copy link
Member Author

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.

Comment on lines +67 to +68
/// Disable SMAP access checks by setting [`RFlags::ALIGNMENT_CHECK`] using
/// the `stac` instruction.
Copy link
Contributor

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.

/// function does not check CR4 because doing so is much slower than just
/// checking the AC flag.
#[inline]
pub fn is_enabled(&self) -> bool {
Copy link
Contributor

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.

@josephlr josephlr mentioned this pull request Nov 19, 2025
@Freax13
Copy link
Member Author

Freax13 commented Nov 20, 2025

Do we think adding example usage in the docs would make sense? Up to you.

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.

@Freax13 Freax13 merged commit 899ee62 into master Nov 20, 2025
12 checks passed
@Freax13 Freax13 deleted the smap branch November 20, 2025 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add stac and clac instructions?

4 participants