···11+From 1683c336e11b3cbe2b48c1be1c9460a661523c71 Mon Sep 17 00:00:00 2001
22+From: Vincent Haupert <mail@vincent-haupert.de>
33+Date: Sat, 8 Jan 2022 17:22:31 +0100
44+Subject: [PATCH 1/3] Linux: fix Nix detection
55+66+Detect the `OS_ID` of Nix by probing for the presence of the `NIX_STORE`
77+environment variable instead of `NIX_PATH`. The latter is only set in a
88+`nix-shell` session but isn't when building a derivation through
99+`nix-build`. In contrast, the `NIX_STORE` environment variable is set in
1010+both cases.
1111+1212+Signed-off-by: Vincent Haupert <mail@vincent-haupert.de>
1313+---
1414+ Linux/sgx/buildenv.mk | 2 +-
1515+ 1 file changed, 1 insertion(+), 1 deletion(-)
1616+1717+diff --git a/Linux/sgx/buildenv.mk b/Linux/sgx/buildenv.mk
1818+index cd8818e..dac23c7 100644
1919+--- a/Linux/sgx/buildenv.mk
2020++++ b/Linux/sgx/buildenv.mk
2121+@@ -65,7 +65,7 @@ $(shell mkdir -p $(PACKAGE_LIB))
2222+ UBUNTU_CONFNAME:=/usr/include/x86_64-linux-gnu/bits/confname.h
2323+ ifneq ("$(wildcard $(UBUNTU_CONFNAME))","")
2424+ OS_ID=1
2525+-else ifeq ($(origin NIX_PATH),environment)
2626++else ifeq ($(origin NIX_STORE),environment)
2727+ OS_ID=3
2828+ else
2929+ OS_ID=2
3030+3131+From f493525face589d759223bfa45bb802c31ddce4f Mon Sep 17 00:00:00 2001
3232+From: Vincent Haupert <mail@vincent-haupert.de>
3333+Date: Sat, 8 Jan 2022 17:33:22 +0100
3434+Subject: [PATCH 2/3] Linux: call binaries relative to PATH
3535+3636+Using an absolute path to call binaries is incompatible with
3737+distributions which do not follow the Filesystem Hierachy Standard;
3838+Nix is an example. Also, it is inconsistent with the rest of the code
3939+base, let alone superfluous.
4040+4141+Signed-off-by: Vincent Haupert <mail@vincent-haupert.de>
4242+---
4343+ Linux/build_openssl.sh | 2 +-
4444+ 1 file changed, 1 insertion(+), 1 deletion(-)
4545+4646+diff --git a/Linux/build_openssl.sh b/Linux/build_openssl.sh
4747+index 7d77b79..e8b59a1 100755
4848+--- a/Linux/build_openssl.sh
4949++++ b/Linux/build_openssl.sh
5050+@@ -38,7 +38,7 @@ SGXSSL_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5151+ echo $SGXSSL_ROOT
5252+5353+ OPENSSL_INSTALL_DIR="$SGXSSL_ROOT/../openssl_source/OpenSSL_install_dir_tmp"
5454+-OPENSSL_VERSION=`/bin/ls $SGXSSL_ROOT/../openssl_source/*1.1.1*.tar.gz | /usr/bin/head -1 | /bin/grep -o '[^/]*$' | /bin/sed -s -- 's/\.tar\.gz//'`
5555++OPENSSL_VERSION=`ls $SGXSSL_ROOT/../openssl_source/*1.1.1*.tar.gz | head -1 | grep -o '[^/]*$' | sed -s -- 's/\.tar\.gz//'`
5656+ if [ "$OPENSSL_VERSION" == "" ]
5757+ then
5858+ echo "In order to run this script, OpenSSL tar.gz package must be located in openssl_source/ directory."
5959+6060+From fdb883d30fff72b5cfb8c61a2288d3d948f64224 Mon Sep 17 00:00:00 2001
6161+From: Vincent Haupert <mail@vincent-haupert.de>
6262+Date: Tue, 11 Jan 2022 10:56:39 +0100
6363+Subject: [PATCH 3/3] Linux: properly extract GCC major version
6464+6565+Calling `gcc -dumpversion` yields the full version string, e.g.,
6666+`10.3.0`. The `build_openssl.sh` bash script uses the `-ge` number
6767+comparison operator to check if the returned version is at least
6868+8. This results in an error if the returned GCC version includes a patch
6969+version; "10.3.0" isn't a valid number.
7070+7171+This commit fixes the version detection by only extracting the relevant
7272+major version of GCC.
7373+7474+Signed-off-by: Vincent Haupert <mail@vincent-haupert.de>
7575+---
7676+ Linux/build_openssl.sh | 3 ++-
7777+ 1 file changed, 2 insertions(+), 1 deletion(-)
7878+7979+diff --git a/Linux/build_openssl.sh b/Linux/build_openssl.sh
8080+index e8b59a1..6e4046f 100755
8181+--- a/Linux/build_openssl.sh
8282++++ b/Linux/build_openssl.sh
8383+@@ -82,6 +82,7 @@ fi
8484+ MITIGATION_OPT=""
8585+ MITIGATION_FLAGS=""
8686+ CC_VERSION=`gcc -dumpversion`
8787++CC_VERSION_MAJOR=`echo "$CC_VERSION" | cut -f1 -d.`
8888+ for arg in "$@"
8989+ do
9090+ case $arg in
9191+@@ -99,7 +100,7 @@ do
9292+ ;;
9393+ -mfunction-return=thunk-extern)
9494+ MITIGATION_FLAGS+=" $arg"
9595+- if [[ $CC_VERSION -ge 8 ]] ; then
9696++ if [[ "$CC_VERSION_MAJOR" -ge 8 ]] ; then
9797+ MITIGATION_FLAGS+=" -fcf-protection=none"
9898+ fi
9999+ shift