summaryrefslogtreecommitdiffstats
path: root/sandbox
diff options
context:
space:
mode:
authorjln@chromium.org <jln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-11 23:39:21 +0000
committerjln@chromium.org <jln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-11 23:39:21 +0000
commit1c3adf3ec249c1df930f10c74707f4f3cc0e49c8 (patch)
treebeab7354415996767d09109d5a35130be073f2fb /sandbox
parentdc5b118a55f623d89447d3037f03e66bdfbd64fa (diff)
downloadchromium_src-1c3adf3ec249c1df930f10c74707f4f3cc0e49c8.zip
chromium_src-1c3adf3ec249c1df930f10c74707f4f3cc0e49c8.tar.gz
chromium_src-1c3adf3ec249c1df930f10c74707f4f3cc0e49c8.tar.bz2
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
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/linux/seccomp-bpf/errorcode.h2
-rw-r--r--sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc38
2 files changed, 37 insertions, 3 deletions
diff --git a/sandbox/linux/seccomp-bpf/errorcode.h b/sandbox/linux/seccomp-bpf/errorcode.h
index 901525c..61ec110 100644
--- a/sandbox/linux/seccomp-bpf/errorcode.h
+++ b/sandbox/linux/seccomp-bpf/errorcode.h
@@ -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,
};
diff --git a/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc b/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
index b5a62c2..2d775f4 100644
--- a/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
+++ b/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
@@ -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