Date: Thu, 9 Feb 2023 21:19:59 GMT From: Cy Schubert <cy@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 1da7a8a06615 - stable/13 - ipfilter: Fix use after free on packet with broken lengths Message-ID: <202302092119.319LJxPN043791@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=1da7a8a066150bf132b3e1a48fad009212a0010a commit 1da7a8a066150bf132b3e1a48fad009212a0010a Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2023-02-02 00:49:08 +0000 Commit: Cy Schubert <cy@FreeBSD.org> CommitDate: 2023-02-09 21:19:41 +0000 ipfilter: Fix use after free on packet with broken lengths Under the scenario with a packet with length of 67 bytes, a header length using the default of 20 bytes and a TCP data offset (th_off) of 48 will cause m_pullup() to fail to make sure bytes are arragned contiguously. m_pullup() will free the mbuf chain and return a null. ipfilter stores the resultant mbuf address (or the resulting NULL) in its fr_info_t structure. Unfortuntely the eroneous packet is not flagged for drop. This results in a kernel page fault at line 410 of sys/netinet/ip_fastfwd.c as it tries to use a now previously freed, by m_pullup(), mbuf. PR: 266442 Reported by: Robert Morris <rtm@lcs.mit.edu> (cherry picked from commit 79f7745c098a766d34a4e072cdd1a06e6d0829d5) --- sys/netpfil/ipfilter/netinet/fil.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sys/netpfil/ipfilter/netinet/fil.c b/sys/netpfil/ipfilter/netinet/fil.c index 5ced528d1263..6fcfd3cea301 100644 --- a/sys/netpfil/ipfilter/netinet/fil.c +++ b/sys/netpfil/ipfilter/netinet/fil.c @@ -1113,8 +1113,10 @@ ipf_pr_pullup(fr_info_t *fin, int plen) if (M_LEN(fin->fin_m) < plen + fin->fin_ipoff) { #if defined(_KERNEL) if (ipf_pullup(fin->fin_m, fin, plen) == NULL) { - DT(ipf_pullup_fail); + DT1(ipf_pullup_fail, fr_info_t *, fin); LBUMP(ipf_stats[fin->fin_out].fr_pull[1]); + fin->fin_reason = FRB_PULLUP; + fin->fin_flx |= FI_BAD; return (-1); } LBUMP(ipf_stats[fin->fin_out].fr_pull[0]); @@ -1127,6 +1129,7 @@ ipf_pr_pullup(fr_info_t *fin, int plen) *fin->fin_mp = NULL; fin->fin_m = NULL; fin->fin_ip = NULL; + fin->fin_flx |= FI_BAD; return (-1); #endif } @@ -3180,6 +3183,14 @@ finished: SPL_X(s); + if (fin->fin_m == NULL && fin->fin_flx & FI_BAD && + fin->fin_reason == FRB_PULLUP) { + /* m_pullup() has freed the mbuf */ + LBUMP(ipf_stats[out].fr_blocked[fin->fin_reason]); + return (-1); + } + + #ifdef _KERNEL if (FR_ISPASS(pass)) return (0);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302092119.319LJxPN043791>