update native sandboxing method for OpenBSD (#5545)

move from systrace(4) (removed in 6.0 release) to pledge(2) (available
since 5.9).
This commit is contained in:
Sebastien Marie 2016-08-18 15:59:36 +02:00 committed by radare
parent 7661c3930a
commit e0ee8cdefa
3 changed files with 40 additions and 3 deletions

View File

@ -19,8 +19,19 @@ the rules are described in a lispy .sb file:
**NOTE**: r2 -S is an alias for -e cfg.sandbox=true **NOTE**: r2 -S is an alias for -e cfg.sandbox=true
OpenBSD OpenBSD (starting to 5.9)
------- -------------------------
OpenBSD comes with support for sandboxing using the pledge(2) syscall.
Only the following are allowed:
- stdio and tty manipulation
- filesystem reading
- mmap(2) `PROT_EXEC` manipulation
OpenBSD (until 5.9)
-------------------
OpenBSD comes with support for sandboxing using the systrace utility. OpenBSD comes with support for sandboxing using the systrace utility.

View File

@ -29,6 +29,17 @@
#define LIBC_HAVE_FORK 1 #define LIBC_HAVE_FORK 1
#endif #endif
#if defined(__OpenBSD__)
#include <sys/param.h>
#undef MAXCOMLEN /* redefined in zipint.h */
#endif
#if (OpenBSD >= 201605) /* release >= 5.9 */
#define LIBC_HAVE_PLEDGE 1
#else
#define LIBC_HAVE_PLEDGE 0
#endif
#ifdef __GNUC__ #ifdef __GNUC__
# define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_ ## x # define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_ ## x
#else #else

View File

@ -53,6 +53,12 @@ R_API int r_sandbox_check_path (const char *path) {
R_API bool r_sandbox_disable (bool e) { R_API bool r_sandbox_disable (bool e) {
if (e) { if (e) {
#if LIBC_HAVE_PLEDGE
if (enabled) {
eprintf ("sandbox mode couldn't be disabled when pledged\n");
return enabled;
}
#endif
disabled = enabled; disabled = enabled;
enabled = 0; enabled = 0;
} else { } else {
@ -63,7 +69,16 @@ R_API bool r_sandbox_disable (bool e) {
R_API bool r_sandbox_enable (bool e) { R_API bool r_sandbox_enable (bool e) {
if (enabled) return true; if (enabled) return true;
return (enabled = !!e); enabled = !!e;
#if LIBC_HAVE_PLEDGE
if (enabled && pledge ("stdio rpath tty prot_exec", NULL) == -1) {
eprintf ("sandbox: pledge call failed\n");
exit (1);
}
#endif
return enabled;
} }
R_API int r_sandbox_system (const char *x, int n) { R_API int r_sandbox_system (const char *x, int n) {