From nobody Sun Sep 10 20:40:34 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RkMDf4X8tz4sWNc; Sun, 10 Sep 2023 20:40:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RkMDf45lTz3gZ5; Sun, 10 Sep 2023 20:40:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694378434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+3kGFx+mPRJqbm0JoktleJJO+lKA6lq8LJMJtlb37+4=; b=P9Gcszkty9boGiFXq/Lg/4/tj7X5JdUj3xHIGFbdGtrkLLad67EUZ8DhEMf3PYSybq37UX EC8v/j1ouJQJ02NNE6jAnznr/vEG1Pvz9SHRgYH5M0FqKGsqGFLMs1d4UnoUgGGsefzLbM Wgr4K5UwUmzATf36gYFZTZcrT8HnWVIy8HST2G3+3cAnjlOvkrjc5tukPlq3RpBHJ4Pcu+ bBtiEC/Ue3U5is3pEzU29zE8Icd7I4mpWZ8sZ5Yeqj07o/PNFZDQ5mCkPNTjQdk6rP+iVG QG3ykt14gG9c/JRgajERvSUadkcrrDgb3YtWHjIugb0OD0XTfChf8jOp59DboQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694378434; a=rsa-sha256; cv=none; b=N89+FP4kqXHEM0///fGUWzeMXm9J+WO5RF6/YgzFZoBhWVicjNYB7ryxPhfJ8JE2jhU0YZ l40cqfAHtFLa1Rs1j/qGBdzplp+RPPXDGacFQ+pQckuqIjOOBnntMW7X/FlV43QE8lBJCD +Kiny/Fd2gxMqSV5rv51BERehlHLNE1wPhHqCzf3cDvvWthea7ec9C13v16owzPbE4cKJX smeLuJQbFeMh6J9WcjbYwTghBtYtgjMUjTWJ8t+dQCR7XxU48LjrssHTiWPIabGzk3OSbS qlMHxN9Q0UkmedsIEDr1IY8SZajopCKU9XIqAGROgPYDoNP8+5km3CpOvc4QMw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694378434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+3kGFx+mPRJqbm0JoktleJJO+lKA6lq8LJMJtlb37+4=; b=BpWFhKMUdKK2VQ/s3ARW6zrxsLJLmrwFiPS86mFsqSKnej3R+J2mTFgun7a6HGl6cnPMiq lOn/+TvHs7aYhdc1Ng6mcKJDqlfe0VQRjdFYLqUycLBAVWpafKl892YZTpgu3Gx+aKGaBC om08Ez7mvVrOT/pBJmK0R5sU2O/rkACTkqrVQGpDE9NzB/u/rihoccHQAHd0woOPx4gPjP iU7tH6hNGXsuUOgufelwNfbtjTaHdOspyi2qZSZq5DTOj0Warmo64TajzVK6de0zlr9Kkc 0YeRVZI+igbUiv1Zw4jMS1htBfPCNNhEcZ2Xn/ZpVQ9mbX9hh+EZWdDF3RSY3Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RkMDf399pz6CZ; Sun, 10 Sep 2023 20:40:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 38AKeYUb067302; Sun, 10 Sep 2023 20:40:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38AKeYjw067299; Sun, 10 Sep 2023 20:40:34 GMT (envelope-from git) Date: Sun, 10 Sep 2023 20:40:34 GMT Message-Id: <202309102040.38AKeYjw067299@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: b6ce41118bb1 - main - pf: fix state leak List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b6ce41118bb11d3db86eae8fbebc8c198e8b330d Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=b6ce41118bb11d3db86eae8fbebc8c198e8b330d commit b6ce41118bb11d3db86eae8fbebc8c198e8b330d Author: Kristof Provost AuthorDate: 2023-09-06 07:58:07 +0000 Commit: Kristof Provost CommitDate: 2023-09-10 20:40:22 +0000 pf: fix state leak If we hit the csfailed case in pf_create_state() we may have allocated a state, so we must also free it. While here reduce the amount of duplicated cleanup code. MFC after: 2 weeks Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D41772 --- sys/netpfil/pf/pf.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 21d2e16e83dc..df4bd47c35d5 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -4885,13 +4885,8 @@ pf_create_state(struct pf_krule *r, struct pf_krule *nr, struct pf_krule *a, if (r->rt) { /* pf_map_addr increases the reason counters */ if ((reason = pf_map_addr(pd->af, r, pd->src, &s->rt_addr, - &s->rt_kif, NULL, &sn)) != 0) { - pf_src_tree_remove_state(s); - s->timeout = PFTM_UNLINKED; - STATE_DEC_COUNTERS(s); - pf_free_state(s); + &s->rt_kif, NULL, &sn)) != 0) goto csfailed; - } s->rt = r->rt; } @@ -4947,11 +4942,7 @@ pf_create_state(struct pf_krule *r, struct pf_krule *nr, struct pf_krule *a, (pd->dir == PF_IN) ? sk : nk, (pd->dir == PF_IN) ? nk : sk, s)) { REASON_SET(&reason, PFRES_STATEINS); - pf_src_tree_remove_state(s); - s->timeout = PFTM_UNLINKED; - STATE_DEC_COUNTERS(s); - pf_free_state(s); - return (PF_DROP); + goto drop; } else *sm = s; @@ -5020,13 +5011,14 @@ csfailed: PF_SRC_NODE_UNLOCK(nsn); } - return (PF_DROP); - drop: - pf_src_tree_remove_state(s); - s->timeout = PFTM_UNLINKED; - STATE_DEC_COUNTERS(s); - pf_free_state(s); + if (s != NULL) { + pf_src_tree_remove_state(s); + s->timeout = PFTM_UNLINKED; + STATE_DEC_COUNTERS(s); + pf_free_state(s); + } + return (PF_DROP); }