Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH 1/2] md/raid5: fix pool_size leak in resize_stripes error path
@ 2026-08-27  3:16 ghuicao
  2026-08-27  3:16 ` [PATCH 2/2] md/raid5: fix NULL pointer dereference in raid5_free_percpu ghuicao
  2026-08-27  3:32 ` [PATCH 1/2] md/raid5: fix pool_size leak in resize_stripes error path sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: ghuicao @ 2026-08-27  3:16 UTC (permalink / raw)
  To: Song Liu
  Cc: Yu Kuai, Li Nan, Xiao Ni, linux-raid, linux-kernel, stable,
	Cao Guanghui

From: Cao Guanghui <caoguanghui@kylinos.cn>

In resize_stripes(), conf->disks is replaced with a new array (ndisks)
in Step 3, but pool_size is only updated at the end with
"if (!err) conf->pool_size = newsize".  If Step 4 (allocating pages for
new stripes) fails, err is set but pool_size is not updated, even though
conf->disks already has newsize entries.

When the array is later torn down, free_conf() iterates only pool_size
(= old value) entries, leaking (newsize - pool_size) extra_page
allocations.

Set pool_size immediately after replacing conf->disks, so it always
matches the actual array size regardless of subsequent failures.

Fixes: ad01c9e3752f ("[PATCH] md: Allow stripes to be expanded in preparation for expanding an array")
Cc: stable@vger.kernel.org
Signed-off-by: Cao Guanghui <caoguanghui@kylinos.cn>
---
 drivers/md/raid5.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2641,6 +2641,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
 		} else {
 			kfree(conf->disks);
 			conf->disks = ndisks;
+			conf->pool_size = newsize;
 		}
 	} else
 		err = -ENOMEM;
@@ -2687,5 +2688,3 @@ static int resize_stripes(struct r5conf *conf, int newsize)
 	/* critical section pass, GFP_NOIO no longer needed */
 
-	if (!err)
-		conf->pool_size = newsize;
 	mutex_unlock(&conf->cache_size_mutex);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-27  3:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-27  3:16 [PATCH 1/2] md/raid5: fix pool_size leak in resize_stripes error path ghuicao
2026-08-27  3:16 ` [PATCH 2/2] md/raid5: fix NULL pointer dereference in raid5_free_percpu ghuicao
2026-08-27  3:32 ` [PATCH 1/2] md/raid5: fix pool_size leak in resize_stripes error path sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox