From nobody Mon Nov 23 00:36:11 2026 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 4jXn6z5rBTz71NFj for ; Mon, 23 Nov 2026 00:36:11 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jXn6z3cSwz4QTW for ; Mon, 23 Nov 2026 00:36:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795394171; 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=pI0ZfdUK1io2VLuYlV9pvT6UBJOPN2/0nIV2Jp7RIb0=; b=DQFWfDP3Mj3nTO49yVe72CY9QQOQQYtSmolh7HsXUGtj6aMO8BIwvTEzr2624sev5vQ/Vv OTzAjMdAEewPNoZUclvQttbKRJYi44Tg9c/A/cZVyyNK8bggA11ldo1rOyt8nek2QfSwQU +bWVQ5Y7plLGbtJNuR210ZTFbG2CwP+IyVct3KqN0+pQLHmgdV4bnAaCuqPJ4wgakRgKyE N0PBcYYtqiOlDBAYBpyPzwhE+XtiTAZnBC32z75a0v4nCYZDD+78T5QOlgRGLziZkfbwrC OmUjDym4RVaqVdKQcf7iY4i/guVES+LrMb/AY3DiHFpS+qVezorHf+hjgtaYTA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795394171; b=cQpNm76z5hihJ/UKU3USi3l4CNuxWAHnzdcU/IbVYkGrs7YULohE5ewARz7UVsyJ9G8jHU qayeqrMjlomWUFmZJ+NtcKRMW82FBsGCTeAcSxuZmxlDNg/AYSdn5xB11Pt4mtyzlipgyY nrGOpBVyhkAe2QYQJvj59rm5CiYJBK7YasxxfoTefa/3k2tZlECjGiLLHzsi+3UN0vYZGY 8Kt5GiY/UdPzy2c9g6qRQik1JBE1oSCOilWM3MAN1sZ3KG49qoImK60BiuBB+KfHdrognv 09F01dB4shmyigtsz0Ouy94ZYyQKCk747f4IriYKQRgOo3luZ+Eel7YCiGNs/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795394171; 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=pI0ZfdUK1io2VLuYlV9pvT6UBJOPN2/0nIV2Jp7RIb0=; b=crHJ5nJZfKiIUUJzt9DSQzOOcSdf9FYIuXDKzc0YYz8yQ80RFhSgqz5zcx1UkLo8tNE0kM 3+pe4MyK7io8YURJPxd7HBA+FE4ckW0jbBNa2dGF+RwN0UPBeGznHbVQEg8vMGdZLVyCJx RHk5FOdLoZ9JzhuWVRRpKu1tqcLPnpzisTpmtStZRobMYnOLOmZ1nOwgMzRoS59pI0KZME pOuqFp6JLDg3lzLueagZZyk6kjTGYyXzZrw3Fzp19crxABupDPwdQylV0C/npvOxRDluJa nBS+9C6ypragKV0/fJsHbgdBQG5FtCtOZ2zWKwRfX07a1h3c4wwesrh6XQcRMg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jXn6z30PLzRlQ for ; Mon, 23 Nov 2026 00:36:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1ef81 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 23 Nov 2026 00:36:11 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: a4a353f0d089 - main - vm_page_unwire_unmanaged(): fix a double free of the page List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a4a353f0d089d35aceeaf26df7ab436de20fc8cb Auto-Submitted: auto-generated Date: Mon, 23 Nov 2026 00:36:11 +0000 Message-Id: <6b038a7b.1ef81.7760a761@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a4a353f0d089d35aceeaf26df7ab436de20fc8cb commit a4a353f0d089d35aceeaf26df7ab436de20fc8cb Author: Konstantin Belousov AuthorDate: 2026-11-22 00:31:44 +0000 Commit: Konstantin Belousov CommitDate: 2026-11-23 00:35:14 +0000 vm_page_unwire_unmanaged(): fix a double free of the page The function decided to free the page when vm_page_unwire_noq() reported that the last wiring was released and a separate load of ref_count then returned zero. For a page that belongs to an object, the object can drop its VPRC_OBJREF reference between the decrement and the load. The load then sees zero, and both threads free the page, which ends up on the free lists twice and is later handed out to two owners. Decide from the value returned by our own atomic decrement instead. Reported by: alc Reviewed by: alc Fixes: fee2a2fa3983 ("Change synchonization rules for vm_page reference counting.") Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D61860 --- sys/vm/vm_page.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index 6ead05a274b2..b69443088002 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -4385,13 +4385,29 @@ vm_page_unwire_managed(vm_page_t m, uint8_t nqueue, bool noreuse) bool vm_page_unwire_unmanaged(vm_page_t m) { + u_int old; + MPASS((m->oflags & VPO_UNMANAGED) != 0); - if (vm_page_unwire_noq(m) && m->ref_count == 0) { - vm_page_free(m); - return (true); - } - return (false); + /* + * Decide from the value returned by our own decrement. If the page + * belongs to an object, the object may drop its VPRC_OBJREF + * reference concurrently, see vm_object_terminate_single_page(), + * and a later load of ref_count could make both threads free the + * page. + */ + old = vm_page_drop(m, 1); + KASSERT(VPRC_WIRE_COUNT(old) != 0, + ("%s: counter underflow for page %p", __func__, m)); + KASSERT((m->flags & PG_FICTITIOUS) == 0 || VPRC_WIRE_COUNT(old) > 1, + ("%s: missing ref on fictitious page %p", __func__, m)); + if (VPRC_WIRE_COUNT(old) > 1) + return (false); + vm_wire_sub(1); + if (old != 1) + return (false); + vm_page_free(m); + return (true); } /*