Commit b1a66504 authored by Guo Chao's avatar Guo Chao Committed by Jens Axboe

loopdev: remove an user triggerable oops

When loopdev is built as module and we pass an invalid parameter,
loop_init() will return directly without deregister misc device, which
will cause an oops when insert loop module next time because we left some
garbage in the misc device list.

Test case:
sudo modprobe loop max_part=1024
(failed due to invalid parameter)
sudo modprobe loop
(oops)

Clean up nicely to avoid such oops.
Signed-off-by: default avatarGuo Chao <yan@linux.vnet.ibm.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Guo Chao <yan@linux.vnet.ibm.com>
Cc: M. Hindess <hindessm@uk.ibm.com>
Cc: Nikanth Karthikesan <knikanth@suse.de>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 7b0576a3
...@@ -1844,11 +1844,15 @@ static int __init loop_init(void) ...@@ -1844,11 +1844,15 @@ static int __init loop_init(void)
max_part = (1UL << part_shift) - 1; max_part = (1UL << part_shift) - 1;
} }
if ((1UL << part_shift) > DISK_MAX_PARTS) if ((1UL << part_shift) > DISK_MAX_PARTS) {
return -EINVAL; err = -EINVAL;
goto misc_out;
}
if (max_loop > 1UL << (MINORBITS - part_shift)) if (max_loop > 1UL << (MINORBITS - part_shift)) {
return -EINVAL; err = -EINVAL;
goto misc_out;
}
/* /*
* If max_loop is specified, create that many devices upfront. * If max_loop is specified, create that many devices upfront.
...@@ -1866,8 +1870,10 @@ static int __init loop_init(void) ...@@ -1866,8 +1870,10 @@ static int __init loop_init(void)
range = 1UL << MINORBITS; range = 1UL << MINORBITS;
} }
if (register_blkdev(LOOP_MAJOR, "loop")) if (register_blkdev(LOOP_MAJOR, "loop")) {
return -EIO; err = -EIO;
goto misc_out;
}
blk_register_region(MKDEV(LOOP_MAJOR, 0), range, blk_register_region(MKDEV(LOOP_MAJOR, 0), range,
THIS_MODULE, loop_probe, NULL, NULL); THIS_MODULE, loop_probe, NULL, NULL);
...@@ -1880,6 +1886,10 @@ static int __init loop_init(void) ...@@ -1880,6 +1886,10 @@ static int __init loop_init(void)
printk(KERN_INFO "loop: module loaded\n"); printk(KERN_INFO "loop: module loaded\n");
return 0; return 0;
misc_out:
misc_deregister(&loop_misc);
return err;
} }
static int loop_exit_cb(int id, void *ptr, void *data) static int loop_exit_cb(int id, void *ptr, void *data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment