interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / om / store / README.md

147 lines · 9652 bytes Raw Blame History Source

Descriptor-secure snapshot store

Program-mode Linux ARM64 storage. Include om/blake2s/blake2s.om, store.om, then storepool.om once. Production logic and native I/O are Omega. The companion owns fixed global descriptor/state cells; callers must serialize all operations.

API

All int results are 0 on success, 1 on refusal or I/O failure, except stcommit, which additionally returns 2 for an uncertain commit.

Ordinary opened descriptors are close-on-exec. The sole exception is explicit quiescent handoff, used by the daemon with directory FD 64 and lock FD 65 (listener FD 66 belongs to the daemon). Controlled /proc/self/exe --resume must keep all three references alive continuously and recover semantic state before serving. The launcher must provide only standard I/O, trusted procfs and a trusted executable without privilege changes. The service must not fork children retaining these descriptors. Structural resume validation does not authenticate a hostile same-UID launcher; same-UID/root trust remains a prerequisite. A returned exec failure must exit, not clear poison, spin, unlink the RPC entry or reacquire the writer lock. No environment variable, request field, or production API injects failures or bypasses validation.

Sole writer and filesystem boundary

The directory must be owned by effective UID, directory type, exactly mode 0700 (including refusal of special permission bits). Files must be owned by effective UID, regular, exactly 0600, single-link and bounded in size. Files use O_NOFOLLOW|O_NONBLOCK; special files cannot block startup. The directory uses O_DIRECTORY|O_NOFOLLOW. Metadata is checked on the opened descriptor, not by a path check preceding open. Existing entries are never repaired to acceptable permissions. An incompatible umask can cause staged-file validation to refuse.

The bind-only abstract AF_UNIX lock name is the bytes omnet.store.v1. followed by little-endian 64-bit st_dev and st_ino. No PID, configurable name, or software version influences this identity. It is never listened on and accepts no requests. The descriptor lives across all storage and RPC activity. Different spellings of the same directory contend for the same lock; process death releases it. A failed bind refuses startup. Only after acquisition may a daemon remove its reserved stale RPC pathname. No connect-failed or stale-PID ownership heuristic is used.

Deployment prerequisites: all writers must follow this protocol in the same network namespace; the operator must provision a trusted ancestor chain; the process is single-threaded and must not change cwd later. O_NOFOLLOW protects only the final directory component, not ancestor symlinks or path traversal through a symlink followed by /. Same-UID processes and root are trusted. Abstract names have no filesystem permissions, so an unrelated local process can deny service by pre-binding a predicted name, but cannot thereby authorize an RPC. A separate-UID headscale adapter cannot traverse this 0700 directory; this is not a claim of that integration or of a separate privilege boundary.

A leftover snapshot.tmp is opened without following symlinks, validated as a private regular single-link file, and removed only under the lock. Its contents need not be valid because interrupted writes are expected. Unsafe temporary entry types/ownership/permissions cause refusal, not deletion. In recovery mode the committed snapshot must validate before stale cleanup. Missing/malformed committed state never means disabled or empty, and a valid temporary file is never promoted.

Version 1 framing

All integers are unsigned little-endian 64-bit. The file begins with the exact 16 ASCII bytes OMNETSNAP0000001. Each nonempty frame contains:

  1. payload byte length (1..65536);
  2. BLAKE2s-256 of that frame's payload (32 bytes);
  3. payload bytes.

Maintain a 32-byte zero-initialized chain. For each frame, replace it with `BLAKE2s-256(previous_chain || payload_digest || length || cumulative_payload_bytes || cumulative_frame_count)`. The final record is zero length, final chain, total payload length, and frame count (56 bytes). Empty snapshots have an all-zero chain and zero totals. No bytes may follow the terminator. Maximum file size is 36175944 bytes (32 MiB payload + 65536 frame headers + header and terminator).

This commits payload, ordering, frame boundaries and completeness; it is corruption integrity, not owner authentication or anti-rollback. An owner can reconstruct a valid file, and restoration of an old valid whole-store backup is undetectable. Service semantics and reconstruction correctness are the daemon's responsibility.

Tests and scope

sh om/store/test/run.sh compiles with the repository-pinned compiler and executes isolated native processes. Python independently constructs BLAKE2s framing. Cases cover restart, explicit initialization, abort, alias writer contention, kill and stale-temp recovery, unsafe metadata/types/links, truncation, corruption, oversized files, maximum frame/payload capacity, self-exec with continuous writer exclusion, invalid inherited descriptors, partial I/O, bounded EINTR handling and injected write/read/fsync/rename failures. Ownership-changing fixtures run only when the test runner is root; non-root runs report that subset as skipped. Injection replaces thin syscall wrappers only in a separately built test binary; production source has no fault controls. A completed-result checksum mutant must differ, rather than crash. Process-kill/restart and syscall-failure tests do not prove power-loss behavior of any specific filesystem. No live state or services are touched.

Third-party material and notices

No third-party code or vectors are copied here. BLAKE2s uses the repository's existing Omega unit. Linux ABI layouts and operation semantics are referenced in the pinned compiler's docs/one_layer/OMEGESE.md section 10 and Linux unix(7), open(2), stat(2), rename(2) and fsync(2).