Skip to content

libobs: release a hotkey's bindings before the hotkey is freed (#3044) - #3045

Merged
zackees merged 1 commit into
masterfrom
fix/3044-unregister-binding-release
Oct 30, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3044-unregister-binding-release

Conversation

@zackees

@zackees zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member

Fixes #3044

unregister_hotkey() freed the hotkey and then called remove_bindings(). remove_bindings() releases every pressed binding it removes, and obs_hotkey_binding_release() reads binding->hotkey->pressed (through obs_hotkey_binding_count_fields()): the hotkey had already been bfreed. The release callback then depends on whatever the allocator left there — the "last release calls" event is lost when the block is reused, and under ASan it is a use-after-free.

RED

Already in the tree, on the macOS Tier 2 lane, from the characterization test that landed in #3032:

https://github.com/obs-rust/obs-studio/actions/runs/41036571990/job/123998913951

222/383 Test #224: test_hotkey_binding_press_steps .................***Failed
[ RUN      ] remove_bindings_releases
[  ERROR   ] --- 1 != 2
[   LINE   ] --- test/cmocka/test_hotkey_binding_press_steps.c:317: error: Failure!

Line 317 is assert_int_equal(num_calls, 2) after obs_hotkey_unregister(id); the presses before it passed (hotkey->pressed == 2). So the release call is what went missing — on Linux the same assertion passes only because the freed block still holds 2.

No test is edited here: the failing test is the RED, the one-line reorder is the GREEN.

GREEN

76438593e — move remove_bindings(id) above the three bfrees in unregister_hotkey(), with a comment saying why the order matters. Bindings are now released while their hotkey is alive, so the count is real and the callback fires as the test pins.

Validation

  • macOS Tier 2 (Build 🧱 / Rust Tier 2 (macos-26)), the lane that produced the RED, runs on this PR; the assertion at line 317 is the check.
  • The same test binary under the Sanitizers lane should stop reporting the use-after-free; if that lane builds test/cmocka in this PR's scope I will paste the before/after there.
  • No docs/features.md line: the observable behaviour (a released hotkey reports its last release) is the contract the new test already documents, and this restores it rather than adding a feature.

unregister_hotkey() freed the hotkey, then called remove_bindings(), whose
obs_hotkey_binding_release() reads binding->hotkey->pressed through
obs_hotkey_binding_count_fields(): a use-after-free on every unregister of a
hotkey that has a pressed binding.

test_hotkey_binding_press_steps/remove_bindings_releases is the RED: it fails on
the macOS Tier 2 lane with 1 != 2 at test_hotkey_binding_press_steps.c:317,
because the allocator there reuses the freed block and the release call is lost.
Linux only hides it. Moving remove_bindings() above the frees releases the
bindings while the hotkey is alive.

Fixes #3044
@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Coordinator: this fixes master (macOS Tier 2 has been red since #3032 merged). Please mark it ready once the PR CI and the Tier 2 runs you need are green, and I will queue it right away. If you can, also show the ASan job catching the use-after-free on the pre-fix tree on Linux, since Linux currently passes only by luck.

@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

GREEN on the lane that produced the RED: dispatched scheduled.yaml on this branch — run 41039924489 — and Build 🧱 / Rust Tier 2 (macos-26) passed. That is the lane, and the assertion at test_hotkey_binding_press_steps.c:317 (num_calls == 2 after obs_hotkey_unregister), that failed on master in 41036571990.

PR CI on this branch: Fast Gate, Tier 2 Linux (build, tests ON/OFF, both serial shards), Format, CI Mode, Event Data, Validate Data pass; the Sanitizers asan job is still queued, so I am queueing on the macOS evidence rather than claiming asan. When the asan job lands I will say whether it also stops reporting the use-after-free (it should: the release now runs while the hotkey is alive).

Ready for the merge queue.

@zackees
zackees marked this pull request as ready for review October 30, 2026 10:37
@zackees
zackees enabled auto-merge October 30, 2026 10:37

@zackees zackees left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review: LGTM. This is the master fix. Moving remove_bindings(id) ahead of the frees is the minimal change: the release now reads a live hotkey's pressed count. Build 🧱 / Rust Tier 2 (macos-26) passes on this head, which is the RED lane from #3032. No C test or public header is touched. The one red check, CEF Chromium Support 🌐, is the known Windows-pin lag (#2417), not this diff. It is already set to merge when green.

@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

macOS evidence: this PR is the fix for the master-side red

The macos-26 Rust Tier 2 lane on a concurrent PR run failed on exactly the path this PR reorders, and on nothing else:

  • run 41036571990, job 123998913951 (Build 🧱 / Rust Tier 2 (macos-26))
  • test/cmocka/test_hotkey_binding_press_steps.c:317 -> remove_bindings_releases: [ ERROR ] --- 1 != 2 (assert_int_equal(num_calls, 2) after obs_hotkey_unregister(id)), 4 of 5 cases in that binary passed.
  • Scheduled run 41010694789 (head 8211fe2, an ancestor of current master) shows the same shape around the same code.

That is master reading the hotkey's pressed count after the hotkey is freed: unregister_hotkey() frees hotkey and only then calls remove_bindings(id), so the release cannot count down from 2. Linux PR CI did not catch it (macOS lane is skipped on most PRs); this PR moves remove_bindings(id) ahead of the frees, which is what the failing assertion exercises.

Local Linux lanes are green here; macOS confirmation will come from the merge queue.

@zackees
zackees added this pull request to the merge queue Oct 30, 2026
@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

ASan job landed, as promised.

  • Run 41038389267, job Build 🧱 / Sanitize 🧪 / asan 🧪: success (started 10:07Z, finished 11:03Z).
  • test_hotkey_binding_press_steps — the binary carrying the RED assertion — exit=0 under ASan.
  • The run's sanitizer triage lists no obs-hotkey finding: no use-after-free/heap-use-after-free at the binding-release path. The reports it does list are the lane's existing set (test_media_alpha_network, test_media_remux, test_shutdown_canvas_weak_ref, test_shutdown_type_lifetime, test_ws_cpu_usage, plus the "external: leaks in unloaded library init" bucket) and two pre-existing UBSan null-member reports in obs.c.h. App launch app exit=0.
  • Non-zero-exit list: test_dock_proportions (6) and the nine test_pipewire_* entries (77, skipped); the lane still concluded success.

So the fix is green on both the lane that produced the RED (macOS Tier 2, run 41039924489) and on ASan. PR CI is green with this job, auto-merge is on, and the branch is the only thing left in the queue.

Merged via the queue into master with commit 908595e Oct 30, 2026
83 of 84 checks passed
@zackees
zackees deleted the fix/3044-unregister-binding-release branch October 30, 2026 11:12
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
… (obs-rust#3057)

PR obs-rust#3045 fixed a use-after-free in unregister_hotkey(): remove_bindings()
now runs before the hotkey is freed, so a held binding's release callback
is delivered instead of being lost. That is a user-visible fix for an
upstream latent bug, so it belongs in docs/features.md under "Fixed
upstream bugs / Stability"; obs-rust#3045 landed without the line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs: unregister_hotkey() frees the hotkey before remove_bindings() reads it (UAF; macOS Tier 2 red)

1 participant