add support for writev sys call

This commit is contained in:
virusdefender 2017-05-20 13:37:06 +08:00 committed by LiYang
parent 817275e13d
commit 3f60f3bb00
3 changed files with 29 additions and 2 deletions

View File

@ -32,6 +32,9 @@ int c_cpp_seccomp_rules(struct config *_config) {
if (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 1, SCMP_A0(SCMP_CMP_LE, 2)) != 0) { if (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 1, SCMP_A0(SCMP_CMP_LE, 2)) != 0) {
return LOAD_SECCOMP_FAILED; return LOAD_SECCOMP_FAILED;
} }
if (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(writev), 1, SCMP_A0(SCMP_CMP_LE, 2)) != 0) {
return LOAD_SECCOMP_FAILED;
}
if (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(lseek), 1, SCMP_A0(SCMP_CMP_LE, 2)) != 0) { if (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(lseek), 1, SCMP_A0(SCMP_CMP_LE, 2)) != 0) {
return LOAD_SECCOMP_FAILED; return LOAD_SECCOMP_FAILED;
} }

View File

@ -33,7 +33,7 @@ class IntegrationTest(base.BaseTestCase):
return super(IntegrationTest, self)._compile_c("../../test_src/integration/" + src_name, extra_flags) return super(IntegrationTest, self)._compile_c("../../test_src/integration/" + src_name, extra_flags)
def _compile_cpp(self, src_name): def _compile_cpp(self, src_name):
return super(IntegrationTest, self)._compile_cpp("integration/" + src_name) return super(IntegrationTest, self)._compile_cpp("../../test_src/integration/" + src_name)
def test_args_validation(self): def test_args_validation(self):
with self.assertRaisesRegexp(ValueError, "Invalid args and kwargs"): with self.assertRaisesRegexp(ValueError, "Invalid args and kwargs"):
@ -314,4 +314,14 @@ class IntegrationTest(base.BaseTestCase):
config["max_stack"] = 128 * 1024 * 1024 config["max_stack"] = 128 * 1024 * 1024
result = _judger.run(**config) result = _judger.run(**config)
self.assertEqual(result["result"], _judger.RESULT_SUCCESS) self.assertEqual(result["result"], _judger.RESULT_SUCCESS)
self.assertEqual("big stack", self.output_content(config["output_path"])) self.assertEqual("big stack", self.output_content(config["output_path"]))
def test_writev(self):
config = self.config
config["exe_path"] = self._compile_cpp("writev.cpp")
config["seccomp_rule_name"] = "c_cpp"
config["input_path"] = self.make_input("111" * 10000 + "\n")
config["output_path"] = config["error_path"] = self.output_path()
result = _judger.run(**config)
self.assertEqual(result["result"], _judger.RESULT_SUCCESS)

View File

@ -0,0 +1,14 @@
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
string s;
cin >> s;
cout << s;
return 0;
}