summaryrefslogtreecommitdiff
path: root/chromium/sandbox/linux/syscall_broker/syscall_dispatcher.h
blob: d8b8874ad9ce441db6b579d00b784dacf9235bf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SANDBOX_LINUX_SYSCALL_BROKER_SYSCALL_DISPATCHER_H_
#define SANDBOX_LINUX_SYSCALL_BROKER_SYSCALL_DISPATCHER_H_

#include <sys/stat.h>
#include <cstddef>

#include "sandbox/linux/system_headers/linux_seccomp.h"

namespace sandbox {
namespace syscall_broker {

// An abstract class that defines all the system calls we perform for the
// sandboxed process.
class SyscallDispatcher {
 public:
  // Emulates access()/faccessat().
  // X_OK will always return an error in practice since the broker process
  // doesn't support execute permissions.
  virtual int Access(const char* pathname, int mode) const = 0;

  // Emulates mkdir()/mkdirat.
  virtual int Mkdir(const char* path, int mode) const = 0;

  // Emulates open()/openat().
  // The implementation only supports certain white listed flags and will
  // return -EPERM on other flags.
  virtual int Open(const char* pathname, int flags) const = 0;

  // Emulates readlink()/readlinkat().
  virtual int Readlink(const char* path, char* buf, size_t bufsize) const = 0;

  // Emulates rename()/renameat()/renameat2().
  virtual int Rename(const char* oldpath, const char* newpath) const = 0;

  // Emulates rmdir().
  virtual int Rmdir(const char* path) const = 0;

  // Emulates stat()/stat64()/lstat()/lstat64()/fstatat()/newfstatat().
  virtual int Stat(const char* pathname,
                   bool follow_links,
                   struct stat* sb) const = 0;
  virtual int Stat64(const char* pathname,
                     bool follow_links,
                     struct stat64* sb) const = 0;

  // Emulates unlink()/unlinkat().
  virtual int Unlink(const char* unlink) const = 0;

  // Validates the args passed to a *statat*() syscall and performs the syscall
  // using Stat() or Stat64().
  int PerformStatat(const arch_seccomp_data& args, bool arch64);

  // Reads the syscall number and arguments, imposes some policy (e.g. the *at()
  // system calls must only allow AT_FDCWD as the first argument), and
  // dispatches to the correct method from above.
  // Async-signal-safe since this might be called in a signal handler.
  int DispatchSyscall(const arch_seccomp_data& args);

 protected:
  virtual ~SyscallDispatcher() = default;
};

}  // namespace syscall_broker
}  // namespace sandbox

#endif  // SANDBOX_LINUX_SYSCALL_BROKER_SYSCALL_DISPATCHER_H_