From nobody Sun Feb 8 05:08:16 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3382B2475CF for ; Wed, 17 Dec 2025 17:19:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765991955; cv=none; b=FvvGBsZcvZCy9xWMfxwEcRvj8N3Y4z2XC5UCjyPJmrEU/xnlRDHWuJHa7pcmm4vtt/Azpeapsen2svAHyl42Q+S5BK2UI37iAS+wleFkKbkHp6K1487g9DBJ+lxXyZ7caJZoYwh6d3Rzn5PREpGNOmnA+cWNTpwKGHBlvwX0FH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765991955; c=relaxed/simple; bh=PhWmqG0vu+gCeyUMnCwiS6JRUSoAjuRw55yZTHXx/ZU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=JhpJ5SlgyZ31H2tEA1NH3ZEoECK+wgV4E81dDUO+GSLU2mb6ZthH7BiMu+n7ESge1svKMmw39FIhcmn6GIISHdLRo3+CIZ2I9heAfbzG7wNBHDzeHrcIxwl/W4Tw7SBql5KbXHuRiqEXH6MNDz8+eCAqpY2d8ST62myuhO1dalM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=d+c8MTey; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="d+c8MTey" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2a137692691so26697705ad.0 for ; Wed, 17 Dec 2025 09:19:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1765991951; x=1766596751; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Y3LrPFakvwygW1mGO7QQNc0jtsk3gCAQdHtYav1hcwg=; b=d+c8MTey3DevbeCLoDsBdo9judcaRHXuWB3qZVzvhW2wiB0tmzl1g79vC3pu8iWVgD 6+/TbKoyb6H5Kke6wZYBQYnSS5ga1gBvPARHrXbHNrYvN6+VL9MFkllyMRYT9W9XJK5M VwBCIFx43hniWMd3wkLGvjonkA2+vq6XIpvk7C/dVE9U0JVS49qfsRljT7ievONX+ZKM mm0qbieSueAYm7A/KrX4f5nUz+HYLoQ/YX+aYYNzFkQ5+RWVTNUwv74GRgx5em4CB7SO d0UqH926tUH5RpxnFokBwvK/R8Le6ZvO7jqVkE369PGzdest5Si9oEsfaDK+OrFXyYU0 QPMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765991951; x=1766596751; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Y3LrPFakvwygW1mGO7QQNc0jtsk3gCAQdHtYav1hcwg=; b=bke0dmCsiUYvRNNtZqNsxNReRN3fFYQtSLMKN2ZMMSU5a3PXQj8i6+fKYhxlCRDOzB om0uv6+QpcyVbVBvIdUU3pBQl3b3B6g+lxMikFayVc8xh2MHDqgIbUehxHULnAvWtUBH T7WCCJUuzT3JgJ+105QHvtpJ1EBQhOOJrG7yMQ1ITZrThxGrs3Wv9uEJqnJHyAADpe6a hcuieqlEiG9VLWA50Eqj8TEt5852/3rfzxnw8R7LTSx4GKWG5qMbDQ9rcx0DCjWdcfZj wJ+ZflBvr1sPjaZ2q0i2jPkRXoz15A9KceIpPlL/SB/gwAYqWB1gWgkKmFdYNKIR63cS KwKA== X-Forwarded-Encrypted: i=1; AJvYcCXykLvta/80IomPP6WoCa+1LyqxcO0x8IdI8zrOUfOY82gQVh3Lym8YjEKTuv4TF4WMOLPJk9a+Ri505Xs=@vger.kernel.org X-Gm-Message-State: AOJu0YxBFLmhS3MVp6nSor67ATUCbaEgiShDM1uFHmFQBtSjm0jMnYB6 byKFnr3bFtlHBb8sZcbvm984o+l879SS1qk8UzP6jYol+KF0TY1Fo9dSp83wA7h1BDk= X-Gm-Gg: AY/fxX7DyFjQE0nk87tbvoS9BnzCU1lUOa2OI6+rC+hvpSlpmZBB2Uz1HGFIYuo2mlg clqMAVmU7CS/e4GuNOsmXo7DGOHvSHDPZgZfsOXOySiHoJ8ByVYEqCapeDNT5DA4j+dUYUqCH/p lNKQ4m8XSFrAXQVuB0hWYjDBT4dK8OtWlIpQAOMas2F8B/cMXLVsqSblaKws5y5KAJ0IvNLk1bW pzqB3jWsRSqNHMgH48cUeG9DOse+4Q2va/NbkUEQ3dVjVzT6Ymyk9S1xRiM3XnBCFkYRWjgxtXJ SsjExWU8AvOkSrYbLSZc9I7qXqtVbPqeCT8AvmXS6v3aFRMnixRQV6iuIPs3PUyUb0yLxznnVQG ioZucqEPcGnpX7gcoQ34tMh+ME1LbTSIla0KLS8B0qFeLVsLyepcWCA595en0AxHuGmwaHkFBu0 ilBmB6zDdJb18WBKkVwOXvBhNmcsMMSu/pAka1Bg== X-Google-Smtp-Source: AGHT+IGLeUXapTBEv/2bQX/CS1eAaM72hI63SCMBxHHzY/vLcw1Jr5zpynwINplOjGbg8sQGjhvXNw== X-Received: by 2002:a05:7022:3a0a:b0:119:e56b:9580 with SMTP id a92af1059eb24-11f34bd915amr17286041c88.5.1765991950520; Wed, 17 Dec 2025 09:19:10 -0800 (PST) Received: from dev-mliang.dev.purestorage.com ([208.88.159.129]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12061a94f2bsm121461c88.16.2025.12.17.09.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 09:19:10 -0800 (PST) From: Michael Liang To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, mliang@purestorage.com Subject: [PATCH] blk-mq: always clear rq->bio in blk_complete_request() Date: Wed, 17 Dec 2025 10:18:53 -0700 Message-Id: <20251217171853.2648851-1-mliang@purestorage.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit ab3e1d3bbab9 ("block: allow end_io based requests in the completion batch handling") changed blk_complete_request() so that rq->bio and rq->__data_len are only cleared when ->end_io is NULL. This conditional clearing is incorrect. The block layer guarantees that all bios attached to the request are fully completed and released before blk_complete_request() is called. Leaving rq->bio pointing to already completed bios results in stale pointers that may be reused immediately by a bioset allocator. 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(). Below is the codepath of such double-free: nvme_pci_complete_batch() nvme_complete_batch() blk_mq_end_request_batch() blk_complete_request() // called on a DM-target clone req bio_endio() // 1st free of all bios of the clone req ... rq->end_io() // calls end_clone_request() since @rq is a clone = req dm_compelte_request(tio->orig) dm_softirq_done() // Note this actually defers to softi= rq context dm_done() dm_end_request() // end the clone request blk_rq_unprep_clone() // 2nd free of BIOs o= n the clone req There is no valid case where rq->bio may still reference live bios at this point. Clear rq->bio and rq->__data_len unconditionally to avoid leaking stale pointer state across completions. Fixes: ab3e1d3bbab9 ("block: allow end_io based requests in the completion batch handling") Signed-off-by: Michael Liang --- block/blk-mq.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index d626d32f6e57..b8b9ca2200e4 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -905,10 +905,8 @@ static void blk_complete_request(struct request *req) * can find how many bytes remain in the request * later. */ - if (!req->end_io) { - req->bio =3D NULL; - req->__data_len =3D 0; - } + req->bio =3D NULL; + req->__data_len =3D 0; } =20 /** --=20 2.34.1