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=1796379706; b=CCTDBqYONhgPTeBix+ztZzlt6SiqUd5YQqKQcMnrFZBBRBQDzZFCTHyZ8ayugxCwhziy sggp8dJDrp2JWJz82BXBJDgFjzZoX9GmV2YD5G9ipW/bqry7wgZmv3w9aQVZKgNlVQf4T 2rwzxcCq5FfxmKvgRO3DQ10JbFH+AbuIHePIhTSMWNHqfGAV/S9NAukZQcEpbqhVz+Ozq dkbwXXn+ZPbQgqRCcWW7ENQqHjKrBl5aSrv3s1tXHe+zLA/mClI0aJGId5+Q9PEguI+Bl 28W/jmS/omuEFD5S5rG6XNMaBYnxd3pwTW4VVNDfi+H/17R5JWnuZuHaq4JHRfbwRHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379706; 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=zQ6Glusg5vBiylIODzkAwB1r60ZF5Ia8E6Vkte5YiRE=; b=X0Nw1gFpZvZMDoJNx+rgZYU54N3XlAQPb/k/bHQ8Ky7geAYzemBCn4boakbdZnhozC9g ZNnfsPSS2ZkpH78iCkDNH7WReNt5X1GZvVtdVpV/QOTDAyhV8YFOPdgc5kkSJIvnuIzRg gMhGUihS3liZCye4kHxfBz7CVkldLYpTEaiCVrOoR3Z2b1qwYiRCfyQ2VMMuJaUnOTJKi 2fE9cRQ2IsqGLqe00jeX0QKebyN8vzpdO3GEhLFHwJg49AfXis+HSh5HPZ+Or227Xtaqy WcS9yl5GpF3E4dDjTDq1uk0XMqUNF/l6mamQTixJovCHhT7Zsd8UiMDoG2LRyQF9xZg== 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=Mg1Auln6; 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 9E066606A32C; Fri, 4 Dec 2026 10:21:46 +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=Mg1Auln6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 114DA1F000C2; Fri, 4 Dec 2026 10:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379706; bh=zQ6Glusg5vBiylIODzkAwB1r60ZF5Ia8E6Vkte5YiRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Mg1Auln609YZear+sx25DR8CbpcsjpdO/wK17FDPJzFmsQRwvpp5stzM0gdLdwcVY jZTXyuQnJLI8k0esqdAXNHW5ivnm9i3H0IiIiVqkbR2P2ErJpy0D+ZUIvRCPtkm/xu gB52wK6Be9+yMXL5cSo8jcnHEeOqtjh4AOOJM93I= 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.6 0053/1167] btrfs: zoned: fix double free of bitmaps on clone failure Date: Fri, 4 Dec 2026 18:51:20 +0900 Message-ID: <20261204100703.452517567@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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 20d752eaefc97..12a11aafc16ca 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -642,6 +642,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