dm ioctl: Refuse to create device named "." or ".."
authorDemi Marie Obenour <demi@invisiblethingslab.com>
Sat, 3 Jun 2023 14:52:44 +0000 (10:52 -0400)
committerMike Snitzer <snitzer@kernel.org>
Fri, 23 Jun 2023 14:31:52 +0000 (10:31 -0400)
Using either of these is going to greatly confuse userspace, as they are
not valid symlink names and so creating the usual /dev/mapper/NAME
symlink will not be possible.  As creating a device with either of these
names is almost certainly a userspace bug, just error out.

Signed-off-by: Demi Marie Obenour <demi@invisiblethingslab.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
drivers/md/dm-ioctl.c

index e172a91..16244a7 100644 (file)
@@ -771,8 +771,10 @@ static int check_name(const char *name)
                return -EINVAL;
        }
 
-       if (strcmp(name, DM_CONTROL_NODE) == 0) {
-               DMERR("device name cannot be \"%s\"", DM_CONTROL_NODE);
+       if (strcmp(name, DM_CONTROL_NODE) == 0 ||
+           strcmp(name, ".") == 0 ||
+           strcmp(name, "..") == 0) {
+               DMERR("device name cannot be \"%s\", \".\", or \"..\"", DM_CONTROL_NODE);
                return -EINVAL;
        }