From nobody@FreeBSD.org  Tue Jan 18 14:38:41 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 0E7D016A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Jan 2005 14:38:41 +0000 (GMT)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id CC00143D48
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Jan 2005 14:38:40 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j0IEce0m023352
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Jan 2005 14:38:40 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j0IEceum023351;
	Tue, 18 Jan 2005 14:38:40 GMT
	(envelope-from nobody)
Message-Id: <200501181438.j0IEceum023351@www.freebsd.org>
Date: Tue, 18 Jan 2005 14:38:40 GMT
From: Eugene Stark <stark@cs.sunysb.edu>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Null pointer dereference in net/bpf.c
X-Send-Pr-Version: www-2.3

>Number:         76410
>Category:       kern
>Synopsis:       [bpf] [patch] Null pointer dereference in net/bpf.c
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 18 14:40:27 GMT 2005
>Closed-Date:    Fri Apr 14 10:40:30 GMT 2006
>Last-Modified:  Fri Apr 14 10:40:30 GMT 2006
>Originator:     Eugene Stark
>Release:        4.10-RELEASE
>Organization:
SUNY at Stony Brook
>Environment:
FreeBSD laptop.starkhome.cs.sunysb.edu 4.10-RELEASE-p4 FreeBSD 4.10-RELEASE-p4 #1: Mon Jan 17 17:51:38 EST 2005     gene@laptop.starkhome.cs.sunysb.edu:/A/src/sys/compile/LAPTOP  i386

>Description:
      After applying the patch I proposed in PR-76207 for a null pointer
dereference in pci/if_xl.c, I found that it exposed a different bug in
net/bpf.c.  Specifically, if a call is made to bpfdetach() when no
devices have been successfully attached and consequently bpf_iflist
is NULL, then it is possible to exit the first loop in bpfdetach() with
bp == NULL, thus causing a NULL pointer dereference in the next statement.

It appears from the comments that the author wished to defend against
the case in which an attempt was made to detach a device that had never
successfully been attached.  However, the code does not properly handle
the situation in which this occurs when there are no other devices that
had been attached.
>How-To-Repeat:
      This occurred after applying the patch I suggest to pci/if_xl.c
in PR-76207.  Although that patch avoided a crash in the xl driver proper,
the next time I saw the error it ended up taking a null pointer dereference in bpfdetach().  So to repeat the problem, one would have to
attempt to bpfdetach() a device that has not been bpfattach()ed, in a
situation in which no other devices are attached to BPF.  The xl driver
will expose this problem under certain conditions.
>Fix:
      I have applied the following patch to net/bpf.c:

*** bpf.c.orig	Wed Dec  1 08:14:54 2004
--- bpf.c	Mon Jan 17 17:51:12 2005
***************
*** 1440,1446 ****
  	}
  
  	/* Interface wasn't attached */
! 	if (bp->bif_ifp == NULL) {
  		splx(s);
  		printf("bpfdetach: %s%d was not attached\n", ifp->if_name,
  		    ifp->if_unit);
--- 1440,1446 ----
  	}
  
  	/* Interface wasn't attached */
! 	if (bp == NULL || bp->bif_ifp == NULL) {
  		splx(s);
  		printf("bpfdetach: %s%d was not attached\n", ifp->if_name,
  		    ifp->if_unit);

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: maxim 
State-Changed-When: Fri Apr 14 10:39:06 UTC 2006 
State-Changed-Why:  
The issue was fixed in HEAD three years ago.  I've just MFC'ed 
the patch to RELENG_4.  Thanks for the submission! 

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