sandbox.h 2.4 KB

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