sandbox.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. /**
  50. * Linux 32 bit definitions
  51. */
  52. #if defined(__i386__)
  53. #define REG_SYSCALL REG_EAX
  54. /**
  55. * Linux 64 bit definitions
  56. */
  57. #elif defined(__x86_64__)
  58. #define REG_SYSCALL REG_RAX
  59. #endif
  60. #endif // __linux__
  61. void sandbox_set_debugging_fd(int fd);
  62. int tor_global_sandbox(void);
  63. const char* sandbox_intern_string(const char *param);
  64. sandbox_cfg_t * sandbox_cfg_new();
  65. int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file);
  66. int sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file);
  67. int sandbox_init(sandbox_cfg_t* cfg);
  68. #endif /* SANDBOX_H_ */