Skip to content

linux-alsa: Fix use-after-free crash when USB mic not plugged in - #11608

Open
R0te wants to merge 1 commit into
obsproject:masterfrom
R0te:alsa-input-use-after-free
Open

linux-alsa: Fix use-after-free crash when USB mic not plugged in#11608
R0te wants to merge 1 commit into
obsproject:masterfrom
R0te:alsa-input-use-after-free

Conversation

@R0te

@R0te R0te commented Dec 9, 2024

Copy link
Copy Markdown

Description

This change fixes a use-after-free crash in the ALSA input plugin that occurs when creating a new scene collection without the previously configured USB microphone plugged in. A shutdown flag is introduced to safely coordinate the termination of background threads and prevent access to freed resources.

Motivation and Context

Previously, _alsa_reopen() could run concurrently after alsa_destroy() freed the device string or other resources, causing a heap-use-after-free crash. This fix ensures that background threads properly exit when the source is destroyed, eliminating the race condition.
#9322

How Has This Been Tested?

  • Started OBS without the USB mic plugged in.
  • Created a new Scene Collection.
  • Switched to the new Scene Collection and waited a few seconds.
  • Confirmed that OBS no longer crashes and that no AddressSanitizer errors are reported.

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@Lain-B

Lain-B commented Dec 14, 2024

Copy link
Copy Markdown
Collaborator

Volatile variables should probably be used with the atomic functions. And if the other volatiles aren't being used with atomic operations, they probably should be.

@WizardCM WizardCM added kind/bug Categorizes issue or PR as related to a bug. platform/linux Categorizes issue or PR as affecting Linux specifically labels Dec 14, 2024
@github-project-automation github-project-automation Bot moved this to Ready For Review in 33.0 Release Tracker Jul 6, 2026
@Warchamp7 Warchamp7 added this to the OBS Studio 33.0 milestone Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. platform/linux Categorizes issue or PR as affecting Linux specifically

Projects

Status: Ready For Review

Development

Successfully merging this pull request may close these issues.

5 participants