From nobody Mon Sep 25 12:27:10 2023 X-Original-To: dev-commits-src-all@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 4RvMZQ74nmz4rGjn; Mon, 25 Sep 2023 12:27:10 +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 4RvMZQ6N01z4DfK; Mon, 25 Sep 2023 12:27:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695644830; 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=/5W4nFLdXzyOcI04+OR6c+5fqvkYxieRSo0Vfpf180A=; b=pqNg1GVqGyw3A3tp5JphH815ni+xAGGusil1tupgoVHaPM3wSRHVhWCwYwtZ3rwlP6m1mK UnuDAeNuKhy/nqTj/38Ckymb1NDtHSoJz7/0CQF0d9zoVyss+Qmz3mlK/+MDT57HF1IdDf LJ4OfKysjX1byoUYMIO/KntLZtcCNz6QUGwPEgYm56PxSgyoJSNCLNC8fzGVFaQRLU0DDD GS6/fSxwnae4XF7wNkkRoEydo9QflYoecF8fa8KCfZV7kmFnOO0mVbkqLY1fTCV5c+JVxP A5D0UKDkrj6tic3PWBTKAbfkuWHlraRqu2wBChRaEQdtDtK4oeGlZrwx/yyoKw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695644830; a=rsa-sha256; cv=none; b=wRBdDYTP9ZQ+IRdMeCIEYdlZfNqOr8PFp4TKVnBoCDfdBJr5d1e0UspksENSjJiAlyKN+7 Ngjn9K0lMLd0ZVuw0ToiJD9ovWHP/HigQODGf/khaqNchXBBeeshxHBAamCxp7Z+aKOXmG M2ysar/ISkbb8DcxpulNOkmqZfMf4v6UfJXPELOrm8bqWL/S517ZwKXTmhSe1aR3U/YD96 SmqKjRrgFtRuKsE5apsMl1neQySver/KGfpwvf8YY1pcCdsM25ZxUki/fkqnmoF+2TNdwX 2TuK/segqIapmZ5305VoQIeVIMjoF86nt68tkB35O1VQNBq7bwM49KFpMal0/Q== 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=1695644830; 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=/5W4nFLdXzyOcI04+OR6c+5fqvkYxieRSo0Vfpf180A=; b=pvdFLPW7cGGottRe2nzOXydFBEv0UZIgNCD1kEBIpZh1xckkPX0fbZaNy2hT8FwElccZ6O odokhaLOAYmyOVN4ejJkN+r/v4EVx1wrKNYKPBn4jBBg3V//PiEMafBqnzaZB2GZ3f8xF6 Ew1WXDNAqf61F+GFLPQcH2wZtWP6b2q4cJueS7WUJ+RiVEL1xPnzdSn8gLrnC1lU6nr/1k mb1Npd3wiIznuo3UMrdrmqjrriX48lSslKx40Hk6tgVadZc3T+4F2YBYsE+5u/ajhCgWyu OJ7ArJw46+DFs9i/RGBUlCxBv8TUPTn1R20bfQvyFoFFTm9REG2cwycv2QcNhw== 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 4RvMZQ5QZpz1SM6; Mon, 25 Sep 2023 12:27:10 +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 38PCRAnt094690; Mon, 25 Sep 2023 12:27:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38PCRAYT094687; Mon, 25 Sep 2023 12:27:10 GMT (envelope-from git) Date: Mon, 25 Sep 2023 12:27:10 GMT Message-Id: <202309251227.38PCRAYT094687@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: ddca690373e5 - stable/13 - pf: fix state leak List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: ddca690373e565a6e86ac1c0e025563ded0a686c Auto-Submitted: auto-generated The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=ddca690373e565a6e86ac1c0e025563ded0a686c commit ddca690373e565a6e86ac1c0e025563ded0a686c Author: Kristof Provost AuthorDate: 2023-09-06 07:58:07 +0000 Commit: Kristof Provost CommitDate: 2023-09-25 12:27:05 +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 (cherry picked from commit b6ce41118bb11d3db86eae8fbebc8c198e8b330d) --- sys/netpfil/pf/pf.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 99fca2d6fabf..51f81172bad2 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -4317,10 +4317,6 @@ pf_create_state(struct pf_krule *r, struct pf_krule *nr, struct pf_krule *a, if (r->rt) { if (pf_map_addr(pd->af, r, pd->src, &s->rt_addr, NULL, &sn)) { REASON_SET(&reason, PFRES_MAPFAILED); - pf_src_tree_remove_state(s); - s->timeout = PFTM_UNLINKED; - STATE_DEC_COUNTERS(s); - pf_free_state(s); goto csfailed; } s->rt_kif = r->rpool.cur->kif; @@ -4381,11 +4377,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; @@ -4461,6 +4453,14 @@ csfailed: PF_HASHROW_UNLOCK(sh); } +drop: + if (s != NULL) { + pf_src_tree_remove_state(s); + s->timeout = PFTM_UNLINKED; + STATE_DEC_COUNTERS(s); + pf_free_state(s); + } + return (PF_DROP); }