From nobody@FreeBSD.ORG Wed Sep 8 04:58:06 1999 Return-Path: Received: by hub.freebsd.org (Postfix, from userid 32767) id 85ED214D07; Wed, 8 Sep 1999 04:58:04 -0700 (PDT) Message-Id: <19990908115804.85ED214D07@hub.freebsd.org> Date: Wed, 8 Sep 1999 04:58:04 -0700 (PDT) From: david@inty.net Sender: nobody@FreeBSD.ORG To: freebsd-gnats-submit@freebsd.org Subject: incorrect handling of TCP reset connection in libalias X-Send-Pr-Version: www-1.0 >Number: 13639 >Category: bin >Synopsis: incorrect handling of TCP reset connection in libalias >Confidential: no >Severity: non-critical >Priority: low >Responsible: ru >State: closed >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Sep 8 05:00:01 PDT 1999 >Closed-Date: Sun Sep 12 09:09:55 PDT 1999 >Last-Modified: Sun Sep 12 09:10:33 PDT 1999 >Originator: David Hedley >Release: 3.2 >Organization: INTY >Environment: FreeBSD server.inty.net 3.2-RELEASE FreeBSD 3.2-RELEASE #1: Thu Jul 22 15:18:40 BST 1999 david@server.inty.net:/usr/src/sys/compile/GENERIC+MODS i386 >Description: If an incoming connection is initiated through natd and deny_incoming is not set, then a new alias_link structure is created to handle the link. If there is nothing listening for the incoming connection, then the kernel responds with a RST for the connection. However, this is not processed correctly in libalias/alias.c:TcpMonitor{In,Out} and libalias/alias_db.c:SetState{In,Out} as it thinks a connection has been established and therefore applies a timeout of 86400 seconds to the link. If many of these half-connections are initiated (during, for example, a port scan of the host), then many thousands of unnecessary links are created and the resident size of natd balloons to 20MB or more. >How-To-Repeat: Run natd without deny_incoming. Run a TCP port scanner against the machine. >Fix: The following patch will tell libalias to realise that a connection hasn't, in fact, been completed and thus will give the newly created link a timeout of TCP_EXPIRE_DEAD: *** /usr/src/lib/libalias/alias.c Wed Mar 24 17:12:00 1999 --- libalias/alias.c Wed Jul 28 10:58:32 1999 *************** *** 139,144 **** --- 139,148 ---- case ALIAS_TCP_STATE_NOT_CONNECTED: if (tc->th_flags & TH_SYN) SetStateIn(link, ALIAS_TCP_STATE_CONNECTED); + if (tc->th_flags & TH_RST) { + SetStateIn(link, ALIAS_TCP_STATE_DISCONNECTED); + SetStateOut(link, ALIAS_TCP_STATE_DISCONNECTED); + } break; case ALIAS_TCP_STATE_CONNECTED: if (tc->th_flags & TH_FIN *************** *** 160,165 **** --- 164,173 ---- case ALIAS_TCP_STATE_NOT_CONNECTED: if (tc->th_flags & TH_SYN) SetStateOut(link, ALIAS_TCP_STATE_CONNECTED); + if (tc->th_flags & TH_RST) { + SetStateIn(link, ALIAS_TCP_STATE_DISCONNECTED); + SetStateOut(link, ALIAS_TCP_STATE_DISCONNECTED); + } break; case ALIAS_TCP_STATE_CONNECTED: if (tc->th_flags & TH_FIN >Release-Note: >Audit-Trail: Responsible-Changed-From-To: freebsd-bugs->ru Responsible-Changed-By: sheldonh Responsible-Changed-When: Wed Sep 8 06:25:00 PDT 1999 Responsible-Changed-Why: Over to the natd maintainer. From: Ruslan Ermilov To: freebsd-gnats-submit@freebsd.org, david@inty.net Cc: Subject: Re: bin/13639: incorrect handling of TCP reset connection in libalias Date: Wed, 8 Sep 1999 18:53:24 +0300 --OXfL5xGRrasGEqWY Content-Type: text/plain; charset=us-ascii Hi, David! What do you think of the following trivial patch? -- Ruslan Ermilov Sysadmin and DBA of the ru@ucb.crimea.ua United Commercial Bank, ru@FreeBSD.org FreeBSD committer, +380.652.247.647 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age --OXfL5xGRrasGEqWY Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=p Index: alias.c =================================================================== RCS file: /usr/FreeBSD-CVS/src/lib/libalias/alias.c,v retrieving revision 1.14 diff -u -r1.14 alias.c --- alias.c 1999/08/29 23:17:02 1.14 +++ alias.c 1999/09/08 15:29:19 @@ -142,7 +142,6 @@ case ALIAS_TCP_STATE_NOT_CONNECTED: if (tc->th_flags & TH_SYN) SetStateIn(link, ALIAS_TCP_STATE_CONNECTED); - break; case ALIAS_TCP_STATE_CONNECTED: if (tc->th_flags & TH_FIN || tc->th_flags & TH_RST) @@ -163,7 +162,6 @@ case ALIAS_TCP_STATE_NOT_CONNECTED: if (tc->th_flags & TH_SYN) SetStateOut(link, ALIAS_TCP_STATE_CONNECTED); - break; case ALIAS_TCP_STATE_CONNECTED: if (tc->th_flags & TH_FIN || tc->th_flags & TH_RST) --OXfL5xGRrasGEqWY-- State-Changed-From-To: open->closed State-Changed-By: ru State-Changed-When: Sun Sep 12 09:09:55 PDT 1999 State-Changed-Why: Fixed in both -stable and -current. Thanks for the report! >Unformatted: