Information about bind mounts and simultaneous access to /dev/ptmx and /dev/pts/ptmx

Paolo De Donato <[email protected]>
Newsgroups org.kernel.vger.linux-man,org.kernel.vger.linux-fsdevel
Message-ID <QyCOf8W8P-XlVQEK451kiApqyxPqPQzth8sY0CNnbkUKXoTzkY-jbKI10jr6bjP_8IfsvYqkHnhmGTlL12HQgfzZ4CiVakdps9kiNuH6rTM=@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
publickey - [email protected] - 0xF470BB6E.asc (application/pgp-keys, 657 B)
-----BEGIN PGP PUBLIC KEY BLOCK-----

xjMEY3IZ2BYJKwYBBAHaRw8BAQdAyHIrSe927LX7kqgXTiTtmnzoMY1F0sY+
w9U/Cc9uBN/NMWRlZG8ucGFvbG8uMjRAcHJvdG9uLm1lIDxkZWRvLnBhb2xv
LjI0QHByb3Rvbi5tZT7CjAQQFgoAPgUCY3IZ2AQLCQcICRDm4GxjmQDIxwMV
CAoEFgACAQIZAQIbAwIeARYhBPRwu24gnxS2ko7wwebgbGOZAMjHAABGjgEA
85iiEFS3PKkLlqDhGSx39fl3TynN1ropo0Y1TxosfwkA/32TNKewKBJAWrjb
7NvaEbnqotFW8WLSHj/kYcLHp5sOzjgEY3IZ2BIKKwYBBAGXVQEFAQEHQH0b
abSG181Mmx7zREtiwfZeOPN1qxRjeTGveQwc01cOAwEIB8J4BBgWCAAqBQJj
chnYCRDm4GxjmQDIxwIbDBYhBPRwu24gnxS2ko7wwebgbGOZAMjHAABm3AD/
b60VysGG5gPK74SYc1t5J5Bs/gSC2/NBPpt7vLaNpdEA/2Kurqiyn9y3CWu7
n1uR0/Vu367vhUcgbHZSF2cud+wE
=Kk63
-----END PGP PUBLIC KEY BLOCK-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.