Android sandbox: workaround for restricted errno values.
On Android, errno are only supported up to 255 and are not processed otherwise. Fix a test to work around this issue. BUG=181647,169416 NOTRY=true TBR=markus Review URL: https://chromiumcodereview.appspot.com/12638015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187410 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
sandbox/linux/seccomp-bpf
@ -34,6 +34,8 @@ class ErrorCode {
|
||||
// indicate success, but it won't actually run the system call.
|
||||
// This is very different from return ERR_ALLOWED.
|
||||
ERR_MIN_ERRNO = 0,
|
||||
// TODO(markus): Android only supports errno up to 255
|
||||
// (crbug.com/181647).
|
||||
ERR_MAX_ERRNO = 4095,
|
||||
};
|
||||
|
||||
|
@ -8,7 +8,9 @@
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(ANDROID)
|
||||
// Work-around for buggy headers in Android's NDK
|
||||
@ -19,6 +21,7 @@
|
||||
#include <ostream>
|
||||
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "build/build_config.h"
|
||||
#include "sandbox/linux/seccomp-bpf/bpf_tests.h"
|
||||
#include "sandbox/linux/seccomp-bpf/syscall.h"
|
||||
#include "sandbox/linux/seccomp-bpf/trap.h"
|
||||
@ -44,6 +47,14 @@ namespace {
|
||||
const int kExpectedReturnValue = 42;
|
||||
const char kSandboxDebuggingEnv[] = "CHROME_SANDBOX_DEBUGGING";
|
||||
|
||||
inline bool IsAndroid() {
|
||||
#if defined(OS_ANDROID)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// This test should execute no matter whether we have kernel support. So,
|
||||
// we make it a TEST() instead of a BPF_TEST().
|
||||
TEST(SandboxBpf, CallSupports) {
|
||||
@ -214,7 +225,7 @@ ErrorCode ErrnoTestPolicy(Sandbox *, int sysno, void *) {
|
||||
#if defined(__NR_setuid32)
|
||||
case __NR_setuid32:
|
||||
#endif
|
||||
// Return errno = 1
|
||||
// Return errno = 1.
|
||||
return ErrorCode(1);
|
||||
case __NR_setgid:
|
||||
#if defined(__NR_setgid32)
|
||||
@ -222,6 +233,9 @@ ErrorCode ErrnoTestPolicy(Sandbox *, int sysno, void *) {
|
||||
#endif
|
||||
// Return maximum errno value (typically 4095).
|
||||
return ErrorCode(ErrorCode::ERR_MAX_ERRNO);
|
||||
case __NR_uname:
|
||||
// Return errno = 42;
|
||||
return ErrorCode(42);
|
||||
default:
|
||||
return ErrorCode(ErrorCode::ERR_ALLOWED);
|
||||
}
|
||||
@ -243,10 +257,28 @@ BPF_TEST(SandboxBpf, ErrnoTest, ErrnoTestPolicy) {
|
||||
BPF_ASSERT(buf[0] == '\x55');
|
||||
|
||||
// Verify that we can return the minimum and maximum errno values.
|
||||
errno = 0;
|
||||
BPF_ASSERT(setuid(0) == -1);
|
||||
BPF_ASSERT(errno == 1);
|
||||
BPF_ASSERT(setgid(0) == -1);
|
||||
BPF_ASSERT(errno == ErrorCode::ERR_MAX_ERRNO);
|
||||
|
||||
// On Android, errno is only supported up to 255, otherwise errno
|
||||
// processing is skipped.
|
||||
// We work around this (crbug.com/181647).
|
||||
if (IsAndroid() && setgid(0) != -1) {
|
||||
errno = 0;
|
||||
BPF_ASSERT(setgid(0) == -ErrorCode::ERR_MAX_ERRNO);
|
||||
BPF_ASSERT(errno == 0);
|
||||
} else {
|
||||
errno = 0;
|
||||
BPF_ASSERT(setgid(0) == -1);
|
||||
BPF_ASSERT(errno == ErrorCode::ERR_MAX_ERRNO);
|
||||
}
|
||||
|
||||
// Finally, test an errno in between the minimum and maximum.
|
||||
errno = 0;
|
||||
struct utsname uts_buf;
|
||||
BPF_ASSERT(uname(&uts_buf) == -1);
|
||||
BPF_ASSERT(errno == 42);
|
||||
}
|
||||
|
||||
// Testing the stacking of two sandboxes
|
||||
|
Reference in New Issue
Block a user