From nobody@FreeBSD.org  Fri Jan  2 03:35:19 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id F37A11065670
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Jan 2009 03:35:18 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id E226A8FC1A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Jan 2009 03:35:18 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n023ZIBI076609
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 2 Jan 2009 03:35:18 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n023ZIb9076608;
	Fri, 2 Jan 2009 03:35:18 GMT
	(envelope-from nobody)
Message-Id: <200901020335.n023ZIb9076608@www.freebsd.org>
Date: Fri, 2 Jan 2009 03:35:18 GMT
From: Mateusz Guzik <mjguzik@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [devctl][patch] in devctl_queue_data(): possible use of bogus pointer to proc to send SIGIO
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         130107
>Category:       kern
>Synopsis:       [devctl] [patch] in devctl_queue_data(): possible use of bogus pointer to proc to send SIGIO
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 02 03:40:02 UTC 2009
>Closed-Date:    Fri Nov 02 22:18:17 UTC 2012
>Last-Modified:  Fri Nov 02 22:18:17 UTC 2012
>Originator:     Mateusz Guzik
>Release:        8.0-CURRENT
>Organization:
>Environment:
FreeBSD eternal 8.0-CURRENT FreeBSD 8.0-CURRENT #13: Fri Jan  2 04:49:43 CET 2009     root@:/usr/obj/usr/src/sys/ETERNAL  i386

>Description:
If devsoftc.async_proc is not NULL, devctl_queue_data() sends SIGIO to the process pointed by it. devctl's reader can use ioctl FIOASYNC to make this happen. But devsoftc.async_proc is not NULLed on close, so if the reader dies, devctl_queue_data() still sends SIGIO (but using bogus pointer).
>How-To-Repeat:

>Fix:
"devsoftc.async_proc = NULL;" at the beginning of devclose() fixes the problem. (perhaps similar line from devopen() can go away?)

Patch attached with submission follows:

--- sys/kern/subr_bus.c.orig	2008-11-18 22:01:54.000000000 +0100
+++ sys/kern/subr_bus.c	2009-01-02 04:34:09.000000000 +0100
@@ -416,6 +416,7 @@
 devclose(struct cdev *dev, int fflag, int devtype, d_thread_t *td)
 {
 	devsoftc.inuse = 0;
+	devsoftc.async_proc = NULL;
 	mtx_lock(&devsoftc.mtx);
 	cv_broadcast(&devsoftc.cv);
 	mtx_unlock(&devsoftc.mtx);


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: vwe 
State-Changed-When: Sun Jan 4 15:16:08 UTC 2009 
State-Changed-Why:  
issue sounds valid 


Responsible-Changed-From-To: freebsd-bugs->dfr 
Responsible-Changed-By: vwe 
Responsible-Changed-When: Sun Jan 4 15:16:08 UTC 2009 
Responsible-Changed-Why:  
Doug, can you please check this and decide which is the right way 
to solve this? IMO it can lead into trouble. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=130107 

From: vwe <volker@vwsoft.com>
To: bug-followup@FreeBSD.org, mjguzik@gmail.com
Cc:  
Subject: Re: kern/130107: [devctl][patch] in devctl_queue_data(): possible
	use of bogus pointer to proc to send SIGIO
Date: Sun, 04 Jan 2009 16:15:16 +0100

 --=-6Bwx+ZsA3NBJH7fzoB4r
 Content-Type: text/plain
 Content-Transfer-Encoding: 7bit
 
 Another approach is to check for a devd process in devctl_queue_data().
 Patch attached.
 
 --=-6Bwx+ZsA3NBJH7fzoB4r
 Content-Disposition: attachment; filename=subr_bus.c.diff
 Content-Type: text/x-patch; name=subr_bus.c.diff; charset=us-ascii
 Content-Transfer-Encoding: 7bit
 
 --- sys/kern/subr_bus.c.orig	2009-01-04 15:59:50.000000000 +0100
 +++ sys/kern/subr_bus.c	2009-01-04 16:01:35.000000000 +0100
 @@ -530,7 +530,7 @@
  	mtx_unlock(&devsoftc.mtx);
  	selwakeup(&devsoftc.sel);
  	p = devsoftc.async_proc;
 -	if (p != NULL) {
 +	if (p != NULL && devctl_process_running()) {
  		PROC_LOCK(p);
  		psignal(p, SIGIO);
  		PROC_UNLOCK(p);
 
 --=-6Bwx+ZsA3NBJH7fzoB4r--
 
State-Changed-From-To: analyzed->patched 
State-Changed-By: emaste 
State-Changed-When: Wed Sep 23 17:35:05 UTC 2009 
State-Changed-Why:  
Warner has fixed this on HEAD. 


Responsible-Changed-From-To: dfr->imp 
Responsible-Changed-By: emaste 
Responsible-Changed-When: Wed Sep 23 17:35:05 UTC 2009 
Responsible-Changed-Why:  
Warner has fixed this on HEAD. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=130107 
State-Changed-From-To: patched->closed 
State-Changed-By: mjg 
State-Changed-When: Fri Nov 2 22:18:16 UTC 2012 
State-Changed-Why:  
Fixed long time ago. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=130107 
>Unformatted:
