Commit graph

60 commits

Author SHA1 Message Date
Lionel Sambuc 8933525b85 Fix default partition in clientctl.
The partition numbering has changed with the new image creation
framework.

Change-Id: I0644e5879913bee067bc31376f81bc5407f4c81f
2015-10-28 16:06:52 +01:00
David van Moolenbroek 7c48de6cc4 Resolve more warnings
Change-Id: Ibc1b7f7cd45ad7295285e59c6ce55888266fece8
2015-09-23 12:04:58 +00:00
David van Moolenbroek e4d99eb9b0 Basic live rerandomization infrastructure
This commits adds a basic infrastructure to support Address Space
Randomization (ASR).  In a nutshell, using the already imported ASR
LLVM pass, multiple versions can be generated for the same system
service, each with a randomized, different address space layout.
Combined with the magic instrumentation for state transfer, a system
service can be live updated into another ASR-randomized version at
runtime, thus providing live rerandomization.

Since MINIX3 is not yet capable of running LLVM linker passes, the
ASR-randomized service binaries have to be pregenerated during
crosscompilation.  These pregenerated binaries can then be cycled
through at runtime.  This patch provides the basic proof-of-concept
infrastructure for both these parts.

In order to support pregeneration, the clientctl host script has
been extended with a "buildasr" command.  It is to be used after
building the entire system with bitcode and magic support, and will
produce a given number of ASR-randomized versions of all system
services.  These services are placed in /usr/service/asr in the
image that is generated as final step by the "buildasr" command.

In order to support runtime updating, a new update_asr(8) command
has been added to MINIX3.  This command attempts to live-update the
running system services into their next ASR-randomized versions.
For now, this command is not run automatically, and thus must be
invoked manually.

Technical notes:

- For various reasons, magic instrumentation is x86-only for now,
  and ASR functionality is therefore to be used on x86 only as well.
- The ASR-randomized binaries are placed in numbered subdirectories
  so as not to have to change their actual program names, which are
  assumed to be static in various places (system.conf, procfs).
- The root partition is typically too small to contain all the
  produced binaries, which is why we introduce /usr/service.  There
  is a symlink from /service/asr to /usr/service/asr for no other
  reason than to let userland continue to assume that all services
  are reachable through /service.
- The ASR count field (r_asr_count/ASRcount) maintained by RS is not
  used within RS in any way; it is only passed through procfs to
  userland in order to allow update_asr(8) to keep track of which
  version is currently loaded without having to maintain own state.
- Ideally, pre-instrumentation linking of a service would remove all
  its randomized versions.  Currently, the user is assumed not to
  perform ASR instrumentation and then recompile system services
  without performing ASR instrumentation again, as the randomized
  binaries included in the image would then be stale.  This aspect
  has to be improved later.
- Various other issues are flagged in the comments of the various
  parts of this patch.

Change-Id: I093ad57f31c18305591f64b2d491272288aa0937
2015-09-17 17:15:03 +00:00
David van Moolenbroek f55e3cae08 libmagic: fix ASR padding for memory mapping
The code could not decide whether to apply the padding to the start
or the end of the region, resulting in strange behavior because part
of the returned range might not have the right properties.  With this
patch, padding is now consistently applied at the end of the region,
since virtual mmap addresses are allocated from high to low.

Also fix a few small related bugs in error handling code.

Change-Id: I327814bb3921d7982ffc1296a5bf365d9c79c1d9
2015-09-17 17:14:47 +00:00
David van Moolenbroek 139ae0da30 ASR pass: disable caller padding by default
The feature is fundamentally broken.  See the comment in the code.

Change-Id: If36b06b0732cc4d18f20240ed96d30a7959b0d21
2015-09-17 17:14:20 +00:00
David van Moolenbroek 0b98e8aad8 Import ASR pass from llvm-apps
Change-Id: I106c5faf8d8f1af5d3f5542fe666532895413909
2015-09-17 17:14:09 +00:00
David van Moolenbroek 78ff1e69b6 libmagic: fail on all state transfer errors
Also do not report debugging information by default.

