chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.98k stars 1.22k forks source link

Add macro ASIO_DISABLE_FIONBIO #1406

Closed caloni closed 7 months ago

caloni commented 10 months ago

On FreeBSD, sockets received from capsicum processes will return ENOTCAPABLE on ioctls. In this scenario, fcntl() is the preferred approach to put the file descriptor in non-blocking mode.

Furthermore, nested kqueues are prevented w/o this patch. FIONBIO is not implemented by kqueue file descriptors. So it's impossible to use ASIO (nested kqueue through posix::stream_descriptor) to await for a procdesc to finish, as an example.

It's also generally unsafe to perform any ioctl on file descriptors received from untrusted processes. Linux is slowly adding support for this type of sandbox through Landlock, so it's not just a FreeBSD problem.

FIONBIO already caused problems to ASIO in this past (cf. commit 607f99ba80df71f1a96f0df71725059ee71e46ff). This patch only exposes a knob that users can also resort to when FIONBIO fail on them.