summaryrefslogtreecommitdiff
path: root/lib/supple/host.lua
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-29 18:12:58 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-29 18:12:58 +0100
commitc9ec1fc955887b4c5eccdb62a250cd994b84abdd (patch)
treefae482b8b3056ad7ef2374247fa419cbea89e6a1 /lib/supple/host.lua
parent340c969dabb6d666d5d052ace26c9b656b7a9126 (diff)
downloadsupple-c9ec1fc955887b4c5eccdb62a250cd994b84abdd.tar.gz
SUPPLE: Everything to get basic sandboxing working
Diffstat (limited to 'lib/supple/host.lua')
-rw-r--r--lib/supple/host.lua76
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/supple/host.lua b/lib/supple/host.lua
new file mode 100644
index 0000000..1226d19
--- /dev/null
+++ b/lib/supple/host.lua
@@ -0,0 +1,76 @@
+-- lib/supple/host.lua
+--
+-- Sandbox (for) Untrusted Procedure Partitioning (in) Lua Engine
+--
+-- Management of the host side of Supple
+--
+-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org>
+--
+-- For licence terms, see COPYING
+--
+
+local luxio = require 'luxio'
+local subprocess = require 'luxio.subprocess'
+
+local comms = require 'supple.comms'
+local objects = require 'supple.objects'
+
+local counter = 0
+
+local function run_wrapper()
+ local wrapperpath = "@@WRAPPER_BIN@@"
+ -- START_TEST_SUPPLE
+ wrapperpath = "./testwrapper"
+ -- END_TEST_SUPPLE
+ local fds = {}
+ local ret, errno = luxio.socketpair(luxio.AF_UNIX, luxio.SOCK_STREAM,
+ luxio.PF_UNIX, fds)
+ if ret ~= 0 then
+ error("Unable to launch subprocess, could not prepare socketpair():"
+ .. luxio.strerror(errno))
+ end
+ local proc, msg = subprocess.spawn {
+ "supple-sandbox",
+ exe = wrapperpath,
+ stdin = fds[1],
+-- stdout = fds[1],
+-- stderr = fds[1],
+ }
+ if not proc then
+ error(msg)
+ end
+ luxio.close(fds[1])
+ return proc, fds[2]
+end
+
+local function run_sandbox(codestr, codename, ...)
+ -- Prepare and start a sandbox,
+ -- compiling the codestr and running it
+ -- with the given args
+ local child, commsfd = run_wrapper()
+
+ counter = counter + 1
+ objects.set_name(("host-%d"):format(counter))
+ comms._set_fd(commsfd)
+ objects.set_proc_call(comms.call)
+
+ local func, err = comms.call("supple:loadstring", "__call", codestr, codename)
+ if not func then
+ error(err)
+ end
+
+ local ret = {func(...)}
+
+ -- We need to clean up, so dump all the objects
+ func = nil
+ objects.clean_down()
+
+ comms._set_fd(-1)
+ luxio.kill(child.pid, luxio.SIGKILL)
+ child:wait()
+ return unpack(ret)
+end
+
+return {
+ run = run_sandbox,
+} \ No newline at end of file