From: Remi Gacogne Date: Thu, 27 Feb 2020 11:34:23 +0000 (+0100) Subject: rec: Enforce 'proxy-protocol-maximum-size' X-Git-Tag: dnsdist-1.5.0-alpha1~12^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95f851d662d5a35ff3fb74f427747f42dd857792;p=thirdparty%2Fpdns.git rec: Enforce 'proxy-protocol-maximum-size' --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 24a94fcd88..596fd5e25e 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -2050,7 +2050,8 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var) the connection was received over UDP or TCP if neede */ bool tcp; bool proxy = false; - if (parseProxyHeader(conn->data, proxy, conn->d_source, conn->d_destination, tcp, conn->proxyProtocolValues) <= 0) { + size_t used = parseProxyHeader(conn->data, proxy, conn->d_source, conn->d_destination, tcp, conn->proxyProtocolValues); + if (used <= 0) { if (g_logCommonErrors) { g_log<d_remote.toStringWithPort() <removeReadFD(fd); return; } + else if (static_cast(used) > g_proxyProtocolMaximumSize) { + if (g_logCommonErrors) { + g_log<d_remote.toStringWithPort() << " is larger than proxy-protocol-maximum-size (" << used << "), dropping"<< endl; + } + ++g_stats.proxyProtocolInvalidCount; + t_fdm->removeReadFD(fd); + return; + } /* check the real source */ /* note that if the proxy header used a 'LOCAL' command, the original source and destination are untouched so everything should be fine */ @@ -2645,17 +2654,25 @@ static void handleNewUDPQuestion(int fd, FDMultiplexer::funcparam_t& var) if (used <= 0) { ++g_stats.proxyProtocolInvalidCount; if (!g_quiet) { - g_log<(used) > g_proxyProtocolMaximumSize) { + if (g_quiet) { + g_log< 512) { /* we only allow UDP packets larger than 512 for those with a proxy protocol header */ g_stats.truncatedDrops++; if (!g_quiet) { - g_log<