Repository navigation
callback: Track the running global signal callback by index - #1639
Conversation
…st#1441) signal_handler_signal keeps a pointer into the global callback array while a global callback runs, and the running callback uses it for signal_handler_remove_current and the signaling count. Three cases move that entry while the pointer is held: - The callback connects enough global callbacks to reallocate the array, then removes itself (heap use-after-free, GHSA-rjwf-j53r-47qr). - A nested signal erases an earlier removed entry, then the outer callback removes itself. - The callback disconnects an earlier global callback, then removes itself. In the last two, the removal marks the next callback instead, and the pass skips that callback. The signal callbacks handle the same cases since obs-rust#1556. Build test_signal with ASan. Its allocator moves every reallocated block, so the first case does not depend on the platform allocator. libobs is not instrumented, so ASan does not report the write itself; the test sees the wrong result. Without ASan, glibc moves the array here too (5 of 5 runs fail). Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]>
signal_handler_signal kept a pointer into the global callback array while a global callback ran. A connect from the callback could reallocate the array, and a nested signal or a disconnect could erase an earlier entry and move the running one. signal_handler_remove_current then wrote to freed memory or marked the next callback, and the signaling count went to the wrong entry. Follow the signal callbacks (obs-rust#1556): - The running global callback is a (handler, index) context. - The handler counts the running global passes. Removed entries are erased only when the outermost pass ends. - signal_handler_disconnect_global only marks the entry while a global pass runs. The per-entry signaling count is no longer needed and is removed. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Confirmed: both reproductions from GHSA-rjwf-j53r-47qr pass on master 01561bf. Setup: libobs built with ASan (C backend, Linux x86_64, Debian 13). The PoCs are built with
The loader check confirmed the ASan libobs in each run. The "partly fixed" note can be removed from my side. |
The ten signal_handler_* exports move into obs-callback. signal_handler_add_array stays inline in signal.h. The handle is one bmalloc block that holds an Arc, as in the audio-controls port, so bnum_allocs sees the handler until its last reference goes (keep_ref_remove_current_last_ref_test reads it). Both are freed when the C reference count reaches zero. signal_handler_signal keeps its own clone while callbacks run and frees the handler after the pass when the pass gave back the last reference. The log texts are the C ones. callback/signal.c moves into the ported group libobs.ported-callback, on its header. The audio-controls oracle defined signal_handler_connect and signal_handler_disconnect as stubs. A test binary that also links obs-callback, such as obs-tests-core, would define them twice (GNU ld stops). Rename the stubs to oracle_audio_controls_* with #define, as the oracle already does for its own exports. Tier 3 runs the original signal.c.h, as fixed by obs-rust#1639, on the decl oracle (oracle/signal.c). Random scripts of add, connect, connect_ref, disconnect, connect_global, disconnect_global and signal run with re-entrant actions. Signal callbacks remove the current one, disconnect or connect another, connect then remove, or start a nested signal. Global callbacks remove the current one, disconnect themselves, connect or disconnect another global callback, connect then remove, or start a nested signal. The test compares every callback call in order and every logged line. Excluded: a destroy from a callback (C frees the handler under the running pass). Against the core without the obs-rust#1639 rule, Tier 3 finds a failing script. Checks on Linux x86_64 (Debian 13), CMake with OBS_BUILD_C_REFERENCE: test_signal.c passes 19/19 against the hybrid libobs and against libobs-c-reference (loader checked). ctest against the hybrid passes 344/344 under xvfb-run, without the xcomposite/xshm tests that do not build on Debian's cmocka. obs-tests-core passes 422/422 with GNU ld. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]>
* test: add failing obs-callback signal tier 1 (Refs obs-rust#1441) Mirror test/cmocka/test_signal.c, as fixed by obs-rust#1556 and obs-rust#1639, against todo stubs in obs-callback. Add: global connect and disconnect matched by callback and data, a connect of many callbacks then remove_current from the running callback, a global signal in a nested pass, and a disconnect from another thread that waits for the running pass. From obs-rust#1639: a global callback that connects more global callbacks then removes itself, a nested pass that must not erase an earlier removed global callback, and a global disconnect during the pass. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]> * obs-callback: signal handler core in Rust (Refs obs-rust#1441) The safe core follows signal.c.h as fixed by obs-rust#1556 and obs-rust#1639: per-signal and global re-entrant locks held while callbacks run, deferred removal while signalling, keep_ref references, and the thread-local running callback. The running callback is a (signal, index) pair instead of a pointer into the callback array, so a connect from the callback cannot leave it dangling. As in the fixed C: - Passes of one signal nest by count, and so do the global passes. Removed callbacks are erased only when the outermost pass ends. A disconnect while a pass runs only marks the callback. The running global callback is an index, as the running signal callback is. - Each callback call saves and restores both running callbacks. A signal callback clears the global one, a global callback clears the signal one. remove_current marks the signal one first. - Global callbacks are found by callback and data only. - A keep_ref reference given back after a pass destroys the handler when it was the last one. signal() reports it to the owner. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]> * obs-callback: swap signal_handler to Rust (Refs obs-rust#1441) The ten signal_handler_* exports move into obs-callback. signal_handler_add_array stays inline in signal.h. The handle is one bmalloc block that holds an Arc, as in the audio-controls port, so bnum_allocs sees the handler until its last reference goes (keep_ref_remove_current_last_ref_test reads it). Both are freed when the C reference count reaches zero. signal_handler_signal keeps its own clone while callbacks run and frees the handler after the pass when the pass gave back the last reference. The log texts are the C ones. callback/signal.c moves into the ported group libobs.ported-callback, on its header. The audio-controls oracle defined signal_handler_connect and signal_handler_disconnect as stubs. A test binary that also links obs-callback, such as obs-tests-core, would define them twice (GNU ld stops). Rename the stubs to oracle_audio_controls_* with #define, as the oracle already does for its own exports. Tier 3 runs the original signal.c.h, as fixed by obs-rust#1639, on the decl oracle (oracle/signal.c). Random scripts of add, connect, connect_ref, disconnect, connect_global, disconnect_global and signal run with re-entrant actions. Signal callbacks remove the current one, disconnect or connect another, connect then remove, or start a nested signal. Global callbacks remove the current one, disconnect themselves, connect or disconnect another global callback, connect then remove, or start a nested signal. The test compares every callback call in order and every logged line. Excluded: a destroy from a callback (C frees the handler under the running pass). Against the core without the obs-rust#1639 rule, Tier 3 finds a failing script. Checks on Linux x86_64 (Debian 13), CMake with OBS_BUILD_C_REFERENCE: test_signal.c passes 19/19 against the hybrid libobs and against libobs-c-reference (loader checked). ctest against the hybrid passes 344/344 under xvfb-run, without the xcomposite/xshm tests that do not build on Debian's cmocka. obs-tests-core passes 422/422 with GNU ld. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
|
This is also the fix for the second half of GHSA-rjwf-j53r-47qr, and I want the record on the PR that closed it. @vpacher reported on that advisory (before it was published) that #1556 fixed only the signal-callback path: the global-callback path still held This PR is exactly that change ( Follow-up, so it does not sit in the same state as before: the advisory is published, so its comment thread is closed and his reply cannot be posted there. I have asked whether #1639 alone closes his repro. If it reproduces on |
|
The repro check is above (my comment of 2026-10-21, after the merge): with #1639 on master 01561bf, the signal PoC and both global variants are clean under ASan, and the two builds before it show the use-after-free. So #1639 closes it. Nothing is open on my side for GHSA-rjwf-j53r-47qr. |
Refs #1441
Follow-up to #1556 for the global signal callbacks. GHSA-rjwf-j53r-47qr is published and #1556 fixes its signal-callback part. This PR fixes the global-callback part, as requested in #1441. All code changes are in
libobs/callback/signal.c.h. signal.c has no Rust port on master yet, so there is no Rust side to change. The port (#1441) follows in a separate PR on top of this one.What and why
signal_handler_signalkept a pointer intohandler->global_callbacks.arraywhile a global callback ran. The running callback used it forsignal_handler_remove_current()and for thesignalingcount. Three cases move the entry while the pointer is held:signal_handler_remove_current(). The pointer refers to freed memory. The write goes there, and the callback stays connected. Withoutremove_current,cb->signaling--writes to freed memory too.signaling--go to the next callback, and the outer pass skips that callback.signal_handler_disconnect_globalerases an earlier entry at once, because that entry is not running. The result is the same as in case 2.The fix follows the signal callbacks of #1556:
(handler, index)context.global_signalling). Removed entries are erased only when the outermost pass ends.signal_handler_disconnect_globalonly marks the entry while a global pass runs.signalingcount is no longer needed and is removed.struct global_callback_infois private tosignal.c.h.test_signalis now built with ASan (obs_test_sanitize(test_signal address)). ASan's allocator moves every reallocated block, so case 1 does not depend on the platform allocator. libobs is not instrumented, so ASan does not report the write itself. The test sees the wrong result.No existing assertion changes. Three tests are new:
global_connect_then_remove_current_testglobal_nested_pass_testglobal_disconnect_during_signal_testRED → GREEN
Linux x86_64 (Debian 13, glibc), CMake build on 0b10a2f, frontend off,
-DOBS_BUILD_C_REFERENCE=ON.test_signalran against the hybridlibobsand againstlibobs-c-reference; the loader check confirmed the selected library each time. signal.c is not ported, so both cores run this C.global_connect_then_remove_current_test(2 != 1),global_nested_pass_test(4 != 5),global_disconnect_during_signal_test(2 != 3). Before the rebase, the same 3 also failed without ASan (glibc moved the array in 5 of 5 runs).-k 0: only the 3test_xcomposite_*targets fail to compile (older Debian cmocka withoutassert_int_in_range; not related). ctest withoutxcomposite|xshm: 343/344. The one failure,test_v4l2_busy_signal, needs an X display; underxvfb-runit passes 5/5.ci/local_gate.py --only clang-formatand--only gersemi: ok.Checklist
masterdocs/features.mdlines added (Stability), next to the callback: Fix signal callback removal across nesting, recursion and registration (split from #1464) #1556 lines