From nobody@FreeBSD.org  Sun Aug 18 11:30:37 2002
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 7879437B400
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 18 Aug 2002 11:30:37 -0700 (PDT)
Received: from www.freebsd.org (www.FreeBSD.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 387F443E6A
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 18 Aug 2002 11:30:37 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.4/8.12.4) with ESMTP id g7IIUaOT005470
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 18 Aug 2002 11:30:36 -0700 (PDT)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.4/8.12.4/Submit) id g7IIUaas005469;
	Sun, 18 Aug 2002 11:30:36 -0700 (PDT)
Message-Id: <200208181830.g7IIUaas005469@www.freebsd.org>
Date: Sun, 18 Aug 2002 11:30:36 -0700 (PDT)
From: "George V. Neville-Neil" <gnn@neville-neil.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: UDP socket remains connected after error
X-Send-Pr-Version: www-1.0

>Number:         41765
>Category:       kern
>Synopsis:       UDP socket remains connected after error
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bms
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 18 11:40:01 PDT 2002
>Closed-Date:    Sun Jul 31 12:18:26 GMT 2005
>Last-Modified:  Sun Jul 31 12:18:26 GMT 2005
>Originator:     George V. Neville-Neil
>Release:        4.6-STABLE and -CURRENT
>Organization:
Neville-Neil Consulting
>Environment:
FreeBSD jchurch.neville-neil.com 4.6-STABLE FreeBSD 4.6-STABLE #4: Sat Jul 13 18:54:53 PDT 2002     root@jchurch.neville-neil.com:/usr/local/src-STABLE/src/sys/compile/JCHURCH  i386
>Description:
In udp_usrreq.c:udp_output() a UDP socket is temporarily connected to transmit the packet.  If an out of mbufs error occurs the socket is never disconnected.

>How-To-Repeat:
Write a lot of UDP packets while using up a lot of mbufs (this occurs in a piece
of propietary software written where I'm working).

>Fix:
This patch from Jinmei Tatuya (against 4.6 but a similar solution is
necessary in -CURRENT):


--- udp_usrreq.c.orig	Tue Aug 13 13:49:50 2002
+++ udp_usrreq.c	Tue Aug 13 13:52:34 2002
@@ -704,9 +704,7 @@
 	M_PREPEND(m, sizeof(struct udpiphdr), M_DONTWAIT);
 	if (m == 0) {
 		error = ENOBUFS;
-		if (addr)
-			splx(s);
-		goto release;
+		goto disconnect;
 	}
 
 	/*
@@ -741,7 +739,7 @@
 #ifdef IPSEC
 	if (ipsec_setsocket(m, inp->inp_socket) != 0) {
 		error = ENOBUFS;
-		goto release;
+		goto disconnect;
 	}
 #endif /*IPSEC*/
 	error = ip_output(m, inp->inp_options, &inp->inp_route,
@@ -754,6 +752,13 @@
 		splx(s);
 	}
 	return (error);
+
+disconnect:
+	if (addr) {
+		in_pcbdisconnect(inp);
+		inp->inp_laddr = laddr;	/* XXX rehash? */
+		splx(s);
+	}
 
 release:
 	m_freem(m);

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: njl 
State-Changed-When: Wed Aug 21 17:45:38 PDT 2002 
State-Changed-Why:  
Looked over the patch and it seems like a good fit for current and stable. 
Fix is to disconnect the socket once it is connected successfully even if 
we later err out. 


Responsible-Changed-From-To: freebsd-bugs->rwatson 
Responsible-Changed-By: njl 
Responsible-Changed-When: Wed Aug 21 17:45:38 PDT 2002 
Responsible-Changed-Why:  
rwatson has been in this file most recently; perhaps he will commit the fix 

http://www.freebsd.org/cgi/query-pr.cgi?pr=41765 
Responsible-Changed-From-To: rwatson->bms 
Responsible-Changed-By: rwatson 
Responsible-Changed-When: Sun May 2 14:58:47 PDT 2004 
Responsible-Changed-Why:  
Change owner to bms, as he's willing to take a look.  At first glance, 
this looks like a reasonable problem description; we'll need to make 
sure to submit a version with working locking to the rwatson_netperf 
branch to match the version committed to the tree. 


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

From: Bruce M Simpson <bms@spc.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc: gnn@neville-neil.com
Subject: Re: kern/41765: UDP socket remains connected after error
Date: Wed, 16 Jun 2004 04:51:09 +0100

 Original author: Jinmei Tatuya
 
 I've revised the patch for -CURRENT slightly, testing.
 
 Key points:
  - INP_LOCK() already held in udp_output(). Therefore locking should be fine.
  - Inlining in_pcbdisconnect() operations buys us nothing, as laddr
    is not part of the inpcb hash or the udbinfo hash. Therefore there
    should be no need to rehash after restoring laddr.
  - Temporary bind/connect should probably be deleted in future
    as an optimization, as described in "A Faster UDP" [Partridge/Pink 1993].
    - It only exists so as to retrieve some necessary information about
      the source and destination from the socket, and create a route, etc.
    - ip_output() gets called with NULL for the route argument anyway.
State-Changed-From-To: analyzed->patched 
State-Changed-By: bms 
State-Changed-When: Wed Jun 16 05:41:10 GMT 2004 
State-Changed-Why:  
Committed to HEAD, thanks! 

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

From: Bruce M Simpson <bms@spc.org>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: kern/41765: UDP socket remains connected after error
Date: Wed, 16 Jun 2004 14:16:21 +0100

 Actually iedowse@ reported that this is fixed by design in -CURRENT
 so I've backed out the patch; this should probably be applied to -STABLE,
 however. -CURRENT does not actually connect/bind the socket, it calls
 the inpcb_*_setup functions which perform the required initialization.

From: Matteo Riondato <rionda@gufi.org>
To: freebsd-gnats-submit@freebsd.org
Cc: bms@FreeBSD.org
Subject: Re: kern/41765: UDP socket remains connected after error
Date: Wed, 13 Apr 2005 13:13:35 +0200

 After a fast code read, I think this problem is still present in
 RELENG_4. OTOH, sys/netinet/udp_usrreq.c doesn't get modified in
 RELENG_4 since 19 months, so perhaps fix the problem in RELENG_4 is
 not a primary interest. If so, this PR can be closed.
 Thank you.
 Best Regards
 -- 
 Rionda aka Matteo Riondato
 Disinformato per default
 G.U.F.I. Staff Member (http://www.gufi.org)
 FreeSBIE Developer (http://www.freesbie.org)
State-Changed-From-To: patched->closed 
State-Changed-By: matteo 
State-Changed-When: Sun Jul 31 12:18:05 GMT 2005 
State-Changed-Why:  
Fixed but won't be MFC'ed to RELENG_4 

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