Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: fix zones_cond memory leak on zone revalidation error paths

When blk_revalidate_disk_zones() fails after disk_revalidate_zone_resources()
has allocated args.zones_cond, the memory is leaked because no error path
frees it.

Fixes: 6e945ffb6555 ("block: use zone condition to determine conventional zones")
Suggested-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
Link: https://patch.msgid.link/20260331111216.24242-1-liu.yun@linux.dev
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Jackie Liu and committed by
Jens Axboe
2a2f520f 267ec4d7

+20 -6
+20 -6
block/blk-zoned.c
··· 2016 2016 { 2017 2017 struct queue_limits *lim = &disk->queue->limits; 2018 2018 unsigned int pool_size; 2019 + int ret = 0; 2019 2020 2020 2021 args->disk = disk; 2021 2022 args->nr_zones = ··· 2039 2038 pool_size = 2040 2039 min(BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE, args->nr_zones); 2041 2040 2042 - if (!disk->zone_wplugs_hash) 2043 - return disk_alloc_zone_resources(disk, pool_size); 2041 + if (!disk->zone_wplugs_hash) { 2042 + ret = disk_alloc_zone_resources(disk, pool_size); 2043 + if (ret) 2044 + kfree(args->zones_cond); 2045 + } 2044 2046 2045 - return 0; 2047 + return ret; 2046 2048 } 2047 2049 2048 2050 /* ··· 2077 2073 disk->zone_capacity = args->zone_capacity; 2078 2074 disk->last_zone_capacity = args->last_zone_capacity; 2079 2075 disk_set_zones_cond_array(disk, args->zones_cond); 2076 + args->zones_cond = NULL; 2080 2077 2081 2078 /* 2082 2079 * Some devices can advertise zone resource limits that are larger than ··· 2358 2353 } 2359 2354 memalloc_noio_restore(noio_flag); 2360 2355 2356 + if (ret <= 0) 2357 + goto free_resources; 2358 + 2361 2359 /* 2362 2360 * If zones where reported, make sure that the entire disk capacity 2363 2361 * has been checked. 2364 2362 */ 2365 - if (ret > 0 && args.sector != capacity) { 2363 + if (args.sector != capacity) { 2366 2364 pr_warn("%s: Missing zones from sector %llu\n", 2367 2365 disk->disk_name, args.sector); 2368 2366 ret = -ENODEV; 2367 + goto free_resources; 2369 2368 } 2370 2369 2371 - if (ret > 0) 2372 - return disk_update_zone_resources(disk, &args); 2370 + ret = disk_update_zone_resources(disk, &args); 2371 + if (ret) 2372 + goto free_resources; 2373 2373 2374 + return 0; 2375 + 2376 + free_resources: 2374 2377 pr_warn("%s: failed to revalidate zones\n", disk->disk_name); 2375 2378 2379 + kfree(args.zones_cond); 2376 2380 memflags = blk_mq_freeze_queue(q); 2377 2381 disk_free_zone_resources(disk); 2378 2382 blk_mq_unfreeze_queue(q, memflags);