Skip to content

Fix handling of rseq syscall #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2023
Merged
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
4 changes: 2 additions & 2 deletions external/libseccomp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ IF((NOT DEFINED LIBSECCOMP_BUILD_OWN AND (NOT EXISTS "${libseccomp_LIB_PATH}" OR
ENDIF()

ExternalProject_Add(seccomp_project
URL https://github.com/seccomp/libseccomp/releases/download/v2.3.3/libseccomp-2.3.3.tar.gz
URL_HASH SHA256=7fc28f4294cc72e61c529bedf97e705c3acf9c479a8f1a3028d4cd2ca9f3b155
URL https://github.com/seccomp/libseccomp/releases/download/v2.5.4/libseccomp-2.5.4.tar.gz
URL_HASH SHA256=d82902400405cf0068574ef3dc1fe5f5926207543ba1ae6f8e7a1576351dcbdb

CONFIGURE_COMMAND
CFLAGS=${EXTRA_FLAGS} CXXFLAGS=${EXTRA_FLAGS} <SOURCE_DIR>/configure
Expand Down
15 changes: 9 additions & 6 deletions src/common/ProcFS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ auto stoull = static_cast<
std::stoull);
const std::map<s2j::procfs::Field, FieldReader> FIELD_READERS = {
{s2j::procfs::Field::VM_PEAK,
FieldReader{"VmPeak",
std::bind(stoull, std::placeholders::_1, nullptr, 10)}},
FieldReader{
"VmPeak",
std::bind(stoull, std::placeholders::_1, nullptr, 10)}},
{s2j::procfs::Field::VM_SIZE,
FieldReader{"VmSize",
std::bind(stoull, std::placeholders::_1, nullptr, 10)}},
FieldReader{
"VmSize",
std::bind(stoull, std::placeholders::_1, nullptr, 10)}},
{s2j::procfs::Field::SIG_CGT,
FieldReader{"SigCgt",
std::bind(stoull, std::placeholders::_1, nullptr, 16)}}};
FieldReader{
"SigCgt",
std::bind(stoull, std::placeholders::_1, nullptr, 16)}}};

} // namespace

Expand Down
16 changes: 8 additions & 8 deletions src/limits/TimeLimitListener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ void TimeLimitListener::onPostExecute() {
verifyTimeUsage(move(time));
}

executor::ExecuteAction TimeLimitListener::verifyTimeUsage(std::unique_ptr<TimeLimitListener::TimeUsage> timeUsage) {
executor::ExecuteAction TimeLimitListener::verifyTimeUsage(
std::unique_ptr<TimeLimitListener::TimeUsage> timeUsage) {
if (rTimelimitUs_ != 0 && timeUsage->realTimeUs > rTimelimitUs_) {
outputBuilder_->setKillReason(
printer::OutputBuilder::KillReason::TLE,
Expand Down Expand Up @@ -141,7 +142,8 @@ uint64_t TimeLimitListener::getRealTimeUsage() const {
return realTimeUsageUs;
}

TimeLimitListener::ProcessTimeUsage TimeLimitListener::getProcessTimeUsage() const {
TimeLimitListener::ProcessTimeUsage TimeLimitListener::getProcessTimeUsage()
const {
std::ifstream stat("/proc/" + std::to_string(childPid_) + "/stat");
if (!stat.good()) {
throw SystemException("Error reading /proc/childPid_/stat");
Expand All @@ -167,13 +169,11 @@ TimeLimitListener::ProcessTimeUsage TimeLimitListener::getProcessTimeUsage() con
return result;
}

std::unique_ptr<TimeLimitListener::TimeUsage> TimeLimitListener::getTimeUsage() const {
return std::make_unique<TimeUsage>(
TimeUsage{
std::unique_ptr<TimeLimitListener::TimeUsage> TimeLimitListener::getTimeUsage()
const {
return std::make_unique<TimeUsage>(TimeUsage{
.realTimeUs = getRealTimeUsage(),
.processTimeUs = getProcessTimeUsage()
}
);
.processTimeUs = getProcessTimeUsage()});
}

} // namespace limits
Expand Down
3 changes: 1 addition & 2 deletions src/printer/RealTimeOIOutputBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ std::string RealTimeOIOutputBuilder::dump() const {

std::stringstream ss;
ss << killReasonName(reason) << " " << exitStatus_ << " "
<< realMilliSecondsElapsed_ << " "
<< 0ULL << " " << memoryPeakKb_ << " "
<< realMilliSecondsElapsed_ << " " << 0ULL << " " << memoryPeakKb_ << " "
<< syscallsCounter_ << std::endl;
dumpStatus(ss);
ss << std::endl;
Expand Down
5 changes: 2 additions & 3 deletions src/s2japp/ApplicationSettings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ const FactoryMap<s2j::printer::OutputBuilder>
std::make_shared<s2j::printer::OITimeToolOutputBuilder>},
{"oiaug",
std::make_shared<s2j::printer::AugmentedOIOutputBuilder>},
{"oireal",
std::make_shared<s2j::printer::RealTimeOIOutputBuilder>}
});
{"oireal",
std::make_shared<s2j::printer::RealTimeOIOutputBuilder>}});
const std::string ApplicationSettings::DEFAULT_OUTPUT_FORMAT = "oitt";

const FactoryMap<s2j::seccomp::policy::BaseSyscallPolicy>
Expand Down
4 changes: 4 additions & 0 deletions src/seccomp/SeccompListener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ std::string SeccompListener::resolveSyscallNumber(
char* name = seccomp_syscall_resolve_num_arch(
SeccompContext::SECCOMP_FILTER_ARCHITECTURES.at(arch),
syscallNumber);
if (name == NULL)
throw Exception(
"Can't resolve the name of syscall number " +
std::to_string(syscallNumber));
std::string syscallName(name);
free(name);
return syscallName;
Expand Down
7 changes: 5 additions & 2 deletions src/seccomp/policy/DefaultPolicy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ void DefaultPolicy::addExecutionControlRules(bool allowFork) {
"clock_nanosleep",
"open",
"epoll_create1",
"openat"
});
"openat"});

rules_.emplace_back(SeccompRule(
"set_thread_area", action::ActionTrace([](auto& /* tracee */) {
Expand Down Expand Up @@ -87,6 +86,10 @@ void DefaultPolicy::addExecutionControlRules(bool allowFork) {
rules_.emplace_back(SeccompRule(syscall, action::ActionTrace()));
}

for (const auto& syscall: {"rseq"}) {
rules_.emplace_back(SeccompRule(syscall, action::ActionErrno(ENOSYS)));
}

if (allowFork) {
allowSyscalls({"fork"});
}
Expand Down