2015: Virtual Table generator in SQLite (prototype) [1] sql> SELECT ... FROM my_virtual_table_in_ruby ... 2016: Redis module [2] (WIP) redis> my_custom.command foo bar baz 2017: Experimenting mruby clustering Goal: Distribute data and computations across a set of connected mruby nodes [1] The Virtual Table Mechanism Of SQLite: https://www.sqlite.org/vtab.html [2] Redis Loadable Module System: http://antirez.com/news/106
to as a kernel call, is a request in a Unix-like operating system made via a software interrupt by an active process for a service performed by the kernel.”
... DESCRIPTION Lsof revision 4.87 lists on its standard output file information about files opened by processes for the following UNIX dialects: ... An open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream or a network file (Internet socket, NFS file or UNIX domain socket.) A specific file or all the files in a file system may be selected by path. ... λ sudo lsof -p 42 λ ruby -e'File.open("my_file", "w+"); gets' What is a system call? ^Z [1] + 42 suspended ruby […]
wrong with tools that monkey-patch Ruby? • Brittle ◦ Doesn’t prevent custom Ruby code from reimplementing the forbidden calls • Break POLS ◦ Shelling out (backticks, execv* functions, ...) is a way to escape those restrictions
• Gems ◦ Install is insecure ◦ Running the legitimate code of a gem is insecure (signing gems doesn’t really help either) • Some defaults are kind of… ¯\_(ツ)_/¯ ◦ Hijacking built-in gem commands is pretty easy [1] • Code audit is near impossible ◦ Tracking self-modifiable code is … hard [2] ◦ Some regulations require companies to show they’ve run an audit of their gems [1] http://franck.verrot.fr/blog/2015/04/21/hijacking-gem-commands/ [2] https://speakerdeck.com/benjaminleesmith/hacking-with-gems-rulu-2013
obtain address of a symbol in a shared object or executable SYNOPSIS #include <dlfcn.h> void *dlsym(void *handle, const char *symbol); ... DESCRIPTION The function dlsym() takes a "handle" of a dynamic loaded shared object returned by dlopen(3) along with a null-terminated symbol name, and returns the address where that symbol is loaded into memory. If the symbol is not found, in the specified object or any of the shared objects that were automatically loaded by dlopen(3) when that object was loaded, dlsym() returns NULL. (The search performed by dlsym() is breadth first through the dependency tree of these shared objects.)
• Can be done for every lib or system calls ◦ Replace glib’s malloc by jemalloc • Brings dynamism when none’s been built in usage: LD_PRELOAD=my_new_malloc.so ruby ...
Manual NAME top truncate, ftruncate - truncate a file to a specified length SYNOPSIS top #include <unistd.h> #include <sys/types.h> int truncate(const char *path, off_t length); int ftruncate(int fd, off_t length);
project tree ◦ Docker-based solution ◦ Cross-compiles to a variety of environments λ ls mruby/build/ host i386-apple-darwin14 i686-pc-linux-gnu i686-w64-mingw32 X86_64-apple-darwin14 x86_64-pc-linux-gnu x86_64-w64-mingw32 ... λ file ./mruby/build/x86_64-w64-mingw32/bin/my_mruby_app.exe my_mruby_app.exe: PE32+ executable for MS Windows (console) Mono/.Net assembly
◦ External DSL to the C implementation • Embedding mruby ◦ Produces low-level artifacts ▪ Static library ▪ Shared library ◦ Highly modular ◦ MultiVM in a single process
• Still a bit fragile ◦ Kernel extension: run mruby at the kernel level ◦ Brittle, but was easy to set up • mruby is my preferred Ruby ◦ Lightweight ◦ Flexible