SecV is a multi-language partitioning approach for TEE software, e.g., with Intel SGX. It is based on GraalVM's Truffle framework, an open source Java library for building programming language implementations. SecV proposes secure AST nodes which can be used to annontate sensitive information in a language-agnostic fashion. The corresponding code is then analyzed with Polytaint, a Truffle-based program analyzer which we developed that splits the program into trusted and untrusted parts running in and out of an SGX TEE respective.
- This PoC implementation accompanies our Middleware'23 paper:
@inproceedings{10.1145/3590140.3629116,
author = {Yuhala, Peterson and Felber, Pascal and Guiroux, Hugo and Lozi, Jean-Pierre and Tchana, Alain and Schiavoni, Valerio and Thomas, Ga\"{e}l},
title = {SecV: Secure Code Partitioning via Multi-Language Secure Values},
year = {2023},
isbn = {9798400701771},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3590140.3629116},
doi = {10.1145/3590140.3629116},
booktitle = {Proceedings of the 24th International Middleware Conference},
pages = {207–219},
numpages = {13},
keywords = {GraalVM, Intel SGX, Java, Managed Execution Environments, Truffle, Trusted Execution Environments},
location = {Bologna, Italy},
series = {Middleware '23}
}-
Polytainttool is a Truffle instrumentation taint tracking tool which analyses Polyglot programs to obtain source sections (i.e methods/functions) which access secure types defined by theSecureL Truffle language implementation. -
Polytaint instruments mainly function call, variable write and variable read nodes to track the desired tainted/trusted functions.
-
The results of the run time analysis are then transfered to the
Partitioningmodule, which partitions the application into two parts:Trustedjava native image application which exposes the trusted functions as GraalVM entry points, and anUntrustednative image java applications which exposes the functions/methods which do not access secure types. -
These images are then build with GraalVM native image tool and used to build the final Intel SGX application.
-
More info on the inner workings of this tool will be provided later on.
-
Polytaint analyses programs in two modes:
fullandpart. -
With
fullmode no instrumentation is done. A single java program/file is created:Trusted.javain theoutputfolder. This java program simply runs the full guest language code snippet using the Java polyglot API. This Java file is copied tosubstratevmwhere it is used to create a native image which will run entirely inside an SGX enclave. -
With
partmode the corresponding program (e.g JS, Python) is run on the JVM and instrumented accordingly. That is, program variables and functions/methods accessing/modifyingSecureLtypes are registered as the program runs. Analysis divides functions into 3 categories:1.Trusted functions: functions which explicitly manipulate secL types or takes secure variables as parameters. NB: A secure variable is either a variable which recieves its variable directly from a
secLscope via the polyglot API, or one whose value originates implicitly from another secL variable. Trusted functions will be exported asstatic Java methodsinTrusted.java. They will have proxies inUntrusted.javawhich will perform Intel SGX transitions.2.Untrusted functions: functions which do not manipulate secure variables explicitly nor take them as input. These will be exported as
static Java methodsinUntrusted.java. The primary argument for this design choice is TCB reduction. They will have proxies inTrusted.javawhich perform Intel SGX transitions.3.Neutral functions: functions which do not explicitly declare/manipulate secure types in their body but take them as input. They are exported fully in both
Trusted.javaandUntrusted.java. The primary argument for this design choice is security (no secure type should be sent out) and performance (no transition needed).
At the end of analysis, the analysis results (i.e trusted, untrusted, neutral functions) are sent to the partitioning module which then creates 2 Java files: Trusted.java and Untrusted.java as well as other useful files (C/C++ headers, EDL files etc) to be used by the sgx module to build the final SGX applications. These Java files have the corresponding guest language functions exported as Java methods using the Polyglot API.
- The Java files are copied to
substratevmand used to build two native images which will run inside (usingTrusted.java) and outside the enclave (usingUntrusted.java).
-
To run the
polytainttool, use therunTaintTrack.shscript as such:./runTaintTrack.sh <guestLanguage> <programFile> <imageType>. -
To partition a program on the other hand, we will run taint tracking with
imageType = part. For example:
./runTaintTrack.sh js polyglot.js part
-
The above command will analyse the program in
polyglot.jswith ourpolytaintinstrumentation tool and determine which functions will beTrusted,UntrustedandNeutral. The result of this analysis is printed at the end of the analysis. The two Java programs are then created as described above and the files are copied tosubstratevmin thegraalfolder. Other files are also created as already explained and moved to the appropriate module. -
To build the partitioned native image, move to the
graalfolder and run the script:./build_polytaint_images.sh. This will build two relocatable.oimages corresponding toTrusted.javanative image andUntrusted.javanative image. These object files are moved to thesgx-modulein thesgxfolder. -
To build the corresponding SGX application, move to the
sgxfolder and runmake clean && make. Run the program with./app. -
To run a the program in
polyglot.jsentirely inside the enclave, we don't need to partition the program. So we use the command:
./runTaintTrack.sh js polyglot.js full
- This will skip taint analysis and just create a single Java application with the JavaScript program embedded. To build the corresponding native image move into the
graalfolder and run:./build_full_poly_image.sh. A native image relocatable filemain.owill be created and moved to thesgx module. - Similarly, to build the corresponding SGX application, move to the
sgxfolder and runmake clean && make. Run the program with./app.
- The partitioning tool uses regular
expressionsparse out function defitions. For JS code, this is more or less feasible. However for Python source code, it is very difficult to extract the function body with a regex. To simplify the process, we introduce amagic string:func_end=1at the end of python function definitions. This is a correct python expression but we are not interested in its result. It simply makes things easier for us when parsing out function definitions. This expression will be removed in the final partitioned program.
- If you install a language locally with
guand use the-f(force) option to prevent version checks, this may lead to the polyglot API not detecting the language in the list of languages even thoughgu listlists the language as installed. This is a weird issue that I'm yet to understand. Nonetheless all works correctly when the language (e.g secureL) is installed with:gu install -L secL-component.jar.