Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d57f025
dnsdist: Harden the Lua FFI interface against misuse
rgacogne Apr 20, 2026
a335855
dnsdist: Document the "tricky" Lua FFI functions a bit better
rgacogne Apr 21, 2026
116a88b
dnsdist: Use NUL-terminated instead of NULL-terminated
rgacogne May 15, 2026
0115fc2
credentials: Try harder to zero out existing data
rgacogne May 15, 2026
6bd36ba
dnsdist: Appease clang-tidy
rgacogne May 15, 2026
48a602f
dnsdist: Appease clang-tidy (again)
rgacogne May 15, 2026
d7f12ea
dnsdist: More clang-tidy fixes
rgacogne May 17, 2026
20efd8b
dnsdist: More clang-tidy fixes
rgacogne May 18, 2026
bd62a03
dnsdist: Ignore valid backend weight coming from YAML
rgacogne May 18, 2026
99d8867
dnsdist: Handle large YAML values for a backend weight
rgacogne May 18, 2026
7564ba0
credentials: Try even harder to clear existing content
rgacogne May 18, 2026
2fd33d1
dnsdist: More clang-tidy fixes
rgacogne May 18, 2026
700d623
credentials: Fix formatting
rgacogne May 18, 2026
39f9b3e
dnsdist: Reformat harder
rgacogne May 18, 2026
c182a28
credentials: Clear the moved-from string before checking its capacity
rgacogne May 19, 2026
412b545
dnsdist: Apply Miod's suggestion
rgacogne May 19, 2026
1f4760a
dnsdist: Stop trying to be clever; just tell clang-tidy to shut up
rgacogne May 19, 2026
e7fa1c3
credentials: Document that we trying to get the linters to shut the h…
rgacogne May 19, 2026
f0b1cbc
Merge pull request #17393 from rgacogne/ddist-check-backend-weight-yaml
rgacogne May 19, 2026
b2f7f27
Merge pull request #17162 from rgacogne/ddist-harden-ffi-interface
rgacogne May 19, 2026
528f368
Merge pull request #17376 from rgacogne/credentials-zero-out
rgacogne May 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions pdns/credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,41 @@ static std::string const pwhash_prefix = "$scrypt$";
static size_t const pwhash_prefix_size = pwhash_prefix.size();
#endif

void SensitiveData::reallyClearContent(void* data, size_t size) noexcept
{
#ifdef HAVE_LIBSODIUM
sodium_memzero(data, size);
#elif defined(HAVE_EXPLICIT_BZERO)
explicit_bzero(data, size);
#elif defined(HAVE_EXPLICIT_MEMSET)
explicit_memset(data, 0, size);
#elif defined(HAVE_GNUTLS_MEMSET)
gnutls_memset(data, 0, size);
#else
/* shamelessly taken from Dovecot's src/lib/safe-memset.c */
if (size == 0) {
return;
}

volatile unsigned int volatile_zero_idx = 0;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): sorry!
volatile unsigned char* p = reinterpret_cast<volatile unsigned char*>(data);
do {
memset(data, 0, size);
} while (p[volatile_zero_idx] != 0);
#endif
}

SensitiveData::SensitiveData(std::string&& data) :
d_data(std::move(data))
{
// linters are complaining that we are calling data() and capacity() on a moved-from object,
// so clear the object first so they shut up
data.clear();
#ifdef HAVE_LIBSODIUM
// let's be nice and try to zero out the SSO buffer, that cannot be moved
reallyClearContent(data.data(), data.capacity());
#endif
#ifdef HAVE_LIBSODIUM
sodium_mlock(d_data.data(), d_data.size());
#endif
Expand Down Expand Up @@ -88,6 +119,9 @@ SensitiveData::~SensitiveData()
void SensitiveData::clear()
{
#ifdef HAVE_LIBSODIUM
// let's be nice and try to zero out the SSO buffer (be careful, sodium_munlock will zero out the current size
// which might be zero if the object was moved)
reallyClearContent(d_data.data(), d_data.capacity());
sodium_munlock(d_data.data(), d_data.size());
#endif
d_data.clear();
Expand Down
2 changes: 2 additions & 0 deletions pdns/credentials.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public:
return d_data;
}

static void reallyClearContent(void* data, size_t size) noexcept;

private:
std::string d_data;
};
Expand Down
9 changes: 8 additions & 1 deletion pdns/dnsdistdist/dnsdist-configuration-yaml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,14 @@ static std::shared_ptr<DownstreamState> createBackendFromConfiguration(const Con
backendConfig.d_numberOfSockets = config.sockets;
backendConfig.d_qpsLimit = config.queries_per_second;
backendConfig.order = config.order;
backendConfig.d_weight = config.weight;
if (config.weight < 1 || config.weight > std::numeric_limits<decltype(backendConfig.d_weight)>::max()) {
SLOG(warnlog("Ignoring invalid weight on backend %s", std::string(config.address)),
context.logger->info(Logr::Warning, "Ignoring invalid weight on backend", "backend.address", Logging::Loggable(config.address)));
}
else {
backendConfig.d_weight = static_cast<decltype(backendConfig.d_weight)>(config.weight);
}

backendConfig.d_maxInFlightQueriesPerConn = config.max_in_flight;
backendConfig.d_maxUDPOutstanding = config.max_udp_outstanding;
backendConfig.d_tcpConcurrentConnectionsLimit = config.max_concurrent_tcp_connections;
Expand Down
204 changes: 109 additions & 95 deletions pdns/dnsdistdist/dnsdist-lua-ffi-interface.h

Large diffs are not rendered by default.

Loading
Loading