From nobody Thu Feb 02 17:41:34 2023 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 4P75gh09HBz3kPP5; Thu, 2 Feb 2023 17:41:36 +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 4P75gg3Ykyz40yM; Thu, 2 Feb 2023 17:41:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675359695; 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=YEP15gX/N8nJ7a5end5gW9gspxFWNfCG/laqHK+4nhs=; b=cP1w3s+GUxIZwWsXMPbAkvtnrEkfYTXSpYAkPdVl4XSCzNweeMwoGeOxax7rmaRogyqW3A u3OXSGa2o+hhKayFIBgj3CNpktvUwCfkeM8OtV03rPWlk8/gP2EAEbDmqOPLclJdvrTGIT bV0Wy7er3RrsHc7eJEqtD5YsZfRadKHgWpGeBXGwAKH5sSmNut688WHL93+Hov3ulJTBEe C3oJlKli3VFskfFynin6xvAX0rxy4cJnPo1w7mJx7HmMcXh9Q7yUjp/chs4+YDIN24APdl 615CxnbICQ1XZVcoYox61UFotSlsqLbzyDcEkuyDSV35K1o5Ekcr+hAfvvUi5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675359695; 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=YEP15gX/N8nJ7a5end5gW9gspxFWNfCG/laqHK+4nhs=; b=m8JbJkXQHKimUAUoBLsBnXlJYgRF9Ra4mRp+1M8mYagJ5KjASDG7KsXViv1U9l3BpK5+2M DmWvb6uO+Bg3Rs2dAqusXqNmXEkbjDmNixPJrK0/qp9iNOlH76nYjzdWku7FWJEHB0rG6q NnG9OwpBvIw29tDzhFUB5x3cVKb1ZgFF/5PT6NTVbB4cyvmX2/5lb+vWPmFhIHPqxzQrc7 Fs6YWIzQoL1ZxsAZ318nNs+qT/lyigMKxisAXsn3ar0UZrxHqQeqr3SivdwaIJi2taX2mW MOgG7Tw30p3CJCzNObiT91iCBCKz8bNyJ+WWY8Gh35Zf7W9azcUkg1iRHb/32g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675359695; a=rsa-sha256; cv=none; b=S3O8ddHTomQn3rltap+0uM1aN3VoynsDDNev4qiXyVnORjisjzcbVq8Tj2igi/aaZcdsqV 2JflhpiNL1P8MZMhlZ/rURa8opEMkbeQ6RQUzS+kidgxtPpBUIzI0T+80xsg/H9MOoPS8w p84nrO5pV0ijGtDrotJDQngY3lrLduaa1ptoialh2i4IA1M/R39RcIuFlUpoDqeO7UyTNl vQO6wapz7hTHX6lNbeh08Pz6IkST6vbyCGFnDSUoQWOGUlMsparv3v06lVkgInjLrKzrDP hBSzKaMAcUWgmZLk2mrpjDftf+XG7CB+wiumhh16YBQ1slFdCpmGljpLC/Rt4w== 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 4P75gf6sjcz13rQ; Thu, 2 Feb 2023 17:41:34 +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 312HfYdA033319; Thu, 2 Feb 2023 17:41:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 312HfYUj033318; Thu, 2 Feb 2023 17:41:34 GMT (envelope-from git) Date: Thu, 2 Feb 2023 17:41:34 GMT Message-Id: <202302021741.312HfYUj033318@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Cy Schubert Subject: git: 79f7745c098a - main - ipfilter: Fix use after free on packet with broken lengths 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: cy X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 79f7745c098a766d34a4e072cdd1a06e6d0829d5 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=79f7745c098a766d34a4e072cdd1a06e6d0829d5 commit 79f7745c098a766d34a4e072cdd1a06e6d0829d5 Author: Cy Schubert AuthorDate: 2023-02-02 00:49:08 +0000 Commit: Cy Schubert CommitDate: 2023-02-02 17:41:22 +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 MFC after: 1 week --- 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);