Attention is currently required from: pespin.

Correct, AF_UNIX would fail here. Worth being precise about what this patch changes for that case: nothing.

Before the patch bind() got sizeof(struct osmo_sockaddr), 128. osmo_sockaddr_size() returns the same 128 for AF_UNIX, because the family falls through to the default branch. AF_UNIX is therefore exactly as broken after this patch as before it, and the patch is a strict fix for AF_INET and AF_INET6 only. No regression, but no improvement either.

The type does not stop it: the union has a sockaddr_storage member, 128 bytes, and sockaddr_un fits in it (106 bytes on Darwin, and well under 128 on glibc too). libosmocore relies on that in osmo_sock_get_name_buf(), which getsockname()s into an osmo_sockaddr and then reads the AF_UNIX case back through a struct sockaddr_un *.

Nor does anything in the function reject it. The AF_UNSPEC case in socket_test.c fails only because it is a BIND|CONNECT pair with mismatched families and the same-family check catches it. A BIND-only call with an unsupported family reaches bind() with namelen 128, unchecked.

In practice AF_UNIX callers use osmo_sock_unix_init(), which computes SUN_LEN() itself, and every in-tree osmo_sock_init_osa() caller passes IP. So this is latent rather than an active bug. It is an exported symbol though, so out-of-tree callers are not covered by that argument.

Two ways to close it, if you want it closed:

(a) osmo_sockaddr_size() default branch: LOGP an error and return 0 instead of sizeof(struct osmo_sockaddr). One place, and it covers bind, connect and the three osmo_io msg_namelen callers, where a bogus family currently makes sendmsg read 128 stray bytes instead of treating msg_name as unset. It does change documented behaviour: the docstring promises the size of struct osmo_sockaddr for an unsupported family.

(b) Early return -EINVAL in osmo_sock_init_osa() for anything other than AF_INET and AF_INET6. Narrower, no contract change.

I lean (a) for the wider effect, but (b) is the conservative one. Either way I would send it as a separate change on top of this one rather than fold it in, since it is a different bug from the namelen fix. Tell me which you prefer, or mark this resolved if you would rather leave it as is.

View Change

1 comment:

To view, visit change 43574. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: comment
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I37cb08a6e1809d51c97e666f980d4c68f8b56933
Gerrit-Change-Number: 43574
Gerrit-PatchSet: 1
Gerrit-Owner: andrei.gosman@gmail.com <andrei.gosman@gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin@sysmocom.de>
Gerrit-Attention: pespin <pespin@sysmocom.de>
Gerrit-Comment-Date: Mon, 21 Sep 2026 18:45:30 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: pespin <pespin@sysmocom.de>