From nobody Mon Mar 25 04:44:51 2024 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 4V30hz459fz5FHws; Mon, 25 Mar 2024 04:44:51 +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 4V30hz3NThz4KGr; Mon, 25 Mar 2024 04:44:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711341891; 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=9StO0E4XKwA9yrTAhVGwhiOePNd5pcOemFcz1M/BTwE=; b=vD1wMMASNnt5KuewHjUwQP+I3DUxcxcZwmIUEMk5n+FGEPZLE3gZYymbQHB2qIJ4v6S3Ab ujnArrSl9ar+YNPD+UCNYhUJwsVuLxR9KOLRl16okPVDKOR+pkuCDndsbED+yr9QCmUBBB XRhStL9t5Sl4Klxll1whBVfjgAUrnT056qdIuDNSGz4QFyzCgugW5YYQPr6uWIVrWZxRMP 65DEbXfAadN5SvqKr8g1MZI8BDEWoLQFvGuc0RUO3FjDn73p96S5vsVavaCdgYqU29Wzgr 8cblR+34yCjb7lhEl5/a77wRLSqBBQbN/sTogP874EkRiExSPJfQF7z31VT4HQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711341891; a=rsa-sha256; cv=none; b=aRNiKlXPugdRa3W7tE3waPx+/Z4o7bu2qr5p0FUHOOAZEe91jxmtE9VPT74xKs7Y76+YwD /zVm0n2H1Urz9vjhn+gpDhDgMPp9Cb8FGgyG6/fZKIWghFhHyQu1skrwykaN6WAPrB6iT/ cnxrJwhNf6yfj58qHT8f7wJkbCVTtK1zJPYFdeCrZyNBTjzhUuiTBOPBmE5EVgSbkmi4kf 4KSdE2sMZ1qeptnx1C77BsrZnv9F0x1nTzyIyjORhw+que3n8pgYVZ1wRb6HiH78ikiUXT is8WZ9sq+KG/Mf52L4lvJxa9EgD4cExfXbsj5RVVJE9hCv1qnH/Ycmq1R8+nBQ== 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=1711341891; 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=9StO0E4XKwA9yrTAhVGwhiOePNd5pcOemFcz1M/BTwE=; b=IijPuZOOaHmFjH9ODbwTxPfkZJt700Ynyy1DPlO0RPBtJCfsHrtvocGxmn9Rq7eaI3PO3P GdtkdTF2fvwnqtp/YB3Fn/ryHa18LgYlCjToUFhVFz5sz0dUs0T7r+ltHTeo9dR6w5kHfd rHaRY/pTydwa8cb1UkSsvTf90xTjNDxBHhQGkDrjkhgNOcy+9i0iBxQqe827CaY7ljJLAM 9QWON97zqy9TDUu+Dguip7uNZOZCrVDoHzPT5Tb4Eh8CSpRlSToPNqajQiVsoNHnaGKosG JaG2cUJqswmbXw6Rc5heqW6DlPnO6exxuRD9PfzlnXh3VAcNbesozengwBdhEQ== 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 4V30hz308xz12X5; Mon, 25 Mar 2024 04:44:51 +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 42P4ipcg049799; Mon, 25 Mar 2024 04:44:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42P4ipuX049796; Mon, 25 Mar 2024 04:44:51 GMT (envelope-from git) Date: Mon, 25 Mar 2024 04:44:51 GMT Message-Id: <202403250444.42P4ipuX049796@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 81debbd60e57 - main - pfsync: fix use of invalidated stack variable 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 81debbd60e5773e812e9227a2003ea88699580be Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=81debbd60e5773e812e9227a2003ea88699580be commit 81debbd60e5773e812e9227a2003ea88699580be Author: Kristof Provost AuthorDate: 2024-03-24 08:46:31 +0000 Commit: Kristof Provost CommitDate: 2024-03-25 04:44:24 +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 --- 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 e90bc60b85fa..6e43071e1d0d 100644 --- a/sys/netpfil/pf/if_pfsync.c +++ b/sys/netpfil/pf/if_pfsync.c @@ -474,6 +474,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); } @@ -1766,6 +1769,7 @@ pfsync_drop(struct pfsync_softc *sc) } b->b_len = PFSYNC_MINPKT; + free(b->b_plus, M_PFSYNC); b->b_plus = NULL; } } @@ -1906,6 +1910,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; } @@ -2563,13 +2568,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); }