Plain socket(2) is permitted in capability mode. The reasoning seems to
be that unconnected, unbound sockets do not represent capabilities.
However, this is false is a few cases:
- raw sockets can be used to receive data without being connected
- routing sockets are automatically connected and provide access to routing tables
- network interfaces are configured with ioctl() on a socket of any type
The system's interface list and routing tables are global namespaces
that should not be accessible to processes in capability mode, even if
they are privileged.
This change plugs these holes. In particular, protocols must now opt in
to allowing creation of a socket in capability mode. This is signaled
by setting PR_CAPATTACH in the protocol switch. Local and internet
sockets are permitted. The former because one may legitimately create
and bind a local socket to a relative path using bindat(2). The latter
because some existing code (e.g., capsicum tests) depends on this
ability.
ioctl() is handled by disallowing calls to ifioctl(), in_control() and
in6_control() from capability model. It may be useful at some point to
enable specific ioctls like we do for sysctls. Some testing with
capsicumized programs in the base system hasn't yet revealed any such
ioctls.