Клиент SOCKS5 в subsys/net/lib/socks/socks.c построил запрос CONNECT в socks5_tcp_connect(), выбрав тип адреса SOCKS5 из семейства адресов прокси (proxy->sa_family) при чтении байтов из адреса назначения, предоставленного для подключения(). Запрос SOCKS5 кодирует пункт назначения независимо от транспорта, используемого для достижения прокси, поэтому два семейства не связаны между собой, и ничто на пути не заставляет их согласиться: set_context_proxy() требует, чтобы семейство прокси соответствовало сокету, а zsock_connect_ctx() входит в ветку SOCKS перед любой проверкой назначения. При использовании прокси-сервера IPv6 и адресата AF_INET код рассматривал 8-байтовую структуру net_sockaddr_in как структуру net_sockaddr_in6 и копировал 16-байтовый sin6_addr из него, считывая 12 байт мимо конца объекта и передавая их прокси-серверу.
С включенным CONFIG_USERSPACE z_vrfy_zsock_connect () копирует только байты пользователя в резидентную структуру net_sockaddr_storage и не применяет минимальную длину для каждого семейства, поэтому негабаритное чтение остается в хранилище, но возвращает устаревшие, неинициализированные байты стека ядра. Таким образом, непривилегированный поток пользовательского режима может открыть сокет потока AF_INET6, указать setsockopt(SO_SOCKS5) на прокси-сервере, которым он управляет, и вызвать connect() с коротким назначением AF_INET, чтобы ядро отправило ему 12 байт остатков стека супервизоров за попытку. Без CONFIG_USERSPACE чтение проходит через конец собственной структуры вызывающего абонента net_sockaddr_in, раскрывая смежную память прокси; несоответствие семейства может возникнуть непреднамеренно, когда получатель получен из DNS, в то время как прокси IPv6 настроен.
Воздействие ограничено раскрытием информации не более 12 байт на вызов connect(), без примитивной записи; утечка доставляется тому, кто управляет прокси SOCKS5. Зеркальное сопряжение (назначение IPv6 через прокси-сервер IPv4) является безопасным для памяти, но кодируется как SOCKS5_ATYP_IPV4 из первых четырех байтов адреса IPv6, в результате чего прокси-сервер подключается к несвязанному хосту. Эксплуатация требует опции CONFIG_SOCKS без дефолта, сокета с настройкой SO_SOCKS5 и поддержки IPv4 и IPv6 в изображении.
Исправление перемещает кодировку в помощник, который выбирает тип адреса из dest->sa_family и проверяет dest_len против соответствующей структуры net_sockaddr_in/struct net_sockaddr_in6 перед копированием, отклоняя недостающие или неподдерживаемые назначения с ошибкой.
Показать оригинальное описание (EN)
The SOCKS5 client in subsys/net/lib/socks/socks.c built the CONNECT request in socks5_tcp_connect() by choosing the SOCKS5 address type from the address family of the proxy (proxy->sa_family) while reading the bytes out of the destination address supplied to connect(). A SOCKS5 request encodes the destination independently of the transport used to reach the proxy, so the two families are unrelated and nothing in the path forces them to agree: set_context_proxy() only requires the proxy family to match the socket, and zsock_connect_ctx() enters the SOCKS branch before any destination validation. With an IPv6 proxy and an AF_INET destination the code treated an 8-byte struct net_sockaddr_in as a struct net_sockaddr_in6 and copied the 16-byte sin6_addr from it, reading 12 bytes past the end of the object and transmitting them to the proxy. With CONFIG_USERSPACE enabled, z_vrfy_zsock_connect() copies only addrlen user bytes into a stack-resident struct net_sockaddr_storage and enforces no per-family minimum length, so the oversized read stays within the storage but returns stale, uninitialised kernel-stack bytes. An unprivileged user-mode thread can therefore open an AF_INET6 stream socket, point setsockopt(SO_SOCKS5) at a proxy it controls, and call connect() with a short AF_INET destination to have the kernel send it 12 bytes of supervisor stack residue per attempt. Without CONFIG_USERSPACE the read runs past the end of the caller's own struct net_sockaddr_in, disclosing adjacent memory to the proxy; the family mismatch can arise unintentionally when a destination is obtained from DNS while an IPv6 proxy is configured. Impact is limited to information disclosure of at most 12 bytes per connect() call, with no write primitive; the leak is delivered to whoever operates the SOCKS5 proxy. The mirrored pairing (IPv6 destination through an IPv4 proxy) is memory-safe but encoded the destination as SOCKS5_ATYP_IPV4 from the first four bytes of the IPv6 address, causing the proxy to connect to an unrelated host. Exploitation requires the non-default CONFIG_SOCKS option, a socket with SO_SOCKS5 configured, and both IPv4 and IPv6 support in the image. The fix moves the encoding into a helper that selects the address type from dest->sa_family and validates dest_len against the matching struct net_sockaddr_in/struct net_sockaddr_in6 before copying, rejecting under-length or unsupported destinations with an error.
Характеристики атаки
Последствия
Строка CVSS v3.1