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 0A40F2E3366; Tue, 15 Jul 2025 13:27:43 +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=1752586063; cv=none; b=ZR5hYXrFBXz7PH2VZrploVv8LMDcCVyOBewFAEB/M/MkOXimBTAEaQUYnNn6+Dx0qA2uubkw4HGpnKLE9gutR4OdwyY8rCh9ypgsbeknX8UrZ3Ot1BdAeyppu9O1gTDCTR0WmMvhcsuWGQv76JPAZkG3pyA8ZxjYDcaHIrYxlFo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752586063; c=relaxed/simple; bh=wyal/KOZkAgOWKtAd5+mLFmbLT7LoYWUvRVWiW1kwp8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AAaGhnWpEf5hw2HbjF3Jq7HGSzih3c8d5i6cHXnmn9c4wLpYNVrmV/Di05RopdQTwt1cU+5sTQ5DgWIl7vOp+m5JigwqIWqLXi/39fJgYmiWlXFoSSaYwgaXrKfECmtA4nou37K7X+rARYpLF+3Urc0WGA3IQJI06xVIisTEsDc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=O0HNfq/z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="O0HNfq/z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90DB7C4CEE3; Tue, 15 Jul 2025 13:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1752586062; bh=wyal/KOZkAgOWKtAd5+mLFmbLT7LoYWUvRVWiW1kwp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O0HNfq/zNC/s0pDXdF3w88rUcy+0ePvG7e1IyNnST6FDu/P6nArlKawcPQnmTDHPf xSIG+cGkcd4mOKqTnSxUxKHJzeclNrWYzLNapwftlZXY7E+pldpW5YiCPWWL/hnfZV nB3Sb5C6m5TVI9yusQTGi3SE8iSNCq8RYvi3nvQ8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Wang Jinchao , Yu Kuai , Sasha Levin Subject: [PATCH 6.6 080/109] md/raid1: Fix stack memory use after return in raid1_reshape Date: Tue, 15 Jul 2025 15:13:36 +0200 Message-ID: <20250715130802.084700816@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250715130758.864940641@linuxfoundation.org> References: <20250715130758.864940641@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wang Jinchao [ Upstream commit d67ed2ccd2d1dcfda9292c0ea8697a9d0f2f0d98 ] In the raid1_reshape function, newpool is allocated on the stack and assigned to conf->r1bio_pool. This results in conf->r1bio_pool.wait.head pointing to a stack address. Accessing this address later can lead to a kernel panic. Example access path: raid1_reshape() { // newpool is on the stack mempool_t newpool, oldpool; // initialize newpool.wait.head to stack address mempool_init(&newpool, ...); conf->r1bio_pool = newpool; } raid1_read_request() or raid1_write_request() { alloc_r1bio() { mempool_alloc() { // if pool->alloc fails remove_element() { --pool->curr_nr; } } } } mempool_free() { if (pool->curr_nr < pool->min_nr) { // pool->wait.head is a stack address // wake_up() will try to access this invalid address // which leads to a kernel panic return; wake_up(&pool->wait); } } Fix: reinit conf->r1bio_pool.wait after assigning newpool. Fixes: afeee514ce7f ("md: convert to bioset_init()/mempool_init()") Signed-off-by: Wang Jinchao Reviewed-by: Yu Kuai Link: https://lore.kernel.org/linux-raid/20250612112901.3023950-1-wangjinchao600@gmail.com Signed-off-by: Yu Kuai Signed-off-by: Sasha Levin --- drivers/md/raid1.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 8b25287c89ed6..4c1f86ca55208 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -3297,6 +3297,7 @@ static int raid1_reshape(struct mddev *mddev) /* ok, everything is stopped */ oldpool = conf->r1bio_pool; conf->r1bio_pool = newpool; + init_waitqueue_head(&conf->r1bio_pool.wait); for (d = d2 = 0; d < conf->raid_disks; d++) { struct md_rdev *rdev = conf->mirrors[d].rdev; -- 2.39.5