aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils
diff options
context:
space:
mode:
authorDavid Carlier <[email protected]>2019-01-06 17:07:53 +0000
committerDavid Carlier <[email protected]>2019-01-06 17:07:53 +0000
commit738a37784f707f7e0ee10d3eca7d03f7ae4063a5 (patch)
treea901965c487f5f80463aea020459fd356116b373 /src/lib/utils
parentaae03e177452a5b7f5a42b4acf0c3fde07fdf045 (diff)
Proposal of sandboxing feature.
For now only used by the TLS server.
Diffstat (limited to 'src/lib/utils')
-rw-r--r--src/lib/utils/os_utils.cpp16
-rw-r--r--src/lib/utils/os_utils.h9
2 files changed, 25 insertions, 0 deletions
diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp
index f373ece99..9ec45a8c1 100644
--- a/src/lib/utils/os_utils.cpp
+++ b/src/lib/utils/os_utils.cpp
@@ -45,6 +45,10 @@
#include <windows.h>
#endif
+#if defined(BOTAN_TARGET_OS_CAP_ENTER)
+ #include <sys/capsicum.h>
+#endif
+
namespace Botan {
// Not defined in OS namespace for historical reasons
@@ -102,6 +106,18 @@ bool OS::running_in_privileged_state()
#endif
}
+bool OS::sandbox_start()
+ {
+#if defined(BOTAN_TARGET_OS_HAS_PLEDGE)
+ const static char *opts = "stdio rpath inet";
+ return (::pledge(opts, nullptr) == 0);
+#elif defined(BOTAN_TARGET_OS_HAS_CAP_ENTER)
+ return (::cap_enter() == 0);
+#else
+ return true;
+#endif
+ }
+
uint64_t OS::get_cpu_cycle_counter()
{
uint64_t rtc = 0;
diff --git a/src/lib/utils/os_utils.h b/src/lib/utils/os_utils.h
index 6ec64b2fd..53471db88 100644
--- a/src/lib/utils/os_utils.h
+++ b/src/lib/utils/os_utils.h
@@ -34,6 +34,14 @@ namespace OS {
uint32_t BOTAN_TEST_API get_process_id();
/**
+* Running current context in a sandboxed manner
+* Usually any sandbox solution might allow to
+* adjust down the permissions but never allow
+* to expand them.
+*/
+bool BOTAN_TEST_API sandbox_start();
+
+/**
* Test if we are currently running with elevated permissions
* eg setuid, setgid, or with POSIX caps set.
*/
@@ -122,6 +130,7 @@ void page_prohibit_access(void* page);
*/
void page_allow_access(void* page);
+
/**
* Run a probe instruction to test for support for a CPU instruction.
* Runs in system-specific env that catches illegal instructions; this