diff options
| author | Zheng Qixing <zhengqixing@huawei.com> | 2025-02-15 10:01:37 +0800 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-04-10 14:44:02 +0200 |
| commit | a815ac87c06d5f37f92e3782008234154a7f120e (patch) | |
| tree | c594d6223adbb4bc892ee2a8b957ac3cde0d7a14 /drivers/md | |
| parent | f97c13dc53c803dded6b6c1f731f40aed73a09cc (diff) | |
| download | linux-a815ac87c06d5f37f92e3782008234154a7f120e.tar.gz linux-a815ac87c06d5f37f92e3782008234154a7f120e.tar.bz2 linux-a815ac87c06d5f37f92e3782008234154a7f120e.zip | |
md/raid1: fix memory leak in raid1_run() if no active rdev
[ Upstream commit 5fbcf76e0dfe68578ffa2a8a691cc44cf586ae35 ]
When `raid1_set_limits()` fails or when the array has no active
`rdev`, the allocated memory for `conf` is not properly freed.
Add raid1_free() call to properly free the conf in error path.
Fixes: 799af947ed13 ("md/raid1: don't free conf on raid0_run failure")
Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
Link: https://lore.kernel.org/linux-raid/20250215020137.3703757-1-zhengqixing@huaweicloud.com
Singed-off-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/md')
| -rw-r--r-- | drivers/md/raid1.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 10ea3af40991..cb108b3e28c4 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -45,6 +45,7 @@ static void allow_barrier(struct r1conf *conf, sector_t sector_nr); static void lower_barrier(struct r1conf *conf, sector_t sector_nr); +static void raid1_free(struct mddev *mddev, void *priv); #define RAID_1_10_NAME "raid1" #include "raid1-10.c" @@ -3256,8 +3257,11 @@ static int raid1_run(struct mddev *mddev) if (!mddev_is_dm(mddev)) { ret = raid1_set_limits(mddev); - if (ret) + if (ret) { + if (!mddev->private) + raid1_free(mddev, conf); return ret; + } } mddev->degraded = 0; @@ -3271,6 +3275,8 @@ static int raid1_run(struct mddev *mddev) */ if (conf->raid_disks - mddev->degraded < 1) { md_unregister_thread(mddev, &conf->thread); + if (!mddev->private) + raid1_free(mddev, conf); return -EINVAL; } |
