security: harden legacy seatbelt diagnostics

ober

5aff6bbb86e23540d2c382ba67bb78d4831f32ea

diff --git a/docs/ffi-audit.md b/docs/ffi-audit.md
index d020fee..061f5f5 100644
--- a/docs/ffi-audit.md
+++ b/docs/ffi-audit.md
@@ -169,7 +169,9 @@ column getters in panic containment, and has regressions for null/nonzero
 inputs and output-buffer validation. The Scheme `(std security seatbelt)`
 binding now resolves `sandbox_init`/`sandbox_free_error` only after the sandbox
 library is loaded and copies/frees the `sandbox_init` error buffer before
-raising a Scheme condition. `secure_fs.rs` now documents
+raising a Scheme condition; the legacy `(std os sandbox)` Seatbelt path now
+uses the same copy/free pattern before printing degraded diagnostics.
+`secure_fs.rs` now documents
 descriptor-relative `openat`/`mkdirat`, fd
 duplication/ownership transfer, stat buffers, directory stream lifecycle,
 caller output slots, atomic output publication, and test-owned fd conversion
diff --git a/docs/kimi3-security-recommmendations.md b/docs/kimi3-security-recommmendations.md
index 5c89302..2f4f9ac 100644
--- a/docs/kimi3-security-recommmendations.md
+++ b/docs/kimi3-security-recommmendations.md
@@ -713,6 +713,8 @@ the current inventory and remediation trail now live in [ffi-audit.md](ffi-audit
   `sandbox_init`/`sandbox_free_error` only after loading the sandbox library and
   copies/frees the `sandbox_init` error buffer before raising a Scheme
   condition, with an invalid-profile regression in `tests/test-seatbelt.ss`.
+  The legacy `(std os sandbox)` Seatbelt path now uses the same copy/free
+  pattern before printing degraded diagnostics.
   `wasm_sm.rs` now compiles under `unsafe_op_in_unsafe_fn` for the
   SpiderMonkey feature, bounds C ABI buffers, validates host-memory offsets,
   converts poisoned handle-store locks into normal FFI errors, and documents
diff --git a/docs/status.md b/docs/status.md
index bf281d3..7331fb5 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -25,7 +25,7 @@ release artifacts are built as Jerboa multicall binaries with `jerboa`,
 | Area | Current state | Remaining work |
 |---|---|---|
 | Kimi security handoff | [kimi3-security-recommmendations.md](kimi3-security-recommmendations.md) is the backlog. Dated evidence and review manifests live under [reviews/](reviews/). | Keep new security evidence in dated review records and summarize the current release state here. |
-| FFI audit phase 5 | [ffi-audit.md](ffi-audit.md) records the scanner output, provisional Scheme binding verdicts, and native Rust export inventory. `make native-export-review-check` gates native export decisions. The worker-launch native path in `aproc.rs`/`seccomp.rs`, crypto FFI buffer path in `crypto.rs`, secure-memory region lifecycle in `secure_mem.rs`, secure filesystem capability boundary in `secure_fs.rs`, TLS native ABI in `tls.rs`, Ed25519/X25519 key-agreement buffers, compression buffers, HTTP parse/writev boundary, embed-crypto ABI, integrity ABI, regex-native ABI, process-control ABI, pcap ABI, inotify ABI, epoll/eventfd ABI, antidebug ABI, SOCKS5 server ABI, PostgreSQL native ABI, Landlock native ABI, wasmi sandbox ABI, SpiderMonkey WASM ABI, DuckDB native ABI, X.509 native ABI, SQLite native ABI, and the Scheme Seatbelt `sandbox_init` error-buffer path now have nearby `SAFETY:` comments or equivalent checked FFI invariants. Generated counts are at 0 unannotated native unsafe sites and 0 Scheme blocking bindings missing `__collect_safe`. | Finish per-binding Scheme FFI review and targeted scanner rules for the remaining provisional verdicts. |
+| FFI audit phase 5 | [ffi-audit.md](ffi-audit.md) records the scanner output, provisional Scheme binding verdicts, and native Rust export inventory. `make native-export-review-check` gates native export decisions. The worker-launch native path in `aproc.rs`/`seccomp.rs`, crypto FFI buffer path in `crypto.rs`, secure-memory region lifecycle in `secure_mem.rs`, secure filesystem capability boundary in `secure_fs.rs`, TLS native ABI in `tls.rs`, Ed25519/X25519 key-agreement buffers, compression buffers, HTTP parse/writev boundary, embed-crypto ABI, integrity ABI, regex-native ABI, process-control ABI, pcap ABI, inotify ABI, epoll/eventfd ABI, antidebug ABI, SOCKS5 server ABI, PostgreSQL native ABI, Landlock native ABI, wasmi sandbox ABI, SpiderMonkey WASM ABI, DuckDB native ABI, X.509 native ABI, SQLite native ABI, and the Scheme Seatbelt `sandbox_init` error-buffer paths now have nearby `SAFETY:` comments or equivalent checked FFI invariants. Generated counts are at 0 unannotated native unsafe sites and 0 Scheme blocking bindings missing `__collect_safe`. | Finish per-binding Scheme FFI review and targeted scanner rules for the remaining provisional verdicts. |
 | Native Rust exports | The native export review now has 190 exported functions: 183 tracked Scheme references and 7 retained standalone C/binary helpers. The previous 35 no-Scheme-reference removal candidates no longer have C ABI export markers. | Re-run `make native-export-review-check` whenever adding or removing native exports. |
 | Confined worker | `(std security worker)` provides the facade, audit lifecycle, output caps, deadlines, process-group kill, memory rlimit pre-exec setup, Linux syscall/ptrace seccomp pre-exec setup, Linux Landlock filesystem/TCP-connect setup for requested axes, macOS Seatbelt deny-default path/exec/no-network setup for supported axes, standard worker-eval Capsicum entry on FreeBSD, explicit sandbox-axis refusal, and egress proxy env wiring. | Keep Linux/macOS/FreeBSD parity tests current; finish arbitrary-command/proxy-aware Capsicum worker paths. |
 | Fuzzing | `tests/fuzz/corpus/` has 15 checked-in seed inputs, `tests/fuzz/regression/` has 11 crash/rejection regressions, `make fuzz-smoke` runs the deterministic regression gate first, and GitHub CI runs smoke fuzzing normally plus deep fuzzing on scheduled daily runs. | Keep adding minimized corpus and regression inputs for every parser/security bug found. |
diff --git a/lib/std/os/sandbox.ss b/lib/std/os/sandbox.ss
index d80ec30..472f7a8 100644
--- a/lib/std/os/sandbox.ss
+++ b/lib/std/os/sandbox.ss
@@ -127,6 +127,21 @@
        "(version 1)(allow default)(deny network*)"]
       [else #f]))
 
+  (def (seatbelt-error-message errmsg)
+    (cond
+      [(= errmsg 0) "Seatbelt enforcement failed"]
+      [else
+       (let ([raw #f])
+         (dynamic-wind
+           (lambda () (void))
+           (lambda ()
+             (set! raw
+               (try (foreign-ref 'string errmsg 0)
+                    (catch (e) "<unreadable Seatbelt error>"))))
+           (lambda ()
+             (c-sandbox-free-error errmsg)))
+         (string-append "Seatbelt enforcement failed: " raw))]))
+
   (def (apply-seatbelt! profile-spec)
     ;; Apply a Seatbelt profile. profile-spec is a symbol or SBPL string.
     ;; Always uses SBPL (flags = 0) since the legacy named-profile path
@@ -148,11 +163,11 @@
                                       (current-error-port))
                              -1)))])])
             (when (< rc 0)
-              (let ([errmsg (foreign-ref 'void* errptr 0)])
-                (unless (= errmsg 0)
-                  (c-sandbox-free-error errmsg)))
-              (display "sandbox: Seatbelt enforcement failed\n"
-                       (current-error-port)))))
+              (display "sandbox: " (current-error-port))
+              (display (seatbelt-error-message
+                        (foreign-ref 'void* errptr 0))
+                       (current-error-port))
+              (newline (current-error-port)))))
         (lambda ()
           (foreign-free errptr)))))