Date: Wed, 17 Feb 2021 13:05:41 GMT From: Kristof Provost <kp@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: f9a66bb91ae1 - stable/13 - pf: Slightly relax pf_rule_addr validation Message-ID: <202102171305.11HD5f0Q064700@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=f9a66bb91ae1f3f175d0c16730c683841525bd1d commit f9a66bb91ae1f3f175d0c16730c683841525bd1d Author: Kristof Provost <kp@FreeBSD.org> AuthorDate: 2021-02-13 15:31:52 +0000 Commit: Kristof Provost <kp@FreeBSD.org> CommitDate: 2021-02-17 13:03:58 +0000 pf: Slightly relax pf_rule_addr validation Ensure we don't reject no-route / urpf-failed addresses. PR: 253479 Reported by: michal AT microwave.sk Revied by: donner@ MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D28650 (cherry picked from commit 5e42cb139fc17f165c9c93ac97069dc7770490e2) --- sys/netpfil/pf/pf_ioctl.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 644a091808cd..edc8443dcc0a 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -1557,9 +1557,33 @@ pf_krule_to_rule(const struct pf_krule *krule, struct pf_rule *rule) rule->u_src_nodes = counter_u64_fetch(krule->src_nodes); } +static int +pf_check_rule_addr(const struct pf_rule_addr *addr) +{ + + switch (addr->addr.type) { + case PF_ADDR_ADDRMASK: + case PF_ADDR_NOROUTE: + case PF_ADDR_DYNIFTL: + case PF_ADDR_TABLE: + case PF_ADDR_URPFFAILED: + case PF_ADDR_RANGE: + break; + default: + return (EINVAL); + } + + if (addr->addr.p.dyn != NULL) { + return (EINVAL); + } + + return (0); +} + static int pf_rule_to_krule(const struct pf_rule *rule, struct pf_krule *krule) { + int ret; #ifndef INET if (rule->af == AF_INET) { @@ -1572,23 +1596,12 @@ pf_rule_to_krule(const struct pf_rule *rule, struct pf_krule *krule) } #endif /* INET6 */ - if (rule->src.addr.type != PF_ADDR_ADDRMASK && - rule->src.addr.type != PF_ADDR_DYNIFTL && - rule->src.addr.type != PF_ADDR_TABLE) { - return (EINVAL); - } - if (rule->src.addr.p.dyn != NULL) { - return (EINVAL); - } - - if (rule->dst.addr.type != PF_ADDR_ADDRMASK && - rule->dst.addr.type != PF_ADDR_DYNIFTL && - rule->dst.addr.type != PF_ADDR_TABLE) { - return (EINVAL); - } - if (rule->dst.addr.p.dyn != NULL) { - return (EINVAL); - } + ret = pf_check_rule_addr(&rule->src); + if (ret != 0) + return (ret); + ret = pf_check_rule_addr(&rule->dst); + if (ret != 0) + return (ret); bzero(krule, sizeof(*krule));
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202102171305.11HD5f0Q064700>