Code Monkey home page Code Monkey logo

sbox's Introduction

sbox

Demo of how to resize PNG images using the excellent STB image manipulation routines from within a Linux SECCOMP_STRICT sandbox, with an easy to use interface from your regular process. Based on a suggestion by Thomas Dullien, implemented with help from Otto Moerbeek (who knows malloc).

The STB authors freely admit that they might have security problems, and that they'll discuss their security issues in public before they fix them. For this reason, a sandbox is nice to have.

SECCOMP_STRICT really allows almost nothing, not even asking the kernel for more memory. Very secure of course, but this messes with later calls to malloc().

The technique used here is to instruct malloc not to be clever, and to first allocate a chunk of memory, then enable SECCOMP_STRICT, and then freeing that memory. This means the allocator has enough space in its arena to work without asking the kernel for more memory.

In the code you'll find some fun notes on how compilers make it hard to actually do this trick, because they often figure out that aren't actually using that large chunk of memory. And then they never allocate it.

What the sbox program does

You can pipe a PNG image (and only a PNG image) to the process, and it will return a 200 pixel wide version of it. That's it. But it does all the exciting things from within SECCOMP_STRICT, which is nice.

How to use this from your code

A demo is in example-client.cc, but the gist is:

#include "client.hh"
int main(int argc, char** argv)
{
  string png = readFile(argv[1]);
  string thumbnail = getThumbnailFromSandbox(png, {"./sbox"});
}

This will fork() and setup connectivity to the sandboxed process, and then launches it for you.

You could also add more parameters to getThumbnailFromSandbox, and perhaps teach the sandbox to use these parameters (so you could specify the desired dimensions of the thumbnail, for example).

Why?

This code might end up in Trifecta, an image sharing site mean to be secure & an example of how to write simple, compact but useful software.

sbox's People

Contributors

berthubert avatar eventualbuddha avatar

Stargazers

Matt avatar Johan Andersson avatar Michael Paepcke avatar Antti Vähä-Sipilä avatar Matteo Bigoi avatar Sunny Chakraborty avatar Pete Markowsky avatar Wilhelm avatar Anthony Weems avatar

Watchers

 avatar  avatar

Forkers

eventualbuddha

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.