Skip to content

Commit

Permalink
Linux sandbox: add space for 8 parameters to the Syscall() class
Browse files Browse the repository at this point in the history
On some architectures (Mips for example) syscalls can take more
than six parameters.

Add support for 8 native-size parameters in Syscall::Call()

BUG=369594
TEST= sandbox_linux_unittests

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@281823 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
nedeljko.babic@imgtec.com committed Jul 8, 2014
1 parent b856433 commit 33447b3
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 23 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ Naveen Bobbili <naveenbobbili@motorola.com>
Naveen Bobbili <qghc36@motorola.com>
Naveen Kumar S G <naveensg@samsung.com>
Nayan Kumar K <qtc746@motorola.com>
Nedeljko Babic <nedeljko.babic@imgtec.com>
Nikhil Bansal <n.bansal@samsung.com>
Nikita Ofitserov <himikof@gmail.com>
Ningxin Hu <ningxin.hu@intel.com>
Expand Down
11 changes: 10 additions & 1 deletion sandbox/linux/seccomp-bpf/syscall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <errno.h>

#include "base/basictypes.h"
#include "base/logging.h"

namespace sandbox {

Expand Down Expand Up @@ -181,7 +182,9 @@ intptr_t Syscall::Call(int nr,
intptr_t p2,
intptr_t p3,
intptr_t p4,
intptr_t p5) {
intptr_t p5,
intptr_t p6,
intptr_t p7) {
// We rely on "intptr_t" to be the exact size as a "void *". This is
// typically true, but just in case, we add a check. The language
// specification allows platforms some leeway in cases, where
Expand All @@ -192,6 +195,12 @@ intptr_t Syscall::Call(int nr,
COMPILE_ASSERT(sizeof(void*) == sizeof(intptr_t),
pointer_types_and_intptr_must_be_exactly_the_same_size);

// TODO(nedeljko): Enable use of more than six parameters on architectures
// where that makes sense.
DCHECK_EQ(p6, 0) << " Support for syscalls with more than six arguments not "
"added for this architecture";
DCHECK_EQ(p7, 0) << " Support for syscalls with more than six arguments not "
"added for this architecture";
const intptr_t args[6] = {p0, p1, p2, p3, p4, p5};

// Invoke our file-scope assembly code. The constraints have been picked
Expand Down
92 changes: 70 additions & 22 deletions sandbox/linux/seccomp-bpf/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,8 @@ namespace sandbox {
// low-level control.
class SANDBOX_EXPORT Syscall {
public:
// This performs system call |nr| with the arguments p0 to p5 from a constant
// userland address, which is for instance observable by seccomp-bpf filters.
// The constant userland address from which these system calls are made will
// be returned if |nr| is passed as -1.
// On error, this function will return a value between -1 and -4095 which
// should be interpreted as -errno.
static intptr_t Call(int nr,
intptr_t p0,
intptr_t p1,
intptr_t p2,
intptr_t p3,
intptr_t p4,
intptr_t p5);

// System calls can take up to six parameters. Traditionally, glibc
// System calls can take up to six parameters (up to eight on some
// architectures). Traditionally, glibc
// implements this property by using variadic argument lists. This works, but
// confuses modern tools such as valgrind, because we are nominally passing
// uninitialized data whenever we call through this function and pass less
Expand All @@ -41,6 +28,47 @@ class SANDBOX_EXPORT Syscall {
// necessary.
// We have to use C-style cast operators as we want to be able to accept both
// integer and pointer types.
template <class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7>
static inline intptr_t
Call(int nr, T0 p0, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7) {
return Call(nr,
(intptr_t)p0,
(intptr_t)p1,
(intptr_t)p2,
(intptr_t)p3,
(intptr_t)p4,
(intptr_t)p5,
(intptr_t)p6,
(intptr_t)p7);
}

template <class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6>
static inline intptr_t
Call(int nr, T0 p0, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6) {
return Call(nr,
(intptr_t)p0,
(intptr_t)p1,
(intptr_t)p2,
(intptr_t)p3,
(intptr_t)p4,
(intptr_t)p5,
(intptr_t)p6,
0);
}

template <class T0, class T1, class T2, class T3, class T4, class T5>
static inline intptr_t
Call(int nr, T0 p0, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5) {
Expand All @@ -50,37 +78,57 @@ class SANDBOX_EXPORT Syscall {
(intptr_t)p2,
(intptr_t)p3,
(intptr_t)p4,
(intptr_t)p5);
(intptr_t)p5,
0,
0);
}

template <class T0, class T1, class T2, class T3, class T4>
static inline intptr_t Call(int nr, T0 p0, T1 p1, T2 p2, T3 p3, T4 p4) {
return Call(nr, p0, p1, p2, p3, p4, 0);
return Call(nr, p0, p1, p2, p3, p4, 0, 0, 0);
}

template <class T0, class T1, class T2, class T3>
static inline intptr_t Call(int nr, T0 p0, T1 p1, T2 p2, T3 p3) {
return Call(nr, p0, p1, p2, p3, 0, 0);
return Call(nr, p0, p1, p2, p3, 0, 0, 0, 0);
}

template <class T0, class T1, class T2>
static inline intptr_t Call(int nr, T0 p0, T1 p1, T2 p2) {
return Call(nr, p0, p1, p2, 0, 0, 0);
return Call(nr, p0, p1, p2, 0, 0, 0, 0, 0);
}

template <class T0, class T1>
static inline intptr_t Call(int nr, T0 p0, T1 p1) {
return Call(nr, p0, p1, 0, 0, 0, 0);
return Call(nr, p0, p1, 0, 0, 0, 0, 0, 0);
}

template <class T0>
static inline intptr_t Call(int nr, T0 p0) {
return Call(nr, p0, 0, 0, 0, 0, 0);
return Call(nr, p0, 0, 0, 0, 0, 0, 0, 0);
}

static inline intptr_t Call(int nr) { return Call(nr, 0, 0, 0, 0, 0, 0); }
static inline intptr_t Call(int nr) {
return Call(nr, 0, 0, 0, 0, 0, 0, 0, 0);
}

private:
// This performs system call |nr| with the arguments p0 to p7 from a constant
// userland address, which is for instance observable by seccomp-bpf filters.
// The constant userland address from which these system calls are made will
// be returned if |nr| is passed as -1.
// On error, this function will return a value between -1 and -4095 which
// should be interpreted as -errno.
static intptr_t Call(int nr,
intptr_t p0,
intptr_t p1,
intptr_t p2,
intptr_t p3,
intptr_t p4,
intptr_t p5,
intptr_t p6,
intptr_t p7);

DISALLOW_IMPLICIT_CONSTRUCTORS(Syscall);
};

Expand Down

0 comments on commit 33447b3

Please sign in to comment.