sys/dev/disk/dm: Remove read/write support for /dev/mapper/control
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 1 May 2016 00:12:10 +0000 (09:12 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 1 May 2016 03:12:34 +0000 (12:12 +0900)
commit963efb759bfcde56802056358895073b943f1dc6
treeadc944c5983b2c18d53de11266b5acc837181705
parent0b0166b05ac205b9dc1112fe8d52a8fbe31f63fa
sys/dev/disk/dm: Remove read/write support for /dev/mapper/control

It's obvious that /dev/mapper/control has nothing to read/write.
Running below results in kernel panic as the code requires properly
initialized a per-table lock while this chrdev has no tables mapped.
(control chrdev and dm blkdevs use the same dm device structures)

-----
 [root@]~# cat ./dm1.c
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
 int main(void)
 {
         int fd;
         char buf[1024];
         fd = open("/dev/mapper/control", O_RDWR);
         if (fd == -1) {
                 perror("open");
                 exit(1);
         }
         if (read(fd, buf, sizeof(buf)) == -1)
                 perror("read");
         if (write(fd, buf, sizeof(buf)) == -1)
                 perror("write");
         close(fd);
         return 0;
 }

With this commit.
-----
 [root@]~# uname
 DragonFly
 [root@]~# kldload dm
 [root@]~# ls -l /dev/mapper/control
 crw-r-----  1 root  operator   65, 0x00000000 May  1 09:25 /dev/mapper/control
 [root@]~# gcc -Wall -g ./dm1.c -o ./dm1
 [root@]~# ./dm1
 read: Operation not supported by device
 write: Operation not supported by device

With Linux kernel.
-----
 [root@localhost]~# uname
 Linux
 [root@localhost]~# ls -l /dev/mapper/control
 crw-rw---- 1 root root 10, 236 Apr 25 12:44 /dev/mapper/control
 [root@localhost]~# gcc -Wall -g ./dm1.c -o ./dm1
 [root@localhost]~# ./dm1
 read: Invalid argument
 write: Invalid argument
sys/dev/disk/dm/device-mapper.c