From nobody Sat Nov 14 04:47:05 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 4jRM6d2T56z70gFt for ; Sat, 14 Nov 2026 04:47:05 +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 4jRM6d1xDQz3HBK for ; Sat, 14 Nov 2026 04:47:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794631625; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VrvaYKgDmSMMkLzK2xKRoX+wlw9/HncS1I1u8BqlBR4=; b=mD+Y2TaPuLpko2G2UgMyYfzGPbacZvmp2SOcRKPp8hpRjq/JMWK8hrs4bikfvRhSvo6vou aOEZoa5oylI8kMpNcYGOdoGVKmZrokn8mVAD1fcpwlPzEeYvZnzDgcrwlH7xSFIGg5pPE0 oePZWtD++WjXAwAwA0Gv2QHb00F7qRpLiB21QjSO4f0KaBCWKEO/On7uNSWb+6MSty3k6E Ml9/dRduqDl2wh8G/6WZFCYQKNkgWrtRmOJoSmoZAmvwyRdcibzJuxi/q9V8P0u7wQbOTl fzOjbKvMa6oSwBuMZnBZHW0hnZdWY+VMpekkyl2j2zDBDGqI8mUutPJTjTKsOA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794631625; b=b0yXhOdB9pSxTDPZrYL8UAsN35A7QWB2Zx6X8R7zsicTI7HBaHZyEtZ4wxjvf/w3dcVMwI DzrZc6liNHs+Y6521px0dSg3NqYF5bW9QhamdjuB7376lEbX2fGIIw3WlHIe9K0/Qs0hmj zawMQpM8aijFhAGtRSJFMVeYr/tXskzntt7DSn6eOzEkgNTZk1W3jV3rCs7Ks5hUVdZmm7 zYBfdODwxKd+G5tZGbwd/kcT8Nwxxndk0dzVjmzZFce1IqXMdFGtlYWIA8/Yq1zJWXodsW ohHc7RIXSPKeB/55fEJ9tUKbZbZG2eib7R5p0Q4H4MztNGme6oY5EIOwc4uIFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794631625; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VrvaYKgDmSMMkLzK2xKRoX+wlw9/HncS1I1u8BqlBR4=; b=YS51i72g8pyi9ZuLsHSRnNSH0t5vz3YaIkrP9ucWFam2sT6gBL0cvsSZBTwUzvMklMk7AX NP5cX+WSLCINy1WK+gLC02xvRQH7r5Brw1kUtuQmFnAkptleiSYcckYJ3K+HreV2dt/Fso Lue2KPb4x3r9ZxkVo+qy8W7sH/Fo7YG9GxP7DJMYaab50RelnRSDWSZH9Cq+QPxWIcz3tc 5cqZKsFmTUXunsyDhRGpwmYw5E5C8RUrWAOaRmixa+Y06hb3+BfnTlbMdxV583zD1Ful6F Sh1TxQPS8eCjLB9g8JYpR90mzp9t9mwGwjq7xsxzFljr0/ZexVxn9NCBmACyFg== 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 4jRM6d1HHzz16HF for ; Sat, 14 Nov 2026 04:47:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 17618 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 14 Nov 2026 04:47:05 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Patrick Domack From: Ryan Moeller Subject: git: fdd6b206a303 - stable/15 - Fix double free when cloning a block with a pending free 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: rmoeller X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: fdd6b206a303a0bdef94a6468b345c10ac53351d Auto-Submitted: auto-generated Date: Sat, 14 Nov 2026 04:47:05 +0000 Message-Id: <6af7e7c9.17618.45990efa@gitrepo.freebsd.org> The branch stable/15 has been updated by rmoeller: URL: https://cgit.FreeBSD.org/src/commit/?id=fdd6b206a303a0bdef94a6468b345c10ac53351d commit fdd6b206a303a0bdef94a6468b345c10ac53351d Author: Patrick Domack AuthorDate: 2026-09-09 18:08:26 +0000 Commit: Ryan Moeller CommitDate: 2026-11-14 04:43:50 +0000 Fix double free when cloning a block with a pending free dmu_read_l0_bps() captures the source block pointers for a clone without consulting dnode_block_freed(). A block whose free is recorded but not yet synced still has a valid on-disk pointer, so the clone registers a BRT reference to a block about to be returned to the allocator, and it is freed twice. On a debug build this trips the metaslab double-free verifier; on a release build the space map is silently corrupted. Check for a pending free and return EAGAIN, as dbuf_read_hole() already does for buffered reads. zfs_clone_range() waits a TXG and retries, by which point the block reads as a hole. Two cases need more than the plain check. A hole has nothing to free, so guard with !BP_IS_HOLE(bp), otherwise a hole inside a pending free range fails a FICLONE that master cloned. When the head dirty record already overrode the BP, only frees after the override count against it, so use dnode_block_freed_after(); dbuf_free_range() leaves the override in place across a later punch, and cloning the clone would otherwise capture it. Reproduced with fstests generic/733, which panicked within a minute on a debug build, and with a FICLONE of a sparse file in a pending free range. Both clean after. bclonesaved is correct and scrub is clean. Suggested-by: mkhllr Reviewed-by: Tony Hutter Reviewed-by: Brian Behlendorf Signed-off-by: Patrick Domack Closes #18842 Closes #18853 Approved by: kevans (mentor) (cherry picked from commit 39764eb06bd079b31cf830c8582870753aebcafb) --- sys/contrib/openzfs/module/zfs/dmu.c | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/sys/contrib/openzfs/module/zfs/dmu.c b/sys/contrib/openzfs/module/zfs/dmu.c index ad654b163195..229729672cde 100644 --- a/sys/contrib/openzfs/module/zfs/dmu.c +++ b/sys/contrib/openzfs/module/zfs/dmu.c @@ -2668,6 +2668,44 @@ dmu_read_l0_bps(objset_t *os, uint64_t object, uint64_t offset, uint64_t length, bp = db->db_blkptr; } + /* + * A block with a pending free (a truncate or hole + * punch not yet synced) must not be cloned: the clone + * would add a BRT reference to a block about to be + * freed, so the pending clone would apply onto an + * already-freed DVA and double free it. Report + * EAGAIN and let the caller retry once the free + * syncs (the block then reads as a hole). + * + * A hole (or absent BP) has nothing to free and is + * cloned as a hole below. When the head dirty record + * overrode the BP (a clone in this txg) only frees + * recorded after the override count against it; + * earlier frees predate it. This mirrors + * dbuf_read_hole(). + */ + if (bp != NULL && !BP_IS_HOLE(bp)) { + dbuf_dirty_record_t *dr = + list_head(&db->db_dirty_records); + boolean_t freed; + + DB_DNODE_ENTER(db); + dnode_t *rdn = DB_DNODE(db); + if (dr != NULL && dr->dt.dl.dr_brtwrite) { + freed = dnode_block_freed_after(rdn, + db->db_blkid, dr->dr_txg); + } else { + freed = dnode_block_freed(rdn, + db->db_blkid); + } + DB_DNODE_EXIT(db); + if (freed) { + mutex_exit(&db->db_mtx); + error = SET_ERROR(EAGAIN); + goto out; + } + } + mutex_exit(&db->db_mtx); if (bp == NULL) {