From nobody@FreeBSD.org  Wed Oct 13 19:51:52 2010
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 56C1E106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Oct 2010 19:51:52 +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 45E078FC1B
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Oct 2010 19:51:52 +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 o9DJpqUH045649
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Oct 2010 19:51:52 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o9DJpp4p045647;
	Wed, 13 Oct 2010 19:51:51 GMT
	(envelope-from nobody)
Message-Id: <201010131951.o9DJpp4p045647@www.freebsd.org>
Date: Wed, 13 Oct 2010 19:51:51 GMT
From: Andrew Boyer <aboyer@averesystems.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Reference leak in ip_dooptions()
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         151435
>Category:       kern
>Synopsis:       Reference leak in ip_dooptions()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bz
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 13 20:00:18 UTC 2010
>Closed-Date:    Sun Oct 17 08:47:31 UTC 2010
>Last-Modified:  Sun Oct 17 08:50:10 UTC 2010
>Originator:     Andrew Boyer
>Release:        head
>Organization:
Avere Systems
>Environment:
N/A
>Description:
SVN 194760 changed ifa_ifwithaddr() so that it returns a reference along with the ifa.  ifa_ifwithaddr_check() was added to simplify things for callers who didn't want to deal with a reference.

On line 344 of sys/netinet/ip_options.c, there's a call to ifa_ifwithaddr() that does not store a return value.  It looks like it should have been converted to ifa_ifwithaddr_check().

This is only an issue if packets with IPOPT_TS_PRESPEC set are received, so it's not likely been a problem for anyone.
>How-To-Repeat:
Unknown - found by code review.
>Fix:
--- sys/netinet/ip_options.c
+++ sys/netinet/ip_options.c
@@ -341,7 +341,7 @@ dropit:
                                }
                                (void)memcpy(&ipaddr.sin_addr, sin,
                                    sizeof(struct in_addr));
-                               if (ifa_ifwithaddr((SA)&ipaddr) == NULL)
+                               if (ifa_ifwithaddr_check((SA)&ipaddr) == 0)
                                        continue;
                                cp[IPOPT_OFFSET] += sizeof(struct in_addr);
                                off += sizeof(struct in_addr);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->bz 
Responsible-Changed-By: bz 
Responsible-Changed-When: Thu Oct 14 10:21:08 UTC 2010 
Responsible-Changed-Why:  
Take; will commit the fix later today; seems to be right. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=151435 
State-Changed-From-To: open->patched 
State-Changed-By: bz 
State-Changed-When: Thu Oct 14 12:33:04 UTC 2010 
State-Changed-Why:  
Comitted to HEAD, MFC in a couple of days. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/151435: commit references a PR
Date: Thu, 14 Oct 2010 12:32:56 +0000 (UTC)

 Author: bz
 Date: Thu Oct 14 12:32:49 2010
 New Revision: 213832
 URL: http://svn.freebsd.org/changeset/base/213832
 
 Log:
   Use ifa_ifwithaddr_check() rather than ifa_ifwithaddr() as we are not
   interested in the result and would leak a reference otherwise.
   
   PR:		kern/151435
   Submitted by:	Andrew Boyer (aboyer averesystems.com)
   MFC after:	3 days
 
 Modified:
   head/sys/netinet/ip_options.c
 
 Modified: head/sys/netinet/ip_options.c
 ==============================================================================
 --- head/sys/netinet/ip_options.c	Thu Oct 14 11:20:23 2010	(r213831)
 +++ head/sys/netinet/ip_options.c	Thu Oct 14 12:32:49 2010	(r213832)
 @@ -341,7 +341,7 @@ dropit:
  				}
  				(void)memcpy(&ipaddr.sin_addr, sin,
  				    sizeof(struct in_addr));
 -				if (ifa_ifwithaddr((SA)&ipaddr) == NULL)
 +				if (ifa_ifwithaddr_check((SA)&ipaddr) == 0)
  					continue;
  				cp[IPOPT_OFFSET] += sizeof(struct in_addr);
  				off += sizeof(struct in_addr);
 _______________________________________________
 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: bz 
State-Changed-When: Sun Oct 17 08:46:54 UTC 2010 
State-Changed-Why:  
The change has been merged to stable/8. 
Thanks a lot for reporting the problem along with the patch. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/151435: commit references a PR
Date: Sun, 17 Oct 2010 08:46:40 +0000 (UTC)

 Author: bz
 Date: Sun Oct 17 08:46:34 2010
 New Revision: 213947
 URL: http://svn.freebsd.org/changeset/base/213947
 
 Log:
   MFC r213832:
   
     Use ifa_ifwithaddr_check() rather than ifa_ifwithaddr() as we are not
     interested in the result and would leak a reference otherwise.
   
   PR:		kern/151435
   Submitted by:	Andrew Boyer (aboyer averesystems.com)
 
 Modified:
   stable/8/sys/netinet/ip_options.c
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/amd64/include/xen/   (props changed)
   stable/8/sys/cddl/contrib/opensolaris/   (props changed)
   stable/8/sys/contrib/dev/acpica/   (props changed)
   stable/8/sys/contrib/pf/   (props changed)
   stable/8/sys/dev/xen/xenpci/   (props changed)
 
 Modified: stable/8/sys/netinet/ip_options.c
 ==============================================================================
 --- stable/8/sys/netinet/ip_options.c	Sun Oct 17 08:44:34 2010	(r213946)
 +++ stable/8/sys/netinet/ip_options.c	Sun Oct 17 08:46:34 2010	(r213947)
 @@ -343,7 +343,7 @@ dropit:
  				}
  				(void)memcpy(&ipaddr.sin_addr, sin,
  				    sizeof(struct in_addr));
 -				if (ifa_ifwithaddr((SA)&ipaddr) == NULL)
 +				if (ifa_ifwithaddr_check((SA)&ipaddr) == 0)
  					continue;
  				cp[IPOPT_OFFSET] += sizeof(struct in_addr);
  				off += sizeof(struct in_addr);
 _______________________________________________
 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"
 
>Unformatted:
