tor  0.4.0.1-alpha
sandbox.h
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef SANDBOX_H_
13 #define SANDBOX_H_
14 
15 #include "orconfig.h"
16 #include "lib/cc/torint.h"
17 
18 #ifndef SYS_SECCOMP
19 
24 #define SYS_SECCOMP 1
25 
26 #endif /* !defined(SYS_SECCOMP) */
27 
28 #if defined(HAVE_SECCOMP_H) && defined(__linux__)
29 #define USE_LIBSECCOMP
30 #endif
31 
32 struct sandbox_cfg_elem;
33 
35 typedef struct sandbox_cfg_elem sandbox_cfg_t;
36 
40 #ifdef USE_LIBSECCOMP
41 
42 #include <sys/ucontext.h>
43 #include <seccomp.h>
44 #include <netdb.h>
45 
46 #define PARAM_PTR 0
47 #define PARAM_NUM 1
48 
52 typedef enum {
54  LIBSECCOMP2 = 0
55 } SB_IMPL;
56 
61 typedef struct smp_param {
63  int syscall;
64 
66  char *value;
68  char *value2;
69 
71  int prot;
72 } smp_param_t;
73 
80 struct sandbox_cfg_elem {
82  SB_IMPL implem;
83 
85  smp_param_t *param;
86 
88  struct sandbox_cfg_elem *next;
89 };
90 
92 typedef int (*sandbox_filter_func_t)(scmp_filter_ctx ctx,
93  sandbox_cfg_t *filter);
94 
96 typedef struct {
98  sandbox_filter_func_t *filter_func;
99 
101  sandbox_cfg_t *filter_dynamic;
102 } sandbox_t;
103 
104 #endif /* defined(USE_LIBSECCOMP) */
105 
106 #ifdef USE_LIBSECCOMP
107 
110 const char* sandbox_intern_string(const char *param);
111 #else /* !(defined(USE_LIBSECCOMP)) */
112 #define sandbox_intern_string(s) (s)
113 #endif /* defined(USE_LIBSECCOMP) */
114 
117 
123 int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file);
124 
125 int sandbox_cfg_allow_chmod_filename(sandbox_cfg_t **cfg, char *file);
126 int sandbox_cfg_allow_chown_filename(sandbox_cfg_t **cfg, char *file);
127 
128 /* DOCDOC */
129 int sandbox_cfg_allow_rename(sandbox_cfg_t **cfg, char *file1, char *file2);
130 
136 int sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file);
137 
142 int sandbox_cfg_allow_stat_filename(sandbox_cfg_t **cfg, char *file);
143 
145 int sandbox_init(sandbox_cfg_t* cfg);
146 
148 int sandbox_is_active(void);
149 
150 #endif /* !defined(SANDBOX_H_) */
struct sandbox_cfg_elem sandbox_cfg_t
Definition: sandbox.h:35
int sandbox_is_active(void)
Definition: sandbox.c:1796
int sandbox_cfg_allow_stat_filename(sandbox_cfg_t **cfg, char *file)
Definition: sandbox.c:1768
int sandbox_init(sandbox_cfg_t *cfg)
Definition: sandbox.c:1730
int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file)
Definition: sandbox.c:1754
Integer definitions used throughout Tor.
#define sandbox_intern_string(s)
Definition: sandbox.h:112
int sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file)
Definition: sandbox.c:1761
sandbox_cfg_t * sandbox_cfg_new(void)
Definition: sandbox.c:1724