2.5.44 Fix uninitialized device struct w/ add_disk()
PATCH 1/1 2.5.44 Fix uninitialized device struct w/ add_disk()
This occurs w/ 2.5 device-mapper; add_disk() is called (w/ a possibly invalid gendisk). add_disk() calls register_disk(), which constructs the device struct (gendisk::disk_dev). First, the bus_id field is initialized, and then device_add() is called. However, device_add() does no initialization of the device struct. So, since the gendisk::disk_dev::parent list is NULL, the gendisk::disk_dev::node field is never initialized. Later on in device_add(), if an error has occurred, list_del_init(&dev->node) is called; dev->node is {NULL,NULL}, and an oops occurs.
Instead of calling device_add(), my patch makes register_disk() call device_register(). This appear to do the same thing as device_add(), but initializes the device struct before calling device_add().
Signature · 2 lines
It's not denial. I'm just selective about the reality I accept. -- Bill Watterson
fs/partitions/check.c +1 -1
@@ -455,7 +455,7 @@ s =strchr (dev->bus_id,'/' );if (s) *s ='!' ; -device_add (dev); +device_register (dev);device_create_file (dev, &disk_attr_dev);device_create_file (dev, &disk_attr_range);device_create_file (dev, &disk_attr_size);
Quoted 10 lines · Andres Salomon
This occurs w/ 2.5 device-mapper;
add_disk()is called (w/ a possibly invalid gendisk).add_disk()callsregister_disk(), which constructs the device struct (gendisk::disk_dev). First, thebus_idfield is initialized, and thendevice_add()is called. However,device_add()does no initialization of the device struct. So, since thegendisk::disk_dev::parentlist is NULL, thegendisk::disk_dev::nodefield is never initialized. Later on indevice_add(), if an error has occurred,list_del_init(&dev->node)is called;dev->nodeis {NULL,NULL}, and an oops occurs.
Quoted 3 lines
Instead of calling
device_add(), my patch makesregister_disk()calldevice_register(). This appear to do the same thing asdevice_add(), but initializes the device struct before callingdevice_add().
Wrong. If device-mapper doesn't create gendisk with alloc_disk() - it's their bug; if it does - initialization is already done at alloc_disk() time.
Fix driver instead of breaking generic code.