Skip to content

Commit 4f3d42b

Browse files
authored
Merge pull request #34 from A-dead-pixel/rseq-PR
Fix handling of rseq syscall
2 parents 7be4e0e + 717181e commit 4f3d42b

File tree

7 files changed

+31
-23
lines changed

7 files changed

+31
-23
lines changed

external/libseccomp.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ IF((NOT DEFINED LIBSECCOMP_BUILD_OWN AND (NOT EXISTS "${libseccomp_LIB_PATH}" OR
5959
ENDIF()
6060

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

6565
CONFIGURE_COMMAND
6666
CFLAGS=${EXTRA_FLAGS} CXXFLAGS=${EXTRA_FLAGS} <SOURCE_DIR>/configure

src/common/ProcFS.cc

+9-6
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ auto stoull = static_cast<
1717
std::stoull);
1818
const std::map<s2j::procfs::Field, FieldReader> FIELD_READERS = {
1919
{s2j::procfs::Field::VM_PEAK,
20-
FieldReader{"VmPeak",
21-
std::bind(stoull, std::placeholders::_1, nullptr, 10)}},
20+
FieldReader{
21+
"VmPeak",
22+
std::bind(stoull, std::placeholders::_1, nullptr, 10)}},
2223
{s2j::procfs::Field::VM_SIZE,
23-
FieldReader{"VmSize",
24-
std::bind(stoull, std::placeholders::_1, nullptr, 10)}},
24+
FieldReader{
25+
"VmSize",
26+
std::bind(stoull, std::placeholders::_1, nullptr, 10)}},
2527
{s2j::procfs::Field::SIG_CGT,
26-
FieldReader{"SigCgt",
27-
std::bind(stoull, std::placeholders::_1, nullptr, 16)}}};
28+
FieldReader{
29+
"SigCgt",
30+
std::bind(stoull, std::placeholders::_1, nullptr, 16)}}};
2831

2932
} // namespace
3033

src/limits/TimeLimitListener.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ void TimeLimitListener::onPostExecute() {
9999
verifyTimeUsage(move(time));
100100
}
101101

102-
executor::ExecuteAction TimeLimitListener::verifyTimeUsage(std::unique_ptr<TimeLimitListener::TimeUsage> timeUsage) {
102+
executor::ExecuteAction TimeLimitListener::verifyTimeUsage(
103+
std::unique_ptr<TimeLimitListener::TimeUsage> timeUsage) {
103104
if (rTimelimitUs_ != 0 && timeUsage->realTimeUs > rTimelimitUs_) {
104105
outputBuilder_->setKillReason(
105106
printer::OutputBuilder::KillReason::TLE,
@@ -141,7 +142,8 @@ uint64_t TimeLimitListener::getRealTimeUsage() const {
141142
return realTimeUsageUs;
142143
}
143144

144-
TimeLimitListener::ProcessTimeUsage TimeLimitListener::getProcessTimeUsage() const {
145+
TimeLimitListener::ProcessTimeUsage TimeLimitListener::getProcessTimeUsage()
146+
const {
145147
std::ifstream stat("/proc/" + std::to_string(childPid_) + "/stat");
146148
if (!stat.good()) {
147149
throw SystemException("Error reading /proc/childPid_/stat");
@@ -167,13 +169,11 @@ TimeLimitListener::ProcessTimeUsage TimeLimitListener::getProcessTimeUsage() con
167169
return result;
168170
}
169171

170-
std::unique_ptr<TimeLimitListener::TimeUsage> TimeLimitListener::getTimeUsage() const {
171-
return std::make_unique<TimeUsage>(
172-
TimeUsage{
172+
std::unique_ptr<TimeLimitListener::TimeUsage> TimeLimitListener::getTimeUsage()
173+
const {
174+
return std::make_unique<TimeUsage>(TimeUsage{
173175
.realTimeUs = getRealTimeUsage(),
174-
.processTimeUs = getProcessTimeUsage()
175-
}
176-
);
176+
.processTimeUs = getProcessTimeUsage()});
177177
}
178178

179179
} // namespace limits

src/printer/RealTimeOIOutputBuilder.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ std::string RealTimeOIOutputBuilder::dump() const {
1717

1818
std::stringstream ss;
1919
ss << killReasonName(reason) << " " << exitStatus_ << " "
20-
<< realMilliSecondsElapsed_ << " "
21-
<< 0ULL << " " << memoryPeakKb_ << " "
20+
<< realMilliSecondsElapsed_ << " " << 0ULL << " " << memoryPeakKb_ << " "
2221
<< syscallsCounter_ << std::endl;
2322
dumpStatus(ss);
2423
ss << std::endl;

src/s2japp/ApplicationSettings.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ const FactoryMap<s2j::printer::OutputBuilder>
9292
std::make_shared<s2j::printer::OITimeToolOutputBuilder>},
9393
{"oiaug",
9494
std::make_shared<s2j::printer::AugmentedOIOutputBuilder>},
95-
{"oireal",
96-
std::make_shared<s2j::printer::RealTimeOIOutputBuilder>}
97-
});
95+
{"oireal",
96+
std::make_shared<s2j::printer::RealTimeOIOutputBuilder>}});
9897
const std::string ApplicationSettings::DEFAULT_OUTPUT_FORMAT = "oitt";
9998

10099
const FactoryMap<s2j::seccomp::policy::BaseSyscallPolicy>

src/seccomp/SeccompListener.cc

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ std::string SeccompListener::resolveSyscallNumber(
193193
char* name = seccomp_syscall_resolve_num_arch(
194194
SeccompContext::SECCOMP_FILTER_ARCHITECTURES.at(arch),
195195
syscallNumber);
196+
if (name == NULL)
197+
throw Exception(
198+
"Can't resolve the name of syscall number " +
199+
std::to_string(syscallNumber));
196200
std::string syscallName(name);
197201
free(name);
198202
return syscallName;

src/seccomp/policy/DefaultPolicy.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ void DefaultPolicy::addExecutionControlRules(bool allowFork) {
4444
"clock_nanosleep",
4545
"open",
4646
"epoll_create1",
47-
"openat"
48-
});
47+
"openat"});
4948

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

89+
for (const auto& syscall: {"rseq"}) {
90+
rules_.emplace_back(SeccompRule(syscall, action::ActionErrno(ENOSYS)));
91+
}
92+
9093
if (allowFork) {
9194
allowSyscalls({"fork"});
9295
}

0 commit comments

Comments
 (0)