Change-Id: I5d80a3df3c3ecc16a577d88abe6e37a792add747
2015-09-17 17:14:03 +00:00
David van Moolenbroek 3a3478dcea magic pass: register additional compatible types
This patch is a first step towards working around the larger problem of
LLVM 3.x's use of bitcasting between structures and their elements to
deal with opaque types, replacing LLVM 2.x's actual unification.  The
patch allows the pass to register a larger number of compatible types,
in particular for structure pointers passed through function calls.
A skeleton is provided for dealing with structure elements as well, but
that part requires much more work.  It remains to be seen whether a
more structural approach to dealing with this problem may be warranted.

For now, this change is necessary to allow instrumented state transfer
of various "minix_timer" structures and pointers in PM and VFS.

Change-Id: Ib717d86ccfced53387e72a92750d22ae980c3466
2015-09-17 17:13:21 +00:00
David van Moolenbroek ebef68bf4c libmagic: supply own ctype macros
Due to the current linker command line ordering, parts of lib(min)c
that are used exclusively by libmagic end up not being instrumented,
which then causes problems transferring pointers such as _ctype_tab_
and _tolower_tab_.  As a temporary workaround, we redefine the macros
that use those pointers.  A better long-term solution should
eventually render this patch obsolete.

Change-Id: Ice1d125ff6fb2f65ac6dcc6cf6eec7cd6176bee1
2015-09-17 17:13:13 +00:00
David van Moolenbroek c8f6986185 libmagic: ignore kernel pointers on MINIX3
Change-Id: I8830cab3d6637bae6141dc2b0e209d319703787f
2015-09-17 17:13:03 +00:00
David van Moolenbroek 5105ab554b Ignore a new ARM driver entry for instrumentation
Change-Id: I710a7534d2ba41107641252b9f80f197d04ba107
2015-09-17 14:08:01 +00:00
David van Moolenbroek c07c198b5f Disable malloc instrumentation for VM (#2)
When the malloc code is instrumented, the global _brksize variable
should not be transferred.  However, when the malloc code is not
instrumented, failing to transfer _brksize would reset the heap
upon state transfer.  In this patch, the magic pass stores the flag
indicating whether memory function instrumentation is disabled, in
the target process.  This allows libmagic to check this flag during
state transfer, to see whether it should transfer _brksize or not.

Change-Id: Ia004651e21e08b0ed3f5305865c53c6659e18f38
2015-09-17 14:07:31 +00:00
David van Moolenbroek 76b68f9f99 Disable malloc instrumentation for VM (#1)
This patch changes the VM makefile to specify that the magic pass is
to skip memory function instrumentation, and to transfer the data
variables of the malloc code (thus overriding the exception we made
for all other system services).  We add two magic pass flags to
achieve this.  Since the magic pass is a big bowl of spaghetti code,
ignoring whitespace changes while viewing this patch is recommended.

Change-Id: I5ab83b23d8437b37c44dea99537bc202469c9df6
2015-09-17 14:05:14 +00:00
David van Moolenbroek b7725c8552 Fix mmap leak in malloc code upon state transfer
The NetBSD libc malloc implementation uses a memory-mapped area for
its page directory.  Since the process heap is reconstructed upon
state transfer for live update, this memory-mapped area must not be
transferred to the new process.  However, as the new instance of the
process being updated inherits all memory-mapped areas of the old
instance, it also automatically inherits the malloc implementation's
page directory.  Thus, we must explicitly free this area in order to
avoid a memory leak.

The magic pass already detects (de)allocation functions called from
within other (de)allocation functions, which is why the mmap(2) and
munmap(2) calls of the malloc code are not instrumented as it is.
This patch changes that particular case to allow a different hook
function to be called for such "nested" allocation calls, for a
particular set of nested calls.  In particular, the malloc(3) code's
mmap(2) and munmap(2) calls are replaced with magic_nested_mmap and
magic_nested_munmap calls, respectively.  The magic library then
tracks memory mapping allocations of the malloc code by providing an
implementation for these two wrappers, and frees the allocations upon
state transfer.

This approach was chosen over various alternatives:

- While it appears that nesting could be established by setting a
  flag while the malloc(3) wrapper is active, and testing the flag in
  the mmap(2)/munmap(2) wrappers, this approach would fail to detect
  memory-mapped allocations made from uninstrumented malloc(3) calls,
  and therefore not a viable option.
- It would be possible to obtain the value of the variables that
  store the information about the memory-mapped area in the malloc
  code.  However, this is rather difficult in practice due to the way
  the libc malloc implementation stores the size of the are, and it
  would make the solution more dependent on the specific libc malloc
  implementation.
- It would be possible to use the special "nested" instrumentation
  for allocations made from certain marked sections.  Since we mark
  the data section of the malloc code already, this would not be hard
  to do.  Switching to this alternative would change very little, and
  if for any reason this approach yields more advantages in the
  future, we can still choose to do so.

Change-Id: Id977405da86a72458dd10f18e076d8460fd2fb75
2015-09-17 14:04:43 +00:00
David van Moolenbroek 9b9bea921f Do not instrument malloc implementation variables
Since the heap is reconstructed upon state transfer, the old malloc
state is discarded.  In order to avoid state transfer errors, we can
and in fact must discard the internal state of the malloc
implementation.  This patch achieves this by using the sectionify
pass to mark the variables in the libminc malloc object as state that
must be skipped during state transfer.

Change-Id: Ie330f582c8bd45f37a878ea41fa0f9d4a18045e1
2015-09-17 14:03:47 +00:00
David van Moolenbroek 40aba308a0 libmagic: free actual dsentry rather than a copy
This resolves an infinite loop during boot, in libblockdriver freeing
DMA memory at the end of a partition(3) call.

Change-Id: I0757aa48f769ea79eab7160f23ee4c97cf58e055
2015-09-17 14:00:07 +00:00
David van Moolenbroek 949a3e52e5 Break loose from llvm-apps entirely
Change-Id: I532f5f44c785c1a72407b504568d54fc6cbabf8f
2015-09-17 13:58:57 +00:00
David van Moolenbroek 0acd3f1ae0 Import magic library from llvm-apps
Change-Id: Icfbcfae6afc731a23e71448a7a5d0045b2c219e5
2015-09-17 13:58:32 +00:00
David van Moolenbroek 3e457fe321 Import magic pass from llvm-apps
Change-Id: I19535b913b50f2ff24aeb80ddefc92e305c31fe8
2015-09-17 13:57:53 +00:00
David van Moolenbroek b5e2faaaaf Import sectionify pass from llvm-apps
Change-Id: I3e3ac102b4898ca22ed1d9c25ec309d77bbe32de
2015-09-17 13:57:29 +00:00
David van Moolenbroek 3956ee9eed LLVM passes: centralize Makefile structure
Make the passes we have so far, hello and WeakAliasModuleOverride,
use settings from a Makefile include file in the parent directory.
This change is in preparation of adding other passes.

Change-Id: Ib195ee7f5c7626f4975368b02c944382e87e3814
2015-09-17 13:56:41 +00:00
Erik van der Kouwe 63a89582ab x86_hdimage: increase image size for bitcode build
Make disk image size sufficient for LLVM bitcode build with symbols.

Edited by David van Moolenbroek to do this only when -b is given.

Change-Id: I3bde164756c477b4af5ed9435ca03da3b186cf7e
2015-09-17 13:55:38 +00:00
Lionel Sambuc 3ceafe99fd Support BUILDVARS from cmd line in configure.llvm
Change-Id: I59527c60cb34c12fd2bed449b37bb812a83c4e42
2015-09-17 13:53:18 +00:00
Cristiano Giuffrida 035cdb2e79 llvm: Never rebuild gold in configure.llvm.
Change-Id: I7378ca38a5a9bf018823b6431d1a4ca8fbb10b58
2015-09-17 13:52:35 +00:00
Cristiano Giuffrida c9590fa23a llvm: Fix OPTFLAGS.
Change-Id: Id35ac2821ad69825735c50a32bdd04d8453edb22
2015-09-17 13:52:24 +00:00
Lionel Sambuc d8d3052dd0 QEMU default command lines updates
- Fix a bug in clientctl which tried to test for kvm. This simply
   remove this faulty test  as the kvm command has been deprecated by the
   QEMU project for a couple of years now.

 - Specify by default 256M of RAM as this is the minimal amount required
   for the whole-OS live update test to succeed.

 - Update the default command printed out at the end of the x86_hdimage
   script to be more generic, less focused on one use-case.

Change-Id: Ic555d50a3a1471f7d35cc7fd369f2292add6ac39
2015-09-17 13:51:14 +00:00
Cristiano Giuffrida 1e7bfb997f llvm: Build scripts improvements.
Change-Id: I278cdebccdba18be7e264bfd240ff02d4480b33c
2015-09-17 13:49:25 +00:00
Cristiano Giuffrida 04c5ac3eb5 llvm: Extend clientctl with many features.
Change-Id: I739eefa46458e956cb79c42a8cbf880428eec794
2015-09-17 13:49:03 +00:00
Cristiano Giuffrida c3041d5c6d llvm: Fix module map generation.
Change-Id: If9c2bef4c0ef3d002ac65a2c66aabcf0cf99ff95
2015-09-17 13:48:40 +00:00
Cristiano Giuffrida 326b9df3db llvm: Improve error handling in configure.llvm.
Change-Id: I9aa8f8a07a512f642447c70dca2e85d40ebe2b2a
2015-09-17 13:48:18 +00:00
Lionel Sambuc 5f8eb6fb0c minix/llvm/passes/Makefile.inc: Fix
This fixes and documents a mistake made during the sources move.
2014-08-29 12:56:57 -04:00
Erik van der Kouwe a7db4b5d19 Skip modules that don't work on x86
Skip the following modules in relink.llvm/build.llvm:
 - i2c
 - gpio
 - cat24c256
 - tsl2550
2014-08-29 12:56:40 -04:00
Erik van der Kouwe 08423ba51f Adjust LLVM MINIX scripts for new source layout
Adjust to the fact that drivers and servers have moved into the minix
subdir.
2014-08-29 12:56:28 -04:00
Erik van der Kouwe 52c6ad72ab build.llvm fix to allow pass arguments
This allows pass arguments to be specified (written by Cristiano)
2014-08-29 12:56:23 -04:00
Lionel Sambuc 84bb300f88 Remove /multiboot
This is just a duplicate of /boot/.temp, and it is not used anymore.

Change-Id: I8a4d6e68829de3ff3628ff0fe15f6d1d0a6b128f
2014-07-31 16:00:31 +02:00
Lionel Sambuc 433d6423c3 New sources layout
Change-Id: Ic716f336b7071063997cf5b4dae6d50e0b4631e9
2014-07-31 16:00:30 +02:00
Ben Gras edb410ffe2 empty Makefile
. needed to avoid a build problem on native minix under some
	  circumstances
2014-07-28 17:06:16 +02:00
Cristiano Giuffrida 592c9e1223 llvm: Use mfs images for clientctl buildisk. 2014-07-28 17:06:14 +02:00
Cristiano Giuffrida dea274570b llvm: Add SERIALOUT option to clientctl script. 2014-07-28 17:06:13 +02:00
Koustubha Bhat 98141c6587 build.llvm: including configure.llvm.inc must be optional 2014-07-28 17:06:13 +02:00
Cristiano Giuffrida bf1ab51c95 llvm: Use a separate common.overrides file for MINIX. 2014-07-28 17:06:12 +02:00
Cristiano Giuffrida 646a6b144b llvm: Fix rc script. 2014-07-28 17:06:12 +02:00
Cristiano Giuffrida 5c95bc4d9f llvm: Add clientctl actions for external disk support. 2014-07-28 17:06:11 +02:00
Cristiano Giuffrida 0810704c3d llvm: Preserve default OPTFLAGS when adding instrumentation. 2014-07-28 17:06:10 +02:00
Cristiano Giuffrida 5119c2fe3a llvm: Use default LLVMPREFIX when building passes. 2014-07-28 17:06:10 +02:00
Erik van der Kouwe ca39637dcc LLVM clientctl: activate the KVM module only if available 2014-07-28 17:06:10 +02:00
Erik van der Kouwe d7b27ed4f9 Fix LLVM clientctl: if the kvm command is not available, just use QEMU directly 2014-07-28 17:06:09 +02:00
Erik van der Kouwe 193bd04207 configure.llvm: add INTERACTIVE environment variable which can be set to no to prevent questions from being asked 2014-07-28 17:06:09 +02:00
Cristiano Giuffrida d27de61ef2 llvm: Fix llvm-apps bridging. 2014-07-28 17:06:08 +02:00
Cristiano Giuffrida 07ae148a06 llvm: serverctl is now clientctl. 2014-07-28 17:06:08 +02:00