From nobody@FreeBSD.org  Fri May 20 12:33:35 2011
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 F27E2106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 20 May 2011 12:33:35 +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 E1E5F8FC16
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 20 May 2011 12:33:35 +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 p4KCXZDq068380
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 20 May 2011 12:33:35 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p4KCXZ1R068374;
	Fri, 20 May 2011 12:33:35 GMT
	(envelope-from nobody)
Message-Id: <201105201233.p4KCXZ1R068374@red.freebsd.org>
Date: Fri, 20 May 2011 12:33:35 GMT
From: Dmitrij Tejblum <tejblum@yandex-team.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] locking error in rip6_input() (sys/netinet6/raw_ip6.c)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         157209
>Category:       kern
>Synopsis:       [ip6] [patch] locking error in rip6_input() (sys/netinet6/raw_ip6.c)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    ae
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 20 12:40:10 UTC 2011
>Closed-Date:    Sun Jun 09 04:34:10 UTC 2013
>Last-Modified:  Sun Jun 09 04:34:10 UTC 2013
>Originator:     Dmitrij Tejblum
>Release:        8.2-STABLE
>Organization:
Yandex
>Environment:
>Description:
On a failure path in rip6_input(), the PCB is unlocked before the lock is taken.
>How-To-Repeat:

>Fix:
A possible quick patch is attached; anothe quick possibility would be to remove the unlock.

Patch attached with submission follows:

--- sys/netinet6/raw_ip6.c	2010-08-31 19:52:12.000000000 +0400
+++ sys/netinet6/raw_ip6.c	2011-05-14 00:27:24.000000000 +0400
@@ -193,20 +193,20 @@
 			if (!IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) &&
 			    prison_check_ip6(in6p->inp_cred,
 			    &ip6->ip6_dst) != 0)
 				continue;
 		}
+		INP_RLOCK(in6p);
 		if (in6p->in6p_cksum != -1) {
 			V_rip6stat.rip6s_isum++;
 			if (in6_cksum(m, proto, *offp,
 			    m->m_pkthdr.len - *offp)) {
 				INP_RUNLOCK(in6p);
 				V_rip6stat.rip6s_badsum++;
 				continue;
 			}
 		}
-		INP_RLOCK(in6p);
 		/*
 		 * If this raw socket has multicast state, and we
 		 * have received a multicast, check if this socket
 		 * should receive it, as multicast filtering is now
 		 * the responsibility of the transport layer.


>Release-Note:
>Audit-Trail:

From: Gleb Smirnoff <glebius@FreeBSD.org>
To: Dmitrij Tejblum <tejblum@yandex-team.ru>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: kern/157209: [patch] locking error in rip6_input()
 (sys/netinet6/raw_ip6.c)
Date: Fri, 20 May 2011 17:34:35 +0400

   Dmitrij,
 
 On Fri, May 20, 2011 at 12:33:35PM +0000, Dmitrij Tejblum wrote:
 D> >Fix:
 D> A possible quick patch is attached; anothe quick possibility would be to remove the unlock.
 
 I think deleting INP_RUNLOCK would be more clean in the current code,
 because in6p_cksum isn't actually protected by INP_RLOCK in the function
 where it is written, the ip6_raw_ctloutput().
 
 However, in_pcb.h says that in6p_cksum should be protected by inp lock.
 So may be a thorough fix would be your patch + adding locking to the
 ip6_raw_ctloutput().
 
 D> Patch attached with submission follows:
 D> 
 D> --- sys/netinet6/raw_ip6.c	2010-08-31 19:52:12.000000000 +0400
 D> +++ sys/netinet6/raw_ip6.c	2011-05-14 00:27:24.000000000 +0400
 D> @@ -193,20 +193,20 @@
 D>  			if (!IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) &&
 D>  			    prison_check_ip6(in6p->inp_cred,
 D>  			    &ip6->ip6_dst) != 0)
 D>  				continue;
 D>  		}
 D> +		INP_RLOCK(in6p);
 D>  		if (in6p->in6p_cksum != -1) {
 D>  			V_rip6stat.rip6s_isum++;
 D>  			if (in6_cksum(m, proto, *offp,
 D>  			    m->m_pkthdr.len - *offp)) {
 D>  				INP_RUNLOCK(in6p);
 D>  				V_rip6stat.rip6s_badsum++;
 D>  				continue;
 D>  			}
 D>  		}
 D> -		INP_RLOCK(in6p);
 D>  		/*
 D>  		 * If this raw socket has multicast state, and we
 D>  		 * have received a multicast, check if this socket
 D>  		 * should receive it, as multicast filtering is now
 D>  		 * the responsibility of the transport layer.
 D> 
 D> 
 
 -- 
 Totus tuus, Glebius.
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat May 21 22:48:21 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=157209 
State-Changed-From-To: open->closed 
State-Changed-By: ae 
State-Changed-When: Sun Jun 9 04:31:46 UTC 2013 
State-Changed-Why:  
This was fixed in r248180 and merged to stable/9, stable/8. 


Responsible-Changed-From-To: freebsd-net->ae 
Responsible-Changed-By: ae 
Responsible-Changed-When: Sun Jun 9 04:31:46 UTC 2013 
Responsible-Changed-Why:  
Take. 

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