From nobody Wed Sep 11 11:18:27 2024 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 4X3dNh28Tmz5WRmZ; Wed, 11 Sep 2024 11:18:28 +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 4X3dNg5c8Cz4XnS; Wed, 11 Sep 2024 11:18:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726053507; 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=qCDQZw25VBKvWndPZ46hqp5MLAlm5T1ORTSH1gUe2aw=; b=Xpz6+33iFNM3K2f/zcNVnXNcQtWs52P6SiH7IDN8Qc5nhXbQ0dAmKTPF8ohU31wDZJ9bIA ovKmWotBJBVytA1q/VYi2WJTxta0sj6g3W0BAsoL+09AV9Cc9WVSK8c0+AwnqGG/KMb6cF mWZZB4W40yVb5XqnO4j5D7C8gFh6rrepJTd+IpVFkx3vCNFuxgUQKvwd7+cuMgJKhPfofN 6+NW9l+YdprHqw8iq2QS9ybC+NfyV8T8Vf/IiKAohL+ZiAcX3g/zao3l0xhOkGej3vSnxj sDv/yBVXkCn3++6qoeDNs+9pWamgM5YXM0xhoZ4LNxllxLD9G74eUy/dVKHynw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726053507; a=rsa-sha256; cv=none; b=gOyzY+BtwQhKw5DF8RXJgB4tyt1GvCLDHCo0mKm0RgmU+xzXiskfcHkSsDo31pao3nDt7e ymFGxUnonZ4+zy7eS1PR1P1891j6EwKRaN+anIUJv/GmPzfDICG4QruYnWlR2Z7JpDgGJw 60snHQiw5jyZc68wPU/t21T2ZYJVgfKR5cmRqc49irrzcerxDyzlucuz9Z1/Ojgg92uHT3 8MBsBUQBRKjp54K0xKIyISVnMjH7p7sYbipN5NoEuRIHe9lMaLyuB2xgB0znFFWFWvjAeB 5xeYubSBVDIw0OPIFBAoaJ1WP9JMDAEzXy4/5lp6GIpUdlU0MgA/aOwBY0my2Q== 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=1726053507; 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=qCDQZw25VBKvWndPZ46hqp5MLAlm5T1ORTSH1gUe2aw=; b=Lc9Y45XBj8wYwqh9PSzpteKXk/8YO4D/KoDGQZIa/ikUrfCsehQPd7xtutgPQQQVISbbOU a3vv6EZklUBRUGxnZdZ6xueevDUkkGr9XRzu5f1LnV7LqHusW5NXVM5V4w1WiWk23l9UNU VTZYhBALbasdqo/3xogiy0z2WD7rbS4g34mRvbrFyiTMklOJkLR7mv6XuMMHif+fTQBwMV 0VVcs8v8mqtsVugLdWS994cqt3hDfKGw71gFNxjSj97E8H4uz17et9DoMddUNnt24JoePL WXwtifbcvE0sRVSG4joYkXaSyjn2oPMnLo2BJMS4aptcjTzZtgbIV8JI85Ak6Q== 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 4X3dNg5CpXzSZs; Wed, 11 Sep 2024 11:18:27 +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 48BBIR8o065139; Wed, 11 Sep 2024 11:18:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48BBIRsY065136; Wed, 11 Sep 2024 11:18:27 GMT (envelope-from git) Date: Wed, 11 Sep 2024 11:18:27 GMT Message-Id: <202409111118.48BBIRsY065136@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: 423b1069af74 - main - pf: ensure mbufs are writable 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-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: 423b1069af744e717bafb3dbd0764926e2aabd88 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=423b1069af744e717bafb3dbd0764926e2aabd88 commit 423b1069af744e717bafb3dbd0764926e2aabd88 Author: Kristof Provost AuthorDate: 2024-09-10 20:16:13 +0000 Commit: Kristof Provost CommitDate: 2024-09-11 11:17:48 +0000 pf: ensure mbufs are writable Ensure that we can modify mbufs before we start processing them. There are a number of paths where pf will m_copyback() or otherwise modify a packet. Ensure that this is safe to do. For example, ip6_forward() will m_copym() the packet before handing it to the output pfil hook. This results in a non-writable mbuf, which would trigger assertion failures (see previous commit). Reviewed by: glebius (previous version) Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D46628 --- sys/netpfil/pf/pf.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 70220dda935e..1535843d81b1 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -8415,6 +8415,12 @@ pf_test_eth(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, if (m->m_flags & M_SKIP_FIREWALL) return (PF_PASS); + if (__predict_false(! M_WRITABLE(*m0))) { + m = *m0 = m_unshare(*m0, M_NOWAIT); + if (*m0 == NULL) + return (PF_DROP); + } + /* Stateless! */ return (pf_test_eth_rule(dir, kif, m0)); } @@ -8553,6 +8559,12 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, return (PF_PASS); } + if (__predict_false(! M_WRITABLE(*m0))) { + m = *m0 = m_unshare(*m0, M_NOWAIT); + if (*m0 == NULL) + return (PF_DROP); + } + memset(&pd, 0, sizeof(pd)); TAILQ_INIT(&pd.sctp_multihome_jobs); if (default_actions != NULL) @@ -9147,6 +9159,12 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb return (PF_DROP); } + if (__predict_false(! M_WRITABLE(*m0))) { + m = *m0 = m_unshare(*m0, M_NOWAIT); + if (*m0 == NULL) + return (PF_DROP); + } + memset(&pd, 0, sizeof(pd)); TAILQ_INIT(&pd.sctp_multihome_jobs); if (default_actions != NULL)