Skip to content

[Critical] Potential data loss in OCI spec Flush() - file truncated before write #2203

Description

@nextjohnp7

Bug Report

Severity

Critical

Description

In internal/oci/spec_file.go, the Flush() method truncates the OCI specification file using os.Create(s.path) before writing new content via flushTo().

If the write operation fails (e.g., disk full, I/O error, permission denied), the original OCI config.json is already destroyed and cannot be recovered.

Affected File

  • internal/oci/spec_file.go (lines 99-111)

Current Behavior

func (s fileSpec) Flush() error {
    if s.Spec == nil {
        return fmt.Errorf("no OCI specification loaded")
    }

    specFile, err := os.Create(s.path)  // ← TRUNCATES FILE HERE
    ...
    return flushTo(s.Spec, specFile)    // ← IF THIS FAILS, DATA IS LOST
}




### Expected Behavior

Write to a temporary file first, then perform an atomic rename/replace only after the write succeeds. This prevents data loss if the write operation fails.

### Impact

- Container runtime configuration (OCI spec) can be permanently destroyed
- Containers using the affected OCI spec will fail to start
- No recovery mechanism if the write fails mid-operation

### Proposed Fix

1. Write modified spec to a temporary file in the same directory
2. If write succeeds, atomically rename temp file to target path
3. If write fails, original file remains intact

### Additional Context

This code path is executed when `nvidia-container-runtime-hook` or `nvidia-container-runtime` applies OCI spec modifications before starting a GPU container.

Activity

  1. added
    bugIssue/PR to expose/discuss/fix a bug
    needs-triageissue or PR has not been assigned a priority-px label
    on Nov 5, 2026
  2. added theissue type on Nov 5, 2026
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

    bugIssue/PR to expose/discuss/fix a bugneeds-triageissue or PR has not been assigned a priority-px label

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions