From nobody Fri Oct 14 09:25:19 2022 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 4MpgwJ10HLz4g20r; Fri, 14 Oct 2022 09:25:20 +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 4MpgwJ0Vg3z3hh6; Fri, 14 Oct 2022 09:25:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665739520; 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=sZEIQBNi7L47XJY0+gPMsZbnGUIvWGhbYw39jmgF3iE=; b=iWe+WOdKhK0Q3njRwvoR2p8UYGqomtPJz/8gRrHZROTquST3THnPDpg9yPn7R6s1UcRd/7 WmU6wHwhngFV1FrVn7VG8Av+iyNSgr6PiWCixu7r2eyCItn7Fw+emObP+X9ozfAaTiIO2s nFpnAnMgr4N2iZ98nMJWRoXaaUrusTmtMNvwv6ItSir9+uJK7gO9sd7kdzDsCMDSi1K5zz uqlWdwn/7Jh1V+R1OuviWblaP1gvZFwypGjbmXJxjk6PCGfq7cXBpTRYur1VKtoxSpNdfh Gr4OOsfHPqvhb0tbzeGrP9ObZkWePJ/O48Ai+NL20eXmlOLK83x912Y4zCU2mA== 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 4MpgwH6gmFzkWK; Fri, 14 Oct 2022 09:25:19 +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 29E9PJSS040730; Fri, 14 Oct 2022 09:25:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29E9PJgk040729; Fri, 14 Oct 2022 09:25:19 GMT (envelope-from git) Date: Fri, 14 Oct 2022 09:25:19 GMT Message-Id: <202210140925.29E9PJgk040729@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: a974702e274c - main - pf: apply the network stack's ICMP rate limiting to ICMP errors sent by pf 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: 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: a974702e274cbed52ae9ad9ecef8501e267b822d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665739520; 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=sZEIQBNi7L47XJY0+gPMsZbnGUIvWGhbYw39jmgF3iE=; b=ZQrOTeypbJdmWBoIBf6kOHS/kmVVMDxDiWfNJeRA7UKdVX+luNjiumrHH5X+s2E1/GL27b vXC0sKyRDbnKGCtUWFBeu+5ZGGS5OBUUIf51EKzZaPHn+OoqAw8F65HFCaWUu/x3Bmj/63 6HmxuSaj5UID+3A/JaQyfJTs6HIiPwNJ35jX1BBoh2aFnvcbuT1jDQGznB7PN1CzU6s0+B zaaIOUQWtust+CvKB75MelhC3KFlV0mb3er3tGjV1mgAqaXaQwdPXktT6usaJvkIHDc9vL VkSD00ewy6w/d4bRQM8aFAmQxIk+8ocoRbLM9o8o9DIH91Ac4DUh5NqnjJxmAg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665739520; a=rsa-sha256; cv=none; b=Kh2b+vuqhC5uUKlb5H6T/wXfDRzx9dnXTsSE72XtwvivPz56Nb4tC9X4G06ZohtrCKC9Ua cQEYC3cvFGruOrSt5A/XRP65c7ftRz+ogLA8kBKGCtZJOzwFw9vMU1Dkmhus8ILf/EGqeu fqTYFT07P3Sn34TVA7uRvL+EoUMI7bQB9cJbJG1Y5CW/AswnFNOyct5+vLt6gv2K0WNCwE rnUkyqWNbRgBciydt+RauK8HrfCIN70aRQ8KweefDhLgzu9WmNjwIJfK4UR+3W36kB4H8j CDVV4tIZ/BXxI/vB0WZMtbyDW6oeW00G1Pgcfa8/gIi7hqrkIFKpIv3uORmJQQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=a974702e274cbed52ae9ad9ecef8501e267b822d commit a974702e274cbed52ae9ad9ecef8501e267b822d Author: Kristof Provost AuthorDate: 2022-10-07 14:22:57 +0000 Commit: Kristof Provost CommitDate: 2022-10-14 08:36:16 +0000 pf: apply the network stack's ICMP rate limiting to ICMP errors sent by pf PR: 266477 Event: Aberdeen Hackathon 2022 Differential Revision: https://reviews.freebsd.org/D36903 --- sys/netinet/icmp6.h | 1 + sys/netinet6/icmp6.c | 3 +-- sys/netpfil/pf/pf.c | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/sys/netinet/icmp6.h b/sys/netinet/icmp6.h index 7429b8173b6a..45a8b8ec0ce8 100644 --- a/sys/netinet/icmp6.h +++ b/sys/netinet/icmp6.h @@ -708,6 +708,7 @@ int icmp6_input(struct mbuf **, int *, int); void icmp6_prepare(struct mbuf *); void icmp6_redirect_input(struct mbuf *, int); void icmp6_redirect_output(struct mbuf *, struct nhop_object *); +int icmp6_ratelimit(const struct in6_addr *, const int, const int); struct ip6ctlparam; void icmp6_mtudisc_update(struct ip6ctlparam *, int); diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 4497041f0330..2cd54abbb76e 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -137,7 +137,6 @@ VNET_DECLARE(int, icmp6_nodeinfo); static void icmp6_errcount(int, int); static int icmp6_rip6_input(struct mbuf **, int); static void icmp6_reflect(struct mbuf *, size_t); -static int icmp6_ratelimit(const struct in6_addr *, const int, const int); static const char *icmp6_redirect_diag(struct in6_addr *, struct in6_addr *, struct in6_addr *); static struct mbuf *ni6_input(struct mbuf *, int, struct prison *); @@ -2727,7 +2726,7 @@ icmp6_ctloutput(struct socket *so, struct sockopt *sopt) * type - not used at this moment * code - not used at this moment */ -static int +int icmp6_ratelimit(const struct in6_addr *dst, const int type, const int code) { diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 2a6efbfe6e7d..d0139dc6bd15 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -3048,6 +3048,22 @@ pf_match_ieee8021q_pcp(u_int8_t prio, struct mbuf *m) return (mpcp == prio); } +static int +pf_icmp_to_bandlim(uint8_t type) +{ + switch (type) { + case ICMP_ECHO: + case ICMP_ECHOREPLY: + return (BANDLIM_ICMP_ECHO); + case ICMP_TSTAMP: + case ICMP_TSTAMPREPLY: + return (BANDLIM_ICMP_TSTAMP); + case ICMP_UNREACH: + default: + return (BANDLIM_ICMP_UNREACH); + } +} + static void pf_send_icmp(struct mbuf *m, u_int8_t type, u_int8_t code, sa_family_t af, struct pf_krule *r) @@ -3056,6 +3072,16 @@ pf_send_icmp(struct mbuf *m, u_int8_t type, u_int8_t code, sa_family_t af, struct mbuf *m0; struct pf_mtag *pf_mtag; + /* ICMP packet rate limitation. */ + if (af == AF_INET6) { + if (icmp6_ratelimit(NULL, type, code)) + return; + } else { + MPASS(af == AF_INET); + if (badport_bandlim(pf_icmp_to_bandlim(type)) != 0) + return; + } + /* Allocate outgoing queue entry, mbuf and mbuf tag. */ pfse = malloc(sizeof(*pfse), M_PFTEMP, M_NOWAIT); if (pfse == NULL)