nanovms / nanos

A kernel designed to run one and only one application in a virtualized environment
https://nanos.org
Apache License 2.0
2.58k stars 133 forks source link

add support for exchanging ancillary data through unix domain sockets #1692

Open wjhun opened 2 years ago

wjhun commented 2 years ago

sendmsg(2) and recvmsg(2) allow the exchange of out-of-band "ancillary data", such as file descriptors and errors. These messages are created and accessed using the CMSG_* macros (see the cmsg(3) man page). Some packages, such as erlang/OTP, use these messages to communicate file descriptors over unix domain sockets. The passage of file descriptors, using type SCM_RIGHTS, may require some special handling beyond simple copying, as queueing a file descriptor is actually storing a reference to the object being described, not the descriptor numbers themselves. (e.g. on a multi-process system, an fd written by one process may be read as a different fd by another process - yet both refer to the same object) Also, the writing of descriptors should count as a reference to the underlying object, as the descriptors may be closed after writing ancillary data containing them - while still allowing the receiving end to read open descriptors.

References: https://www.man7.org/linux/man-pages/man3/cmsg.3.html https://blog.cloudflare.com/know-your-scm_rights/

0x9n0p commented 10 months ago

I'm working on it. May you assign it to me.

francescolavra commented 10 months ago

@0x9n0p you have been assigned. Thanks!

0x9n0p commented 10 months ago

It seems that there is nothing to do. It has already been done.

francescolavra commented 10 months ago

It has not been done, transfer of ancillary data through Unix domain socket is still not implemented. For example, if you try to run a Ruby application that uses the send_io or recv_iomethods of the UNIXSocket class, you will get a [BUG] rb_maygvl_fd_fix_cloexec: fcntl(-2075168, F_GETFD) failed: Bad file descriptor error message, due to the fact that the file descriptor that the application expects to receive as ancillary data in the socket is not being transferred. How to reproduce: