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-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
9 * \brief Header file for sandbox.c.
16 #include "lib/cc/torint.h"
21 * Used by SIGSYS signal handler to check if the signal was issued due to a
22 * seccomp2 filter violation.
26 #endif /* !defined(SYS_SECCOMP) */
28 #if defined(HAVE_SECCOMP_H) && defined(__linux__)
29 #define USE_LIBSECCOMP
32 struct sandbox_cfg_elem_t
;
34 /** Typedef to structure used to manage a sandbox configuration. */
35 typedef struct sandbox_cfg_elem_t sandbox_cfg_t
;
42 #include <sys/ucontext.h>
50 * Enum used to manage the type of the implementation for general purpose.
53 /** Libseccomp implementation based on seccomp2*/
58 * Configuration parameter structure associated with the LIBSECCOMP2
61 typedef struct smp_param_t
{
62 /** syscall associated with parameter. */
65 /** parameter value. */
67 /** parameter value, second argument. */
70 /** parameter flag (0 = not protected, 1 = protected). */
75 * Structure used to manage a sandbox configuration.
77 * It is implemented as a linked list of parameters. Currently only controls
78 * parameters for open, openat, execve, stat64.
80 struct sandbox_cfg_elem_t
{
81 /** Sandbox implementation which dictates the parameter type. */
84 /** Configuration parameter. */
87 /** Next element of the configuration*/
88 struct sandbox_cfg_elem_t
*next
;
91 /** Function pointer defining the prototype of a filter function.*/
92 typedef int (*sandbox_filter_func_t
)(scmp_filter_ctx ctx
,
93 sandbox_cfg_t
*filter
);
95 /** Type that will be used in step 3 in order to manage multiple sandboxes.*/
97 /** function pointers associated with the filter */
98 sandbox_filter_func_t
*filter_func
;
100 /** filter function pointer parameters */
101 sandbox_cfg_t
*filter_dynamic
;
104 #endif /* defined(USE_LIBSECCOMP) */
106 #ifdef USE_LIBSECCOMP
107 const char* sandbox_intern_string(const char *param
);
108 bool sandbox_interned_string_is_missing(const char *s
);
109 #else /* !defined(USE_LIBSECCOMP) */
110 #define sandbox_intern_string(s) (s)
111 #define sandbox_interned_string_is_missing(s) (false)
112 #endif /* defined(USE_LIBSECCOMP) */
114 /** Creates an empty sandbox configuration file.*/
115 sandbox_cfg_t
* sandbox_cfg_new(void);
118 * Function used to add a open allowed filename to a supplied configuration.
119 * The (char*) specifies the path to the allowed file; we take ownership
122 int sandbox_cfg_allow_open_filename(sandbox_cfg_t
**cfg
, char *file
);
124 int sandbox_cfg_allow_chmod_filename(sandbox_cfg_t
**cfg
, char *file
);
125 int sandbox_cfg_allow_chown_filename(sandbox_cfg_t
**cfg
, char *file
);
128 int sandbox_cfg_allow_rename(sandbox_cfg_t
**cfg
, char *file1
, char *file2
);
131 * Function used to add a openat allowed filename to a supplied configuration.
132 * The (char*) specifies the path to the allowed file; we steal the pointer to
135 int sandbox_cfg_allow_openat_filename(sandbox_cfg_t
**cfg
, char *file
);
138 * Function used to add a opendir allowed filename to a supplied configuration.
139 * The (char*) specifies the path to the allowed dir; we steal the pointer to
142 int sandbox_cfg_allow_opendir_dirname(sandbox_cfg_t
**cfg
, char *dir
);
145 * Function used to add a stat/stat64 allowed filename to a configuration.
146 * The (char*) specifies the path to the allowed file; that pointer is stolen.
148 int sandbox_cfg_allow_stat_filename(sandbox_cfg_t
**cfg
, char *file
);
150 /** Function used to initialise a sandbox configuration.*/
151 int sandbox_init(sandbox_cfg_t
* cfg
);
153 /** Return true iff the sandbox is turned on. */
154 int sandbox_is_active(void);
156 #endif /* !defined(SANDBOX_H_) */