From nobody Tue Dec 17 20:33:45 2024 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 4YCT6d3m5cz5hhYS; Tue, 17 Dec 2024 20:33:45 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YCT6d34Dnz4c5W; Tue, 17 Dec 2024 20:33:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734467625; 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=RMoDBhnmpjlIJgbn/oQQYVwb5SeaYlVBxj4jNLtlHwk=; b=fAzKLWH2agQQOwYt0gBiWi8ZOIJFlHVspQ0DdNM3buV3vBHFFHBepYxcJZJXUQoMlEmWIZ u/v7Y7n9acT1fWeMWEwMlVHtsD8MPe8ENlQ8+gx9pVfJqkBdVGfUOzzSryte3vZdHXbUKF MXYNMm/4YWKZ/Zt8JzQislVvZ/3wWPtNuZVu9jkfVF5Csn6OOJbi/M7rUD80Sk0OXcGPFE ln0OB7dgoMBk5wUUKstwTDWu7BW0NgtbIsTSREsRzXRqA77Fk0az2BWukn6KR2NedzLddQ vj6qLwGKgiSI1RD/XZ5hZx7rxQy2Ik+CjrMTJwnA5irVyHKmpAe3+J3OBrSDPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734467625; 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=RMoDBhnmpjlIJgbn/oQQYVwb5SeaYlVBxj4jNLtlHwk=; b=SvQ6bPC1N1D1z9EObkxvDHAskiMuKiWzfuQvmayT75meAYhnTg7i18YGUqMYTyIUOl53ic HqYVcKBQLT7h+DDU4AK/rB6hjUZ9GZjZxyrPbLXSnB/FPUL2TFneEv41+bgBW4QN+XOPvi 5gU2H4KCbejxilVq1cxbmgSMgaL4S4rGS5yA4rAB/K1P1rgBa43M64rGPIf4SdJ4iWJ6MF AKa/rFjdD5icv188iX23dY8M+VEKXlXaSAlpZ8NTlWcF65cXcVwkbaH1KuENhH3LOTXues XHQoI5+8m55EPiGf/Lx0PRtX7r57dACJbIUC/k56ErXqEcfuiba+Kv5STC2iNA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734467625; a=rsa-sha256; cv=none; b=R9112IKKBHe60zBiXeuMu1YWn/FpvfAveuKnxx0Z2jC+cNLi5GRnTol2g478fefv1tY0hU LSj7h80+i9zbnMqKrGygW0lOSWhZMXVIn7t7aSra7MSzGUlN340uN41mKkxGsFkVLQcQWM Be7a4jXIKBpCCPDyI6ZI5Q6/XfC5R/4tQsTxu9D/ffHGyYzd1ex6gCGpEq8eAR9RFJ3MxH 2joKazJ/gGzBtmjKrZP4FfmfjFlAPvsVZCNVSZpcCGWOaNK/6ptR1ytFoB/yySdWxyUSun fB6Gq3JVi6EbMPPaVoXnepfzwl01zuZacOl9hUz3KA4hr91McdtbLCKNmuvFEQ== 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 4YCT6d2grpzfFG; Tue, 17 Dec 2024 20:33:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BHKXj2s098760; Tue, 17 Dec 2024 20:33:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BHKXjsE098757; Tue, 17 Dec 2024 20:33:45 GMT (envelope-from git) Date: Tue, 17 Dec 2024 20:33:45 GMT Message-Id: <202412172033.4BHKXjsE098757@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: 01eb1261443d - main - pf: fix double free in pf_state_key_attach() 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/main X-Git-Reftype: branch X-Git-Commit: 01eb1261443dddcb50a3a278f1278fffdfb0d36e Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=01eb1261443dddcb50a3a278f1278fffdfb0d36e commit 01eb1261443dddcb50a3a278f1278fffdfb0d36e Author: Kristof Provost AuthorDate: 2024-12-11 22:27:21 +0000 Commit: Kristof Provost CommitDate: 2024-12-17 20:33:11 +0000 pf: fix double free in pf_state_key_attach() In 371bd29d4b we fixed a state key leak, but unintentionally introduced a double free. We pass through the relevant code twice, first for PF_SK_WIRE, then for PF_SK_STACK. If we fail to attach on the second pass we have a more complex cleanup job, handled by pf_detach_state(). We must only free the state keys manually on the first pass, on the second one pf_detach_state() takes care of everything. Tested by: yds Fixes: 371bd29d4b22257a7e92e1e711cca3d94cfbd00d MFC after: 2 weeks Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/netpfil/pf/pf.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index f2e19693b863..11d37747b3a0 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1477,11 +1477,13 @@ keyattach: s->timeout = PFTM_UNLINKED; PF_HASHROW_UNLOCK(ih); KEYS_UNLOCK(); - uma_zfree(V_pf_state_key_z, skw); - if (skw != sks) - uma_zfree(V_pf_state_key_z, sks); - if (idx == PF_SK_STACK) + if (idx == PF_SK_WIRE) { + uma_zfree(V_pf_state_key_z, skw); + if (skw != sks) + uma_zfree(V_pf_state_key_z, sks); + } else { pf_detach_state(s); + } return (EEXIST); /* collision! */ } }