Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

R0te
Copy link

@R0te R0te commented Dec 9, 2024

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
Copy link
Collaborator

Lain-B commented Dec 14, 2024

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 Bug Fix Non-breaking change which fixes an issue Linux Affects Linux labels Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Non-breaking change which fixes an issue Linux Affects Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants