Skip to content

Safety Guards Security and Platform Support

buntatoes edited this page Nov 28, 2026 · 1 revision

Safety Guards, Security, and Platform Support

Writing raw sectors to block devices is inherently destructive. Cinderboot enforces defense-in-depth across device enumeration, pre-write validation, privilege separation, and loopback UI isolation, with full parity between Linux and Windows.


Hardware Write-Protection Guards (internal/device)

Every flash operation validates its target drive twice — once during CLI/UI selection and again inside the privileged worker (flash.Execute, device.PrepareForWrite, and device.OpenRawWrite) via device.ValidateTarget:

  1. Non-Empty Path & Non-Zero Capacity: Rejects empty device paths (ErrEmptyDevice) and zero-capacity devices (ErrZeroCapacity).
  2. System Disk Block (ErrSystemDisk): Rejects any drive flagged IsSystemDisk (such as the disk hosting Windows %SystemDrive% or a Linux protected mount).
  3. Protected Mount Point Block (IsProtectedMount): Rejects any drive hosting any of the following OS-critical mount paths, even if it is attached over USB and even when --include-fixed is enabled:
    • Linux: /, /boot, /boot/efi, /efi, /home, /usr, /var, /etc, /opt, /nix, /root
    • Windows: C: (case-insensitive, trailing slashes stripped) and the physical disk backing %SystemDrive%
  4. USB Bus Requirement (ErrNotRemovable): Requires IsUSB == true. Internal NVMe, SATA, SCSI, virtio, loop, RAM, device-mapper (dm-*), zram, sr*, md*, nbd*, and floppy (fd*) devices are unconditionally excluded and cannot be unlocked by any flag.
  5. Removable Media Filter: By default, non-removable external USB HDDs/SSDs (Removable == false) are hidden and rejected. Users must explicitly opt in via --include-fixed (CLI) or Show fixed USB HDDs (UI) to target external fixed USB enclosures.
  6. Interactive Erase Confirmation:
    • CLI: Requires typing ERASE verbatim (unless --yes is explicitly passed for automation).
    • Desktop UI: Opens a destructive-write confirmation modal displaying the full drive label, device path, image list, and flash mode before triggering elevation.

Privilege Separation & Cancellation Flow

Cinderboot runs unprivileged while enumerating drives, inspecting ISOs, and serving the desktop UI. Elevated privileges are requested only for the duration of an active flash via a short-lived cinderboot worker subprocess (internal/elevate).

sequenceDiagram
    participant UI as Unprivileged UI or CLI
    participant Elev as internal/elevate
    participant OS as pkexec/sudo or UAC runas
    participant W as Elevated cinderboot worker
    participant USB as Removable USB Drive

    UI->>Elev: RunFlash(ctx, JobSpec)
    Elev->>Elev: Create temp dir (0600 spec.json + cancel path)
    Elev->>OS: Spawn selfExe worker --spec ... --cancel ...
    OS->>W: Authenticate user & launch elevated worker
    W->>USB: ValidateTarget -> PrepareForWrite -> OpenRawWrite
    loop Streaming Progress
        W-->>Elev: JSONL ProgressEvent (stdout on Linux / events.jsonl on Windows)
        Elev-->>UI: ProgressSink / SSE /api/events
    end
    alt User clicks Cancel or presses Ctrl+C
        UI->>Elev: Cancel ctx
        Elev->>W: Write cancel sentinel file (+ close stdin on Linux)
        W->>W: Detect cancel (50 ms poll / stdin EOF) -> close USB handles
        W-->>Elev: ProgressEvent(phase="cancelled", done=true), exit 130
    else Completed
        W->>USB: Sync(), Verify (raw), RelocateBackupGPT, RereadPartitionTable
        W-->>Elev: ProgressEvent(phase="complete", done=true), exit 0
    end
    Elev->>Elev: Remove temp job directory
Loading

Why a Cancel Sentinel File?

