comparison src/core/ngx_connection.c @ 7119:fef61d26da39

Fixed buffer overread with unix sockets after accept(). Some OSes (notably macOS, NetBSD, and Solaris) allow unix socket addresses larger than struct sockaddr_un. Moreover, some of them (macOS, Solaris) return socklen of the socket address before it was truncated to fit the buffer provided. As such, on these systems socklen must not be used without additional check that it is within the buffer provided. Appropriate checks added to ngx_event_accept() (after accept()), ngx_event_recvmsg() (after recvmsg()), and ngx_set_inherited_sockets() (after getsockname()). We also obtain socket addresses via getsockname() in ngx_connection_local_sockaddr(), but it does not need any checks as it is only used for INET and INET6 sockets (as there can be no wildcard unix sockets).
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 04 Oct 2017 21:19:33 +0300
parents c0d89f602d08
children 66aa2c1e82e6
comparison
equal deleted inserted replaced
7118:b6dc472299da 7119:fef61d26da39
161 ngx_log_error(NGX_LOG_CRIT, cycle->log, ngx_socket_errno, 161 ngx_log_error(NGX_LOG_CRIT, cycle->log, ngx_socket_errno,
162 "getsockname() of the inherited " 162 "getsockname() of the inherited "
163 "socket #%d failed", ls[i].fd); 163 "socket #%d failed", ls[i].fd);
164 ls[i].ignore = 1; 164 ls[i].ignore = 1;
165 continue; 165 continue;
166 }
167
168 if (ls[i].socklen > (socklen_t) sizeof(ngx_sockaddr_t)) {
169 ls[i].socklen = sizeof(ngx_sockaddr_t);
166 } 170 }
167 171
168 switch (ls[i].sockaddr->sa_family) { 172 switch (ls[i].sockaddr->sa_family) {
169 173
170 #if (NGX_HAVE_INET6) 174 #if (NGX_HAVE_INET6)