oxidecomputer / oxidecomputer/omicron

sled-agent swap_device declares path buffers as [i8] but casts them to *mut c_char, breaking any build where char is unsigned

Open Beginner friendly
#11,269 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
572
Forks
97
Avg merge
2d 12h
Merged PRs (30d)
96

Description

Description

sled-agent/src/swap_device.rs, in list_swap_devices(), allocates three
PATH_MAX buffers with an explicit i8 element type and then hands them to the
kernel as c_char pointers:

const MAXPATHLEN: usize = libc::PATH_MAX as usize;
let mut p1 = [0i8; MAXPATHLEN];
let mut p2 = [0i8; MAXPATHLEN];
let mut p3 = [0i8; MAXPATHLEN];
let entries: [swapent; N_SWAPENTS] = [
    swapent {
        ste_path: &mut p1 as *mut libc::c_char,
        ..Default::default()
    },
    ...

c_char is signed on x86_64 and unsigned on aarch64, so the cast is only valid
on the former:

error[E0606]: casting `&mut [i8; 4096]` as `*mut u8` is invalid
   --> sled-agent/src/swap_device.rs:415:27
    |
415 |                 ste_path: &mut p1 as *mut libc::c_char,
    |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Three errors, one per buffer. The code is already using libc::c_char on the
cast side, so the mismatch is purely in the declaration.

This is inside #[cfg(target_os = "illumos")]-adjacent code for a
platform-specific facility, so I do not expect it to matter for any shipping
configuration. It is reported because it costs nothing to make the declaration
agree with the cast, and because it blocks compilation of the whole
omicron-sled-agent crate — which the simulated stack builds — on
aarch64 Linux, a target the README lists as supported for simulated mode.

Steps to reproduce

  1. On aarch64 Linux, cargo build --bin omicron-dev.
  2. Compilation of omicron-sled-agent fails with the three errors above.

Expected result

The buffers are typed consistently with the pointer they are cast to, and the
crate compiles wherever libc::c_char is defined.

Actual result

error[E0606] x3; omicron-sled-agent does not build.

Suggested fix

Declare the buffers with the same type as the cast target:

let mut p1 = [0 as libc::c_char; MAXPATHLEN];
let mut p2 = [0 as libc::c_char; MAXPATHLEN];
let mut p3 = [0 as libc::c_char; MAXPATHLEN];

No behavioural change on x86_64, where c_char is i8.

Environment

omicron df990b0578fbee4afcf805423a20d85e23544e0d (2026-09-04)
platform aarch64-unknown-linux-gnu, Ubuntu 24.04
rust 1.98.1 (pinned by rust-toolchain.toml)

Related: the same signed/unsigned c_char assumption appears in scuffle,
libnet (netadm-sys) and nvpair (rust-libzfs), all reachable from omicron's
dependency graph. Filed separately against those repositories.


Disclosure: this issue was investigated and written up with AI assistance
(Claude). Everything in it was measured rather than inferred — the timings,
error output, version numbers and reproduction steps are all from real runs on
real hardware, and where a fix is suggested it is one I am actually running. I
have read it through before filing. Happy to clarify anything or test a patch.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open sled-agent/src/swap_device.rs and inspect list_swap_devices(), especially the three PATH_MAX buffers and their swapent pointer casts. Reproduce with cargo build --bin omicron-dev on aarch64 Linux. Done means the buffers compile consistently with libc::c_char and the omicron-sled-agent crate builds without the three E0606 errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system, operating-systems
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.