From nobody Thu Feb 09 21:21:07 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 4PCVCm067Nz3nl8n; Thu, 9 Feb 2023 21:21:08 +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 4PCVCl6gYJz488G; Thu, 9 Feb 2023 21:21:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675977667; 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=8+kOWDT7pSwhL7Fp0aQmw61wrOKiwpprTvmIf6HXsds=; b=Vz4Bzv7Sb9CS71WMRXXQK3C68IGMR5nsVfBFA4TFeB1auEIBkacSGwrGr6xeUaSGJlHqcq EhyWD08CbI+om//hf08hICqCO8uXlwsWKlpGxXDVlOM/ITlyEHba/GB9x4yXWYzNJGd94Y TMcBYdUzw0cctGQHto4vOts1y9w7X71BXxu38GYLf90E9+/7bL7YGXAZQfE3bRD5ZmUK88 /XrTBGfcLaNgrzApWT2WOEbp2RzT6kaElWfzdIMN/U5TRSmDXqaRH/Uf1d+uh4bfMnEhg4 QbFBw8jveGgL5Avll+25HX+CwLVITU8u3Bw9ftNWMrm3GPikqLvhjSYkLkZziQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675977667; 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=8+kOWDT7pSwhL7Fp0aQmw61wrOKiwpprTvmIf6HXsds=; b=IO2zb70UPTGOTUQ1JzXliqoO0OyiDPoC/IU8wS6GvOJTCD3EvoEx5iDKGUlrvQfk2bCzTO L7xiodtl2BaoiJ/5tWdny557wu1Znwlrb87ckbB5wzn3TDmS81GEK1LJbr182iB1BoAOER yhIKsf03Fzns6ccgRNWfeUoCGoRCbraqhxeZn1iohbWqEZmVNjVasu4KG70yXmCXWHUTH9 8BJC1NOLOsDhkDAGXzlBWSWePXivksiBubmgQMEXmokvNmcsSVCp6L7twRhFM7yX5H4Zrb ejjKbcC4GPaHiMpUB9FGmHu1MiLla0edEYqrVHLsys3pDPiDDxOvP96ie8dX9A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675977667; a=rsa-sha256; cv=none; b=ItPv80/jpK4a0PUNPtkYjpofP/rPE0TRzUh0tS6uhL0ALmGoB25+IS58mThNOOW/RJ8Rp6 6WBmN1msaeoEKer8sxqCoX7lNZaI4Or9rk83pVvUdknRIceAaZmyfIrwYakmndzmrM4Suc lqsuAE/0k6+TmiyHqQCO141MmGRo514WWv9IHLKRLj31jUhEBr6IQS4eRyasNDynhRCcb6 SO8+QC/aw2kLHFlLYtJPOkLfJmqKC5C6eM9KAHydFjxpZifFv9rTuo2tPRDpS+23xzrv5D qWEyAWugUptMAtbO2X3ISZF5wlqg2rb8rwXe89UKR3cVC1RWdbzoXLAOrT2Tew== 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 4PCVCl5LWJzs1N; Thu, 9 Feb 2023 21:21:07 +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 319LL7YJ056818; Thu, 9 Feb 2023 21:21:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 319LL7LI056817; Thu, 9 Feb 2023 21:21:07 GMT (envelope-from git) Date: Thu, 9 Feb 2023 21:21:07 GMT Message-Id: <202302092121.319LL7LI056817@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: 351f2f68852a - stable/12 - 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/12 X-Git-Reftype: branch X-Git-Commit: 351f2f68852ac3e1d0ef745dc024dd745b07a34f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=351f2f68852ac3e1d0ef745dc024dd745b07a34f commit 351f2f68852ac3e1d0ef745dc024dd745b07a34f Author: Cy Schubert AuthorDate: 2023-02-02 00:49:08 +0000 Commit: Cy Schubert CommitDate: 2023-02-09 21:20:51 +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 4fa90f64fb33..3cf9111340a3 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);