From nobody Thu Feb 16 08:26:24 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 4PHShc2k1vz3pLwx; Thu, 16 Feb 2023 08:26:24 +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 4PHShc2DlLz3NG5; Thu, 16 Feb 2023 08:26:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676535984; 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=rzIOO+xNeZz7Ap3Ey6KETUDWIU6hNvs8LXeIXbW3Z3I=; b=utbhegPCVAxwi94FWNsCNtgQKujoyC0ltSzOrT3raaMy9Mt8gT6VeMRg2Ns1gFMcDdsrAt AcPDzqUtQjbsPQ3izPc8v66xNYYwhpBiR0Vw2+/Bn9DNFGGwddtFeIsQPmZgN6Y+PzmQne +sBOpNZF5mB+KY8lfk7LcuH9ORy5yXKGEXAVASqekFWrURgDP45zuHBrX/L8ZBV0lKpZ9i de44UOBxuHsY6qPo9ID+WH0kkN1D2o3wgTATSELvO91NSF55DSFbXDglILkn0bzlKqiaxe hXDjn4NvNjeD0Wq0c0a3ceFMoD6QCQ9ifALQTR0D7XioT60Y0xYKuy1nOoO2mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676535984; 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=rzIOO+xNeZz7Ap3Ey6KETUDWIU6hNvs8LXeIXbW3Z3I=; b=DH082i0/oHq/ueXXx2kO9pQyAg96vfMekczcdQmkkiUQaLnFA6j5ZXNtoZ+dLI4VcbVFwV VcbIs5xoMF4f66SVHi8UDgYS6vZwfyjHkq78VhMVsMCMKKhk1PFlc20WWUv6mkJss5HFq4 NHkhbsIW+P9VSxxn5I6Mx2laBCSvUysShIjsai0MatCRIlFhbmby5sdyNcVUXztI0i5knc pfdt030UZt5891OR7yeqJzz5txj/zis6NtU040mBoRIfgL8Mv+D5j6MrYO/N3Bi/ir18KY YgdvQtvBmJs0EjHpqZkKk0O7mU9kbUHWtf2G7kRvyiwuD4Ygu0PhTQKzubD77A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676535984; a=rsa-sha256; cv=none; b=mnGiHd9Cif/edbcBbnFFmZqmB/gFANRa14t6NtUhrWmgYoTv+S+9RKoD2Kue4znMeRJTip 3YAKqXOdT++UpUIIps5SNV4KxwQywmtN/Rat+J3VCyRAiVfONsOVVPpGVKW3RhGHVmGf72 tVrdaOjd6ugUo3aRb+3+WuCfjufVBkugtIGOqUNVZHxZaKXmbTZFpPXfsVWyMPMC/7J6HE Ruq+B08T8HYXj4dTu3WCeHf/GtzssDxGlA69+O24iIqkM8lU84TL0ozUFjeBTDxZah87/G HTHtIt/gqHW7KVSV0VvXUnmGNkHxjlB3pkxQcvmeE5QZmu0mZsdKQP7Z1TG8KQ== 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 4PHShc1J3VzxGy; Thu, 16 Feb 2023 08:26:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31G8QOsn055941; Thu, 16 Feb 2023 08:26:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31G8QO3c055940; Thu, 16 Feb 2023 08:26:24 GMT (envelope-from git) Date: Thu, 16 Feb 2023 08:26:24 GMT Message-Id: <202302160826.31G8QO3c055940@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: 9a1cab6d79b7 - main - pfsync: support deferring IPv6 packets 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/main X-Git-Reftype: branch X-Git-Commit: 9a1cab6d79b7286e5f650f57ed95625e6ddb8e4b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=9a1cab6d79b7286e5f650f57ed95625e6ddb8e4b commit 9a1cab6d79b7286e5f650f57ed95625e6ddb8e4b Author: Kristof Provost AuthorDate: 2023-02-14 06:11:38 +0000 Commit: Kristof Provost CommitDate: 2023-02-16 06:43:04 +0000 pfsync: support deferring IPv6 packets When we send out a deferred packet we must make sure to call ip6_output() for IPv6 packets. If not we might end up attempting to ip_fragment() an IPv6 packet, which could lead to us reading outside of the mbuf. PR: 268246 Reviewed by: melifaro, zlei MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D38586 --- sys/netpfil/pf/if_pfsync.c | 91 +++++++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 33 deletions(-) diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c index 2301dc475e27..1c8d8d325346 100644 --- a/sys/netpfil/pf/if_pfsync.c +++ b/sys/netpfil/pf/if_pfsync.c @@ -103,9 +103,13 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include + #include struct pfsync_bucket; +struct pfsync_softc; union inet_template { struct ip ipv4; @@ -171,6 +175,7 @@ static void pfsync_q_ins(struct pf_kstate *, int, bool); static void pfsync_q_del(struct pf_kstate *, bool, struct pfsync_bucket *); static void pfsync_update_state(struct pf_kstate *); +static void pfsync_tx(struct pfsync_softc *, struct mbuf *); struct pfsync_upd_req_item { TAILQ_ENTRY(pfsync_upd_req_item) ur_entry; @@ -187,8 +192,6 @@ struct pfsync_deferral { struct mbuf *pd_m; }; -struct pfsync_sofct; - struct pfsync_bucket { int b_id; @@ -1837,13 +1840,7 @@ pfsync_defer_tmo(void *arg) free(pd, M_PFSYNC); PFSYNC_BUCKET_UNLOCK(b); - switch (sc->sc_sync_peer.ss_family) { -#ifdef INET - case AF_INET: - ip_output(m, NULL, NULL, 0, NULL, NULL); - break; -#endif - } + pfsync_tx(sc, m); pf_release_state(st); @@ -2326,6 +2323,56 @@ pfsync_push_all(struct pfsync_softc *sc) } } +static void +pfsync_tx(struct pfsync_softc *sc, struct mbuf *m) +{ + struct ip *ip; + int error, af; + + ip = mtod(m, struct ip *); + MPASS(ip->ip_v == IPVERSION || ip->ip_v == (IPV6_VERSION >> 4)); + + af = ip->ip_v == IPVERSION ? AF_INET : AF_INET6; + + /* + * We distinguish between a deferral packet and our + * own pfsync packet based on M_SKIP_FIREWALL + * flag. This is XXX. + */ + switch (af) { +#ifdef INET + case AF_INET: + if (m->m_flags & M_SKIP_FIREWALL) { + error = ip_output(m, NULL, NULL, 0, + NULL, NULL); + } else { + error = ip_output(m, NULL, NULL, + IP_RAWOUTPUT, &sc->sc_imo, NULL); + } + break; +#endif +#ifdef INET6 + case AF_INET6: + if (m->m_flags & M_SKIP_FIREWALL) { + error = ip6_output(m, NULL, NULL, 0, + NULL, NULL, NULL); + } else { + MPASS(false); + /* We don't support pfsync over IPv6. */ + /*error = ip6_output(m, NULL, NULL, + IP_RAWOUTPUT, &sc->sc_imo6, NULL);*/ + } + break; +#endif + } + + if (error == 0) + V_pfsyncstats.pfsyncs_opackets++; + else + V_pfsyncstats.pfsyncs_oerrors++; + +} + static void pfsyncintr(void *arg) { @@ -2333,7 +2380,7 @@ pfsyncintr(void *arg) struct pfsync_softc *sc = arg; struct pfsync_bucket *b; struct mbuf *m, *n; - int c, error; + int c; NET_EPOCH_ENTER(et); CURVNET_SET(sc->sc_ifp->if_vnet); @@ -2353,29 +2400,7 @@ pfsyncintr(void *arg) n = m->m_nextpkt; m->m_nextpkt = NULL; - /* - * We distinguish between a deferral packet and our - * own pfsync packet based on M_SKIP_FIREWALL - * flag. This is XXX. - */ - switch (sc->sc_sync_peer.ss_family) { -#ifdef INET - case AF_INET: - if (m->m_flags & M_SKIP_FIREWALL) { - error = ip_output(m, NULL, NULL, 0, - NULL, NULL); - } else { - error = ip_output(m, NULL, NULL, - IP_RAWOUTPUT, &sc->sc_imo, NULL); - } - break; -#endif - } - - if (error == 0) - V_pfsyncstats.pfsyncs_opackets++; - else - V_pfsyncstats.pfsyncs_oerrors++; + pfsync_tx(sc, m); } } CURVNET_RESTORE();