Mount soong sandbox chroot as read-only

It's safer to disallow writing to the root filesystem of the sandbox.
Still allow write access to the source, tmp, out and dist directories.

Test: build aosp_cf_x86_64_phone-userdebug
Change-Id: Idf0d3a420669fbf6c3aba24e058f09a314ec6d0e
This commit is contained in:
Diego Wilson 2020-04-02 18:11:28 +00:00
parent 1c5d4fe4f7
commit a22240bf22

View file

@ -54,6 +54,9 @@ var sandboxConfig struct {
working bool
group string
srcDir string
outDir string
distDir string
}
func (c *Cmd) sandboxSupported() bool {
@ -72,12 +75,20 @@ func (c *Cmd) sandboxSupported() bool {
sandboxConfig.group = "nobody"
}
sandboxConfig.srcDir = absPath(c.ctx, ".")
sandboxConfig.outDir = absPath(c.ctx, c.config.OutDir())
sandboxConfig.distDir = absPath(c.ctx, c.config.DistDir())
cmd := exec.CommandContext(c.ctx.Context, nsjailPath,
"-H", "android-build",
"-e",
"-u", "nobody",
"-g", sandboxConfig.group,
"-B", "/",
"-R", "/",
"-B", sandboxConfig.srcDir,
"-B", "/tmp",
"-B", sandboxConfig.outDir,
"-B", sandboxConfig.distDir,
"--disable_clone_newcgroup",
"--",
"/bin/bash", "-c", `if [ $(hostname) == "android-build" ]; then echo "Android" "Success"; else echo Failure; fi`)
@ -144,8 +155,20 @@ func (c *Cmd) wrapSandbox() {
"--rlimit_fsize", "soft",
"--rlimit_nofile", "soft",
// For now, just map everything. Eventually we should limit this, especially to make most things readonly.
"-B", "/",
// For now, just map everything. Make most things readonly.
"-R", "/",
// Mount source are read-write
"-B", sandboxConfig.srcDir,
//Mount out dir as read-write
"-B", sandboxConfig.outDir,
//Mount dist dir as read-write
"-B", sandboxConfig.distDir,
// Mount a writable tmp dir
"-B", "/tmp",
// Disable newcgroup for now, since it may require newer kernels
// TODO: try out cgroups