sandbox.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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-2013, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file sandbox.h
  8. * \brief Header file for sandbox.c.
  9. **/
  10. #ifndef SANDBOX_H_
  11. #define SANDBOX_H_
  12. #ifndef SYS_SECCOMP
  13. /**
  14. * Used by SIGSYS signal handler to check if the signal was issued due to a
  15. * seccomp2 filter violation.
  16. */
  17. #define SYS_SECCOMP 1
  18. #endif
  19. #include "torint.h"
  20. /**
  21. * Linux definitions
  22. */
  23. #ifdef __linux__
  24. #ifndef __USE_GNU
  25. #define __USE_GNU
  26. #endif
  27. #include <sys/ucontext.h>
  28. #include <seccomp.h>
  29. #define MAX_PARAM_LEN 64
  30. #define PARAM_PTR 0
  31. #define PARAM_NUM 1
  32. typedef struct {
  33. int syscall;
  34. char ptype;
  35. char pindex;
  36. intptr_t param;
  37. char prot;
  38. } sandbox_static_cfg_t;
  39. struct pfd_elem {
  40. int syscall;
  41. char ptype;
  42. char pindex;
  43. intptr_t param;
  44. char prot;
  45. struct pfd_elem *next;
  46. };
  47. typedef struct pfd_elem sandbox_cfg_t;
  48. typedef int (*sandbox_filter_func_t)(scmp_filter_ctx ctx,
  49. sandbox_cfg_t *filter);
  50. typedef struct {
  51. // function pointers associated with filter
  52. sandbox_filter_func_t *filter_func;
  53. // filter function pointer parameters
  54. sandbox_cfg_t *filter_dynamic;
  55. } sandbox_t;
  56. /**
  57. * Linux 32 bit definitions
  58. */
  59. #if defined(__i386__)
  60. #define REG_SYSCALL REG_EAX
  61. /**
  62. * Linux 64 bit definitions
  63. */
  64. #elif defined(__x86_64__)
  65. #define REG_SYSCALL REG_RAX
  66. #endif
  67. #endif // __linux__
  68. void sandbox_set_debugging_fd(int fd);
  69. int tor_global_sandbox(void);
  70. const char* sandbox_intern_string(const char *param);
  71. sandbox_cfg_t * sandbox_cfg_new();
  72. int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file,
  73. char fr);
  74. int sandbox_cfg_allow_open_filename_array(sandbox_cfg_t **cfg, int num, ...);
  75. int sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file,
  76. char fr);
  77. int sandbox_cfg_allow_openat_filename_array(sandbox_cfg_t **cfg, int num, ...);
  78. int sandbox_cfg_allow_execve(sandbox_cfg_t **cfg, char *com);
  79. int sandbox_cfg_allow_execve_array(sandbox_cfg_t **cfg, int num, ...);
  80. int sandbox_init(sandbox_cfg_t* cfg);
  81. #endif /* SANDBOX_H_ */