Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 37 additions & 0 deletions bin/controller/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@
#include <iostream>
#include <string>

#ifdef Linux
#include <sys/prctl.h>
#endif

namespace {

//! Prevent same-UID peers (e.g. a compromised pytorch_inference / JVM Attach
//! agent in the shared pod) from writing this process's memory via
//! /proc/<pid>/mem. That path was used to overwrite access@GOT and turn a
//! controller spawn into dlopen (elastic/security#12621). Fail closed: if we
//! cannot establish the boundary, refuse to accept commands.
bool makeProcessNonDumpable() {
#ifdef Linux
if (::prctl(PR_SET_DUMPABLE, 0) != 0) {
LOG_ERROR(<< "prctl PR_SET_DUMPABLE(0) failed: " << std::strerror(errno));
return false;
}
// Confirm the attribute stuck — a silent no-op would leave the process exposed.
if (::prctl(PR_GET_DUMPABLE) != 0) {
LOG_ERROR(<< "process remains dumpable after PR_SET_DUMPABLE(0)");
return false;
}
return true;
#else
// /proc/<pid>/mem same-UID writes are a Linux concern; no equivalent gate here.
return true;
#endif
}
}

int main(int argc, char** argv) {
const std::string& defaultNamedPipePath{ml::core::CNamedPipeFactory::defaultPath()};
const std::string& progName{ml::core::CProgName::progName()};
Expand Down Expand Up @@ -122,6 +152,13 @@ int main(int argc, char** argv) {
// statically links its own version library.
LOG_INFO(<< ml::ver::CBuildInfo::fullInfo());

// Harden against same-UID /proc/<pid>/mem writes before accepting commands.
if (makeProcessNonDumpable() == false) {
LOG_FATAL(<< "Could not mark ML controller non-dumpable");
cancellerThread.stop();
return EXIT_FAILURE;
}

// Unlike other programs we DON'T reduce the process priority here, because
// the controller is critical to the overall system. Also its resource
// requirements should always be very low.
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog/3081.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
area: Machine Learning
issues: []
pr: 3081
summary: Mark ML controller non-dumpable before accepting commands
type: bug