From nobody Thu Feb 9 21:19:59 2023 X-Original-To: dev-commits-src-branches@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 4PCVBR6Lkrz3nl5x; Thu, 9 Feb 2023 21:19:59 +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 4PCVBR4sG9z46PV; Thu, 9 Feb 2023 21:19:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675977599; 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=ts4wQC1hpaXkN0sv/Xme+m9HB6t9+z0e1Eajp/RvKyA=; b=OB+Y5NVywTaxHKFAOFv6UhBAwSMUG4z4KIMRCeHkXkuKTuUqhrztTJpW/wsCjHunanW709 H+QYuEGiJO+mUDQGxb3G1Byd2aSVwAP6nJ7zV8ROtEGG5er03QAJ0nn6OncWCJVq0nflmD 5irZ0MPzgOktAPHPMGuc05gTzMx6/iTfEKiFUaJBbOP0r7GYBEWn7iT5baSEHdeaN3Vuk3 hjEUPOnjx8Suit0MGpXFmYq8RoTzoXxoLS1VU+Lfib6YRLccEyc3v8Mi1HQGjMfQDmfVAz uJBjaikCaPDGswCu7sQoXPBr4D+ZJpWpqlFfeWu+lCfbQPTzbK3H+GcX9dnYeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675977599; 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=ts4wQC1hpaXkN0sv/Xme+m9HB6t9+z0e1Eajp/RvKyA=; b=BKlTga5cFCwDBdcCYp0wjNsQTdHylBqU3ZY9ng9vgmz/V/dKwF/oilncIVsACQJuKVTB54 XBe3CoPjm3qHinrrbWUn2B3pOq4aSToK1iHvsiSfrQCQExGYyL6CEQWbKmcJ2I95DoEGSl +oi5oIKryVZUQLIsI5Y/jrrn3QuCfTu9gAilPMSgmUeAMhu2tqcLqO0dh5Is3E9VEszlXQ 9voN7F2qWVaiPpSFFjJEeIlVw/3DFi9I5/BPxyPJ2atoHCgj+ssK+b6gCp4l3f/DiSJgrl dJZV4Wo70EV3Wg3Xl39e1oX0Wu5LiSuA9G7v03HxzaKUaqiy92thdQrE0j0+rQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675977599; a=rsa-sha256; cv=none; b=Z+tz+ci68kKX2Wb7XTG1elhRvXlETBvwegcFnbXip0+zvFBTLZtYmfnnIuGCfXKGmOdVpd aVGsHOi2FguVGzxRG8bH14a3zWhyKXAtrnpc6NpZcZT6QTbluln3XjCcdtT3hXx+c4MWyv AQ+4uUJB0+0eB7BG41dALdrZ8+EMkCybmOk3VqupvSfqoEJxULTJGe6iWA5iaoBnOOu+tq PQDqckclCZSdIFirlBWIRDfEkNBbcqQE8npJyVvlO6O2jItS1bSNFLVM1nkdepSvdwYsYF Xcjbq5DxonMd5CmQXxIoi/jcjaZsS5Z5rfVebDEIk1aU+8v3ds6Pf8YmhXWZFQ== 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 4PCVBR2tMBzs1F; Thu, 9 Feb 2023 21:19:59 +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 319LJxTq043792; Thu, 9 Feb 2023 21:19:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 319LJxPN043791; Thu, 9 Feb 2023 21:19:59 GMT (envelope-from git) Date: Thu, 9 Feb 2023 21:19:59 GMT Message-Id: <202302092119.319LJxPN043791@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Cy Schubert Subject: git: 1da7a8a06615 - stable/13 - ipfilter: Fix use after free on packet with broken lengths List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cy X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1da7a8a066150bf132b3e1a48fad009212a0010a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=1da7a8a066150bf132b3e1a48fad009212a0010a commit 1da7a8a066150bf132b3e1a48fad009212a0010a Author: Cy Schubert AuthorDate: 2023-02-02 00:49:08 +0000 Commit: Cy Schubert 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 (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);