Tor 0.4.9.13
Loading...
Searching...
No Matches
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-2021, The Tor Project, Inc. */
5/* See LICENSE for licensing information */
6
7/**
8 * \file sandbox.h
9 * \brief Header file for sandbox.c.
10 **/
11
12#ifndef SANDBOX_H_
13#define SANDBOX_H_
14
15#include "orconfig.h"
16#include "lib/cc/torint.h"
17
18#ifdef HAVE_SIGNAL_H
19#include <signal.h>
20#endif
21
22#ifndef HAVE_SYS_SECCOMP
23/**
24 * Used by SIGSYS signal handler to check if the signal was issued due to a
25 * seccomp2 filter violation.
26 */
27#define SYS_SECCOMP 1
28#endif /* !defined(HAVE_SYS_SECCOMP) */
29
30#if defined(HAVE_SECCOMP_H) && defined(__linux__)
31#define USE_LIBSECCOMP
32#endif
33
34struct sandbox_cfg_elem_t;
35
36/** Typedef to structure used to manage a sandbox configuration. */
37typedef struct sandbox_cfg_elem_t sandbox_cfg_t;
38
39/**
40 * Linux definitions
41 */
42#ifdef USE_LIBSECCOMP
43
44#include <sys/ucontext.h>
45#include <seccomp.h>
46#include <netdb.h>
47
48#define PARAM_PTR 0
49#define PARAM_NUM 1
50
51/**
52 * Enum used to manage the type of the implementation for general purpose.
53 */
54typedef enum {
55 /** Libseccomp implementation based on seccomp2*/
56 LIBSECCOMP2 = 0
57} SB_IMPL;
58
59/**
60 * Configuration parameter structure associated with the LIBSECCOMP2
61 * implementation.
62 */
63typedef struct smp_param_t {
64 /** syscall associated with parameter. */
65 int syscall;
66
67 /** parameter value. */
68 char *value;
69 /** parameter value, second argument. */
70 char *value2;
71
72 /** parameter flag (0 = not protected, 1 = protected). */
73 int prot;
74} smp_param_t;
75
76/**
77 * Structure used to manage a sandbox configuration.
78 *
79 * It is implemented as a linked list of parameters. Currently only controls
80 * parameters for open, openat, execve, stat64.
81 */
82struct sandbox_cfg_elem_t {
83 /** Sandbox implementation which dictates the parameter type. */
84 SB_IMPL implem;
85
86 /** Configuration parameter. */
87 smp_param_t *param;
88
89 /** Next element of the configuration*/
90 struct sandbox_cfg_elem_t *next;
91};
92
93/** Function pointer defining the prototype of a filter function.*/
94typedef int (*sandbox_filter_func_t)(scmp_filter_ctx ctx,
95 sandbox_cfg_t *filter);
96
97/** Type that will be used in step 3 in order to manage multiple sandboxes.*/
98typedef struct {
99 /** function pointers associated with the filter */
100 sandbox_filter_func_t *filter_func;
101
102 /** filter function pointer parameters */
103 sandbox_cfg_t *filter_dynamic;
104} sandbox_t;
105
106#endif /* defined(USE_LIBSECCOMP) */
107
108#ifdef USE_LIBSECCOMP
109const char* sandbox_intern_string(const char *param);
110bool sandbox_interned_string_is_missing(const char *s);
111#else /* !defined(USE_LIBSECCOMP) */
112#define sandbox_intern_string(s) (s)
113#define sandbox_interned_string_is_missing(s) (false)
114#endif /* defined(USE_LIBSECCOMP) */
115
116/** Creates an empty sandbox configuration file.*/
118
119/**
120 * Function used to add a open allowed filename to a supplied configuration.
121 * The (char*) specifies the path to the allowed file; we take ownership
122 * of the pointer.
123 */
125
126int sandbox_cfg_allow_chmod_filename(sandbox_cfg_t **cfg, char *file);
127int sandbox_cfg_allow_chown_filename(sandbox_cfg_t **cfg, char *file);
128
129/* DOCDOC */
130int sandbox_cfg_allow_rename(sandbox_cfg_t **cfg, char *file1, char *file2);
131
132/**
133 * Function used to add a openat allowed filename to a supplied configuration.
134 * The (char*) specifies the path to the allowed file; we steal the pointer to
135 * that file.
136 */
138
139/**
140 * Function used to add a opendir allowed filename to a supplied configuration.
141 * The (char*) specifies the path to the allowed dir; we steal the pointer to
142 * that dir.
143 */
145
146/**
147 * Function used to add a stat/stat64 allowed filename to a configuration.
148 * The (char*) specifies the path to the allowed file; that pointer is stolen.
149 */
151
152/** Function used to initialise a sandbox configuration.*/
154
155/** Return true iff the sandbox is turned on. */
156int sandbox_is_active(void);
157
158#endif /* !defined(SANDBOX_H_) */
int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file)
Definition sandbox.c:2322
int sandbox_cfg_allow_stat_filename(sandbox_cfg_t **cfg, char *file)
Definition sandbox.c:2343
sandbox_cfg_t * sandbox_cfg_new(void)
Definition sandbox.c:2292
struct sandbox_cfg_elem_t sandbox_cfg_t
Definition sandbox.h:37
int sandbox_init(sandbox_cfg_t *cfg)
Definition sandbox.c:2298
int sandbox_is_active(void)
Definition sandbox.c:2371
int sandbox_cfg_allow_opendir_dirname(sandbox_cfg_t **cfg, char *dir)
Definition sandbox.c:2336
#define sandbox_intern_string(s)
Definition sandbox.h:112
int sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file)
Definition sandbox.c:2329
Integer definitions used throughout Tor.