Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/audio audio(4): Grab sc->sc_cred under sc->sc_lock b...



details:   https://anonhg.NetBSD.org/src/rev/ac58b3ac27fd
branches:  trunk
changeset: 1021497:ac58b3ac27fd
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Jun 01 21:14:52 2021 +0000

description:
audio(4): Grab sc->sc_cred under sc->sc_lock before freeing.

Otherwise we may race with open, leaking a cred no longer in use and
freeing a cred still in use.

diffstat:

 sys/dev/audio/audio.c |  11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diffs (42 lines):

diff -r 10b8d2239ac3 -r ac58b3ac27fd sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Tue Jun 01 21:12:47 2021 +0000
+++ b/sys/dev/audio/audio.c     Tue Jun 01 21:14:52 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.98 2021/06/01 21:12:47 riastradh Exp $     */
+/*     $NetBSD: audio.c,v 1.99 2021/06/01 21:14:52 riastradh Exp $     */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.98 2021/06/01 21:12:47 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.99 2021/06/01 21:14:52 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2584,6 +2584,7 @@
 int
 audio_unlink(struct audio_softc *sc, audio_file_t *file)
 {
+       kauth_cred_t cred = NULL;
        int error;
 
        mutex_enter(sc->sc_lock);
@@ -2655,11 +2656,13 @@
                        sc->hw_if->close(sc->hw_hdl);
                        mutex_exit(sc->sc_intr_lock);
                }
+               cred = sc->sc_cred;
+               sc->sc_cred = NULL;
        }
 
        mutex_exit(sc->sc_lock);
-       if (sc->sc_popens + sc->sc_ropens == 0)
-               kauth_cred_free(sc->sc_cred);
+       if (cred)
+               kauth_cred_free(cred);
 
        TRACE(3, "done");
 



Home | Main Index | Thread Index | Old Index