Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Dec 2012 12:48:58 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r244184 - head/sys/netpfil/pf
Message-ID:  <201212131248.qBDCmw26034917@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Thu Dec 13 12:48:57 2012
New Revision: 244184
URL: http://svnweb.freebsd.org/changeset/base/244184

Log:
    Initialize state id prior to attaching state to key hash. Otherwise a
  race can happen, when pf_find_state() finds state via key hash, and locks
  id hash slot 0 instead of appropriate to state id slot.

Modified:
  head/sys/netpfil/pf/pf.c

Modified: head/sys/netpfil/pf/pf.c
==============================================================================
--- head/sys/netpfil/pf/pf.c	Thu Dec 13 11:11:15 2012	(r244183)
+++ head/sys/netpfil/pf/pf.c	Thu Dec 13 12:48:57 2012	(r244184)
@@ -1080,9 +1080,6 @@ pf_state_insert(struct pfi_kif *kif, str
 
 	s->kif = kif;
 
-	if (pf_state_key_attach(skw, sks, s))
-		return (-1);
-
 	if (s->id == 0 && s->creatorid == 0) {
 		/* XXX: should be atomic, but probability of collision low */
 		if ((s->id = V_pf_stateid[curcpu]++) == PFID_MAXID)
@@ -1092,6 +1089,9 @@ pf_state_insert(struct pfi_kif *kif, str
 		s->creatorid = V_pf_status.hostid;
 	}
 
+	if (pf_state_key_attach(skw, sks, s))
+		return (-1);
+
 	ih = &V_pf_idhash[PF_IDHASH(s)];
 	PF_HASHROW_LOCK(ih);
 	LIST_FOREACH(cur, &ih->states, entry)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212131248.qBDCmw26034917>