1*4b9c6d91SCole Faust# Minijail 2*4b9c6d91SCole Faust 3*4b9c6d91SCole FaustThe Minijail homepage is 4*4b9c6d91SCole Fausthttps://google.github.io/minijail/. 5*4b9c6d91SCole Faust 6*4b9c6d91SCole FaustThe main source repo is 7*4b9c6d91SCole Fausthttps://chromium.googlesource.com/chromiumos/platform/minijail. 8*4b9c6d91SCole Faust 9*4b9c6d91SCole FaustThere might be other copies floating around, but this is the official one! 10*4b9c6d91SCole Faust 11*4b9c6d91SCole Faust[TOC] 12*4b9c6d91SCole Faust 13*4b9c6d91SCole Faust## What is it? 14*4b9c6d91SCole Faust 15*4b9c6d91SCole FaustMinijail is a sandboxing and containment tool used in ChromeOS and Android. 16*4b9c6d91SCole FaustIt provides an executable that can be used to launch and sandbox other programs, 17*4b9c6d91SCole Faustand a library that can be used by code to sandbox itself. 18*4b9c6d91SCole Faust 19*4b9c6d91SCole Faust## Getting the code 20*4b9c6d91SCole Faust 21*4b9c6d91SCole FaustYou're one `git clone` away from happiness. 22*4b9c6d91SCole Faust 23*4b9c6d91SCole Faust``` 24*4b9c6d91SCole Faust$ git clone https://chromium.googlesource.com/chromiumos/platform/minijail 25*4b9c6d91SCole Faust$ cd minijail 26*4b9c6d91SCole Faust``` 27*4b9c6d91SCole Faust 28*4b9c6d91SCole FaustReleases are tagged as `linux-vXX`: 29*4b9c6d91SCole Fausthttps://chromium.googlesource.com/chromiumos/platform/minijail/+refs 30*4b9c6d91SCole Faust 31*4b9c6d91SCole Faust## Building 32*4b9c6d91SCole Faust 33*4b9c6d91SCole FaustSee the [HACKING.md](./HACKING.md) document for more details. 34*4b9c6d91SCole Faust 35*4b9c6d91SCole Faust## Release process 36*4b9c6d91SCole Faust 37*4b9c6d91SCole FaustSee the [RELEASE.md](./RELEASE.md) document for more details. 38*4b9c6d91SCole Faust 39*4b9c6d91SCole Faust## Additional tools 40*4b9c6d91SCole Faust 41*4b9c6d91SCole FaustSee the [tools/README.md](./tools/README.md) document for more details. 42*4b9c6d91SCole Faust 43*4b9c6d91SCole Faust## Contact 44*4b9c6d91SCole Faust 45*4b9c6d91SCole FaustWe've got a couple of contact points. 46*4b9c6d91SCole Faust 47*4b9c6d91SCole Faust* [[email protected]]: Public user & developer mailing list. 48*4b9c6d91SCole Faust* [[email protected]]: Internal Google user mailing list. 49*4b9c6d91SCole Faust* [[email protected]]: Internal Google developer mailing list. 50*4b9c6d91SCole Faust* [crbug.com/list]: Existing bug reports & feature requests. 51*4b9c6d91SCole Faust* [crbug.com/new]: File new bug reports & feature requests. 52*4b9c6d91SCole Faust* [Chromium Gerrit]: Code reviews. 53*4b9c6d91SCole Faust 54*4b9c6d91SCole Faust[[email protected]]: https://groups.google.com/a/chromium.org/forum/#!forum/minijail 55*4b9c6d91SCole Faust[[email protected]]: https://groups.google.com/a/google.com/forum/#!forum/minijail-users 56*4b9c6d91SCole Faust[[email protected]]: https://groups.google.com/a/google.com/forum/#!forum/minijail-dev 57*4b9c6d91SCole Faust[crbug.com/list]: https://crbug.com/?q=component:OS>Systems>Minijail 58*4b9c6d91SCole Faust[crbug.com/new]: https://bugs.chromium.org/p/chromium/issues/entry?components=OS>Systems>Minijail 59*4b9c6d91SCole Faust[Chromium Gerrit]: https://chromium-review.googlesource.com/q/project:chromiumos/platform/minijail 60*4b9c6d91SCole Faust 61*4b9c6d91SCole Faust## Talks and presentations 62*4b9c6d91SCole Faust 63*4b9c6d91SCole FaustThe following talk serves as a good introduction to Minijail and how it can be used. 64*4b9c6d91SCole Faust 65*4b9c6d91SCole Faust[Video](https://drive.google.com/file/d/0BwPS_JpKyELWZTFBcTVsa1hhYjA/preview), 66*4b9c6d91SCole Faust[slides](https://docs.google.com/presentation/d/e/2PACX-1vRBqpin5xR9sng6lIBPjG0XQtu-uWWgr0ds-M3zW13XpDO-bTcMERLwoHUEB9078p1yqr9L-su9n5dk/pub). 67*4b9c6d91SCole Faust 68*4b9c6d91SCole Faust## Example usage 69*4b9c6d91SCole Faust 70*4b9c6d91SCole FaustThe ChromiumOS project has a comprehensive 71*4b9c6d91SCole Faust[sandboxing](https://chromium.googlesource.com/chromiumos/docs/+/master/sandboxing.md) 72*4b9c6d91SCole Faustdocument that is largely based on Minijail. 73*4b9c6d91SCole Faust 74*4b9c6d91SCole FaustAfter you play with the simple examples below, you should check that out. 75*4b9c6d91SCole Faust 76*4b9c6d91SCole Faust### Change root to any user 77*4b9c6d91SCole Faust 78*4b9c6d91SCole Faust``` 79*4b9c6d91SCole Faust# id 80*4b9c6d91SCole Faustuid=0(root) gid=0(root) groups=0(root),128(pkcs11) 81*4b9c6d91SCole Faust# minijail0 -u jorgelo -g 5000 /usr/bin/id 82*4b9c6d91SCole Faustuid=72178(jorgelo) gid=5000(eng) groups=5000(eng) 83*4b9c6d91SCole Faust``` 84*4b9c6d91SCole Faust 85*4b9c6d91SCole Faust### Drop root while keeping some capabilities 86*4b9c6d91SCole Faust 87*4b9c6d91SCole Faust``` 88*4b9c6d91SCole Faust# minijail0 -u jorgelo -c 3000 -- /bin/cat /proc/self/status 89*4b9c6d91SCole FaustName: cat 90*4b9c6d91SCole Faust... 91*4b9c6d91SCole FaustCapInh: 0000000000003000 92*4b9c6d91SCole FaustCapPrm: 0000000000003000 93*4b9c6d91SCole FaustCapEff: 0000000000003000 94*4b9c6d91SCole FaustCapBnd: 0000000000003000 95*4b9c6d91SCole Faust``` 96*4b9c6d91SCole Faust 97*4b9c6d91SCole Faust## Historical notes 98*4b9c6d91SCole Faust 99*4b9c6d91SCole FaustQ. "Why is it called minijail0?" 100*4b9c6d91SCole Faust 101*4b9c6d91SCole FaustA. It is minijail0 because it was a rewrite of an earlier program named 102*4b9c6d91SCole Faustminijail, which was considerably less mini, and in particular had a dependency 103*4b9c6d91SCole Fauston libchrome (the ChromeOS packaged version of Chromium's //base). We needed a 104*4b9c6d91SCole Faustnew name to not collide with the deprecated one. 105*4b9c6d91SCole Faust 106*4b9c6d91SCole FaustWe didn't want to call it minijail2 or something that would make people 107*4b9c6d91SCole Fauststart using it before we were ready, and it was also concretely _less_ since it 108*4b9c6d91SCole Faustdropped libbase, etc. Technically, we needed to be able to fork/preload with 109*4b9c6d91SCole Faustminimal extra syscall noise which was too hard with libbase at the time (onexit 110*4b9c6d91SCole Fausthandlers, etc that called syscalls we didn't want to allow). Also, Elly made a 111*4b9c6d91SCole Fauststrong case that C would be the right choice for this for linking and ease of 112*4b9c6d91SCole Faustcontrolled surprise system call use. 113*4b9c6d91SCole Faust 114*4b9c6d91SCole Fausthttps://crrev.com/c/4585/ added the original implementation. 115*4b9c6d91SCole Faust 116*4b9c6d91SCole FaustSource: Conversations with original authors, ellyjones@ and wad@. 117