From nobody@FreeBSD.org  Mon Aug 31 11:10:01 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 916E410656A6
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 31 Aug 2009 11:10:01 +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 7FB498FC2D
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 31 Aug 2009 11:10:01 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n7VBA1pn012200
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 31 Aug 2009 11:10:01 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n7VBA1Op012199;
	Mon, 31 Aug 2009 11:10:01 GMT
	(envelope-from nobody)
Message-Id: <200908311110.n7VBA1Op012199@www.freebsd.org>
Date: Mon, 31 Aug 2009 11:10:01 GMT
From: Patroklos Argyroudis <argp@census-labs.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: NULL pointer dereference in pcfclock_open() in file sys/dev/ppbus/pcfclock.c
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         138388
>Category:       kern
>Synopsis:       [ppbus] [patch] NULL pointer dereference in pcfclock_open() in file sys/dev/ppbus/pcfclock.c
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    brueffer
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 31 11:20:02 UTC 2009
>Closed-Date:    Mon Oct 10 20:15:24 CEST 2011
>Last-Modified:  Mon Oct 10 20:15:24 CEST 2011
>Originator:     Patroklos Argyroudis
>Release:        8.0-CURRENT
>Organization:
census, inc
>Environment:
N/A
>Description:
There is a NULL pointer dereference in pcfclock_open() in file sys/dev/ppbus/pcfclock.c at line 153.  The NULL check at line 157 should be before the dereference of sc at line 153.
>How-To-Repeat:
N/A
>Fix:
Patch attached.

Patch attached with submission follows:

--- ./sys/dev/ppbus/pcfclock.c.orig	2009-08-28 16:24:15.000000000 +0300
+++ ./sys/dev/ppbus/pcfclock.c	2009-08-28 16:25:34.000000000 +0300
@@ -150,13 +150,16 @@
 pcfclock_open(struct cdev *dev, int flag, int fms, struct thread *td)
 {
 	struct pcfclock_data *sc = dev->si_drv1;
-	device_t pcfclockdev = sc->dev;
-	device_t ppbus = device_get_parent(pcfclockdev);
+	device_t pcfclockdev;
+	device_t ppbus;
 	int res;
 
 	if (!sc)
 		return (ENXIO);
 
+	pcfclockdev = sc->dev;
+	ppbus = device_get_parent(pcfclockdev);
+
 	ppb_lock(ppbus);
 	res = ppb_request_bus(ppbus, pcfclockdev,
 	    (flag & O_NONBLOCK) ? PPB_DONTWAIT : PPB_WAIT);


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: brueffer 
State-Changed-When: Thu Oct 22 08:52:06 CEST 2009 
State-Changed-Why:  
Committed, thanks! 


Responsible-Changed-From-To: freebsd-bugs->brueffer 
Responsible-Changed-By: brueffer 
Responsible-Changed-When: Thu Oct 22 08:52:06 CEST 2009 
Responsible-Changed-Why:  
MFC reminder. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/138388: commit references a PR
Date: Thu, 22 Oct 2009 06:51:41 +0000 (UTC)

 Author: brueffer
 Date: Thu Oct 22 06:51:29 2009
 New Revision: 198358
 URL: http://svn.freebsd.org/changeset/base/198358
 
 Log:
   Check pointer for NULL before dereferencing it, not after.
   
   PR:		138387, 138388
   Submitted by:	Patroklos Argyroudis <argp@census-labs.com>
   MFC after:	1 week
 
 Modified:
   head/sys/dev/ppbus/lpt.c
   head/sys/dev/ppbus/pcfclock.c
 
 Modified: head/sys/dev/ppbus/lpt.c
 ==============================================================================
 --- head/sys/dev/ppbus/lpt.c	Thu Oct 22 06:17:04 2009	(r198357)
 +++ head/sys/dev/ppbus/lpt.c	Thu Oct 22 06:51:29 2009	(r198358)
 @@ -486,12 +486,15 @@ lptopen(struct cdev *dev, int flags, int
  {
  	int trys, err;
  	struct lpt_data *sc = dev->si_drv1;
 -	device_t lptdev = sc->sc_dev;
 -	device_t ppbus = device_get_parent(lptdev);
 +	device_t lptdev;
 +	device_t ppbus;
  
  	if (!sc)
  		return (ENXIO);
  
 +	lptdev = sc->sc_dev;
 +	ppbus = device_get_parent(lptdev);
 +
  	ppb_lock(ppbus);
  	if (sc->sc_state) {
  		lprintf(("%s: still open %x\n", device_get_nameunit(lptdev),
 
 Modified: head/sys/dev/ppbus/pcfclock.c
 ==============================================================================
 --- head/sys/dev/ppbus/pcfclock.c	Thu Oct 22 06:17:04 2009	(r198357)
 +++ head/sys/dev/ppbus/pcfclock.c	Thu Oct 22 06:51:29 2009	(r198358)
 @@ -150,12 +150,14 @@ static int
  pcfclock_open(struct cdev *dev, int flag, int fms, struct thread *td)
  {
  	struct pcfclock_data *sc = dev->si_drv1;
 -	device_t pcfclockdev = sc->dev;
 -	device_t ppbus = device_get_parent(pcfclockdev);
 +	device_t pcfclockdev;
 +	device_t ppbus;
  	int res;
  
  	if (!sc)
  		return (ENXIO);
 +	pcfclockdev = sc->dev;
 +	ppbus = device_get_parent(pcfclockdev);
  
  	ppb_lock(ppbus);
  	res = ppb_request_bus(ppbus, pcfclockdev,
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: brueffer 
State-Changed-When: Mon Oct 10 20:14:54 CEST 2011 
State-Changed-Why:  
MFC done. Sorry for the long delay! 

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