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 1A45B2E3AEA; Tue, 15 Jul 2025 13:48:41 +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=1752587321; cv=none; b=TaNdG4Wn5hwHkRhniTR2TOsZrgfl0TK+QVY/xPxxa1rSBKurVBMBTcTm4NuGWowUhQskRUHX/4T9Int+OuwOR7jpbZm9QUPm0z1BhQ13XRuQDkjHnTS1OIYcdsSlhySGpwI2nDVvvMLPwhr3I9kJGdJPjhrpIGX976olkx/E6lc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752587321; c=relaxed/simple; bh=nVxaRsAd9M51rQ0u3jHAq0nmxILF3lr7AUuxkmrgcJE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tbIIcQAqqGu+AnhOgpbdPm/ko4YtIxg1L2qV79ps4FuhQbtQLZoU2hsAQQv+9GiWzO/zCoPzXkEfDWcee53nBB/5T8wyh6cSHEAc1JEYjoi6IYapaWBvGBic1TnqFv8vzWx57Za6zea+5eETE+bF1k/QMKhoQzIWwVjMhf+Y+aU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=k5uxJHoQ; 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="k5uxJHoQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A141AC4CEE3; Tue, 15 Jul 2025 13:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1752587321; bh=nVxaRsAd9M51rQ0u3jHAq0nmxILF3lr7AUuxkmrgcJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k5uxJHoQ0QoZcevZ1AewxrjctsFgzDZ8L70mnUjgJ1/OZb9XZWVLSxauSpzj3S10I GQNHKba15XviqaexhBbAkGca4uUnbJR7d6yVtp8CwntoYi9/g1n5pjlHJzcuFgjTSU 2eeDiozOF1DVlkuTJwK1MkC9h5t11Fk+KUQKpssE= 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.1 56/88] md/raid1: Fix stack memory use after return in raid1_reshape Date: Tue, 15 Jul 2025 15:14:32 +0200 Message-ID: <20250715130756.811453362@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250715130754.497128560@linuxfoundation.org> References: <20250715130754.497128560@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.1-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 38e77a4b6b338..ebff40a3423ae 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -3306,6 +3306,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