Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/lsan.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Facts that live for the whole process are built once, inside a OnceLock, and
# leaked on purpose so readers get `&'static` values: text in `os::keep`, the
# OS records in `os::from_facts`. A unit test that builds one directly drops
# the only reference, which LeakSanitizer reports.
leak:sys_lib::os::keep
leak:sys_lib::os::from_facts
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,49 @@ jobs:
MIRIFLAGS: "-Zmiri-disable-isolation"
PROPTEST_CASES: "16"

asan:
name: AddressSanitizer (${{ matrix.name }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Linux
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
leaks: "1"
# LeakSanitizer does not run on macOS.
- name: macOS
os: macos-latest
target: aarch64-apple-darwin
leaks: "0"
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
with:
key: asan
# Readable leak stacks, which the suppressions in .github/lsan.supp
# match against.
- name: Find a symbolizer
if: runner.os == 'Linux'
run: |
s=$(command -v llvm-symbolizer || ls /usr/bin/llvm-symbolizer-* 2>/dev/null | sort -V | tail -1)
test -n "$s"
echo "ASAN_SYMBOLIZER_PATH=$s" >> "$GITHUB_ENV"
# Every test, the FFI backends included, with each allocation and
# access checked (threat T12). Naming the target keeps build scripts
# out of the instrumented build. Allocation stacks are unwound from
# debug information: std is built without frame pointers, so the fast
# unwinder drops the frame that called into it.
- name: Tests under AddressSanitizer
run: cargo test --target ${{ matrix.target }} --all-features --lib --tests
env:
RUSTFLAGS: "-Zsanitizer=address"
ASAN_OPTIONS: "detect_leaks=${{ matrix.leaks }}:detect_stack_use_after_return=1:fast_unwind_on_malloc=0"
LSAN_OPTIONS: "suppressions=${{ github.workspace }}/.github/lsan.supp:print_suppressions=1"
PROPTEST_CASES: "32"

# A DLL in the import table that a stripped-down Windows lacks stops the whole
# program before `main`, so a real binary runs where the fewest DLLs exist.
nanoserver:
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/fuzz-round.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Fuzz round

# One round of the long fuzz run (fuzz.yml, `rounds` input): every target for
# `seconds`, starting from the corpus the previous round left in the cache.
on:
workflow_call:
inputs:
seconds:
type: string
required: true
round:
type: string
required: true

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"

jobs:
fuzz:
name: Round ${{ inputs.round }} (${{ matrix.target }})
runs-on: ubuntu-latest
timeout-minutes: 345
strategy:
fail-fast: false
# Eight at a time, so the long run leaves runners for other work.
max-parallel: 8
matrix:
target:
- os_release
- release
- version
- cpu_list
- cpuinfo
- cpu_name
- proc_status
- mountinfo
- cgroup
- pid_file
- instance_id
- bytes_display
- procfs
- smbios
- uevent
- resolv
- utmp
- windows_zones
- fingerprint
- pci_ids
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
with:
workspaces: fuzz
key: ${{ matrix.target }}
- name: Install cargo-fuzz
uses: taiki-e/install-action@v2
with:
tool: cargo-fuzz
- name: Restore the corpus
uses: actions/cache/restore@v4
with:
path: fuzz/corpus/${{ matrix.target }}
key: corpus-${{ matrix.target }}-${{ github.run_id }}-${{ inputs.round }}
restore-keys: corpus-${{ matrix.target }}-
- name: Fuzz
run: |
mkdir -p "fuzz/corpus/${{ matrix.target }}"
echo "corpus: $(ls "fuzz/corpus/${{ matrix.target }}" | wc -l) inputs"
cargo fuzz run --target x86_64-unknown-linux-gnu ${{ matrix.target }} \
"fuzz/corpus/${{ matrix.target }}" tests/fixtures -- \
-max_total_time=${{ inputs.seconds }} -print_final_stats=1
- name: Save the corpus
if: always()
uses: actions/cache/save@v4
with:
path: fuzz/corpus/${{ matrix.target }}
key: corpus-${{ matrix.target }}-${{ github.run_id }}-${{ inputs.round }}
- uses: actions/upload-artifact@v5
if: failure()
with:
name: crash-round${{ inputs.round }}-${{ matrix.target }}
path: fuzz/artifacts/
retention-days: 30
70 changes: 67 additions & 3 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Fuzz

# Ten minutes per parser every night (dev/PLAN.md section 19.1); 24 hours per
# target is run by hand before 0.8. Crashes are uploaded as artifacts and fixed
# test-first (fuzz/README.md).
# Ten minutes per parser every night (dev/PLAN.md section 19.1). The long runs
# before a release (`long`): 24 hours of fuzzing per target, as five chained
# rounds of fuzz-round.yml, each starting from the corpus the last one saved,
# and the soak run (bench/src/bin/soak.rs) for as long as a hosted job may run.
# Crashes are uploaded as artifacts and fixed test-first (fuzz/README.md).
on:
schedule:
- cron: "17 3 * * *"
Expand All @@ -11,13 +13,18 @@ on:
seconds:
description: Seconds per target
default: "600"
long:
description: 24 hours per target in five rounds, and the soak runs
type: boolean
default: false

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"

jobs:
fuzz:
name: Fuzz (${{ matrix.target }})
if: ${{ !inputs.long }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -42,6 +49,7 @@ jobs:
- utmp
- windows_zones
- fingerprint
- pci_ids
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@nightly
Expand All @@ -66,3 +74,59 @@ jobs:
name: crash-${{ matrix.target }}
path: fuzz/artifacts/
retention-days: 30

round1:
if: ${{ inputs.long }}
uses: ./.github/workflows/fuzz-round.yml
with:
seconds: "17400"
round: "1"

round2:
needs: round1
if: ${{ !cancelled() && inputs.long }}
uses: ./.github/workflows/fuzz-round.yml
with:
seconds: "17400"
round: "2"

round3:
needs: round2
if: ${{ !cancelled() && inputs.long }}
uses: ./.github/workflows/fuzz-round.yml
with:
seconds: "17400"
round: "3"

round4:
needs: round3
if: ${{ !cancelled() && inputs.long }}
uses: ./.github/workflows/fuzz-round.yml
with:
seconds: "17400"
round: "4"

round5:
needs: round4
if: ${{ !cancelled() && inputs.long }}
uses: ./.github/workflows/fuzz-round.yml
with:
seconds: "17400"
round: "5"

soak:
name: Soak (${{ matrix.os }})
if: ${{ inputs.long }}
runs-on: ${{ matrix.os }}
timeout-minutes: 355
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- name: Soak, 5 h 40 min (the hosted job limit is 6 h)
working-directory: bench
shell: bash
run: cargo run --release --bin soak -- 20400
57 changes: 56 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,60 @@

---

## [0.8.0] - 2026-12-02

Hardening: every threat in the model has a named attack test, the process
guard is as strict on Windows as on Unix, and the release went through a
24-hour fuzz run per parser and a soak run.

### Added

- `docs/SECURITY.md`: what the crate guarantees, every threat with its
defence, its cost, and its test, and how to report a vulnerability.
- An AddressSanitizer job on Linux and macOS that runs every test.
- A soak run (`bench/src/bin/soak.rs`) that calls every reading in a loop and
fails if memory or open descriptors grow, and the long runs before a release
(`fuzz.yml` with `long`: 24 hours per fuzz target, and the soak run).

### Changed

- **Windows process guard:** a missing lock directory is created for this
account, `SYSTEM`, and `Administrators` alone, and a lock directory another
account can change is refused, as group- or world-writable directories are
on Unix. A program that used a directory under `C:\ProgramData` directly
must move its lock to a private directory. The default directory is created
the same way.
- `Error::AlreadyRunning` names a pid only when that process is running and
started before its pid file was written; otherwise the pid is `None`. It
never names a process that cannot be the other copy.
- `mem::total()`, `mem::host_total()`, and `mem::limit()` read only what they
return: no VM counters for a total, and on Linux no soft or swap limit files
for the total. macOS and FreeBSD read the installed memory once.
- macOS memory and CPU readings no longer fetch and return the host port on
every call, and `device::id` finds the platform device by path instead of
searching the registry.
- The minimum Windows is 10 version 1511, or Server 2016.
- Requires path-lib 1.3 (with the `guard` feature).

### Fixed

- Windows disk busy time no longer reads 0% for a while after the clock is set
back, or one spike after it is set forward.
- Error codes are read straight after the call that failed, and calls that set
none (`getloadavg`, `localtime_r`, a `proc_listallpids` or `proc_pidinfo`
answer of 0) report `Malformed` instead of a stale or zero code.
- FreeBSD `disk::io_totals()` asks again when a disk comes or goes during the
read, instead of failing once.
- A Windows drive whose product string has no terminator no longer carries the
next fields into the drive's name, and only a cloud's fixed asset tag is kept
from the firmware table.
- The message for a user without a home directory had stray spaces.
- A very long CPU name, such as a crafted `model name` in a container's
`/proc/cpuinfo`, no longer takes seconds to minutes to clean: names are cut
to 256 bytes first. Real ones are at most 48.

---

## [0.7.0] - 2026-11-11

Optimisation: every reading measured against the crates people use for it, the
Expand Down Expand Up @@ -406,7 +460,8 @@ The scaffold and the plan. No functional code yet.
`dev/ROADMAP.md`.
- `tests/fixtures/` and `fuzz/` skeletons.

[Unreleased]: https://github.com/jamesgober/sys-lib/compare/v0.7.0...HEAD
[Unreleased]: https://github.com/jamesgober/sys-lib/compare/v0.8.0...HEAD
[0.8.0]: https://github.com/jamesgober/sys-lib/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/jamesgober/sys-lib/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/jamesgober/sys-lib/compare/v0.5.1...v0.6.0
[0.5.1]: https://github.com/jamesgober/sys-lib/compare/v0.5.0...v0.5.1
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# =============================================================================
[package]
name = "sys-lib"
version = "0.7.0"
version = "0.8.0"

# Minimum Supported Rust Version (MSRV)
# 1.89: `std::fs::File::lock` and `File::try_lock` are stable from 1.89.0, so
Expand Down Expand Up @@ -103,7 +103,7 @@ device-id = ["dep:crypt-io"]
clock-lib = { version = "1.1", optional = true, default-features = false, features = ["std"] }
crypt-io = { version = "1.2.2", optional = true, default-features = false, features = ["std", "mac-blake3", "zeroize"] }
id-forge = { version = "1.0", optional = true, default-features = false, features = ["ulid"] }
path-lib = { version = "1.0", optional = true }
path-lib = { version = "1.3", optional = true }


# DEV DEPENDENCIES
Expand All @@ -129,6 +129,7 @@ windows-sys = { version = "0.61", features = [
"Win32_NetworkManagement_Ndis",
"Win32_Networking_WinSock",
"Win32_Security",
"Win32_Security_Authorization",
"Win32_System_Diagnostics_Debug",
"Win32_System_Diagnostics_ToolHelp",
"Win32_System_LibraryLoader",
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<div align="center">
<a href="https://crates.io/crates/sys-lib"><img alt="Crates.io" src="https://img.shields.io/crates/v/sys-lib"></a>
<a href="https://crates.io/crates/sys-lib"><img alt="Downloads" src="https://img.shields.io/crates/d/sys-lib?color=%230099ff"></a>
<a href="https://docs.rs/sys-lib"><img alt="docs.rs" src="https://img.shields.io/docsrs/sys-lib"></a>
<a href="https://docs.rs/sys-lib"><img alt="Documentation" src="https://docs.rs/sys-lib/badge.svg"></a>
<a href="https://github.com/jamesgober/sys-lib/actions"><img alt="CI" src="https://github.com/jamesgober/sys-lib/actions/workflows/ci.yml/badge.svg"></a>
<a href="https://github.com/rust-lang/rfcs/blob/master/text/2495-min-rust-version.md"><img alt="MSRV" src="https://img.shields.io/badge/MSRV-1.89%2B-blue"></a>
<a href="#license"><img alt="License" src="https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg"></a>
</div>

<br>
Expand All @@ -29,7 +30,7 @@
<strong>MSRV is 1.89+</strong> (Rust 2024 edition). <code>unsafe</code> is denied at the crate root and allowed only in one OS module per platform.
</p>
<blockquote>
<strong>Status: <code>0.7.0</code>, feature complete and measured.</strong> The boot kit, the live readings (memory, CPU, disks, network, pressure, this process), detection and identity (virtualization, form factor, topology, power, DNS, the time zone, firmware, launch context, <code>summary()</code>, an application-scoped device id), and now the server readiness, benchmark environment, and security posture reports, temperatures, graphics adapters, and explicit roots for monitoring agents. Linux (64-bit, and 32-bit glibc on x86 and Arm), macOS, Windows, and FreeBSD; Android and iOS best effort. 0.7 measured every reading against the crates people use for it (<a href="./docs/PERFORMANCE.md"><code>docs/PERFORMANCE.md</code></a>); 0.8 to 1.0 harden; the API is in <a href="./docs/API.md"><code>docs/API.md</code></a>. Design: <a href="./dev/PLAN.md"><code>dev/PLAN.md</code></a>; schedule: <a href="./dev/ROADMAP.md"><code>dev/ROADMAP.md</code></a>.
<strong>Status: <code>0.8.0</code>, feature complete, measured, and hardened.</strong> The boot kit, the live readings (memory, CPU, disks, network, pressure, this process), detection and identity (virtualization, form factor, topology, power, DNS, the time zone, firmware, launch context, <code>summary()</code>, an application-scoped device id), and now the server readiness, benchmark environment, and security posture reports, temperatures, graphics adapters, and explicit roots for monitoring agents. Linux (64-bit, and 32-bit glibc on x86 and Arm), macOS, Windows, and FreeBSD; Android and iOS best effort. 0.7 measured every reading against the crates people use for it (<a href="./docs/PERFORMANCE.md"><code>docs/PERFORMANCE.md</code></a>); 0.8 hardened it, with every threat and its test in <a href="./docs/SECURITY.md"><code>docs/SECURITY.md</code></a>; the API is in <a href="./docs/API.md"><code>docs/API.md</code></a>. Design: <a href="./dev/PLAN.md"><code>dev/PLAN.md</code></a>; schedule: <a href="./dev/ROADMAP.md"><code>dev/ROADMAP.md</code></a>.
</blockquote>
</div>

Expand All @@ -40,15 +41,22 @@

Static facts read once and cached (OS name and version, CPU model, core counts, CPU features, caches, topology, virtualization, form factor); live readings read fresh on every call with no allocation for single values (memory, swap, uptime, load, disk space, this process's memory and CPU time); caller-owned samplers for values that need two readings (CPU usage, network rates); the boot kit (build info, instance info, process guard); and an opt-in device id derived with a keyed hash, so raw hardware identifiers never leave the library. It does not read other processes' details, change system settings, or run in the background; the few readings that walk the process table (`host::processes()` on macOS and FreeBSD, `process::threads()` on Windows) say so and their cost.

## Quick start
## Installation

Cargo's rename makes the crate `sys` in your code:

```toml
[dependencies]
sys = { package = "sys-lib", version = "0.7" }
sys = { package = "sys-lib", version = "0.8" }

# The application-scoped device id (brings crypt-io's BLAKE3 stack):
sys = { package = "sys-lib", version = "0.8", features = ["device-id"] }
```

The default features are `instance` (instance info) and `guard` (the process guard). `default-features = false` keeps every reading and report and brings no dependency at all.

## Quick start

Tier 1 is one plain call per fact. Static facts are read once and cached, so
every later call costs about a nanosecond:

Expand Down
Loading
Loading