openssl/crypto/bio
Alexandr Nedvedicky c062403abd OpenSSL 3.2.0, QUIC, macOS, error 56 on connected UDP socket
current `translate_msg()` function attempts to set `->msg_name`
(and `->msg_namelen`) with `BIO`'s peer name (connection destination)
regardless if underlying socket is connected or not. Such implementation
uncovers differences in socket implementation between various OSes.

As we have learned hard way `sendmsg()` and `sendmmsg()` on `OpenBSD`
and (`MacOS` too) fail to send messages with `->msg_name` being
set on connected socket. In such case the caller receives
`EISCON` errro.

I think `translate_msg()` caller should provide a hint to indicate
whether we deal with connected (or un-connected) socket. For
connected sockets the peer's name should not be set/filled
by `translate_msg()`. On the other hand if socket is un-connected,
then `translate_msg()` must populate `->msg_name` and `->msg_namelen`
members.

The caller can use `getpeername(2)` to see if socket is
connected. If `getpeername()` succeeds then we must be dealing
with connected socket and `translate_msg()` must not set
`->msg_name` and `->msg_namelen` members. If `getpeername(2)`
fails, then `translate_msg()` must provide peer's name (destination
address) in `->msg_name` and set `->msg_namelen` accordingly.

The propposed fix introduces `is_connected()` function,
which applies `getpeername()` to socket bound to `BIO` instance.
The `dgram_sendmmsg()` uses `is_connected()` as a hint
for `translate_msg()` function, so msghdr gets initialized
with respect to socket state.

The change also modifies existing `test/quic_client_test.c`
so it also covers the case of connected socket. To keep
things simple we can introduce optional argument `connect_first`
to `./quic_client_test` function. Without `connect_first`
the test run as usual. With `connect_first` the test creates
and connects socket first. Then it passes such socket to
`BIO` sub-system to perform `QUIC` connect test as usual.

Fixes #23251

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23396)
2024-04-16 16:36:57 +02:00
..
bf_buff.c Copyright year updates 2023-09-07 09:59:15 +01:00
bf_lbuf.c Copyright year updates 2023-09-07 09:59:15 +01:00
bf_nbio.c
bf_null.c
bf_prefix.c
bf_readbuff.c
bio_addr.c Copyright year updates 2023-09-28 14:23:29 +01:00
bio_cb.c
bio_dump.c Optimize circular buffer to avoid modulo 2023-12-22 14:45:55 +01:00
bio_err.c
bio_lib.c Fix socket descriptor checks on Windows 2024-04-10 09:25:23 +02:00
bio_local.h Copyright year updates 2023-09-07 09:59:15 +01:00
bio_meth.c Copyright year updates 2024-04-09 13:43:26 +02:00
bio_print.c Fix typos found by codespell 2023-09-13 08:13:08 +02:00
bio_sock2.c
bio_sock.c Fix socket descriptor checks on Windows 2024-04-10 09:25:23 +02:00
bss_acpt.c Copyright year updates 2023-09-07 09:59:15 +01:00
bss_bio.c
bss_conn.c BIO_s_connect: Do not set keepalive on dgram sockets 2024-04-02 19:04:10 +02:00
bss_core.c
bss_dgram_pair.c Fix a failure in bio_dgram_test on the NonStop platform 2023-09-13 11:53:13 +01:00
bss_dgram.c OpenSSL 3.2.0, QUIC, macOS, error 56 on connected UDP socket 2024-04-16 16:36:57 +02:00
bss_fd.c
bss_file.c
bss_log.c Copyright year updates 2023-09-07 09:59:15 +01:00
bss_mem.c Copyright year updates 2023-09-07 09:59:15 +01:00
bss_null.c
bss_sock.c Copyright year updates 2023-09-28 14:23:29 +01:00
build.info
ossl_core_bio.c Copyright year updates 2023-09-07 09:59:15 +01:00