Page MenuHomeFreeBSD

sockets: on accept(2) don't copy all of so_options to new socket
ClosedPublic

Authored by glebius on Aug 10 2023, 10:22 PM.
Tags
None
Referenced Files
F103828814: D41412.diff
Fri, Nov 29, 11:45 PM
Unknown Object (File)
Tue, Nov 19, 4:08 PM
Unknown Object (File)
Wed, Nov 13, 1:06 PM
Unknown Object (File)
Oct 29 2024, 1:20 PM
Unknown Object (File)
Oct 2 2024, 2:34 AM
Unknown Object (File)
Oct 2 2024, 12:28 AM
Unknown Object (File)
Sep 24 2024, 9:44 AM
Unknown Object (File)
Sep 23 2024, 11:22 PM
Subscribers

Details

Summary

As uncovered by e3ba0d6adde3 we are copying lots of irrelevant options
from the listener to an accepted socket, even those that aren't relevant
to a non-listener, e.g. SO_REUSE*, SO_ACCEPTFILTER. Stop doing that
and provide a fixed opt-in list for options to be inherited. Ideally
we shall not inherit anything at all. For compatibility inherit a set
of options that are meaningful for a non-listening socket of a protocol
that can listen(2).

Fixes: e3ba0d6adde3c694f46a30b3b67eba43a7099395

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 53037
Build 49928: arc lint + arc unit

Event Timeline

sys/kern/uipc_socket.c
765

What about SO_DEBUG? Not that this is actually used right now, but I could envision a use case where I want to investigate all sockets related to a specific server and I would cover the period of time where it is still in the accept queue.

sys/kern/uipc_socket.c
765

I skipped it due to being unused. I wanted to make the list as small as possible. I can add it if there is a plan to ever reuse it.

sys/kern/uipc_socket.c
765

I think rscheff@ mentioned that he uses it for controlling adhoc debug code.

I personally would prefer to either remove SO_DEBUG completely or have it inherited. Both look consistent to me. Having it, but not inheriting it look inconsistent to me.

sys/kern/uipc_socket.c
765

We are keeping it in /usr/include/sys/socket.h to avoid unnecessary compilation failures for historic applications.

sys/kern/uipc_socket.c
762

IMHO it would be nice to put this info in a user-facing document, i.e., accept.2.

765
sys/kern/uipc_socket.c
762

I think it would be great to document this.

Maybe add a table to getsockopt(2) specifying for each SOL_SOCKET level socket option, whether it is inherited or not from a listener. Or to accept(2). However, getsockopt(2) already contains a list of SOL_SOCKET level socket options...

sys/kern/uipc_socket.c
765

Indeed I use it for ad-hoc debugging, since it has no side-effects (other than enabling my local debugging stuff). But I don't need inheritance of it generally, so I'm fine with the current list.

This revision was not accepted when it landed; it landed in state Needs Review.Aug 14 2023, 7:57 PM
This revision was automatically updated to reflect the committed changes.