From nobody Mon Apr 01 07:34:35 2024 X-Original-To: dev-commits-src-all@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 4V7N7c0JYYz5Fqk5; Mon, 1 Apr 2024 07:34: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 4V7N7b6WjGz4k6B; Mon, 1 Apr 2024 07:34:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711956875; 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=4Dux3zrwOGtt5R3l+cIy7iNZBn7eWD7GPIzfQC2DjPc=; b=e+So13rsYvwe2YwSip2YQ1fMUv6RcVNfLqzp4IEx+DBxzSiwQl4PH2749DD/Qer/19uG9F WJDW7YUNfpsCOMLs5qoXqoVxlvxN4uhMvt8Gpr1YK8otX5GbJmjDK+XouD9UC87fpPtKbi BaeLuMrnyRCAFtTiDsbdDn/LQhiOu/Sc/t1FAElOmRS8UcCukrPwFTW9lDWJUsQuIZNGIt Sqb2VGtbih0qlYZD6CLiyqN0C6wssf8wWuyXvUFfxISpNwsCvggZ09vW5xF8XHGTYEIvbY 1/l5WBU/OMxb9w5e1Id+yliZqPr1UqrnQwvEKTUNie64Avg7UOnQAA+l/sDEvg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711956875; a=rsa-sha256; cv=none; b=gBtxi6mSljWfsBhgljTBy0ZQuvIzNLsXm+4PknbIXR8O+zqI0R6hKJgS5q0QsDwVveQkAT F/QjismOFzICSSFQAM2rH4EY3T0EWg158B4p+ZREJkZ+x4vZlwpRp8T5IuhbmouAcAt42i G50uBT/OQFRigIsGuuq4uOs/7jyNPufp/pcatoigJuSQY4Wtpsaec9Kdo+Ezndbc+b/cYj agJnpw8wuri+RmXYC2aX9jKxsCoHpA7Pa9ktPotnVVV9cxIu0Z16Y1v3dhuAR/jfEhBSyz h661O1qpPYPdPAM1l/58mvIPI3THm4MpUciY5T9H0A1yqKC2mXoBs0cWyHSYPA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711956875; 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=4Dux3zrwOGtt5R3l+cIy7iNZBn7eWD7GPIzfQC2DjPc=; b=oOovrqnoogKAoyZl0a2s93JbXmxRaLgooMFuSq2HlSdtQdM1AIiFnWA3R2m21qharPs1UF xGzmyATtQ56hmdBRWnWGPVFJSnEflp5Cf8WNP4uR+b665OmzbmIKbWoVebfMtV+X5q49vY MDogYRUKs+JtMnbylNFrAA7g4KUxZUMBLDlk2aIGl8W1Cjk12FPxlqlJlUw8E7udBr+l/R YkIbVCwsQS9LvCdk80+vqob8YuwvdT+naPWrmL2czZv1+gArJzRNb7/lFfcRDmLw+1dzKE 3GUhpYxQK8jCMYQ6+LTjqyPsASdoV4Sd6QbbgBnZa3/wTKXHGIc64UVKJ6Boew== 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 4V7N7b67CWz1Bym; Mon, 1 Apr 2024 07:34:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4317YZnT037611; Mon, 1 Apr 2024 07:34:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4317YZke037607; Mon, 1 Apr 2024 07:34:35 GMT (envelope-from git) Date: Mon, 1 Apr 2024 07:34:35 GMT Message-Id: <202404010734.4317YZke037607@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 0ade521bac78 - stable/13 - pfsync: fix use of invalidated stack variable List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 0ade521bac78929941081b6757e45316befd79f7 Auto-Submitted: auto-generated The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=0ade521bac78929941081b6757e45316befd79f7 commit 0ade521bac78929941081b6757e45316befd79f7 Author: Kristof Provost AuthorDate: 2024-03-24 08:46:31 +0000 Commit: Kristof Provost CommitDate: 2024-04-01 07:33:36 +0000 pfsync: fix use of invalidated stack variable Calls to pfsync_send_plus() pass pointers to stack variables. If pfsync_sendout() then fails it retains the pointer to these stack variables, accesing them later. Allocate a buffer and copy the data instead, so that we can retain the pointer safely. Reported by: CI KASAN, markj MFC after: 1 week (cherry picked from commit 81debbd60e5773e812e9227a2003ea88699580be) --- sys/netpfil/pf/if_pfsync.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c index 939a4d5451a9..a08a8334683a 100644 --- a/sys/netpfil/pf/if_pfsync.c +++ b/sys/netpfil/pf/if_pfsync.c @@ -419,6 +419,9 @@ pfsync_clone_destroy(struct ifnet *ifp) MPASS(TAILQ_EMPTY(&b->b_deferrals)); PFSYNC_BUCKET_UNLOCK(b); + free(b->b_plus, M_PFSYNC); + b->b_plus = NULL; + callout_drain(&b->b_tmo); } @@ -1557,6 +1560,7 @@ pfsync_drop(struct pfsync_softc *sc) } b->b_len = PFSYNC_MINPKT; + free(b->b_plus, M_PFSYNC); b->b_plus = NULL; } } @@ -1669,6 +1673,7 @@ pfsync_sendout(int schedswi, int c) bcopy(b->b_plus, m->m_data + offset, b->b_pluslen); offset += b->b_pluslen; + free(b->b_plus, M_PFSYNC); b->b_plus = NULL; } @@ -2287,13 +2292,21 @@ pfsync_send_plus(void *plus, size_t pluslen) PFSYNC_BUCKET_LOCK(b); + MPASS(b->b_plus == NULL); + if (b->b_len + pluslen > sc->sc_ifp->if_mtu) pfsync_sendout(1, b->b_id); - b->b_plus = plus; + b->b_plus = malloc(pluslen, M_PFSYNC, M_NOWAIT); + if (b->b_plus == NULL) + goto out; + + memcpy(b->b_plus, plus, pluslen); b->b_len += (b->b_pluslen = pluslen); pfsync_sendout(1, b->b_id); + +out: PFSYNC_BUCKET_UNLOCK(b); }