mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Fix UB in AMX support checks
Rust's aliasing rules do not permit mutating a `usize` through a shared reference. Unsafe blocks and FFI are no exception. This PR fixes such a violation detected in the AMX support checks by passing a raw mutable pointer instead of a shared reference in the syscall. Signed-off-by: Oliver Anderson <oliver.anderson@cyberus-technology.de> On-behalf-of: SAP <oliver.anderson@sap.com>
This commit is contained in:
committed by
Rob Bradford
parent
bb713e8c01
commit
4c16285dde
@@ -730,11 +730,16 @@ impl CpuManager {
|
||||
if amx_tile != 0 {
|
||||
return Err(Error::AmxEnable(anyhow!("Guest AMX usage not supported")));
|
||||
} else {
|
||||
let mask: usize = 0;
|
||||
// SAFETY: the mask being modified (not marked mutable as it is
|
||||
// modified in unsafe only which is permitted) isn't in use elsewhere.
|
||||
let mut mask: usize = 0;
|
||||
// SAFETY: Syscall with valid parameters. We use a raw mutable pointer to
|
||||
// the `mask` place in order to ensure that we do not violate Rust's
|
||||
// aliasing rules.
|
||||
let result = unsafe {
|
||||
libc::syscall(libc::SYS_arch_prctl, ARCH_GET_XCOMP_GUEST_PERM, &mask)
|
||||
libc::syscall(
|
||||
libc::SYS_arch_prctl,
|
||||
ARCH_GET_XCOMP_GUEST_PERM,
|
||||
&raw mut mask,
|
||||
)
|
||||
};
|
||||
if result != 0 || (mask & XFEATURE_XTILEDATA_MASK) != XFEATURE_XTILEDATA_MASK {
|
||||
return Err(Error::AmxEnable(anyhow!("Guest AMX usage not supported")));
|
||||
|
||||
Reference in New Issue
Block a user