what happens if I create a file using vim in /dev directory. How the file will be created as the /dev is not standard file system

328 views Asked by At

What happens if I create a file using vim in the /dev directory. How will the file be created as the /dev is not a standard file system. I can see a file being created but standard Kernel file operation create was not called. Now I am not sure how this file was created by kernel. Will it use some udev bound Kernel API to create this file.

Note : I can see the file in /dev after creation. Look at the ls output below.

crw-rw-rw- 1 root tty 5, 0 Aug 24 17:32 tty
-rw-r--r-- 1 root root 35 Aug 24 17:37 abc
-rw-r--r-- 1 root root 0 Aug 24 17:37 ght
-rw-r--r-- 1 root root 0 Aug 24 17:51 ioiu

I want to find this out to determine what will happen if some illegal SW forcefully writes to /dev directory , how can I find that out.

1

There are 1 answers

0
kenlukas On

If you try in MacOS it won't work even as root.
If you try in CentOS 8 it will work if you're root.
Other Linux flavors your mileage may vary.

It is a very interesting directory that highlights one important aspect of the Linux filesystem - everything is a file or a directory.

Example

[root]# date > /dev/date
[root]# cat /dev/date
Tue Aug 24 19:13:04 UTC 2021

All that being said, your concern about nefarious software creating a file in this specific directory seems too specific. If the software has the ability to write to /dev it can write to anywhere and hide in plain site. If you're really concerned about this, install a file integrity monitoring (FIM) package to monitor file CRUD.

References
dev filesystem