block: clear ia_ranges on sysfs registration failure
Subsystems (2)
PATCH 1/1 block: clear ia_ranges on sysfs registration failure
disk_register_independent_access_ranges() clears disk->ia_ranges when creating the top-level kobject fails. However, if adding one of the range kobjects fails, the cleanup drops the final reference to iars and frees it while disk->ia_ranges still points at it.
A concurrent disk revalidation can wait for q->sysfs_lock and then call disk_unregister_independent_access_ranges(), which dereferences the stale pointer after registration releases the mutex.
Clear disk->ia_ranges before dropping the kobject references on the child registration error path, matching the top-level error handling.
--- block/blk-ia-ranges.c | 1 + 1 file changed, 1 insertion(+)
block/blk-ia-ranges.c +1 -0
@@ -135,6 +135,7 @@ int disk_register_independent_access_ranges(struct gendisk *disk) &blk_ia_range_ktype, &iars->kobj, "%d", i);if (ret) { + disk->ia_ranges =NULL ;while (--i >=0 )kobject_del (&iars->ia_range[i].kobj);kobject_del (&iars->kobj);
Signature · 1 line
2.43.0
Looks good:
Quoted 35 lines · Shuangpeng Bai
disk_register_independent_access_ranges()clearsdisk->ia_rangeswhen creating the top-level kobject fails. However, if adding one of the range kobjects fails, the cleanup drops the final reference to iars and frees it whiledisk->ia_rangesstill points at it.A concurrent disk revalidation can wait for
q->sysfs_lockand then calldisk_unregister_independent_access_ranges(), which dereferences the stale pointer after registration releases the mutex.Clear
disk->ia_rangesbefore dropping the kobject references on the child registration error path, matching the top-level error handling.Fixes a2247f19ee1c ("block: Add independent access ranges support")Signed-off-by Shuangpeng Bai <[email protected]>--- block/blk-ia-ranges.c | 1 + 1 file changed, 1 insertion(+)block/blk-ia-ranges.c +1
-0@@ -135,6 +135,7 @@ int disk_register_independent_access_ranges(struct gendisk *disk) &blk_ia_range_ktype, &iars->kobj, "%d", i);if (ret) { + disk->ia_ranges =NULL ;while (--i >=0 )kobject_del (&iars->ia_range[i].kobj);kobject_del (&iars->kobj);Signature · 1 line
2.43.0
---end quoted text---