Skip to content

Commit

Permalink
dm ioctl: log an error if the ioctl structure is corrupted
Browse files Browse the repository at this point in the history
This will help triage bugs when userspace is passing invalid ioctl
structure to the kernel.

Signed-off-by: Mikulas Patocka <[email protected]>
[snitzer: log errors using DMERR instead of DMWARN]
Signed-off-by: Mike Snitzer <[email protected]>
  • Loading branch information
Mikulas Patocka authored and Mike Snitzer committed Apr 1, 2022
1 parent 3f72821 commit dbdcc90
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions drivers/md/dm-ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,15 +891,21 @@ static struct hash_cell *__find_device_hash_cell(struct dm_ioctl *param)
struct hash_cell *hc = NULL;

if (*param->uuid) {
if (*param->name || param->dev)
if (*param->name || param->dev) {
DMERR("Invalid ioctl structure: uuid %s, name %s, dev %llx",
param->uuid, param->name, (unsigned long long)param->dev);
return NULL;
}

hc = __get_uuid_cell(param->uuid);
if (!hc)
return NULL;
} else if (*param->name) {
if (param->dev)
if (param->dev) {
DMERR("Invalid ioctl structure: name %s, dev %llx",
param->name, (unsigned long long)param->dev);
return NULL;
}

hc = __get_name_cell(param->name);
if (!hc)
Expand Down Expand Up @@ -1851,8 +1857,11 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl *param_kern
if (copy_from_user(param_kernel, user, minimum_data_size))
return -EFAULT;

if (param_kernel->data_size < minimum_data_size)
if (param_kernel->data_size < minimum_data_size) {
DMERR("Invalid data size in the ioctl structure: %u",
param_kernel->data_size);
return -EINVAL;
}

secure_data = param_kernel->flags & DM_SECURE_DATA_FLAG;

Expand Down

0 comments on commit dbdcc90

Please sign in to comment.