Compare commits

..

2 Commits

Author SHA1 Message Date
Aurélien Bombo
9d4fcd3708 runtime-rs: Use fully qualified NixPath::is_empty()
This avoids issues like below which are now errors in Rust 1.94:

error: a method with this name may be added to the standard library in the future
   --> src/libs/kata-sys-util/src/mount.rs:265:12
    |
265 |     if src.is_empty() {
    |            ^^^^^^^^
    |
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
    = help: call with fully qualified syntax `nix::NixPath::is_empty(...)` to keep using the current method

Signed-off-by: Aurélien Bombo <abombo@microsoft.com>
2026-03-19 17:07:02 -05:00
Aurélien Bombo
78272ad7b7 runtime-rs: Remove unnecessary unsafe blocks
This avoids issues like below which are now errors in Rust 1.94.

error: unnecessary `unsafe` block
   --> src/libs/kata-sys-util/src/protection.rs:129:19
    |
129 |         let fn0 = unsafe { x86_64::__cpuid(0) };
    |                   ^^^^^^ unnecessary `unsafe` block
    |
    = note: `-D unused-unsafe` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(unused_unsafe)]`

Signed-off-by: Aurélien Bombo <abombo@microsoft.com>
2026-03-19 17:07:02 -05:00
5 changed files with 12 additions and 53 deletions

View File

@@ -1,41 +0,0 @@
name: 'Stale issues with activity before a fixed date'
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
inputs:
date:
description: "Date of stale cut-off. All issues not updated since this date will be marked as stale. Format: YYYY-MM-DD e.g. 2022-10-09"
default: "2022-10-09"
required: false
type: string
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
stale:
name: stale
runs-on: ubuntu-24.04
permissions:
actions: write # Needed to manage caches for state persistence across runs
issues: write # Needed to add/remove labels, post comments, or close issues
steps:
- name: Calculate the age to stale
run: |
echo AGE=$(( ( $(date +%s) - $(date -d "${DATE:-2022-10-09}" +%s) ) / 86400 )) >> "$GITHUB_ENV"
env:
DATE: ${{ inputs.date }}
- name: Run the stale action
uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9.1.0
with:
stale-pr-message: 'This issue has had no activity for at least ${AGE} days. Please comment on the issue, or it will be closed in 30 days'
days-before-pr-stale: -1
days-before-pr-close: -1
days-before-issue-stale: ${AGE}
days-before-issue-close: 30

View File

@@ -103,7 +103,7 @@ impl BrandString {
/// of the host CPU.
fn from_host_cpuid() -> Result<Self, Error> {
let mut this = Self::new();
let mut cpuid_regs = unsafe { host_cpuid(0x8000_0000) };
let mut cpuid_regs = host_cpuid(0x8000_0000);
if cpuid_regs.eax < 0x8000_0004 {
// Brand string not supported by the host CPU
@@ -111,7 +111,7 @@ impl BrandString {
}
for leaf in 0x8000_0002..=0x8000_0004 {
cpuid_regs = unsafe { host_cpuid(leaf) };
cpuid_regs = host_cpuid(leaf);
this.set_reg_for_leaf(leaf, Reg::Eax, cpuid_regs.eax);
this.set_reg_for_leaf(leaf, Reg::Ebx, cpuid_regs.ebx);
this.set_reg_for_leaf(leaf, Reg::Ecx, cpuid_regs.ecx);
@@ -393,7 +393,7 @@ mod tests {
match BrandString::from_host_cpuid() {
Ok(bstr) => {
for leaf in 0x8000_0002..=0x8000_0004_u32 {
let host_regs = unsafe { host_cpuid(leaf) };
let host_regs = host_cpuid(leaf);
assert_eq!(bstr.get_reg_for_leaf(leaf, Reg::Eax), host_regs.eax);
assert_eq!(bstr.get_reg_for_leaf(leaf, Reg::Ebx), host_regs.ebx);
assert_eq!(bstr.get_reg_for_leaf(leaf, Reg::Ecx), host_regs.ecx);
@@ -403,7 +403,7 @@ mod tests {
Err(Error::NotSupported) => {
// from_host_cpuid() should only fail if the host CPU doesn't support
// CPUID leaves up to 0x80000004, so let's make sure that's what happened.
let host_regs = unsafe { host_cpuid(0x8000_0000) };
let host_regs = host_cpuid(0x8000_0000);
assert!(host_regs.eax < 0x8000_0004);
}
_ => panic!("This function should not return another type of error"),

View File

@@ -25,7 +25,7 @@ pub fn get_cpuid(function: u32, count: u32) -> Result<CpuidResult, Error> {
// TODO: replace with validation based on `has_cpuid()` when it becomes stable:
// https://doc.rust-lang.org/core/arch/x86/fn.has_cpuid.html
// this is safe because the host supports the `cpuid` instruction
let max_function = unsafe { __get_cpuid_max(function & leaf_0x80000000::LEAF_NUM).0 };
let max_function = __get_cpuid_max(function & leaf_0x80000000::LEAF_NUM).0;
if function > max_function {
return Err(Error::InvalidParameters(format!(
"Function not supported: 0x{function:x}",
@@ -33,7 +33,7 @@ pub fn get_cpuid(function: u32, count: u32) -> Result<CpuidResult, Error> {
}
// this is safe because the host supports the `cpuid` instruction
let entry = unsafe { __cpuid_count(function, count) };
let entry = __cpuid_count(function, count);
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 {
return Err(Error::InvalidParameters(format!("Invalid count: {count}")));
}

View File

@@ -225,7 +225,7 @@ pub fn create_mount_destination<S: AsRef<Path>, D: AsRef<Path>, R: AsRef<Path>>(
/// Caller needs to ensure safety of the `dst` to avoid possible file path based attacks.
pub fn bind_remount<P: AsRef<Path>>(dst: P, readonly: bool) -> Result<()> {
let dst = dst.as_ref();
if dst.is_empty() {
if NixPath::is_empty(dst) {
return Err(Error::NullMountPointPath);
}
let dst = dst
@@ -262,10 +262,10 @@ pub fn bind_mount_unchecked<S: AsRef<Path>, D: AsRef<Path>>(
let src = src.as_ref();
let dst = dst.as_ref();
if src.is_empty() {
if NixPath::is_empty(src) {
return Err(Error::NullMountPointPath);
}
if dst.is_empty() {
if NixPath::is_empty(dst) {
return Err(Error::NullMountPointPath);
}
let abs_src = src
@@ -760,7 +760,7 @@ pub fn umount_timeout<P: AsRef<Path>>(path: P, timeout: u64) -> Result<()> {
/// # Safety
/// Caller needs to ensure safety of the `path` to avoid possible file path based attacks.
pub fn umount_all<P: AsRef<Path>>(mountpoint: P, lazy_umount: bool) -> Result<()> {
if mountpoint.as_ref().is_empty() || !mountpoint.as_ref().exists() {
if NixPath::is_empty(mountpoint.as_ref()) || !mountpoint.as_ref().exists() {
return Ok(());
}

View File

@@ -126,7 +126,7 @@ pub fn arch_guest_protection(
// shouldn't hurt to double-check and have better logging if anything
// goes wrong.
let fn0 = unsafe { x86_64::__cpuid(0) };
let fn0 = x86_64::__cpuid(0);
// The values in [ ebx, edx, ecx ] spell out "AuthenticAMD" when
// interpreted byte-wise as ASCII. No need to bother here with an
// actual conversion to string though.
@@ -139,7 +139,7 @@ pub fn arch_guest_protection(
}
// AMD64 Architecture Prgrammer's Manual Fn8000_001f docs on pg. 640
let fn8000_001f = unsafe { x86_64::__cpuid(0x8000_001f) };
let fn8000_001f = x86_64::__cpuid(0x8000_001f);
if fn8000_001f.eax & 0x10 == 0 {
return Err(ProtectionError::CheckFailed("SEV not supported".to_owned()));
}