From owner-svn-src-projects@FreeBSD.ORG Tue Aug 28 12:19:14 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EA5561065676; Tue, 28 Aug 2012 12:19:14 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D59628FC1A; Tue, 28 Aug 2012 12:19:14 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q7SCJE3r066024; Tue, 28 Aug 2012 12:19:14 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q7SCJEug066022; Tue, 28 Aug 2012 12:19:14 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201208281219.q7SCJEug066022@svn.freebsd.org> From: Gleb Smirnoff Date: Tue, 28 Aug 2012 12:19:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r239773 - projects/pf/head/sys/contrib/pf/net X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Aug 2012 12:19:15 -0000 Author: glebius Date: Tue Aug 28 12:19:14 2012 New Revision: 239773 URL: http://svn.freebsd.org/changeset/base/239773 Log: Protection against race between pf_unlink_state() vs pf_unlink_state(). This may happen in a very rare case, when a forwarding thread creates a state, and encounters state with same key but with both sides in >= TCPS_FIN_WAIT_2. The old state is deleted then, and it can race with deletion by expiry thread. Modified: projects/pf/head/sys/contrib/pf/net/pf.c Modified: projects/pf/head/sys/contrib/pf/net/pf.c ============================================================================== --- projects/pf/head/sys/contrib/pf/net/pf.c Tue Aug 28 11:35:09 2012 (r239772) +++ projects/pf/head/sys/contrib/pf/net/pf.c Tue Aug 28 12:19:14 2012 (r239773) @@ -1503,6 +1503,18 @@ pf_unlink_state(struct pf_state *s, u_in else PF_HASHROW_ASSERT(ih); + if (s->timeout == PFTM_UNLINKED) { + /* + * State is being processed + * by pf_unlink_state() in + * an other thread. + */ + PF_HASHROW_UNLOCK(ih); + return (0); /* XXXGL: undefined actually */ + } + + s->timeout = PFTM_UNLINKED; + if (s->src.state == PF_TCPS_PROXY_DST) { /* XXX wire key the right one? */ pf_send_tcp(NULL, s->rule.ptr, s->key[PF_SK_WIRE]->af, @@ -1520,7 +1532,6 @@ pf_unlink_state(struct pf_state *s, u_in if (export_pflow_ptr != NULL) export_pflow_ptr(s); #endif - s->timeout = PFTM_UNLINKED; pf_src_tree_remove_state(s); PF_HASHROW_UNLOCK(ih);