2013-06-17 12:07:14 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
|
|
|
* Copyright (c) 2007-2013, The Tor Project, Inc. */
|
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file sandbox.h
|
|
|
|
* \brief Header file for sandbox.c.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef SANDBOX_H_
|
|
|
|
#define SANDBOX_H_
|
|
|
|
|
|
|
|
#ifndef SYS_SECCOMP
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used by SIGSYS signal handler to check if the signal was issued due to a
|
|
|
|
* seccomp2 filter violation.
|
|
|
|
*/
|
|
|
|
#define SYS_SECCOMP 1
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-07-23 09:14:25 +02:00
|
|
|
#include "torint.h"
|
|
|
|
|
2013-06-17 12:07:14 +02:00
|
|
|
/**
|
|
|
|
* Linux definitions
|
|
|
|
*/
|
|
|
|
#ifdef __linux__
|
|
|
|
|
2013-07-29 15:30:39 +02:00
|
|
|
#ifndef __USE_GNU
|
2013-06-17 12:07:14 +02:00
|
|
|
#define __USE_GNU
|
2013-07-29 15:30:39 +02:00
|
|
|
#endif
|
2013-06-17 12:07:14 +02:00
|
|
|
#include <sys/ucontext.h>
|
2013-07-30 20:23:30 +02:00
|
|
|
#include <seccomp.h>
|
2013-06-17 12:07:14 +02:00
|
|
|
|
2013-07-23 13:01:53 +02:00
|
|
|
#define MAX_PARAM_LEN 64
|
2013-07-18 17:03:10 +02:00
|
|
|
|
2013-07-23 09:49:56 +02:00
|
|
|
#define PARAM_PTR 0
|
|
|
|
#define PARAM_NUM 1
|
|
|
|
|
2013-07-18 17:03:10 +02:00
|
|
|
typedef struct {
|
|
|
|
int syscall;
|
2013-07-23 09:49:56 +02:00
|
|
|
|
|
|
|
char ptype;
|
2013-07-23 13:22:31 +02:00
|
|
|
char pindex;
|
2013-07-23 09:49:56 +02:00
|
|
|
intptr_t param;
|
|
|
|
|
2013-07-18 17:03:10 +02:00
|
|
|
char prot;
|
2013-07-25 12:25:20 +02:00
|
|
|
} sandbox_static_cfg_t;
|
2013-07-24 16:06:06 +02:00
|
|
|
|
|
|
|
struct pfd_elem {
|
|
|
|
int syscall;
|
|
|
|
|
|
|
|
char ptype;
|
|
|
|
char pindex;
|
|
|
|
intptr_t param;
|
|
|
|
|
|
|
|
char prot;
|
|
|
|
|
|
|
|
struct pfd_elem *next;
|
|
|
|
};
|
2013-07-25 12:25:20 +02:00
|
|
|
typedef struct pfd_elem sandbox_cfg_t;
|
2013-07-18 17:03:10 +02:00
|
|
|
|
2013-08-05 14:40:23 +02:00
|
|
|
typedef int (*sandbox_filter_func_t)(scmp_filter_ctx ctx,
|
|
|
|
sandbox_cfg_t *filter);
|
2013-07-30 20:23:30 +02:00
|
|
|
|
2013-08-05 15:01:31 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
// function pointers associated with filter
|
|
|
|
sandbox_filter_func_t *filter_func;
|
|
|
|
|
|
|
|
// filter function pointer parameters
|
|
|
|
sandbox_cfg_t *filter_dynamic;
|
|
|
|
} sandbox_t;
|
|
|
|
|
2013-06-17 12:07:14 +02:00
|
|
|
/**
|
|
|
|
* Linux 32 bit definitions
|
|
|
|
*/
|
|
|
|
#if defined(__i386__)
|
|
|
|
|
|
|
|
#define REG_SYSCALL REG_EAX
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Linux 64 bit definitions
|
|
|
|
*/
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
|
|
|
|
#define REG_SYSCALL REG_RAX
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // __linux__
|
|
|
|
|
|
|
|
void sandbox_set_debugging_fd(int fd);
|
|
|
|
int tor_global_sandbox(void);
|
2013-07-29 15:30:39 +02:00
|
|
|
const char* sandbox_intern_string(const char *param);
|
2013-07-25 13:08:02 +02:00
|
|
|
|
|
|
|
sandbox_cfg_t * sandbox_cfg_new();
|
2013-07-25 12:25:20 +02:00
|
|
|
int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file);
|
2013-07-30 18:09:28 +02:00
|
|
|
int sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file);
|
2013-08-05 14:40:23 +02:00
|
|
|
int sandbox_cfg_allow_execve(sandbox_cfg_t **cfg, char *com);
|
2013-07-25 13:08:02 +02:00
|
|
|
int sandbox_init(sandbox_cfg_t* cfg);
|
2013-06-17 12:07:14 +02:00
|
|
|
|
|
|
|
#endif /* SANDBOX_H_ */
|
|
|
|
|