Index | Thread | Search

From:
Kirill A. Korinsky <kirill@korins.ky>
Subject:
Re: sys/uvideo: avoid using queue.h
To:
Vitaliy Makkoveev <mvs@openbsd.org>
Cc:
marcus@nazgul.ch, tech@openbsd.org
Date:
Fri, 21 Mar 2025 23:02:35 +0100

Download raw body.

Thread
On Fri, 21 Mar 2025 15:39:21 +0100,
Vitaliy Makkoveev <mvs@openbsd.org> wrote:
> 
> Concurrent videoopen() could be called during possible context switch
> provided by sc->hw_if->close(). At least uvideo_vs_close() has such
> points.
> 

Thanks to notice it. Here an updated diff which keeps sc_open at original
place, and shouldn't introduce race condition.

Index: sys/dev/video.c
===================================================================
RCS file: /home/cvs/src/sys/dev/video.c,v
diff -u -p -r1.60 video.c
--- sys/dev/video.c	21 Mar 2025 13:27:37 -0000	1.60
+++ sys/dev/video.c	21 Mar 2025 21:59:51 -0000
@@ -181,9 +181,15 @@ videoclose(dev_t dev, int flags, int fmt
 	if (sc == NULL)
 		return (ENXIO);
 
+	if (!sc->sc_open) {
+		error = ENXIO;
+		goto done;
+	}
+
 	error = video_stop(sc);
 	sc->sc_open = 0;
 
+done:
 	device_unref(&sc->dev);
 	return (error);
 }