Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

popen blocked by other sandboxes #210

Open
chruss2 opened this issue Nov 1, 2017 · 1 comment
Open

popen blocked by other sandboxes #210

chruss2 opened this issue Nov 1, 2017 · 1 comment

Comments

@chruss2
Copy link

chruss2 commented Nov 1, 2017

I ran across a bug in the Lua sandbox when two inputs in Hindsight are using io.popen. They aren't sandboxed well enough. In the example below, Input 2 waiting for data prevents Input 1 from running properly.

Input 1:

require "io"
function process_message()
  -- Heavy initialization that takes some time to load.
  -- For demo purposes, I'll just sleep so that some time goes by.
  fh = io.popen("sleep 1", "r")
  fh:close()
  -- Now the actual popen call. It should run right away, but instead hangs
  -- until Input 2 gets out of its lines() iterator.
  fh = io.popen("echo I got here on `date` > /tmp/status", "r")
end

Input 2:

require "io"
function process_message()
  fh = io.popen("while true; do sleep 86400; echo One per day; done", "r")
  for line in fh:lines() do
    -- process and inject messages here
  end
end

The cause of this is lua_popen (a macro in include/luasandbox/luaconf.h) which calls fflush(NULL) before calling popen. The popen(3) man page does recommend doing this to avoid garbled input or output, but it is harmful in the case of multiple sandboxes and threads.

@trink
Copy link
Contributor

trink commented Nov 1, 2017

Yes there are known issues with popen in the sandbox see: mozilla-services/hindsight#35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants