Page MenuHomeFreeBSD

snd_dummy: Drain callout during detach
ClosedPublic

Authored by christos on Sep 20 2024, 2:57 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Mar 13, 3:38 AM
Unknown Object (File)
Sun, Mar 9, 12:37 PM
Unknown Object (File)
Thu, Feb 20, 5:58 AM
Unknown Object (File)
Mon, Feb 17, 10:17 PM
Unknown Object (File)
Feb 3 2025, 8:44 AM
Unknown Object (File)
Jan 30 2025, 12:19 PM
Unknown Object (File)
Jan 29 2025, 3:57 PM
Unknown Object (File)
Jan 26 2025, 6:08 PM
Subscribers

Details

Summary

If we do not enter dummy_chan_trigger() before detaching, we'll get a
use-after-free since the callout(9) callback might be called after
having been detached.

Sponsored by: The FreeBSD Foundation
MFC after: 2 days

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

callout_drain perhaps?

callout_drain() will wait for the callout to finish, instead of stopping it immediately. Is there an advantage to using this?

callout_drain perhaps?

callout_drain() will wait for the callout to finish, instead of stopping it immediately. Is there an advantage to using this?

Yes, it ensures that the callout won't be running while dummy_detach() runs concurrently. This patch makes the use-after-free harder to hit, but doesn't fix it completely.

callout_drain perhaps?

callout_drain() will wait for the callout to finish, instead of stopping it immediately. Is there an advantage to using this?

Yes, it ensures that the callout won't be running while dummy_detach() runs concurrently. This patch makes the use-after-free harder to hit, but doesn't fix it completely.

If the callout stops before pcm_unregister() is called, read/write operations will have stopped already in the case of snd_dummy, so we shouldn't hit any use-after-free. That being said, I guess it could be made even more robust by check whether &sc->chans[i] is NULL in the dummy_chan_io() loop, even though the channels pointed to by sc->chans are freed in pcm_unregister().

christos retitled this revision from snd_dummy: Cancel callout during detach to snd_dummy: Drain callout during detach.Sep 21 2024, 3:13 PM
This revision is now accepted and ready to land.Sep 21 2024, 3:18 PM
This revision was automatically updated to reflect the committed changes.