From 95f851d662d5a35ff3fb74f427747f42dd857792 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 27 Feb 2020 12:34:23 +0100 Subject: [PATCH] rec: Enforce 'proxy-protocol-maximum-size' --- pdns/pdns_recursor.cc | 23 ++++++- .../test_ProxyProtocol.py | 63 ++++++++++++++++--- 2 files changed, 76 insertions(+), 10 deletions(-) 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<