diff options
| author | riastradh <riastradh@NetBSD.org> | 2022-04-19 09:19:53 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2022-04-19 09:19:53 +0000 |
| commit | a6fe4e24ed8a82d57e164cf81125322b032e8a0d (patch) | |
| tree | 0d785721148e85c22c56b8d8e117316e6f1f7a5d /sys/dev/audio | |
| parent | fed82111aa6892d74da251df870379681e3ba36a (diff) | |
audio(4): Wait for opens to drain in detach.
Otherwise detach may barge ahead and start freeing things before open
has finished and is about to use them after free.
Reported-by: syzbot+31d2619e72c2c8436cc9@syzkaller.appspotmail.com
Diffstat (limited to 'sys/dev/audio')
| -rw-r--r-- | sys/dev/audio/audio.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/sys/dev/audio/audio.c b/sys/dev/audio/audio.c index 06aeec99070..625c5b63144 100644 --- a/sys/dev/audio/audio.c +++ b/sys/dev/audio/audio.c @@ -1,4 +1,4 @@ -/* $NetBSD: audio.c,v 1.123 2022/04/09 23:35:58 riastradh Exp $ */ +/* $NetBSD: audio.c,v 1.124 2022/04/19 09:19:53 riastradh Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -181,7 +181,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.123 2022/04/09 23:35:58 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.124 2022/04/19 09:19:53 riastradh Exp $"); #ifdef _KERNEL_OPT #include "audio.h" @@ -1344,6 +1344,7 @@ audiodetach(device_t self, int flags) { struct audio_softc *sc; struct audio_file *file; + int maj, mn; int error; sc = device_private(self); @@ -1359,6 +1360,16 @@ audiodetach(device_t self, int flags) return error; /* + * Prevent new opens and wait for existing opens to complete. + */ + maj = cdevsw_lookup_major(&audio_cdevsw); + mn = device_unit(self); + vdevgone(maj, mn|SOUND_DEVICE, mn|SOUND_DEVICE, VCHR); + vdevgone(maj, mn|AUDIO_DEVICE, mn|AUDIO_DEVICE, VCHR); + vdevgone(maj, mn|AUDIOCTL_DEVICE, mn|AUDIOCTL_DEVICE, VCHR); + vdevgone(maj, mn|MIXER_DEVICE, mn|MIXER_DEVICE, VCHR); + + /* * This waits currently running sysctls to finish if exists. * After this, no more new sysctls will come. */ |
