Prevent getenv and trace file-system for security applications#550
Prevent getenv and trace file-system for security applications#550lefessan wants to merge 1 commit intoocaml:trunkfrom
Conversation
|
I forgot another application of C plugins: they can be used to "virtualize" an application from the file-system, i.e. redirect |
fa9eae8 to
1347dd8
Compare
|
I understand the |
|
I am still working on the CAML_CPLUGINS part anyway, it seems not to work correctly because asmrun files are not compiled in -fPIC by default... |
1347dd8 to
6744baa
Compare
|
Ok, the new version works both with bytecode and native code. @gasche As it is a runtime thing, I am planning to ask @damiendoligez for both, since he is the author of most the recommendations of LafoSec :-) |
|
I think it would still be nicer to split the two separate features in two separate commits. |
|
these seem like quite distinct features -- the |
Wouldn't you do this anyway (for other |
Preference is to remove getenv and fix up the C libraries where possible. This may be impractical, but slightly less so now that the OCaml runtime can be configured to not trigger a zillion dynamic |
6744baa to
02e3106
Compare
|
@lefessan If you're going to split the plugins part off, could I suggest you also make a third pull request which does something like adding a "configure" option for PIC, which does the right thing (i.e. C compiler flags etc + the asmrun/Makefile change that is required)? (We also need this for the gdb plugin.) |
|
As a proof-of-concept, here is an experimental set of plugins: For example, the |
|
@mshinwell I am not an expert of |
02e3106 to
523574b
Compare
|
I would prefer if |
|
@drbo what would be the semantics of linking together some modules compiled with |
|
From what I understood at the core-dev meeting, there was not a strong interest in this patch, but neither any opposition. Since it is interesting for us, I will rebase it, add access to a few more variables/functions (especially hooks), and merge it in the next weeks. |
|
I am not fond of runtime variants. OPAM provides the possibility to have multiple switches, I find it better to provide a compiler with |
|
With N different configure-time flags (no-getenv, fp, afl instrumentation, ...), will we have 2^N OPAM switches? Can switches be created "lazily" on the user machine (based on some configure-time options)? |
|
I wouldn't actually create an
Not sure I understand your question, but a possible answer would be to modify the |
|
I was thinking about supporting that in OPAM. You could do |
|
It's probably worth submitting an issue on |
|
Oh, but then you would need also a way to "unsplit" the variables in the command line: |
|
I don't understand what's wrong with using runtime variants as @damiendoligez suggests -- the "no getenv" feature is purely constrained to affecting This would save the (much more heavyweight) option of a new compiler flag for features that absolutely require them since they affect OCaml compilation units (like AFL fuzzing, or flambda). |
Because, for security reasons, you want all your toolchain to be unaffected by environment variables. Suppose you have a completely scripted build system, that cannot be modified, but you can change env variables before starting it. Then, an engineer can set an env. variable to connect to the OCaml compiler during the build, and inject some code in the generated object, that will be linked in the executable at the end. That's the kind of security holes that ANSSI (French equivalent of NSA) is trying to prevent. I don't see how you can prevent that with runtime variants, unless you actually set PS: a good complement would be to disable |
A configure option to disable the installation of the standard runtime library (and debug version) would work here, wouldn't it? Presumably any such locked down OCaml distribution would have its own distribution system, and this could choose which runtime variants to install as a matter of local security policy. |
|
What if the attack happens during the compilation of OCaml itself ? Code could be injected inside stdlib for example, while the standard runtime variant is still being used. If we add an option to configure to change that, I don't see the benefit over the |
I'm afraid I don't understand your threat model. Presumably you would build your toolchain in a deterministic environment (e.g. a locked down Docker container with tight seccomp allowances, and a trusted kernel), and provide that as a binary toolchain for untrusted code to be compiled.
One person's |
The threat model is not to compile untrusted code, but untrusted engineers who would want to inject their untrusted code in a trusted code. In such a setting, everything should be static... but most developers won't want to work in such an environment ! |
+1 to that. As for merging soon, lack of interest is not enough, you need at least a code review. You also need approval from another core developer, unless the patch is really small (which it isn't in its current state). I have one question about the patch: why don't you Finally, I really think this should be two separate PRs, as the tracing stuff has nothing to do with security. |
The rationale was that the addition of C plugins was creating a security hole (well, not bigger than the current debugger support), and that the
I will see if Pierre can do it.
I think it's really a bad practice to |
Good arguments, but for security you want to make sure the macros are always used, right? |
|
Here, the idea was to prevent |
|
|
||
| This function can then be used to query the address of other symbols | ||
| in the executable, limited to the following queries: | ||
| */ |
There was a problem hiding this comment.
This explanation is really unclear: there are two variables called query, and I don't understand what the two queries do.
523574b to
8a87ae2
Compare
|
Replaced by #668 |
The newer-version-of relation is entirely orthogonal to inlinability, so `meet` and `join` should cause inlinability to be recomputed.
Lazy effects test
64235a3 flambda-backend: Change Float.nan from sNaN to qNaN (ocaml#466) 14a8e27 flambda-backend: Track GC work for all managed bigarray allocations (upstream 11022) (ocaml#569) c3cda96 flambda-backend: Add two new methods to targetint for dwarf (ocaml#560) e6f1fed flambda-backend: Handle arithmetic overflow in select_addr (ocaml#570) dab7209 flambda-backend: Add Target_system to ocaml/utils (ocaml#542) 82d5044 flambda-backend: Enhance numbers.ml with more primitive types (ocaml#544) 216be99 flambda-backend: Fix flambda_o3 and flambda_oclassic attributes (ocaml#536) 4b56e07 flambda-backend: Test naked pointer root handling (ocaml#550) 40d69ce flambda-backend: Stop local function optimisation from moving code into function bodies; opaque_identity fixes for class compilation (ocaml#537) f08ae58 flambda-backend: Implemented inlining history and use it inside inlining reports (ocaml#365) ac496bf flambda-backend: Disable the local keyword in typing (ocaml#540) 7d46712 flambda-backend: Bugfix for Typedtree generation of arrow types (ocaml#539) 61a7b47 flambda-backend: Insert missing page table check in roots_nat.c (ocaml#541) 323bd36 flambda-backend: Compiler error when -disable-all-extensions and -extension are used (ocaml#534) d8956b0 flambda-backend: Persistent environment and reproducibility (ocaml#533) 4a0c89f flambda-backend: Revert "Revert bswap PRs (480 and 482)" (ocaml#506) 7803705 flambda-backend: Cause a C warning when CAMLreturn is missing in C stubs. (ocaml#376) 6199db5 flambda-backend: Improve unboxing during cmm for Flambda (ocaml#295) 96b9e1b flambda-backend: Print diagnostics at runtime for Invalid (ocaml#530) 42ab88e flambda-backend: Disable bytecode compilers in ocamltest (ocaml#504) 58c72d5 flambda-backend: Backport ocaml#10595 from upstream/trunk (ocaml#471) 1010539 flambda-backend: Use C++ name mangling convention (ocaml#483) 81881bb flambda-backend: Local allocation test no longer relies on lifting (ocaml#525) f5c4719 flambda-backend: Fix an assertion in Closure that breaks probes (ocaml#505) c2cf2b2 flambda-backend: Add some missing command line arguments to ocamlnat (ocaml#499) git-subtree-dir: ocaml git-subtree-split: 64235a3
The following PR provides two features:
--no-getenvthat prevents the runtime from usinggetenv(Sys.getenvis still working normally). It can be used to compile an application in a security context, to prevent attackers from using the env. variables used by the runtime to temper the application behavior (debugger socket, gc tuning, etc.)CAML_CPLUGINSenv variable, for example to monitor calls to some system calls in a security context (they could also be used to add setup GC hooks for example). This ability can be disabled using a new configure option--no-cplugins(and of course, it is disabled by--no-getenv).