Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wjhun opened this issue Mar 15, 2022 · 4 comments
Open

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

wjhun opened this issue Mar 15, 2022 · 4 comments
Assignees

Comments

@wjhun
Copy link
Contributor

wjhun commented Mar 15, 2022

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
Copy link

0x9n0p commented Nov 1, 2023

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

@francescolavra
Copy link
Member

@0x9n0p you have been assigned. Thanks!

@0x9n0p
Copy link

0x9n0p commented Nov 5, 2023

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

@francescolavra
Copy link
Member

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:

  • install Ruby on your machine
  • create a file named send_io.rb with these contents:
require 'socket'
s1, s2 = UNIXSocket.pair
s1.send_io STDOUT
stdout = s2.recv_io
p STDOUT.fileno #=> 1
p stdout.fileno #=> 6
stdout.puts "hello" # outputs "hello\n" to standard output.
  • create a file named config.json with these contents (adjust the file paths to match your Ruby installation directory):
{
  "Args": ["send_io.rb"],
  "Files": ["send_io.rb"],
  "MapDirs": {
    "/usr/local/lib/ruby/3.0.0/*": "/usr/local/lib/ruby/3.0.0/",
    "/usr/local/lib/ruby/gems/3.0.0/*": "/usr/local/lib/ruby/gems/3.0.0/"
  }
}
  • run ops run /usr/local/bin/ruby -c config.json
  • you will see the above error message, followed by a backtrace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants