tools/dm_restrict: Unshare mount and IPC namespaces on Linux
authorGeorge Dunlap <george.dunlap@citrix.com>
Tue, 6 Nov 2018 15:41:24 +0000 (15:41 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Tue, 6 Nov 2018 15:41:24 +0000 (15:41 +0000)
commit371a23e65db5eb3a80a148586aeb551d4d0015f1
tree9f111803377d333029d1488f0eb48c446bc0f4c1
parent7414750be1fed21687a0a28f67cc2397ebb0d0ba
tools/dm_restrict: Unshare mount and IPC namespaces on Linux

QEMU running under Xen doesn't need mount or IPC functionality.
Create and enter separate namespaces for each of these before
executing QEMU, so that in the event that other restrictions fail, the
process won't be able to even name system mount points or exsting
non-file-based IPC descriptors to attempt to attack them.

Unsharing is something a process can only do to itself (it would
seem); so add an os-specific "dm_preexec_restrict()" hook just before
we exec() the device model.

Also add checks to depriv-process-checker.sh to verify that dm is
running in a new namespace (or at least, a different one than the
caller).

Suggested-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
Changes since v4:
- Fix function prototype for netbsd code

Changes since v3:
- Fix some more style issues

Changes since v2:
- Return an error rather than calling exit()
- Use LOGE() and print to the current stderr fd, rather than
  printing to the new stderr fd via write()
- Use r for external return values rather than rc.

CC: Ian Jackson <ian.jackson@citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Anthony Perard <anthony.perard@citrix.com>
docs/designs/qemu-deprivilege.md
tools/libxl/libxl_dm.c
tools/libxl/libxl_freebsd.c
tools/libxl/libxl_internal.h
tools/libxl/libxl_linux.c
tools/libxl/libxl_netbsd.c