Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions nixos/modules/services/security/aesmd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,25 @@ in
];

serviceConfig = {
ExecStartPre = pkgs.writeShellScript "copy-aesmd-data-files.sh" ''
set -euo pipefail
whiteListFile="${aesmDataFolder}/white_list_cert_to_be_verify.bin"
if [[ ! -f "$whiteListFile" ]]; then
${pkgs.coreutils}/bin/install -m 644 -D \
"${storeAesmFolder}/data/white_list_cert_to_be_verify.bin" \
"$whiteListFile"
fi
'';
ExecStartPre =
let
script = pkgs.writeShellScript "copy-aesmd-data-files.sh" ''
set -euo pipefail

# For some reason systemd 257+ won't properly bind mount the
# StateDirectory with the aesmd DynamicUser owning it
chown -R aesmd:aesmd /var/opt/aesmd

whiteListFile="${aesmDataFolder}/white_list_cert_to_be_verify.bin"
if [[ ! -f "$whiteListFile" ]]; then
install -m 644 -o aesmd -g aesmd -D \
"${storeAesmFolder}/data/white_list_cert_to_be_verify.bin" \
"$whiteListFile"
fi
'';
# Run setup with elevated privileges
in
"+${script}";
ExecStart = "${sgx-psw}/bin/aesm_service --no-daemon";
ExecReload = ''${pkgs.coreutils}/bin/kill -SIGHUP "$MAINPID"'';

Expand All @@ -196,9 +206,8 @@ in
RuntimeDirectoryMode = "0750";

# Hardening

# chroot into the runtime directory
RootDirectory = "%t/aesmd";
# # chroot prevents the setup from locating the aesmd DynamicUser
# RootDirectory = "%t/aesmd";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

Copy link
Contributor Author

@phlip9 phlip9 Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the comment could be clearer. When I tested this, RootDirectory (which as I understand it, chroot's into the given directory), seemed to interact poorly with DynamicUser and prevented the service from starting properly.

EDIT: for more context, this first became an issue after NixOS updated to systemd-v257

BindReadOnlyPaths = [
builtins.storeDir
# Hardcoded path AESM_CONFIG_FILE in psw/ae/aesm_service/source/utils/aesm_config.cpp
Expand Down
12 changes: 12 additions & 0 deletions pkgs/os-specific/linux/sgx/psw/add-missing-header-pr-1063.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/psw/enclave_common/sgx_enclave_common.cpp b/psw/enclave_common/sgx_enclave_common.cpp
index 9867ecc86..46fcf8733 100644
--- a/psw/enclave_common/sgx_enclave_common.cpp
+++ b/psw/enclave_common/sgx_enclave_common.cpp
@@ -35,6 +35,7 @@
#include <dlfcn.h>
#include <map>
#include <functional>
+#include <algorithm>
#include "sgx_enclave_common.h"
#include "sgx_urts.h"
#include "arch.h"
12 changes: 8 additions & 4 deletions pkgs/os-specific/linux/sgx/psw/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
stdenv.mkDerivation rec {
pname = "sgx-psw";
# Version as given in se_version.h
version = "2.25.100.3";
version = "2.26.100.0";
# Version as used in the Git tag
versionTag = "2.25";
versionTag = "2.26";

src = fetchFromGitHub {
owner = "intel";
repo = "linux-sgx";
rev = "sgx_${versionTag}";
hash = "sha256-RR+vFTd9ZM6XUn3KgQeUM+xoj1Ava4zQzFYA/nfXyaw=";
hash = "sha256-g7t51Js4JoF7QeEngzmJJcRP2bQDbEMeKimVzqNDkFI=";
fetchSubmodules = true;
};

Expand All @@ -52,7 +52,7 @@ stdenv.mkDerivation rec {
# Fetch the Data Center Attestation Primitives (DCAP) platform enclaves
# and pre-built sgxssl.
dcap = rec {
version = "1.22";
version = "1.23";
filename = "prebuilt_dcap_${version}.tar.gz";
prebuilt = fetchurl {
url = "https://download.01.org/intel-sgx/sgx-dcap/${version}/linux/${filename}";
Expand Down Expand Up @@ -90,6 +90,10 @@ stdenv.mkDerivation rec {
# binary. Without changes, the `aesm_service` will be different after every
# build because the embedded zip file contents have different modified times.
./cppmicroservices-no-mtime.patch

# Add missing `#include <algorithm>` to fix build with GCC 14
# PR: <https://github.com/intel/linux-sgx/pull/1063>
./add-missing-header-pr-1063.patch
];

postPatch =
Expand Down