Skip to content

UB found by miri: Uninitialized memory #9

Description

@yilin0518

Hi!

We are a team of researchers studying memory safety in Rust. As part of our ongoing research, we tested ioctl-rs (version: 0.2.0) and found that the following code snippet is reported as undefined behavior by Miri:

Minimal Problematic Snippet

#![feature(allocator_api)]
extern crate alloc;
use ioctl_rs::*;
fn main() {
    let v1 = 50i32;
    let v2 = tiocmget(v1);
}

Miri Error Excerpt

     Running `/home/rose/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/case10`
error: Undefined Behavior: reading memory at alloc119[0x0..0x4], but memory is uninitialized at [0x0..0x4], and this operation requires initialized memory
  --> /home/rose/projects/lifesonar-tests1/new_crates/analyze-poc/ioctl-rs-0.2.0/src/lib.rs:45:36
   |

Root-Cause Hypothesis

After analyzing the Miri report and the source code, we assume the UB is rooted in:

  • Suspect location: src/lib.rs:45
  • Invariant being broken: uninitialized memory read (use of mem::uninitialized)
  • Causality chain: tiocmget uses mem::uninitialized to create bits, passes &mut bits into ioctl, Miri reports reading uninitialized memory

Command used:

MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tree-borrows" RUSTFLAGS=-Awarnings RUST_BACKTRACE=1 cargo miri run

Possible Fix

Use MaybeUninit to replace mem::uninitialized()

We would appreciate it if you could take a look and confirm whether this behavior indicates a real issue, or if it is a false positive / expected limitation of Miri.

Thank you very much for your time and for maintaining this great project!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions