Fixes for sandbox unit tests on Android

In bionic, open, access and dup2 are wrappers of openat, faccessat and dup3 instead of real syscalls.

BUG=166704

Review URL: https://codereview.chromium.org/226923003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263107 0039d316-1c4b-4281-b951-d872f2087c98
parent 3e014b68
...@@ -213,7 +213,11 @@ ErrorCode ErrnoTestPolicy(SandboxBPF*, int sysno, void*) { ...@@ -213,7 +213,11 @@ ErrorCode ErrnoTestPolicy(SandboxBPF*, int sysno, void*) {
} }
switch (sysno) { switch (sysno) {
#if defined(ANDROID)
case __NR_dup3: // dup2 is a wrapper of dup3 in android
#else
case __NR_dup2: case __NR_dup2:
#endif
// Pretend that dup2() worked, but don't actually do anything. // Pretend that dup2() worked, but don't actually do anything.
return ErrorCode(0); return ErrorCode(0);
case __NR_setuid: case __NR_setuid:
...@@ -703,9 +707,15 @@ intptr_t BrokerOpenTrapHandler(const struct arch_seccomp_data& args, ...@@ -703,9 +707,15 @@ intptr_t BrokerOpenTrapHandler(const struct arch_seccomp_data& args,
BPF_ASSERT(aux); BPF_ASSERT(aux);
BrokerProcess* broker_process = static_cast<BrokerProcess*>(aux); BrokerProcess* broker_process = static_cast<BrokerProcess*>(aux);
switch (args.nr) { switch (args.nr) {
#if defined(ANDROID)
case __NR_faccessat: // access is a wrapper of faccessat in android
return broker_process->Access(reinterpret_cast<const char*>(args.args[1]),
static_cast<int>(args.args[2]));
#else
case __NR_access: case __NR_access:
return broker_process->Access(reinterpret_cast<const char*>(args.args[0]), return broker_process->Access(reinterpret_cast<const char*>(args.args[0]),
static_cast<int>(args.args[1])); static_cast<int>(args.args[1]));
#endif
case __NR_open: case __NR_open:
return broker_process->Open(reinterpret_cast<const char*>(args.args[0]), return broker_process->Open(reinterpret_cast<const char*>(args.args[0]),
static_cast<int>(args.args[1])); static_cast<int>(args.args[1]));
...@@ -728,7 +738,11 @@ ErrorCode DenyOpenPolicy(SandboxBPF* sandbox, int sysno, void* aux) { ...@@ -728,7 +738,11 @@ ErrorCode DenyOpenPolicy(SandboxBPF* sandbox, int sysno, void* aux) {
} }
switch (sysno) { switch (sysno) {
#if defined(ANDROID)
case __NR_faccessat:
#else
case __NR_access: case __NR_access:
#endif
case __NR_open: case __NR_open:
case __NR_openat: case __NR_openat:
// We get a InitializedOpenBroker class, but our trap handler wants // We get a InitializedOpenBroker class, but our trap handler wants
...@@ -799,6 +813,17 @@ ErrorCode SimpleCondTestPolicy(SandboxBPF* sandbox, int sysno, void*) { ...@@ -799,6 +813,17 @@ ErrorCode SimpleCondTestPolicy(SandboxBPF* sandbox, int sysno, void*) {
// can uniquely test for these values. In a "real" policy, you would want // can uniquely test for these values. In a "real" policy, you would want
// to return more traditional values. // to return more traditional values.
switch (sysno) { switch (sysno) {
#if defined(ANDROID)
case __NR_openat: // open is a wrapper of openat in android
// Allow opening files for reading, but don't allow writing.
COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_be_all_zero_bits);
return sandbox->Cond(2,
ErrorCode::TP_32BIT,
ErrorCode::OP_HAS_ANY_BITS,
O_ACCMODE /* 0x3 */,
ErrorCode(EROFS),
ErrorCode(ErrorCode::ERR_ALLOWED));
#else
case __NR_open: case __NR_open:
// Allow opening files for reading, but don't allow writing. // Allow opening files for reading, but don't allow writing.
COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_be_all_zero_bits); COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_be_all_zero_bits);
...@@ -808,6 +833,7 @@ ErrorCode SimpleCondTestPolicy(SandboxBPF* sandbox, int sysno, void*) { ...@@ -808,6 +833,7 @@ ErrorCode SimpleCondTestPolicy(SandboxBPF* sandbox, int sysno, void*) {
O_ACCMODE /* 0x3 */, O_ACCMODE /* 0x3 */,
ErrorCode(EROFS), ErrorCode(EROFS),
ErrorCode(ErrorCode::ERR_ALLOWED)); ErrorCode(ErrorCode::ERR_ALLOWED));
#endif
case __NR_prctl: case __NR_prctl:
// Allow prctl(PR_SET_DUMPABLE) and prctl(PR_GET_DUMPABLE), but // Allow prctl(PR_SET_DUMPABLE) and prctl(PR_GET_DUMPABLE), but
// disallow everything else. // disallow everything else.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment