From nobody Fri Jun 6 11:17:15 2025 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 4bDJgc1hnmz5yCV1; Fri, 06 Jun 2025 11:17:16 +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 4bDJgb5kYXz3K1R; Fri, 06 Jun 2025 11:17:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749208635; 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=8g9VnbHgOX0eguVmSM4Fha1DsDRwGnSDw7Ucs08h0CM=; b=yX7FevlUDVdDEXOaWqgy7sItFdNLmxXX3c2/Dm67WkKlaEB1Vyo0Xuk1pSAYutDvqlTdcr qw7qzwSKBwFYv0L9YotKgd2B6zGHp1Al7fFSToVW4Q+OoIpLitOCOFw1MEPMg4+cUHTLae nLEettwRM3zGDlXmxAEY6JyXgSC7JvaMwbfmHHbaS2pi92Gy2qHnNKUjtPpsO19Knq8w/6 rvNFZELemh8FsKizAuN5jNF1l+sJlO/UpXoMviLct09vyuMMWwrvjYEc+O5jHuI7NspIFi I1PjRliJyuz2826i3UNJbzYHdSAvMRTgVZeI3GHa26ACdqNL/O0DqpE09pK9tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749208635; 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=8g9VnbHgOX0eguVmSM4Fha1DsDRwGnSDw7Ucs08h0CM=; b=Jw/IO3de6uM3g1/Bro+L0baen8rTNWkdgKb9Y+M5Bxp5WbNtvhMJ3uT9ZhAGbvJTzhYgHD xzjsG/vAKFkLTkpfeEXcfke3S0kwUNC68eol5fiBRGyhjYhzPhuZ+U0ig8RCUIdy8t83fL LpdDp9GaWWR8cLgyOUnCjqpI4LEpfjCzSa+nK2xYU4HKSA5fWPnF/vkjxehNZwhuIdeVsS H0TP0GVyyqfrO+lEQwNRLhLyg8RR+S5xSKwJG60dvm5WTt7gHAF/oD0Ks7hSF4wqXrdXiE DfunqVgTQxWZR37a5v1OMXHZ3RtCxSGwP2uGsdtrCu7udPEjrDB9mJPrQ4oSIA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1749208635; a=rsa-sha256; cv=none; b=SWN2PipJLDCDLOUQhXo4BnUmBYvgYkX1Y71TkbbxqRYvqK1VX3LWXzV0ENvIKNuwNfMe1B r8mbBP/9bJl3a2dc+x7qzh3gfXdYWePBVcPQgLBs5M83aUyERpvh2LrGhLgnoJ7SiMt390 fnOsXwUUC9h269rk3AoUpWY1d3fMlIshh+VqdHr2h0ynP7uXZV9L6H549imT3YrROeI7XT C6PcvU94XnBQxjoJmMbrsel31q0q6PGRqayo6lnIBV21aiLXugpJFm+IQUFtIVWJJJlcz2 OltaCIzOBBmmcgfDlRUIcP01uCGZ5dDXbG8n29QdZxcnu4q39pnyQb1tFr8cJw== 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 4bDJgb59b4zsBP; Fri, 06 Jun 2025 11:17:15 +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 556BHFTf083748; Fri, 6 Jun 2025 11:17:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 556BHFbH083745; Fri, 6 Jun 2025 11:17:15 GMT (envelope-from git) Date: Fri, 6 Jun 2025 11:17:15 GMT Message-Id: <202506061117.556BHFbH083745@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: ee97d8918389 - main - pf: align option handling for IPv4 and IPv6 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: ee97d89183896e45d3ff40d0f3a5b727b7a534cb Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=ee97d89183896e45d3ff40d0f3a5b727b7a534cb commit ee97d89183896e45d3ff40d0f3a5b727b7a534cb Author: Kristof Provost AuthorDate: 2025-05-27 14:44:56 +0000 Commit: Kristof Provost CommitDate: 2025-06-06 11:16:00 +0000 pf: align option handling for IPv4 and IPv6 Block IPv6 packets in pf(4) that have hop-by-hop options header or destination options header. Such packets can be passed by adding "allow-opts" to the rule. So IPv6 options are handled like their counterpart in IPv4 now. tested by benno@; OK henning@ Obtained from: OpenBSD, bluhm , c50c83ac27 Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D50662 --- share/man/man5/pf.conf.5 | 13 +++++++------ sys/netpfil/pf/pf.c | 11 +++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/share/man/man5/pf.conf.5 b/share/man/man5/pf.conf.5 index 6cabdc6741a6..df1e0a99a47e 100644 --- a/share/man/man5/pf.conf.5 +++ b/share/man/man5/pf.conf.5 @@ -27,7 +27,7 @@ .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd May 26, 2025 +.Dd May 27, 2025 .Dt PF.CONF 5 .Os .Sh NAME @@ -2147,20 +2147,21 @@ pass all tos 0x10 pass all tos 16 .Ed .It Ar allow-opts -By default, IPv4 packets with IP options or IPv6 packets with routing -extension headers are blocked. +By default, packets with IPv4 options or IPv6 hop-by-hop or destination +options header are blocked. When .Ar allow-opts is specified for a .Ar pass rule, packets that pass the filter based on that rule (last matching) -do so even if they contain IP options or routing extension headers. +do so even if they contain options. For packets that match state, the rule that initially created the state is used. The implicit .Ar pass -rule that is used when a packet does not match any rules does not -allow IP options. +rule, that is used when a packet does not match +any rules, does not allow IP options or option headers. +Note that IPv6 packets with type 0 routing headers are always dropped. .It Ar label Aq Ar string Adds a label (name) to the rule, which can be used to identify the rule. For instance, diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index f1b04a96590b..fa4c4b73809c 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -9707,6 +9707,8 @@ pf_walk_header(struct pf_pdesc *pd, struct ip *h, u_short *reason) REASON_SET(reason, PFRES_SHORT); return (PF_DROP); } + if (hlen != sizeof(struct ip)) + pd->badopts++; end = pd->off + ntohs(h->ip_len); pd->off += hlen; pd->proto = h->ip_p; @@ -9814,6 +9816,11 @@ pf_walk_header6(struct pf_pdesc *pd, struct ip6_hdr *h, u_short *reason) pd->fragoff = pd->extoff = pd->jumbolen = 0; pd->proto = h->ip6_nxt; for (hdr_cnt = 0; hdr_cnt < PF_HDR_LIMIT; hdr_cnt++) { + switch (pd->proto) { + case IPPROTO_HOPOPTS: + case IPPROTO_DSTOPTS: + pd->badopts++; + } switch (pd->proto) { case IPPROTO_FRAGMENT: if (fraghdr_cnt++) { @@ -10007,10 +10014,6 @@ pf_setup_pdesc(sa_family_t af, int dir, struct pf_pdesc *pd, struct mbuf **m0, pd->tot_len = ntohs(h->ip_len); pd->act.rtableid = -1; pd->df = h->ip_off & htons(IP_DF); - - if (h->ip_hl > 5) /* has options */ - pd->badopts++; - pd->virtual_proto = (h->ip_off & htons(IP_MF | IP_OFFMASK)) ? PF_VPROTO_FRAGMENT : pd->proto;