From nobody@FreeBSD.org  Tue Feb 21 20:25:28 2012
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 7BCE0106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 21 Feb 2012 20:25:28 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 6BCFA8FC1A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 21 Feb 2012 20:25:28 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q1LKPSYA052390
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 21 Feb 2012 20:25:28 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q1LKPSno052389;
	Tue, 21 Feb 2012 20:25:28 GMT
	(envelope-from nobody)
Message-Id: <201202212025.q1LKPSno052389@red.freebsd.org>
Date: Tue, 21 Feb 2012 20:25:28 GMT
From: Arnaud Lacombe <lacombar@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Obvious use-after-free in ipfw_nat()
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         165373
>Category:       kern
>Synopsis:       [ipfw] Obvious use-after-free in ipfw_nat()
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ipfw
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 21 20:30:11 UTC 2012
>Closed-Date:    Sun Feb 26 10:22:37 UTC 2012
>Last-Modified:  Sun Feb 26 10:30:05 UTC 2012
>Originator:     Arnaud Lacombe
>Release:        10-current
>Organization:
n/a
>Environment:
>Description:
ipfw_nat() reads the following:

        mcl = m_megapullup(m, m->m_pkthdr.len);
        if (mcl == NULL) {
                args->m = NULL;
                return (IP_FW_DENY);
        }
        ip = mtod(mcl, struct ip *);
        [...]
        if (retval == PKT_ALIAS_RESPOND)
                m->m_flags |= M_SKIP_FIREWALL

It is quite obvious that `m' is no longer valid in the second conditional.

I reported this months ago on freebsd-net@ and did provide a patch to
fix it, but no developers seems to actually care about such a bug.
>How-To-Repeat:
read the code.
>Fix:
s/m/mcl/

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-ipfw 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Feb 22 03:43:51 UTC 2012 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165373 
State-Changed-From-To: open->patched 
State-Changed-By: ae 
State-Changed-When: Wed Feb 22 04:19:55 UTC 2012 
State-Changed-Why:  
Patched in head/. Thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/165373: commit references a PR
Date: Wed, 22 Feb 2012 04:19:46 +0000 (UTC)

 Author: ae
 Date: Wed Feb 22 04:19:33 2012
 New Revision: 231991
 URL: http://svn.freebsd.org/changeset/base/231991
 
 Log:
   Don't use `m' after m_megapullup.
   
   PR:		kern/165373
   MFC after:	3 days
 
 Modified:
   head/sys/netinet/ipfw/ip_fw_nat.c
 
 Modified: head/sys/netinet/ipfw/ip_fw_nat.c
 ==============================================================================
 --- head/sys/netinet/ipfw/ip_fw_nat.c	Wed Feb 22 03:36:15 2012	(r231990)
 +++ head/sys/netinet/ipfw/ip_fw_nat.c	Wed Feb 22 04:19:33 2012	(r231991)
 @@ -315,7 +315,7 @@ ipfw_nat(struct ip_fw_args *args, struct
  	}
  
  	if (retval == PKT_ALIAS_RESPOND)
 -		m->m_flags |= M_SKIP_FIREWALL;
 +		mcl->m_flags |= M_SKIP_FIREWALL;
  	mcl->m_pkthdr.len = mcl->m_len = ntohs(ip->ip_len);
  
  	/*
 _______________________________________________
 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: ae 
State-Changed-When: Sun Feb 26 10:22:10 UTC 2012 
State-Changed-Why:  
Merged to stable/8 and stable/9. Thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/165373: commit references a PR
Date: Sun, 26 Feb 2012 10:20:30 +0000 (UTC)

 Author: ae
 Date: Sun Feb 26 10:20:13 2012
 New Revision: 232171
 URL: http://svn.freebsd.org/changeset/base/232171
 
 Log:
   MFC r231991:
     Don't use `m' after m_megapullup.
   
     PR:		kern/165373
 
 Modified:
   stable/9/sys/netinet/ipfw/ip_fw_nat.c
 Directory Properties:
   stable/9/sys/   (props changed)
 
 Modified: stable/9/sys/netinet/ipfw/ip_fw_nat.c
 ==============================================================================
 --- stable/9/sys/netinet/ipfw/ip_fw_nat.c	Sun Feb 26 06:04:44 2012	(r232170)
 +++ stable/9/sys/netinet/ipfw/ip_fw_nat.c	Sun Feb 26 10:20:13 2012	(r232171)
 @@ -315,7 +315,7 @@ ipfw_nat(struct ip_fw_args *args, struct
  	}
  
  	if (retval == PKT_ALIAS_RESPOND)
 -		m->m_flags |= M_SKIP_FIREWALL;
 +		mcl->m_flags |= M_SKIP_FIREWALL;
  	mcl->m_pkthdr.len = mcl->m_len = ntohs(ip->ip_len);
  
  	/*
 _______________________________________________
 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"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/165373: commit references a PR
Date: Sun, 26 Feb 2012 10:21:04 +0000 (UTC)

 Author: ae
 Date: Sun Feb 26 10:20:55 2012
 New Revision: 232172
 URL: http://svn.freebsd.org/changeset/base/232172
 
 Log:
   MFC r231991:
     Don't use `m' after m_megapullup.
   
     PR:		kern/165373
   Approved by:	re (kib)
 
 Modified:
   stable/8/sys/netinet/ipfw/ip_fw_nat.c
 Directory Properties:
   stable/8/sys/   (props changed)
 
 Modified: stable/8/sys/netinet/ipfw/ip_fw_nat.c
 ==============================================================================
 --- stable/8/sys/netinet/ipfw/ip_fw_nat.c	Sun Feb 26 10:20:13 2012	(r232171)
 +++ stable/8/sys/netinet/ipfw/ip_fw_nat.c	Sun Feb 26 10:20:55 2012	(r232172)
 @@ -315,7 +315,7 @@ ipfw_nat(struct ip_fw_args *args, struct
  	}
  
  	if (retval == PKT_ALIAS_RESPOND)
 -		m->m_flags |= M_SKIP_FIREWALL;
 +		mcl->m_flags |= M_SKIP_FIREWALL;
  	mcl->m_pkthdr.len = mcl->m_len = ntohs(ip->ip_len);
  
  	/*
 _______________________________________________
 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:
