From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379629; b=VCSjtQhEzSftZaimtlVljxk8+LZP9qdkA1nZoaxLSHXwdXyHtRTf7Zk6DVizAxII1biG 5wUFDN25o6/yq2BYKLkXqC1OWwq81NmrskGrsRrwuyVdfHuXjdQ4Emmz4XZRJTVm1nJ/5 xj9gKwdWF6rzcCW3kiNIUSIzI+BqhqmIo4SZBKQLpDm+dJnC1wo9pUjfFhpuiRHQjZ+Hj Rt66SvQ+YOSHcnDD7EgC9M4fHjEG1Yl5aAzze8iWif3BB2GYQz8BsuHMjDUZZH7S0kIh3 7If8aO1ECcSlVQflmyGyeC2BKt6hbGIXTmBnjuRPs4TPIpDPhx7NRs0EqREyH8w2IAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379629; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=TUk2rVqFdazr5H7xnhF8yPU53QkjBj72IYc0u/4jouY=; b=zN0nPCofw39X8vSt1QZCv2j0CTjcg8SX7sZSOOSDIbN9bgakczMYXlfxp/GDb8i1IahI Dzi72gS8q4xLkZxYKqNyCuzHzKHzXeLwIIl9uyqFvSTCpdWuqJ5gB7d+NKDqnNlTyKD0n bUYX5RhnoQI/75Sn5pnrpuwxctY208M7ZPx6lsmlEkbf1O8Hnawf/pFvPA8vxyVKsR1Do Nub4O8n+YqJi0GhT6+TK8iANPHjjw2V4sunZ/GZg4brmE5yt6vIgKAxV20pmQkrWDiex+ aB1z6E/vj0DRBcArJHZSRxIc6M5yvyyiOjZ4BCYO+/i/o8kGcMffH3p83VexniNYkUg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=V8Enxiy2; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E281606A322; Fri, 4 Dec 2026 10:20:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=V8Enxiy2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4C581F000C2; Fri, 4 Dec 2026 10:20:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379629; bh=TUk2rVqFdazr5H7xnhF8yPU53QkjBj72IYc0u/4jouY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=V8Enxiy2o3vJVO+1UxENPifYgADLmNrUemCReT15On3+EFG/BrHb82nlxJ+e4F0dy nSP4ZF6ZC5VrpNrguDZKDcaVSaVVEfCBCo0MPVzHkH6FzWxhKgwDgq+0sqf0OQLAYU O+E9oeNHeQxsmI/isdBVqdnvQIGLfZcBUz9bfR7w= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Johannes Thumshirn , Thomas Fourier , David Sterba , Sasha Levin Subject: [PATCH 6.1 0037/1059] btrfs: zoned: fix double free of bitmaps on clone failure Date: Fri, 4 Dec 2026 18:52:48 +0900 Message-ID: <20261204100645.006480801@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Fourier [ Upstream commit 8c66a6aa59a5df1d672d72b7cd379d897ff73200 ] btrfs_clone_dev_zone_info() duplicates the original orig_dev->zone_info with kmemdup(), which also copies the seq_zones, empty_zones and active_zones pointers. The clone then replaces them one by one with fresh bitmaps. If one of the allocations fails, the error path frees all three pointers, including those not yet replaced, which still point to the bitmaps owned by the original device. Clear the three pointers right after kmemdup() so the error path only frees what this function allocated. Fixes: 21e61ec6d0bb ("btrfs: zoned: clone zoned device info when cloning a device") Reviewed-by: Johannes Thumshirn Signed-off-by: Thomas Fourier Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/zoned.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 2f9c6540b2655..d3f320e4dc7ce 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -652,6 +652,11 @@ struct btrfs_zoned_device_info *btrfs_clone_dev_zone_info(struct btrfs_device *o if (!zone_info) return NULL; + /* Don't let the error path free the bitmaps still owned by @orig_dev. */ + zone_info->seq_zones = NULL; + zone_info->empty_zones = NULL; + zone_info->active_zones = NULL; + zone_info->seq_zones = bitmap_zalloc(zone_info->nr_zones, GFP_KERNEL); if (!zone_info->seq_zones) goto out; -- 2.53.0