UBI: fix use after free in ubi_remove_volume()
Subsystems (2)
PATCH 1/1 UBI: fix use after free in ubi_remove_volume()
We can't use "vol" after it has been freed.
Fixes 493cfaeaa0c9 ("mtd: utilize new cdev_device_add helper function")
Signed-off-by Wen Yang <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc Vignesh Raghavendra <[email protected]>
--- drivers/mtd/ubi/vmt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/ubi/vmt.c +2 -1
@@ -375,7 +375,6 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl) }cdev_device_del (&vol->cdev, &vol->dev); -put_device (&vol->dev);spin_lock (&ubi->volumes_lock); ubi->rsvd_pebs -= reserved_pebs;
@@ -388,6 +387,8 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)if (!no_vtbl)self_check_volumes (ubi); +put_device (&vol->dev); +return 0 ; out_err:
Signature · 1 line
1.8.3.1
Reviewed-by Hou Tao <[email protected]>
Quoted 35 lines · Wen Yang
We can't use "vol" after it has been freed.
Fixes 493cfaeaa0c9 ("mtd: utilize new cdev_device_add helper function")Signed-off-by Wen Yang <[email protected]>Cc Richard Weinberger <[email protected]>Cc Miquel Raynal <[email protected]>Cc Vignesh Raghavendra <[email protected]>--- drivers/mtd/ubi/vmt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/mtd/ubi/vmt.c +2
-1@@ -375,7 +375,6 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl) }cdev_device_del (&vol->cdev, &vol->dev); -put_device (&vol->dev);spin_lock (&ubi->volumes_lock); ubi->rsvd_pebs -= reserved_pebs;@@ -388,6 +387,8 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)if (!no_vtbl)self_check_volumes (ubi); +put_device (&vol->dev); +return 0 ; out_err:
Hi,
Quoted 2 lines · Hou Tao
Reviewed-by Hou Tao <[email protected]>
Sorry for my early conclusion.
The reference of ubi_volume had already been increased in ubi_open_volume() in ubi_cdev_ioctl(), so this reference dropped in ubi_remove_volume() will not be the last one, and there will no use-after-free problem.
Regards,
Tao
Quoted 43 lines · Wen Yang
Quoted 27 lines
We can't use "vol" after it has been freed.
Fixes 493cfaeaa0c9 ("mtd: utilize new cdev_device_add helper function")Signed-off-by Wen Yang <[email protected]>Cc Richard Weinberger <[email protected]>Cc Miquel Raynal <[email protected]>Cc Vignesh Raghavendra <[email protected]>--- drivers/mtd/ubi/vmt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/mtd/ubi/vmt.c +0
-1@@ -375,7 +375,6 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl) }cdev_device_del (&vol->cdev, &vol->dev); -put_device (&vol->dev);spin_lock (&ubi->volumes_lock); ubi->rsvd_pebs -= reserved_pebs;drivers/mtd/ubi/vmt.c int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl) · line 394
Quoted 8 lines
drivers/mtd/ubi/vmt.c +2
-0@@ -388,6 +387,8 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)if (!no_vtbl)self_check_volumes (ubi); +put_device (&vol->dev); +return 0 ; out_err:______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/