Page MenuHomeFreeBSD

snd_dummy: Drain callout during detach
AcceptedPublic

Authored by christos on Fri, Sep 20, 2:57 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Sep 29, 10:16 PM
Unknown Object (File)
Sun, Sep 29, 10:16 PM
Unknown Object (File)
Sun, Sep 29, 10:16 PM
Unknown Object (File)
Sat, Sep 28, 6:10 PM
Unknown Object (File)
Thu, Sep 26, 6:10 AM
Unknown Object (File)
Wed, Sep 25, 5:53 PM
Unknown Object (File)
Wed, Sep 25, 4:56 PM
Unknown Object (File)
Tue, Sep 24, 9:54 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 Skipped
Unit
Tests Skipped
Build Status
Buildable 59554
Build 56441: arc lint + arc unit

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.Sat, Sep 21, 3:13 PM
This revision is now accepted and ready to land.Sat, Sep 21, 3:18 PM