Information about bind mounts and simultaneous access to /dev/ptmx and /dev/pts/ptmx
Paolo De Donato <[email protected]>
| Newsgroups | gmane.linux.man,gmane.linux.file-systems |
|---|---|
| Message-ID | <OL6NOlULLLkBGa0xCeh8WaHQwIqYDyatnuI7X2kfZRVGNtRGHbaarbdGEC9QUCfrYoEtX-k7B1gVRUg1iN4WJE2ES7QU1cgnRMuz9J5KdXo=@proton.me> |
Dear Alexander Viro,
I have noticed that trying to open /dev/ptmx device file through a bind mount will always fail. More precisely, calling
open("/dev/ptmx", O_RDWR)
usually succeeds, however it will always fail if you previously launched the following command:
# mount --bind /dev/ptmx /dev/ptmx
I think the root cause of this is the relationship between /dev/ptmx and the devpts virtual filesystem, usually mounted at /dev/pts since all operations on /dev/ptmx are forwarded to /dev/pts/ptmx. This issue makes unfeasible to share access to /dev/ptmx through a mount namespace, however bind mounts work as expected with /dev/pts/ptmx (if devpts has been mounted with the option ptmxmode=0666).
My question is if it is safe to give full access to both /dev/ptmx and /dev/pts/ptmx (through ptmxmode=0666) at the same time, or if there are some racing conditions that would make simultaneous access insecure. Documentation at https://docs.kernel.org/filesystems/devpts.html and man 4 pts say nothing about this scenario, but I think this information will be very helpful for all people that needs having pseudoterminal access inside a mount namespace.
Bests,
Paolo