Skip to content

Commit cb335f8

Browse files
nschichanneilbrown
authored andcommitted
md: check command validity early in md_ioctl().
Verify that the cmd parameter passed to md_ioctl() is valid before doing anything. This fixes mddev->hold_active being set to 0 when an invalid ioctl command is passed to md_ioctl() before the array has been configured. Clearing mddev->hold_active in that case can lead to a livelock situation when an invalid ioctl number is given to md_ioctl() by a process when the mddev is currently being opened by another process: Process 1 Process 2 --------- --------- md_alloc() mddev_find() -> returns a new mddev with hold_active == UNTIL_IOCTL add_disk() -> sends KOBJ_ADD uevent (sees KOBJ_ADD uevent for device) md_open() md_ioctl(INVALID_IOCTL) -> returns ENODEV and clears mddev->hold_active md_release() md_put() -> deletes the mddev as hold_active is 0 md_open() mddev_find() -> returns a newly allocated mddev with mddev->gendisk == NULL -> returns with ERESTARTSYS (kernel restarts the open syscall) Signed-off-by: Nicolas Schichan <nschichan@freebox.fr> Signed-off-by: NeilBrown <neilb@suse.de>
1 parent 830778a commit cb335f8

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎drivers/md/md.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6356,6 +6356,32 @@ static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo)
63566356
return 0;
63576357
}
63586358

6359+
static inline bool md_ioctl_valid(unsigned int cmd)
6360+
{
6361+
switch (cmd) {
6362+
case ADD_NEW_DISK:
6363+
case BLKROSET:
6364+
case GET_ARRAY_INFO:
6365+
case GET_BITMAP_FILE:
6366+
case GET_DISK_INFO:
6367+
case HOT_ADD_DISK:
6368+
case HOT_REMOVE_DISK:
6369+
case PRINT_RAID_DEBUG:
6370+
case RAID_AUTORUN:
6371+
case RAID_VERSION:
6372+
case RESTART_ARRAY_RW:
6373+
case RUN_ARRAY:
6374+
case SET_ARRAY_INFO:
6375+
case SET_BITMAP_FILE:
6376+
case SET_DISK_FAULTY:
6377+
case STOP_ARRAY:
6378+
case STOP_ARRAY_RO:
6379+
return true;
6380+
default:
6381+
return false;
6382+
}
6383+
}
6384+
63596385
static int md_ioctl(struct block_device *bdev, fmode_t mode,
63606386
unsigned int cmd, unsigned long arg)
63616387
{
@@ -6364,6 +6390,9 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
63646390
struct mddev *mddev = NULL;
63656391
int ro;
63666392

6393+
if (!md_ioctl_valid(cmd))
6394+
return -ENOTTY;
6395+
63676396
switch (cmd) {
63686397
case RAID_VERSION:
63696398
case GET_ARRAY_INFO:

0 commit comments

Comments
 (0)