From nobody Mon Jan 20 16:27:52 2025 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 4YcG3D2L86z5kKmq; Mon, 20 Jan 2025 16:27:52 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YcG3D1p1tz3StN; Mon, 20 Jan 2025 16:27:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737390472; 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=Puheg5tWKDriOHlHV8I++IR49mvsmAdcBmrzHKAt66s=; b=EJk9BLNy4StThiRh1IGnyLR+KjEzotz5xrtggb1c3eTYEJSzonha7PzVAcecllfhDnagbd 1Hjl5Izyb46BSmA98hV9ISVr64zYF69BbSuFT0aNm+Hm1qbIHQ7r3ERur3oUM3LAUVoAoK uk9wqjcZSWmYbcvt43Z2izec4FDNEIgN/XroIT3tkj1DpWLcd5DvM0F9++db1Y3of1hCuD FfdM+orzqnd1LRa+eSH/EB4+s1Oc16J8GZALwTRTSoRyv/X7T8v5gXQ0v58v9tHIG36u4k B3vtPVaE0Ss2bHdf3MX0mMPQmVxzykPB61nXes2Lnm2OXT4U7veSUnHsuLEfPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737390472; 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=Puheg5tWKDriOHlHV8I++IR49mvsmAdcBmrzHKAt66s=; b=XeOCfHP/ZjrUrxYCclr9xUHbZW/3P3jE6/qaZH7JYKHKwtSxE2KyMlJ+rqeXnxPwCv8b53 yYLs1zyrhGr0TDYbk5c8EBHRsCXSzm1uDE71I5UJrI/WyhwmziKCDhmzr3TGjAa0LduYgo UwW+8rambzVOgrDN7hrJ21dd2X3Q8xh2B3Wms91TisWZgSlogAUkNLQfbKomlegRddeqH6 S/jKM+Tmb5zjcpwL2G6ypnpCwEz88ZfuTSdWAHZ4nUFG/lglbBRWHO3dCE6CnDiR7qqlvN xHJzWG3vCSBtRj0GkA1TUBAsdScJZChbKsjhHewrhq4L5xH9b/MgQu0sSYdKOQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737390472; a=rsa-sha256; cv=none; b=npPbxuD4pKjNQewM1bhXCpr5yxgK/VJ0fWeNjWX9M6cS7xQ3kMK34hdd/sHSmTOpSBB34c qc7R55deYGPZxW7+0TPMDZ+J5uJt0Q51wqWDE/AHvWhgJnFSkcEzLelW0c/Cb7B7pB8M+6 sae3/l9wxk/Tb0C6gqEoZHF5cTgl0fuSJHchAyhsSvH+YDPjInroCThGEioeYfe/sNn5X1 1kt7wX1Jnk7oROEg35B9IoWQzdHyorqBmP9dk7klpKeEMxBgpjRLg8yhrqj1ZZN3X7v4LP nrb3xQvnSP/r17dRdMRhXe8bU2iCUdDUXOXl88gSf5zD3mHfONb0iXvpMLSINg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YcG3D0xCwzCD3; Mon, 20 Jan 2025 16:27:52 +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 50KGRqVj012577; Mon, 20 Jan 2025 16:27:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50KGRqYc012574; Mon, 20 Jan 2025 16:27:52 GMT (envelope-from git) Date: Mon, 20 Jan 2025 16:27:52 GMT Message-Id: <202501201627.50KGRqYc012574@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: 980eedb0cad6 - stable/14 - pf: avoid use-after-free on reassembly 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 980eedb0cad684c1e4a64d063df2ee7d28fa693d Auto-Submitted: auto-generated The branch stable/14 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=980eedb0cad684c1e4a64d063df2ee7d28fa693d commit 980eedb0cad684c1e4a64d063df2ee7d28fa693d Author: Kristof Provost AuthorDate: 2025-01-06 20:08:04 +0000 Commit: Kristof Provost CommitDate: 2025-01-20 16:26:49 +0000 pf: avoid use-after-free on reassembly Ensure we update the mbuf pointer returned by pf_normalize_ip() or pf_normalize_ip6() even if they fail. Otherwise we'd risk using a freed mbuf. PR: 283705 Reported by: Yichen Chai , Zhuo Ying Jiang Li Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 5d28f4cab8d5919aba1365e885a91a96c0655b59) --- sys/netpfil/pf/pf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 18b907c45d38..31c3dd8009de 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -8424,6 +8424,7 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, if (mtag != NULL) m_tag_delete(m, mtag); } else if (pf_normalize_ip(m0, kif, &reason, &pd) != PF_PASS) { + m = *m0; /* We do IP header normalization and packet reassembly here */ action = PF_DROP; goto done; @@ -8629,6 +8630,10 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, done: PF_RULES_RUNLOCK(); + + if (m == NULL) + goto out; + if (action == PF_PASS && h->ip_hl > 5 && !((s && s->state_flags & PFSTATE_ALLOWOPTS) || r->allow_opts)) { action = PF_DROP; @@ -8968,6 +8973,7 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb /* We do IP header normalization and packet reassembly here */ if (pf_normalize_ip6(m0, kif, &reason, &pd) != PF_PASS) { + m = *m0; action = PF_DROP; goto done; } @@ -9237,6 +9243,9 @@ done: n = NULL; } + if (m == NULL) + goto out; + /* handle dangerous IPv6 extension headers. */ if (action == PF_PASS && rh_cnt && !((s && s->state_flags & PFSTATE_ALLOWOPTS) || r->allow_opts)) {