All of lore.kernel.org
 help / color / mirror / Atom feed
* [dm-devel] [PATCH] dm-ioctl: log an error if the ioctl structure is corrupted
@ 2022-03-20 21:12 Mikulas Patocka
  0 siblings, 0 replies; only message in thread
From: Mikulas Patocka @ 2022-03-20 21:12 UTC (permalink / raw)
  To: Mike Snitzer; +Cc: dm-devel

Log an error if the ioctl structure is corrupted. This will help us triage
bugs when when userspace is passing invalid ioctl structure to the kernel.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 drivers/md/dm-ioctl.c |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Index: linux-dm/drivers/md/dm-ioctl.c
===================================================================
--- linux-dm.orig/drivers/md/dm-ioctl.c	2022-03-17 19:19:31.000000000 +0100
+++ linux-dm/drivers/md/dm-ioctl.c	2022-03-20 20:37:34.000000000 +0100
@@ -891,15 +891,21 @@ static struct hash_cell *__find_device_h
 	struct hash_cell *hc = NULL;
 
 	if (*param->uuid) {
-		if (*param->name || param->dev)
+		if (*param->name || param->dev) {
+			DMWARN("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) {
+			DMWARN("Invalid ioctl structure: name %s, dev %llx",
+				param->name, (unsigned long long)param->dev);
 			return NULL;
+		}
 
 		hc = __get_name_cell(param->name);
 		if (!hc)
@@ -1851,8 +1857,10 @@ static int copy_params(struct dm_ioctl _
 	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) {
+		DMWARN("Invalid data size in the ioctl structure: %u", param_kernel->data_size);
 		return -EINVAL;
+	}
 
 	secure_data = param_kernel->flags & DM_SECURE_DATA_FLAG;
 
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-20 21:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-20 21:12 [dm-devel] [PATCH] dm-ioctl: log an error if the ioctl structure is corrupted Mikulas Patocka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.