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
Differential D46715 Authored by christos on Sep 20 2024, 2:57 PM.
Details Summary If we do not enter dummy_chan_trigger() before detaching, we'll get a Sponsored by: The FreeBSD Foundation
Diff Detail
Event TimelineHerald added a subscriber: imp. · View Herald TranscriptSep 20 2024, 2:57 PM2024-09-20 14:57:08 (UTC+0) Harbormaster completed remote builds in B59538: Diff 143539.Sep 20 2024, 2:57 PM2024-09-20 14:57:09 (UTC+0) Comment Actions
callout_drain() will wait for the callout to finish, instead of stopping it immediately. Is there an advantage to using this? Comment Actions
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. Comment Actions
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 PM2024-09-21 15:13:12 (UTC+0) Harbormaster completed remote builds in B59554: Diff 143573.Sep 21 2024, 3:13 PM2024-09-21 15:13:24 (UTC+0) This revision is now accepted and ready to land.Sep 21 2024, 3:18 PM2024-09-21 15:18:45 (UTC+0) Closed by commit rGe42c82678219: snd_dummy: Drain callout during detach (authored by christos). · Explain WhyOct 18 2024, 8:45 AM2024-10-18 08:45:42 (UTC+0) This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 143539 sys/dev/sound/dummy.c
|
99% of the time assert(3) will just compile out in userspace. Does this library have any other use of assert(3) (i.e. does it expect anybody to actually compile with -DDEBUG or whatever)?