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, Jan 30, 12:19 PM
Unknown Object (File)
Wed, Jan 29, 3:57 PM
Unknown Object (File)
Sun, Jan 26, 6:08 PM
Unknown Object (File)
Fri, Jan 24, 5:10 PM
Unknown Object (File)
Tue, Jan 21, 12:04 AM
Unknown Object (File)
Dec 13 2024, 12:32 PM
Unknown Object (File)
Dec 13 2024, 5:07 AM
Unknown Object (File)
Nov 25 2024, 12:52 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.