Repository navigation
rust: Deny unsafe_code in the port crates - #290
Conversation
|
thank you for handling that i'll follow up on the boundary seam later |
The testing policy says the safe cores contain no `unsafe`, and nothing enforced it. Deny the lint for the whole of every port crate and allow it back only where the C ABI lives: the `ffi` modules, plus the two Windows platform modules that call Win32 directly (`pipe::windows`, `utf8::windows`), which the pipe port documents as deliberate. With this commit alone the crates do not build: the lint fires on the two safe cores that still hold `unsafe`. Refs obs-rust#143
The `unsafe_code` denial now passes, with the two offending safe cores cleaned up: - config_file: `get_string` returned the value through the `config_get_string` address after the lock was dropped, so a writer that replaced the value in between freed the buffer the pointer came from. Copy the bytes with the lock held instead. Same bytes, no observable difference. - profiler: the `blog` declaration, the `bmalloc` adoption and the box drop move into the shim. `profile_end` reports what `profiler.c` logs through a callback the shim implements, the split the pipe port already uses for a failed `CreateProcessW`. Tier 1 gains a case for those two log lines, which cmocka cannot observe. `cargo test --workspace`: 70 of 71 test binaries pass. The exception, `buffered_file_serializer_parity`, aborts with STATUS_ACCESS_VIOLATION in `defaults_match_oracle` on this machine and does so on unmodified master too (verified by stashing this change first), so it is not from here. Refs obs-rust#143
The policy already said the safe cores have no `unsafe`; say which lint enforces it and where `allow` is written back. Refs obs-rust#143
The audio-io port (obs-rust#289) merged with 54 unsafe sites in its safe core, which the new deny(unsafe_code) rejects. Allow it on the module with a pointer to obs-rust#294, which moves that code into src/ffi; every other module stays under the lint. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=63a892fb6ff84969dfc38d23be2f2b9923ce553a secs=114 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791769092,"gate":"rust/all/fmt","host":"linux-x86_64","key":"1ab3f600ca0050bca59f435d6ac45dde91181ac092d7b4c93a504c64ca7415ca","lane":"lint","parents":["2260b8992d1aeb76f94aacdc152fe1667d64b494"],"secs":14,"stamp":"5ad062e4a22509f1f532eeea1e502669","tree":"63a892fb6ff84969dfc38d23be2f2b9923ce553a","v":1,"via":"run"} Ci-Attestation: {"at":1791769092,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"1ab3f600ca0050bca59f435d6ac45dde91181ac092d7b4c93a504c64ca7415ca","lane":"lint","parents":["2260b8992d1aeb76f94aacdc152fe1667d64b494"],"secs":14,"stamp":"6f07834adae2cd0f49955dab4643f20d","tree":"63a892fb6ff84969dfc38d23be2f2b9923ce553a","v":1,"via":"run"} Ci-Attestation: {"at":1791769092,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"313badc9388c6f37a20dfac00209e8950e9008b086a82482e43137ddafc03b89","lane":"rust-test","parents":["2260b8992d1aeb76f94aacdc152fe1667d64b494"],"secs":47,"stamp":"27ba81a320fbccbcb6b31e042abfe257","tree":"63a892fb6ff84969dfc38d23be2f2b9923ce553a","v":1,"via":"run"} Ci-Attestation: {"at":1791769092,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"217841ec98a6c6f2d928fc014925c0eec19795d829d8080fc907b2c7dd9bcf77","lane":"tier2-linux","parents":["2260b8992d1aeb76f94aacdc152fe1667d64b494"],"secs":53,"stamp":"d8ca05bee2805bf43c4f3bc60f9f5239","tree":"63a892fb6ff84969dfc38d23be2f2b9923ce553a","v":1,"via":"run"}
dcb1837 to
4b3eaab
Compare
|
Verified locally, rebased onto master and stamped. The new head is
One addition after the rebase: the audio-io port (#289) merged just before this and has 54 Local gate: lint, rust-test and tier2-linux all passed. Thanks for picking up this part of #143. Merging once CI is green. |
|
Thanks - the boundary seam is yours to call, and I will not push over a stamped head. My local rebase is parked on a scratch branch ( Two exact numbers for the record, because three different figures are now in play (7 in your note, 10 in my RED commit message, 64 in reality after the rebase):
I also ran your head on this Windows host (rustc 1.97.1, On #294: the plan you wrote is the one I would have proposed, and I fixed the boundary list from the port's own Still unclaimed in #143 and locally verifiable from Windows: the |
Refs #143
What and why
The testing policy says a safe core contains no
unsafe, and nothing enforcedit:
src/ffi/is the only place the policy allows, but the lint that wouldcatch a stray block was off. Issue #143 lists that enforcement as unclaimed,
with
rust/obs-util/src/config_file.rs:949as the example.This denies
unsafe_codefor all four port crates (obs-util,obs-codec,obs-graphics,obs-media-io) and allows it back only where the C boundaryis:
src/ffi/module, which is what the policy permits;obs_util::pipe::windowsandobs_util::utf8::windows, the two Windowsplatform modules that call Win32 directly. The pipe port (rust: Port util/pipe-windows.c to obs-util #259) documents
that choice: a shim may not contain logic, so the handle calls stay in the
platform module and they are
unsafeby nature.Both Windows modules carry their own
#[allow(unsafe_code)]with the reason,so the exception is visible where the module is declared.
Cleaning up the two safe cores that failed the lint turned up one real defect:
config_file'sget_stringread the value back through the address thatconfig_get_stringreturns, after the lock had been dropped. A writer thatreplaces the value in between frees the buffer, so the safe Rust API could
read freed memory. It copies the bytes with the lock held now. The bytes
returned are unchanged, so there is no observable difference from C.
profiler's safe core held theblogdeclaration, abmallocadoption andthe box drop. The shim owns them now:
profile_endreports the twoLOG_ERRORlinesprofiler.cprints through a callback the shim implements(
ProfileLog), which is the split the pipe port already uses for a failedCreateProcessW. Tier 1 gains a case for those two lines; cmocka cannotobserve them, because
blog's output is not capturable there.docs/rust-port/testing-policy.mdnow records the invariant and the twoallowed exceptions.
RED → GREEN
rust: Deny unsafe_code in the port crates (RED)).With the denial and nothing else,
cargo check --workspacefails with 10E0133errors:config_file.rs:949, andprofiler.rs:17, 105, 111, 115, 117, 137, 142, 495, 504.cargo check --workspacecleancargo clippy --workspace --all-targets -- -D warningsexit 0cargo fmt --all --checkexit 0cargo test --workspace: 70 of 71 test binaries passHonest state of the local run
I could not run the repo's gate on this machine, so this head carries no
attestation and is not stamped. The reasons, so you can judge the evidence:
so the tests ran as
cargo test --workspace --ignore-rust-version;soldrand no Docker here, so the Tier 2 lane did not run at all: CI'stier2-linuxandrust-tier2are the first check of the C side. Nothing inthis diff touches C, exported symbols or a header;
buffered_file_serializer_parity, aborts withSTATUS_ACCESS_VIOLATIONindefaults_match_oracle. I re-ran it with thisbranch stashed, i.e. on unmodified master, and it aborts the same way, so it
is not from this change. It looks windows-gnullvm-specific (CI runs MSVC); I
can file it separately with the raw output if that is useful.
Two local shims were needed to build the oracle on a windows-gnu host at all,
and neither is in this diff: three MSVC intrinsics LLVM-MinGW's
intrin.hdoes not declare, and the pthread implementation, because
obs-c-oracle/build.rspicks pthread by compiler rather than by target. If youwant, I can send that one as its own small PR (keyed on
CARGO_CFG_WINDOWSplus the GCC/clang
deps/w32-pthreadspath instead ofis_like_msvc()).Checklist
masterno Docker, and the MSRV is one behind, so CI's jobs are the first full check
config_filereturns the samebytes, and
profilerkeeps the sameblogcalls with the same arguments inthe same order.