-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable SMAP if supported. If supported, SMAP is enabled if CR4.SMAP bit is set, and if RFLAGS.AC is unset. It means that we need to clear RFLAGS.AC in entries, to have the kernel running with RFLAGS.AC = 0. Two asm macros (asm_clac and asn_stac) have been created to respectively clear and set RFLAGS.AC from assembly. Two Rust functions have also been created to perform exactly the same but from Rust code. This is still unused but it will will be useful when we'll have CPL3 support, to be able to read/write in userspace (eg. in syscall handlers, or even with user #VC). Signed-off-by: Thomas Leroy <[email protected]>
- Loading branch information
Showing
9 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// Copyright (c) 2024 SUSE LLC | ||
// | ||
// Authors: Thomas Leroy <[email protected]> | ||
|
||
pub mod smap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// Copyright (c) 2024 SUSE LLC | ||
// | ||
// Authors: Thomas Leroy <[email protected]> | ||
|
||
.code64 | ||
|
||
.section .text | ||
.macro asm_clac | ||
.if !CFG_NOSMAP | ||
clac | ||
.endif | ||
.endm | ||
|
||
.macro asm_stac | ||
.if !CFG_NOSMAP | ||
stac | ||
.endif | ||
.endm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// Copyright (c) 2024 SUSE LLC | ||
// | ||
// Authors: Thomas Leroy <[email protected]> | ||
|
||
use core::arch::asm; | ||
|
||
/// Clears RFLAGS.AC to enable SMAP. | ||
/// This is currently only used when SMAP is supported and enabled. | ||
/// SMAP protection is effective only if CR4.SMAP is set and if RFLAGS.AC = 0. | ||
#[inline(always)] | ||
pub fn clac() { | ||
if !cfg!(feature = "nosmap") { | ||
unsafe { asm!("clac", options(att_syntax, nomem, nostack, preserves_flags)) } | ||
} | ||
} | ||
|
||
/// Sets RFLAGS.AC to disable SMAP. | ||
/// This is currently only used when SMAP is supported and enabled. | ||
/// SMAP protection is effective only if CR4.SMAP is set and if RFLAGS.AC = 0. | ||
#[inline(always)] | ||
pub fn stac() { | ||
if !cfg!(feature = "nosmap") { | ||
unsafe { asm!("stac", options(att_syntax, nomem, nostack, preserves_flags)) } | ||
} | ||
} |