An unprivileged parent process cannot send SIGTERM directly to a root-owned (pkexec/sudo) or Administrator-elevated (UAC) child process without hitting EPERM / access denied. Cinderboot solves this cleanly on both platforms:

  • Linux (elevate_linux.go): Writes a user-owned cancel sentinel file (polled every 50 ms by the worker) and closes the worker's stdin pipe (triggering immediate EOF cancellation), with a 4-second fallback SIGTERM if already running as root.
  • Windows (elevate_windows.go): Writes the cancel sentinel file, waits up to 3,000 ms (WaitForSingleObject) for the elevated worker to flush and close USB handles cleanly, and falls back to TerminateProcess only if it does not exit in time.

Loopback UI Hardening & Zero Telemetry

The local desktop UI server (internal/ui/server.go) applies strict local-origin security controls:

  • Loopback-Only Bind: Listens exclusively on 127.0.0.1:<port> (ephemeral port by default, never 0.0.0.0).
  • DNS Rebinding Protection: Rejects any HTTP request whose Host header does not exactly match the bound 127.0.0.1:<port> address (403 Forbidden).
  • Per-Session Cryptographic Token: Generates a 24-byte (crypto/rand, 48 hex characters) token at startup. All /api/* endpoints require X-Cinderboot-Token: <token>, and /api/events SSE requires ?token=<token>.
  • Security Headers: Every response sets:
    • Content-Security-Policy: default-src 'self' 'unsafe-inline' data:
    • X-Content-Type-Options: nosniff
    • Cache-Control: no-store
    • ReadHeaderTimeout: 10s
  • Single Active Job Lock: Concurrent /api/flash requests while a flash is running are rejected with 409 Conflict.
  • Zero Telemetry / Offline by Design: Cinderboot makes zero outbound network requests and collects no analytics, crash dumps, or hardware identifiers.

Linux vs. Windows Platform Implementation Matrix

Subsystem Linux (linux/amd64) Windows (windows/amd64)
Drive Discovery Reads /sys/block, resolves symlinks checking /usb, reads removable, size (512-byte sectors), queue/logical_block_size, device/{vendor,model,serial}, and cross-references /proc/mounts (with octal unescaping) Probes \\.\PhysicalDrive0..63 via IOCTL_STORAGE_QUERY_PROPERTY (BusType == 7 / USB, RemovableMedia) and IOCTL_DISK_GET_DRIVE_GEOMETRY_EX; maps drive letters via GetLogicalDrives + IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
Pre-Write Preparation Unmounts all child partitions sorted deepest-path-first via syscall.Unmount (up to 4 retries with backoff on EBUSY) Opens each volume \\.\X: and sends FSCTL_LOCK_VOLUME (up to 5 retries × 300 ms) + FSCTL_DISMOUNT_VOLUME, then sends IOCTL_DISK_DELETE_DRIVE_LAYOUT + IOCTL_DISK_UPDATE_PROPERTIES on the physical disk
Raw Write Handle syscall.Open(..., O_RDWR | O_EXCL | O_CLOEXEC) (exclusive kernel lock) CreateFileW(..., GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH)
Read-Back Cache Flush ioctl(fd, BLKFLSBUF) (0x1261) before verification reads No-op (OpenRawWrite uses FILE_FLAG_WRITE_THROUGH)
Partition Table Rescan ioctl(fd, BLKRRPART) (0x125f) with up to 4 retries on EBUSY IOCTL_DISK_UPDATE_PROPERTIES (0x00070140)
Privilege Elevation os.Geteuid() == 0 check; otherwise pkexec (preferred) or sudo streaming JSONL over stdout shell32.dll!IsUserAnAdmin check; otherwise shell32.dll!ShellExecuteExW("runas", SW_HIDE) tailing events.jsonl every 150 ms
App Window Launcher Checks chromium, google-chrome, google-chrome-stable, brave, microsoft-edge, vivaldi with --app=<url> --window-size=780,860, falling back to xdg-open Checks msedge.exe (x86/x64 Program Files) and chrome.exe with --app=<url> --window-size=780,860, falling back to rundll32.exe url.dll,FileProtocolHandler
Native File Picker kdialog --getopenfilename or zenity --file-selection Win32 comdlg32.dll!GetOpenFileNameW

Tip

Security vulnerabilities should never be reported in public GitHub issues. Use GitHub Security Advisories as documented in SECURITY.md.