Skip to content

Commit

Permalink
feat(judge): use bwrap to limit program. Thanks to @HeRaNO
Browse files Browse the repository at this point in the history
  • Loading branch information
alphagocc committed Jun 16, 2024
1 parent ceabc60 commit 4dc6170
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion makespec/BUILDVERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
256
258
37 changes: 36 additions & 1 deletion src/core/judgingthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,39 @@ void JudgingThread::runProgram() {
watcher.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner);
auto *runner = new QProcess(this);
QStringList argumentsList;

argumentsList << "--ro-bind"
<< "/usr"
<< "/usr";
argumentsList << "--symlink"
<< "/usr/lib"
<< "/lib";
argumentsList << "--symlink"
<< "/usr/lib64"
<< "/lib64";
argumentsList << "--symlink"
<< "/usr/bin"
<< "/bin";
argumentsList << "--symlink"
<< "/usr/sbin"
<< "/sbin";
argumentsList << "--tmpfs"
<< "/tmp";

argumentsList << "--unshare-all"
<< "--die-with-parent";

argumentsList << "--chdir" << workingDirectory;

argumentsList << "--bind" << workingDirectory << workingDirectory;

if (task->getStandardInputCheck()) {
argumentsList << "--ro-bind" << QFileInfo(inputFile).absoluteFilePath()
<< QFileInfo(inputFile).absoluteFilePath();
}

argumentsList << watcher.fileName();

argumentsList << QString("\"%1\" %2").arg(executableFile, arguments);

if (task->getStandardInputCheck()) {
Expand All @@ -902,9 +935,11 @@ void JudgingThread::runProgram() {
argumentsList << QString("%1").arg(timeLimit + extraTime);
argumentsList << QString("%1").arg(memoryLimit);

qDebug() << argumentsList;

runner->setProcessEnvironment(environment);
runner->setWorkingDirectory(workingDirectory);
runner->start(watcher.fileName(), argumentsList);
runner->start("/usr/bin/bwrap", argumentsList);

if (! runner->waitForStarted(-1)) {
delete runner;
Expand Down

0 comments on commit 4dc6170

Please sign in to comment.