From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1A7A3F6ADA; Sat, 28 Feb 2026 17:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772300562; cv=none; b=Sk3IwrfuFzPN5R3ESnjgVPbmnzKDQdwT+DYQdXp5G0WIDT1eyY2ZOjwF5SD0CDq3YGMVhIxkxd+fXR/QW/sOV1r+dwRjO1I2w1SSnuw3MHN7m4H8079w6tmJilx6UuRSgRLse1gbYGipFqAPPRMPMklQYJ1d8aQ0w9czrD3TM5E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772300562; c=relaxed/simple; bh=g+lQ6eEmCsqoIVmNzQsNBTXxuJYWt6+/ZurWb0pCyQ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iVhnVMx9NFER3fIvso0HLV8D4H+C+Ik8UOY7x+GEHw4ldqVBRdcfS+BzWi3omvwEwDUMMTQfvh8iQ+L6hIgNtOjPmuQnr7k/YV80SJ8/lTLY9J5Kx1yhEUdQ+WJcGj0qsWr3gHY+Ofw1zZAAODuTEdVsTDxgud5PPTyF/Mdf/io= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BCA9oAB2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BCA9oAB2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BECF4C19423; Sat, 28 Feb 2026 17:42:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772300562; bh=g+lQ6eEmCsqoIVmNzQsNBTXxuJYWt6+/ZurWb0pCyQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BCA9oAB24od+rO+L47PDP8gxkF+jO2Z/vf2oDY7C2bEIlYrLhfwEq/etvvk/eP/Eo WflEek7a4cpG+njOOnr2mvw9/p4xyK82fkJVXHEMdeYCaqrll62HDiUcLr1I7cnKee F6XxGoAGqMIu33YQC9v7VR1rj8o2mMtDA3pcrfqCZ2DEQFwFuzQ5f8/eTihEMl6JsB Lml1ubTI6ZNoPcl0KqCDVqA9F8aFrfBuhkyv6+ooQhaQ801PBvV7KuixlwxofqmBrm zSDqURZSCeg3L574CpKwFpRXuMIxa4SzcJzVyfXMh4iPac6rxWlL1SIl9yn3hlze4u rjsueGfVSpI8w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Michael Liang , Mohamed Khalfella , Mikulas Patocka , Sasha Levin Subject: [PATCH 6.19 602/844] dm: clear cloned request bio pointer when last clone bio completes Date: Sat, 28 Feb 2026 12:28:35 -0500 Message-ID: <20260228173244.1509663-603-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260228173244.1509663-1-sashal@kernel.org> References: <20260228173244.1509663-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Michael Liang [ Upstream commit fb8a6c18fb9a6561f7a15b58b272442b77a242dd ] Stale rq->bio values have been observed to cause double-initialization of cloned bios in request-based device-mapper targets, leading to use-after-free and double-free scenarios. One such case occurs when using dm-multipath on top of a PCIe NVMe namespace, where cloned request bios are freed during blk_complete_request(), but rq->bio is left intact. Subsequent clone teardown then attempts to free the same bios again via blk_rq_unprep_clone(). The resulting double-free path looks like: nvme_pci_complete_batch() nvme_complete_batch() blk_mq_end_request_batch() blk_complete_request() // called on a DM clone request bio_endio() // first free of all clone bios ... rq->end_io() // end_clone_request() dm_complete_request(tio->orig) dm_softirq_done() dm_done() dm_end_request() blk_rq_unprep_clone() // second free of clone bios Fix this by clearing the clone request's bio pointer when the last cloned bio completes, ensuring that later teardown paths do not attempt to free already-released bios. Signed-off-by: Michael Liang Reviewed-by: Mohamed Khalfella Signed-off-by: Mikulas Patocka Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin --- drivers/md/dm-rq.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c index 5e08546696145..923252fb57aec 100644 --- a/drivers/md/dm-rq.c +++ b/drivers/md/dm-rq.c @@ -109,14 +109,21 @@ static void end_clone_bio(struct bio *clone) */ tio->completed += nr_bytes; + if (!is_last) + return; + /* + * At this moment we know this is the last bio of the cloned request, + * and all cloned bios have been released, so reset the clone request's + * bio pointer to avoid double free. + */ + tio->clone->bio = NULL; + exit: /* * Update the original request. * Do not use blk_mq_end_request() here, because it may complete * the original request before the clone, and break the ordering. */ - if (is_last) - exit: - blk_update_request(tio->orig, BLK_STS_OK, tio->completed); + blk_update_request(tio->orig, BLK_STS_OK, tio->completed); } static struct dm_rq_target_io *tio_from_request(struct request *rq) -- 2.51.0