Giter Club home page Giter Club logo

sgx-step's Introduction

A Practical Attack Framework for Precise Enclave Execution Control CI

logo

SGX-Step is an open-source framework to facilitate side-channel attack research on Intel x86 processors in general and Intel SGX platforms in particular. SGX-Step consists of an adversarial Linux kernel driver and a small user-space operating system library that allows to configure untrusted page table entries and/or x86 APIC timer interrupts completely from user space. SGX-Step has been leveraged in our own research, as well as by independent researchers, to enable several new and improved enclaved execution attacks that gather side-channel observations at a maximal temporal resolution (i.e., by interrupting the victim enclave after every single instruction).

License. SGX-Step is free software, licensed under GPLv3. The SGX-Step logo is derived from Eadweard Muybridge's iconic public domain "Sallie Gardner at a Gallop" photo series, which, like our enclave single-stepping goal, breaks down the galloping horse dynamics into a series of individual photo frames to reveal overall horse gait properties.

SGX-Step release Changelog features
v1.5.0 Stabilization fixes (KPTI, kernel ISR mapping); (experimental) Gramine port; IPI support.
v1.4.0 Privileged interrupt/call gates (Plundervolt).
v1.3.0 Transient-execution support (Foreshadow).
v1.2.0 User-space interrupt handling and deterministic zero-step filtering (Nemesis).
v1.1.0 IA32 support.
v1.0.0 User-space page table manipulation and APIC timer single-stepping.

Publications. SGX-Step has been employed by several independent research groups and has enabled a new line of high-resolution SGX attacks. A full up-to-date list of known projects using SGX-Step is included at the bottom of this README. A copy of the original paper is available here.

@inproceedings{vanbulck2017sgxstep,
    title     = {{SGX-Step}: A Practical Attack Framework for Precise Enclave Execution Control},
    author    = {Van Bulck, Jo and Piessens, Frank and Strackx, Raoul},
    booktitle = {2nd Workshop on System Software for Trusted Execution {(SysTEX)}},
    publisher = {{ACM}},
    pages     = {4:1--4:6},
    month     = Oct,
    year      = 2017,
}

Demo. The app/memcmp directory contains a small demo application that illustrates the power of SGX-Step attacks by single-stepping a sample enclave that contains subtle, non-constant-time memcmp password comparison logic. As opposed to traditional, notoriously noisy timing attacks, SGX-Step can deterministically brute-force the password character-per-character in linear time:

sgxstep-memcmp-demo

Overview

Crucial to the design of SGX-Step, as opposed to previous enclave preemption proposals, is the creation of user-space virtual memory mappings for physical memory locations holding page table entries, as well as for the local APIC memory-mapped I/O configuration registers and the x86 Interrupt Descriptor Table (IDT). This allows an untrusted, attacker-controlled host process to easily (i) track or modify enclave page table entries, (ii) configure the APIC timer one-shot/periodic interrupt source, (iii) trigger inter-processor interrupts, and (iv) register custom interrupt handlers completely within user space.

sgx-step-framework

The above figure summarizes the sequence of hardware and software steps when interrupting and resuming an SGX enclave through our framework.

  1. The local APIC timer interrupt arrives within an enclaved instruction.
  2. The processor executes the AEX procedure that securely stores execution context in the enclave’s SSA frame, initializes CPU registers, and vectors to the (user space) interrupt handler registered in the IDT.
  3. At this point, any attack-specific, spy code can easily be plugged in.
  4. The library returns to the user space AEP trampoline. We modified the untrusted runtime of the official SGX SDK to allow easy registration of a custom AEP stub. Furthermore, to enable precise evaluation of our approach on attacker-controlled benchmark debug enclaves, SGX-Step can optionally be instrumented to retrieve the stored instruction pointer from the interrupted enclave's SSA frame (using Linux's /proc/self/mem interface and the EDBGRD instruction).
  5. Thereafter, we configure the local APIC timer for the next interrupt by writing into the initial-count memory-mapped I/O register, just before executing (6) ERESUME.

Source code overview

This repository is organized as follows:

.
├── app        -- Collection of sample client applications using SGX-Step to
│                 attack different victim enclave scenarios.
├── doc        -- Papers and reference material.
├── kernel     -- Minimal dynamically loadable Linux kernel driver to export
│                 physical memory to user space and bootstrap `libsgxstep`.
├── libsgxstep -- Small user-space operating system library that implements the
│                 actual SGX-Step functionality, including x86 page-table and
│                 APIC timer manipulations.
└── sdk        -- Bindings to use SGX-Step with different SGX SDKs and libOSs.

Framework features and applications

SGX-Step is a universal execution control framework that enables the precise interleaving of victim enclave instructions with arbitrary attacker code. Some of the main use cases of the SGX-Step framework are summarized in the figure below (see also the bottom of this README for an up-to-date list of publications using SGX-Step).

SGX-Step attacks overview

Building and running

0. System requirements

SGX-Step requires an SGX-capable Intel processor, and an off-the-shelf Linux kernel. Our original evaluation was performed on i7-6500U/6700 CPUs, running Ubuntu 18.04 with a stock Linux 4.15.0 kernel. More recent Linux kernels and distributions are also supported. We summarize Linux kernel parameters below.

Linux kernel parameter Motivation
nox2apic Configure local APIC device in memory-mapped I/O mode (to make use of SGX-Step's precise single-stepping features).
iomem=relaxed no_timer_check Suppress unneeded warning messages in the kernel logs.
nmi_watchdog=0 Suppress the kernel NMI watchdog.
isolcpus=1 Affinitize the victim process to an isolated CPU core.
clearcpuid=308,295,514 Disable supervisor mode access prevention (SMAP, bits 295), supervisor mode execution prevention (SMEP, bits 308) and user-mode instruction prevention (UMIP, bits 514) features.
pti=off Disable Kernel Page-Table Isolation (to avoid kernel panics with user IRQ handlers).
rcupdate.rcu_cpu_stall_suppress=1 Disable the kernel's read-copy update (RCU) CPU stall detector (to avoid warnings when single-stepping for a long time without calling the kernel's timer interrupt handler.)
msr.allow_writes=on Suppress kernel warning messages for model-specific register (MSR) writes by SGX-Step.
vdso=0 Only on recent Linux kernels: disable vdso_sgx_enter_enclave library (not compatible with AEP interception patches).
dis_ucode_ldr Optionally disable CPU microcode updates (recent transient-execution attack mitigations may necessitate re-calibrating the single-stepping interval).

Pass the desired boot parameters to the kernel as follows:

  # if you don't have vim, use nano instead
$ sudo vim /etc/default/grub
  # Add the following line: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nox2apic iomem=relaxed no_timer_check clearcpuid=308,295,514 pti=off isolcpus=1 nmi_watchdog=0 rcupdate.rcu_cpu_stall_suppress=1 msr.allow_writes=on vdso=0"

$ sudo update-grub && reboot

To check that the currently running kernel is configured correctly, execute:

$ sudo ./check_sys.sh
.. Checking recommended SGX-Step parameters          [OK]
.. Checking unknown kernel parameters                [OK]
.. Checking CPU features                             [OK]
.. Checking kernel page-table isolation              [OK]

Finally, to improve overall execution time stability, you may opt to additionally disable C-States and SpeedStep technology in the BIOS configuration.

1. Build and load /dev/sgx-step

SGX-Step comes with a loadable kernel module that exports an IOCTL interface to the libsgxstep user-space library. The driver is mainly responsible for (i) hooking the APIC timer interrupt handler, (ii) collecting untrusted page table mappings, and optionally (iii) fetching the interrupted instruction pointer for benchmark enclaves.

To build and load the /dev/sgx-step driver, execute:

$ cd kernel/
$ ./install_SGX_driver.sh              # tested on Ubuntu 20.04/22.04
$ make clean load

Note (/dev/sgx_enclave). SGX-Step supports both the legacy Intel /dev/isgx out-of-tree driver that should work on all platforms, as well as well as the upstream /dev/sgx_enclave driver for platforms with recent Linux kernels >5.11 plus hardware support for flexible-launch control. The install_SGX_driver.sh script should automatically detect whether an in-tree /dev/sgx_enclave driver is available, and, if not, build and load the out-of-tree /dev/isgx driver via the git submodule that points to an unmodified v2.14 linux-sgx-driver.

Note (/dev/mem). We rely on Linux's virtual /dev/mem device to construct user-level virtual memory mappings for APIC physical memory-mapped I/O registers and page table entries of interest. Recent Linux distributions typically enable the CONFIG_STRICT_DEVMEM option which prevents such use, however. Our /dev/sgx-step driver therefore includes an approach to bypass devmem_is_allowed checks, without having to recompile the kernel.

2. Patch and install SGX SDK

To enable easy registration of a custom Asynchronous Exit Pointer (AEP) stub, we modified the untrusted runtime of the official Intel SGX SDK. Proceed as follows to checkout linux-sgx v2.23 and apply our patches.

$ cd sdk/intel-sdk/
$ ./install_SGX_SDK.sh                 # tested on Ubuntu 20.04/22.04
$ source /opt/intel/sgxsdk/environment # add to ~/.bashrc to preserve across terminal sessions
$ sudo service aesmd status            # stop/start aesmd service if needed

The above install scripts are tested on Ubuntu 22.04 LTS. For other GNU/Linux distributions, please follow the instructions in the linux-sgx project to build and install the Intel SGX SDK and PSW packages. You will also need to build and load an (unmodified) linux-sgx-driver SGX kernel module in order to use SGX-Step.

Note (local installation). The patched SGX SDK and PSW packages can be installed locally, without affecting a compatible system-wide 'linux-sgx' installation. For this, the example Makefiles support an SGX_SDK environment variable that points to the local SDK installation directory. When detecting a non-default SDK path (i.e., not /opt/intel/sgxsdk), the "run" Makefile targets furthermore dynamically link against the patched libsgx_urts.so untrusted runtime built in the local linux-sgx directory (using the LD_LIBRARY_PATH environment variable).

Note (32-bit support). Instructions (outdated and not maintained!) for building 32-bit versions of the SGX SDK and SGX-Step can be found in README-m32.md.

3. Build and run test applications

User-space applications can link to the libsgxstep library to make use of SGX-Step's single-stepping and page table manipulation features. Have a look at the example applications in the "app" directory.

interrupt abstract box

First, check the APIC and interrupt-descriptor table setup:

$ cd app/idt
$ make run    # fires interrupts in an infinite loop to stress-test stability; exit with CTRL-C

For example, to build and run an elementary example application to test page table manipulation features and SDK patches:

$ cd app/aep-redirect
$ make run

To test timer single-stepping functionality, try for example building and running the strlen attack from the paper for a benchmark enclave that processes the secret string 100 repeated times:

$ cd app/bench
$ NUM=100 STRLEN=1 make parse   # alternatively vary NUM and use BENCH=1 or ZIGZAG=1
$ # (above command defaults to the Dell Inspiron 13 7359 evaluation laptop machine;
$ # use DESKTOP=1 to build for a Dell Optiplex 7040 machine)
$ # use SGX_SDK=/home/jo/sgxsdk/ for a local SDK installation
$ # use M32=1 To produce a 32-bit executable

The above command builds libsgxstep, the benchmark victim enclave, and the untrusted attacker host process, where the attack scenario and instance size are configured via the corresponding environment variables. The same command also runs the resulting binary non-interactively (to ensure deterministic timer intervals), and finally calls an attack-specific post-processing Python script to parse the resulting enclave instruction pointer benchmark results.

Note (performance). Single-stepping enclaved execution incurs a substantial slowdown. We measured execution times of up to 15 minutes for the experiments described in the paper. SGX-Step's page table manipulation features allow to initiate single-stepping for selected functions only, for instance by revoking access rights on specific code or data pages of interest.

Note (timer interval). The exact timer interval value depends on CPU frequency, and hence remains inherently platform-specific (see also app/apic for detailed microbenchmarks assessing the accuracy of various APIC timer modes). Configure a suitable value in /app/bench/main.c. We established precise timer intervals for our evaluation platforms (see table below) by tweaking and observing the NOP microbenchmark enclave instruction pointer trace results, as further outlined below.

Note (stability). In order to avoid the Linux kernel getting stuck or panicking, SGX-Step should automatically restore the interrupt-descriptor table and local APIC timer after exiting the libsgxstep process. You can check if the APIC timer is still firing on all cores as follows:

$ watch -n0.1 "cat /proc/interrupts | grep 'Local timer interrupts'"

Calibrating the single-stepping interval

The table below lists currently supported Intel CPUs, together with their single-stepping APIC timer interval (libsgxstep/config.h). Note that the exact single-stepping interval may depend on the microcode version of the processor when recent transient-execution attack mitigations are in place to flush microarchitectural buffers on enclave entry/exit. Some different microcode versions are provided for reference in the table below.

Model name CPU Base frequency ucode (date) APIC timer interval
Skylake i7-6700 3.4 GHz ? 19
Skylake i7-6500U 2.5 GHz ? 25
Skylake i5-6200U 2.3 GHz ? 28
Kaby Lake R i7-8650U 1.9 GHz ? 34
Kaby Lake R i7-8650U 1.9 GHz 0xca (2019-10-03) 54
Coffee Lake R i7-9700 3 GHz 0xf4 (2022-07-31) 26
Coffee Lake R i9-9900K 3.6 GHz ? 21
Coffee Lake HR i7-9750H 2.6 GHz 0xf4 (2023-02-23) 37
Ice Lake i5-1035G1 1.00 GHz 0x32 (2019-07-05) 135
Ice Lake i5-1035G1 1.00 GHz 0xb0 (2022-03-09) 255

Note (calibration). Currently, the easiest way to configure a reliable timer interval is to use the app/bench benchmarking tool with a long NOP slide and gradually increase/decrease SGX_STEP_TIMER_INTERVAL. You can probably start around 20 and then execute NUM=100 make parse to get a summary of single-steps, zero-steps, and multi-steps for a NOP slide of 100 instructions (once you have a more or less stable interval you can switch to longer slides). Too many zero-steps indicate that you have to increase the timer interval, whereas multi-steps demand lowering the timer interval.

Note (filtering out zero-steps). Important: do not worry when there are some zero-steps left, as long as you make progress, you can always deterministically filter out zero-steps by looking at the enclave's code PTE accessed bit (which is only set when the instruction actually retires and a single-step occured). Thus, after configuring a conservative timer interval that always precludes multi-steps, SGX-Step can achieve noiseless single-stepping at a perfect, instruction-level granularity.

Note (extending the interrupt "landing window"). As clarified in the root-cause analysis below, the slower the page table walk to resolve the (code) address of the first enclave instruction following ERESUME, the longer the interrupt "landing window" and, hence, the more reliable SGX-Step's single-stepping rate will be. For instance, we found that, on top of clearing the enclave's PMD accessed bit, the landing window can be even further extended by flushing one or more of the unprotected page-table entries from the CPU cache before ERESUME, effectively forcing the CPU to wait for slow memory during the page-table walk. Thus, when you cannot find a reliable timer-interval configuration, make sure to (i) clear the enclave's code PTE/PMD "accessed" bit and (ii) flush (CLFLUSH) one or more enclave page-table entries in the AEP handler.

Note (microcode). Another word of caution relates to recent Foreshadow/ZombieLoad/RIDL/etc microcode mitigations that flush leaky uarch buffers on enclave entry/exit. Be aware that when these mitigations are enabled, the timer interval will have to be increased as enclave entry takes longer (e.g., on my i7-8650U CPU I found the single-step timer interval goes up to 54 with recent ucode, from only 34 with pre-Foreshadow ucode). The additional flushing operations may furthermore somewhat increase the variance of enclave entry time, which implies that you might have to configure the timer more conservatively with more zero-steps (which can be deterministically filtered out as explained above).

SGX-Step root-cause analysis

A detailed root-cause analysis of how exactly SGX-Step succeeds in reliably interrupting the first (possibly very short!) enclave instruction following the notoriously complex ERESUME instruction is described in the AEX-Notify paper. We found that the key to SGX-Step's success lies in its use of the "accessed" (A) bit. Specifically, SGX-Step always clears the A-bit in the victim en clave's page-middle directory (PMD) before arming the APIC to fire a one-shot interrupt. The A-bit is only ever set by the processor when at least one instruction is executed by the enclave and can, hence, be used to deterministically distinguish between zero-steps versus single-steps.

assist window root-cause analysis

Crucially, as the processor's page-miss handler is optimized for the common fast path and uses a much slower "microcode assist" to handle the less frequent and more complex case where a PMD or PTE needs to be modified, this assist has the effect of prolonging the execution of the first enclave instruction following ERSUME by several hundreds of cycles. This "assist window" thus effectively opens a spacious landing space for the coarse-grained, normally distributed APIC timer interrupt to arrive with high accuracy.

Using SGX-Step in your own projects

The easiest way to get started using the SGX-Step framwork in your own projects, is through git submodules:

$ cd my/git/project
$ git submodule add https://github.com/jovanbulck/sgx-step.git
$ cd sgx-step # Now build `/dev/sgx-step` and `libsgxstep` as described above

Have a look at the Makefiles in the app directory to see how a client application can link to libsgxstep plus any local SGX SDK/PSW packages.

The following is a list of known projects that use SGX-Step. Feel free to open a pull request if your project uses SGX-Step but is not included below.

Title Publication details Source code SGX-Step features used
TeeJam: Sub-Cache-Line Leakages Strike Back CHES24 Github (full) Single-stepping interrupt latency, PTE A/D
AEX-Notify: Thwarting Precise Single-Stepping Attacks through Interrupt Awareness for Intel SGX Enclaves USEC23 GitHub (SGX SDK mitigation) Single-Stepping, PTE A/D
BunnyHop: Exploiting the Instruction Prefetcher USEC23 GitHub (non-SGX PoC) Single-stepping, PTE A/D
Downfall: Exploiting Speculative Data Gathering USEC23 GitHub (non-SGX PoC) Single-stepping, zero-stepping
All Your PC Are Belong to Us: Exploiting Non-control-Transfer Instruction BTB Updates for Dynamic PC Extraction ISCA23 - Single-stepping
Cache-timing attack against HQC CHES23 - Single-stepping, PTE A/D
FaultMorse: An automated controlled-channel attack via longest recurring sequence ComSec23 GitHub (post processing) Page fault
On (the Lack of) Code Confidentiality in Trusted Execution Environments arXiv22 - Single-stepping
AEPIC Leak: Architecturally Leaking Uninitialized Data from the Microarchitecture USEC22 GitHub (full) Single-Stepping, PTE A/D
MoLE: Mitigation of Side-channel Attacks against SGX via Dynamic Data Location Escape ACSAC22 - Single-Stepping, page fault, transient execution
WIP: Interrupt Attack on TEE-Protected Robotic Vehicles AutoSec22 - Single-stepping, multi-stepping
Towards Self-monitoring Enclaves: Side-Channel Detection Using Performance Counters NordSec22 - Page fault, LVI.
ENCLYZER: Automated Analysis of Transient Data Leaks on Intel SGX SEED22 GitHub (full) Page-table manipulation
Side-Channeling the Kalyna Key Expansion CT-RSA22 - Single-Stepping, PTE A/D
Rapid Prototyping for Microarchitectural Attacks USENIX22 GitHub (full) Single-stepping, page fault, PTE A/D, etc.
Util::Lookup: Exploiting Key Decoding in Cryptographic Libraries CCS21 GitHub (full) Single-Stepping, PTE A/D
SmashEx: Smashing SGX Enclaves Using Exceptions CCS21 - Single-Stepping
Online Template Attacks: Revisited CHES21 Zenodo (simulation) Single-stepping, page fault, PTE A/D
Aion Attacks: Manipulating Software Timers in Trusted Execution Environment DIMVA21 - Single-stepping, interrupts(?)
Platypus: Software-based Power Side-Channel Attacks on x86 S&P21 GitHub (simulated PoC) Single-stepping, zero-stepping
CrossTalk: Speculative Data Leaks Across Cores Are Real S&P21 - Single-stepping, page fault
Frontal Attack: Leaking Control-Flow in SGX via the CPU Frontend USEC21 GitHub (full, artifact evaluated) Single-stepping interrupt latency, PTE A/D
PThammer: Cross-User-Kernel-Boundary Rowhammer through Implicit Accesses - MICRO20 Page table walk
SpeechMiner: A Framework for Investigating andMeasuring Speculative Execution Vulnerabilities NDSS20 GitHub (full) Page-table manipulation
Déjà Vu: Side-Channel Analysis of Mozilla's NSS CCS20 - Page fault
From A to Z: Projective coordinates leakage in the wild CHES20 - Page fault
LVI: Hijacking Transient Execution through Microarchitectural Load Value Injection S&P20 GitHub (PoC) Single-stepping, page-table manipulation
CopyCat: Controlled Instruction-Level Attacks on Enclaves USEC20 - Single-stepping, page fault, PTE A/D
When one vulnerable primitive turns viral: Novel single-trace attacks on ECDSA and RSA CHES20 - Single-stepping, page fault, PTE A/D
Big Numbers - Big Troubles: Systematically Analyzing Nonce Leakage in (EC)DSA Implementations USEC20 - Page fault
Plundervolt: Software-based Fault Injection Attacks against Intel SGX S&P20 GitHub (full) Privileged interrupt/call gates, MSR
Bluethunder: A 2-level Directional Predictor Based Side-Channel Attack against SGX CHES20 - Single-stepping
Fallout: Leaking Data on Meltdown-resistant CPUs CCS19 - PTE A/D
A Tale of Two Worlds: Assessing the Vulnerability of Enclave Shielding Runtimes CCS19 GitHub (full) Single-stepping, page fault, PTE A/D
ZombieLoad: Cross-Privilege-Boundary Data Sampling CCS19 GitHub (PoC) Single-stepping, zero-stepping, page-table manipulation
SPOILER: Speculative Load Hazards Boost Rowhammer and Cache Attacks USEC19 - Single-stepping interrupt latency
Nemesis: Studying Microarchitectural Timing Leaks in Rudimentary CPU Interrupt Logic CCS18 GitHub (full) Single-stepping interrupt latency, page fault, PTE A/D
Foreshadow: Extracting the Keys to the Intel SGX Kingdom with Transient Out-of-Order Execution USEC18 GitHub (PoC) Single-stepping, zero-stepping, page-table manipulation
Single Trace Attack Against RSA Key Generation in Intel SGX SSL AsiaCCS18 - Page fault
Off-Limits: Abusing Legacy x86 Memory Segmentation to Spy on Enclaved Execution ESSoS18 link (full, artifact evaluated) Single-stepping, IA32 segmentation, page fault
SGX-Step: A Practical Attack Framework for Precise Enclave Execution Control SysTEX17 GitHub (full) Single-stepping, page fault, PTE A/D

sgx-step's People

Contributors

0xhilbert avatar danacus avatar dn0sar avatar flowyroll avatar its-luca avatar jagogyselinck avatar jovanbulck avatar martonbognar avatar mlq avatar onetwo avatar oytunkuday avatar randoruf avatar w-woloszyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sgx-step's Issues

Uncacheable memory type when remapping APIC MMIO

dmesg warnings

[   45.321866] [sgx-step] listening on /dev/sgx-step
[   56.452386] x86/PAT: app:2512 map pfn RAM range req uncached-minus for [mem 0x481488000-0x481488fff], got write-back
[   56.452489] x86/PAT: app:2512 map pfn RAM range req uncached-minus for [mem 0x2810e6000-0x2810e6fff], got write-back
[   78.424127] x86/PAT: app:2672 map pfn RAM range req uncached-minus for [mem 0x481488000-0x481488fff], got write-back
[   78.424228] x86/PAT: app:2672 map pfn RAM range req uncached-minus for [mem 0x2810e6000-0x2810e6fff], got write-back

Trying to run app/memcmp but gives assertion error

I am trying to run app/memcmp and it tells me that the assertion that pwd_len < MAX_LEN is false. I have gotten foreshadow, aep-redirect, and bench to work. I can't figure out whats the issue here. I tested it unmodified and with Debug set to 1.
Screenshot from 2023-06-29 11-51-02

Automated timer interval configuration

A fully automated single-stepping timer configuration benchmark program would repeatedly interrupt an enclaved nop instruction slide, each time adjusting the current timer interval guess -- in a binary search fashion based on the previous in-enclave instruction pointer (zero-step vs. multi-step).

Refactor build system

Keeping here for future reference (low priority): Current Makefiles contain a lot of unnecessary duplicated variables and config.

Better include a top-level Makefile.include file or so.

or even consider using cmake

Refactor: abstract SDK interface for `libsgxstep`

Ideally libsgxstep should be less tightly coupled to the Intel SGX-SDK and rely on a clean and stable interface that can be easily ported to other SDKs or libOSs, eg at least the following:

  • set AEP by hooking EENTER to allow for custom AEP stub for single-stepping
  • get TCS for current enclave to allow to retrieve metadata (eg base address) via the driver. This should be similarly possible by intercepting EENTER
  • refactor build system to more easily link libsgxstep to other SDKs

At least the user-space SDK components should be easily pluggable. Integration with the kernel space isgx driver may be more tight, but that should be less of an issue as most SDKs rely on the isgx driver anyway..

Foreshadow app doesn't read correctly

hello, thank you for the answer on my previous issue.
i'm now facing a different one when running the Foreshadow app, the results that the attack reads are mostly 0, and on some runs it provides random values that are mostly incorrect.

Foreshadow-fails

is there anything i missed?
thanks,
Bar.

victim.base && "no enclave found in /proc/self/maps

hello
when i run app/aep-redirect, the error happen

idt.c] locking IRQ handler pages 0x558324224000/0x55832422a000 [main.c] Creating enclave... [main.c] Dry run to allocate pages [main.c] revoking data page access rights.. [main.c] data at 0x7f200d811190 with PTE: [pt.c] /dev/sgx-step opened! [pt.c] /dev/mem opened! +-------------------------------------------------------------------------------------------+ | XD | PK | IGN | RSVD | PHYS ADRS | IGN | G | PAT | D | A | PCD | PWT | U/S | R/W | P | | 1 | x | x | 0 | 0x00008097f000 | x | x | x | 0 | 1 | x | x | 1 | 1 | 1 | +-------------------------------------------------------------------------------------------+ +-------------------------------------------------------------------------------------------+ | XD | PK | IGN | RSVD | PHYS ADRS | IGN | G | PAT | D | A | PCD | PWT | U/S | R/W | P | | 0 | x | x | 1 | 0x007f7f680000 | x | x | x | 0 | 1 | x | x | 0 | 0 | 0 | +-------------------------------------------------------------------------------------------+ [main.c] revoking code page access rights.. [main.c] code at 0x7f200d803000 with PTE: +-------------------------------------------------------------------------------------------+ | XD | PK | IGN | RSVD | PHYS ADRS | IGN | G | PAT | D | A | PCD | PWT | U/S | R/W | P | | 0 | x | x | 0 | 0x000080971000 | x | x | x | 0 | 1 | x | x | 1 | 0 | 1 | +-------------------------------------------------------------------------------------------+ +-------------------------------------------------------------------------------------------+ | XD | PK | IGN | RSVD | PHYS ADRS | IGN | G | PAT | D | A | PCD | PWT | U/S | R/W | P | | 0 | x | x | 1 | 0x007f7f68e000 | x | x | x | 0 | 1 | x | x | 0 | 0 | 0 | +-------------------------------------------------------------------------------------------+ ==== Victim Enclave ==== [enclave.c] assertion 'victim.base && "no enclave found in /proc/self/maps"' failed: No such file or directory Aborted

How could I solve it? Thanks.

Refactor: page-fault abstraction in libsgxstep

Currently, page-fault attack code is rather unclean and has a lot of code duplication to setup fault handlers and revoke enclave page permissions through either mprotect calls and/or PTE remapping + editing..

Goal: Offer a simple and intuitive abstraction in libsgxstep/pf.c to mount page-fault controlled-channel attacks on enclaves so applications need only to focus on the actual attack logic (state machines) to interpret page-fault sequences.

Refactor: Offer single-step library abstraction

SGX_STEP_PLATFORM and SGX_STEP_TIMER_INTERVAL and actual timer configuration AEP code should better be encapsulated in libsgxstep plus a common Makefile.config, such that the actual application AEP callback code can focus exclusively on gathering side-channel information.

libsgxstep: default to position-independent code

Hello

I was trying to reproduce the project, however, I failed to build the project

I am using Ubuntu 18.04 and gcc7.3.0

This is the error message I got

foreshadow $ make
[===] Enclave [===]
[GEN] sgx_edger8r encl.edl
[CC]  encl_t.c (trusted edge)
[CC]  encl.c (core)
[LD]   encl.o encl_t.o -lsgx_trts encl.unsigned.so
[SGN] encl.unsigned.so
[CC]  encl_u.c (untrusted edge)
[AR]   libencl_proxy.a
[===] ../../libsgxstep [===]
[CC]  apic.c
[CC]  cpu.c
[CC]  debug.c
[CC]  enclave.c
[CC]  file.c
[CC]  foreshadow.c
[CC]  gdt.c
[CC]  idt.c
[CC]  pt.c
[CC]  sched.c
[CC]  spy.c
[AS]  aep_trampoline.S
[AS]  irq_entry.S
[AS]  rtm.S
[AS]  transient.S
[AR]  libsgx-step.a
[CC]  main.c
[LD] main.o -o app
/usr/bin/ld: ../../libsgxstep/libsgx-step.a(aep_trampoline.o): relocation R_X86_64_32S against symbol `sgx_step_tcs' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Makefile:56: recipe for target 'app' failed
make: *** [app] Error 1

Have you experienced similar issues before?

Thanks!

Error while running sgx-step/app/foreshadow attack.

I did all the necessary steps present at [https://github.com//issues/24] for running the foreshadow app.

  1. When i set 'LD_LIBRARY_PATH=/opt/intel/sgxsdk/lib64/ ldd ./app' to this i am getting this error when executing ./app

Screenshot 2021-01-17 at 22 12 40

  1. When i set 'LD_LIBRARY_PATH=/usr/lib/ ldd ./app' to this i am getting this error when executing ./app :

Screenshot 2021-01-17 at 22 13 12

In both the cases i am not able to run ./app. What should i do to resolve this issue ?
Also i ran Sample codes present in this : sdk/intel-sdk/linux-sgx/SampleCode/ and i am able to run it.

error when running bench: [file.c] assertion '(f = fopen(path, "w"))' failed: No such file or directory

Hi Researchers,

I am doing experiments using sgx-step. It is really strong. I follow the steps on the top README.md. But I encountered a strange problem related to file.c.

Environment

Cloud Vendor: Alibaba Cloud ECS Security-enhanced family (SGX-capable)
OS: Ubuntu 18.04 LTS
model name: Intel(R) Xeon(R) Platinum 8369B CPU @ 2.70GHz
bugs: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit

I just follow the steps in README to set up.

aep-redirect
I use the same command provided in README and everything is normal.

bench
I use the same command provided in README but I am getting this error:

# NUM=100 STRLEN=1 make parse
[===] Enclave [===]
[RM] encl.o asm.o asm_nop.o encl.unsigned.so encl.so libencl_proxy.a
[RM] encl_t.o encl_u.o encl_t.h encl_t.c encl_u.h encl_u.c
[===] ../../libsgxstep [===]
[RM] apic.o cpu.o debug.o enclave.o file.o foreshadow.o gdt.o idt.o pt.o sched.o spy.o aep_trampoline.o irq_entry.o rtm.o transient.o libsgx-step.a
[RM] main.o app
[===] Enclave [===]
[GEN] sgx_edger8r encl.edl
[CC]  encl_t.c (trusted edge)
[CC]  encl.c (core)
[AS]  asm.S (core)
[AS]  asm_nop.S (core)
[LD]   encl.o asm.o asm_nop.o encl_t.o -lsgx_trts encl.unsigned.so
[SGN] encl.unsigned.so
[CC]  encl_u.c (untrusted edge)
[AR]   libencl_proxy.a
[===] ../../libsgxstep [===]
[CC]  apic.c
[CC]  cpu.c
[CC]  debug.c
[CC]  enclave.c
[CC]  file.c
[CC]  foreshadow.c
[CC]  gdt.c
[CC]  idt.c
[CC]  pt.c
[CC]  sched.c
[CC]  spy.c
[AS]  aep_trampoline.S
[AS]  irq_entry.S
[AS]  rtm.S
[AS]  transient.S
[AR]  libsgx-step.a
[CC]  main.c
[LD] main.o -o app
[file.c] assertion '(f = fopen(path, "w"))' failed: No such file or directory
Aborted
Makefile:64: recipe for target 'run' failed
make: *** [run] Error 134

The same error reports when I try to run foreshadow and lvi as well. However, I never encounter it when running aep-redirect. What could be the problem and the solution?

Thank you very much.

Best regards

./install_SGX_SDK.sh can't find python2

Trying to run ./install_SGX_SDK.sh but it says "E: Unable to locate package python2". I checked and I do have python 2.7 installed in "/usr/bin/python2". I removed "python2" from the installing prequisites part of ./install_SGX_SDK.sh and it ran, even saying that the SDK was successfully installed, but testing it out with the commands "cd app/idt" and then "make run", it gives the error " assertion '(fd_step = open("/dev/sgx-step", O_RDWR)) >= 0' failed: No such file or directory"

AEP redirection and single-stepping in SGX-LKL

I got the same error message " general protection fault: 0031 [#1] SMP PTI......." , as shown in #GP issue #6, when testing app/idt.
The original app/idt is fine. The error message shows when using periodical APIC timer mode, or when I move the "apic_timer_irq" within the for-loop from "main" to the "hello_world" handler.
The respective solution (247d921) for app/bench seems not applicable for app/idt.
Do you have any idea how to solve this issue for app/idt?

You might be curious why I did that.
I attempt to attack SGX-LKL with sgx-step. But SGX-LKL is not based on SGX SDK, and for some reason SGX-LKL doesn't support AEP stub registration freely.
So I cannot trigger interrupts in AEX handler as done in app/bench.
Instead, my idea is to set periodic interrupts, or trigger interrupts in userspace handler, e.g. "hello_world" in app/idt.
Do you have better ideas?

Sometimes get screen freeze when doing single step [SOLVED: #GP for ring-3 IRQ handler from kernel]

Hi, I'm learning single-step technology, but I found that I sometimes(with high probability) get screen freeze once I run the attack( project bench), and thus I have to manually restart the machine. So far, I've tried on three different laptops which are all Ubuntu with 5.3.0-28-generic Kernel and they all have this problem.

Besides, once I load the sgx-step kernel, System always warn me that System program problem detected.

And in the case that I could successfully execute the program, I could achieve single-step perfectly.

Do you have any clue on this problem? Is it an universal issue or it might because of my kernel version or something else?

Thanks for your help !

Below is my cpu information:( Here I disabled 2 physical cores and disbaled the hyper-threading)

Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 142
Model name: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
Stepping: 11
CPU MHz: 1391.847
CPU max MHz: 3900.0000
CPU min MHz: 400.0000
BogoMIPS: 3600.00
Virtualisation: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 6144K
NUMA node0 CPU(s): 0,1

foreshadow/lvi building error , memcmp running error

  1. Building error

For app/foreshadow/, run $make,
[===] Enclave [===]
[GEN] sgx_edger8r encl.edl
[CC] encl_t.c (trusted edge)
[CC] encl.c (core)
[LD] encl.o encl_t.o -lsgx_trts encl.unsigned.so
[SGN] encl.unsigned.so
make[1]: *** [Makefile:53: encl.so] Error 255
make: *** [Makefile:73: build-Enclave] Error 2

For app/lvi/, run $make,
[===] Enclave [===]
[GEN] sgx_edger8r encl.edl
[CC] encl_t.c (trusted edge)
[CC] encl.c (core)
[AS] asm.S (core)
[LD] encl.o asm.o encl_t.o -lsgx_trts encl.unsigned.so
[SGN] encl.unsigned.so
make[1]: *** [Makefile:53: encl.so] Error 255
make: *** [Makefile:66: build-Enclave] Error 2

  1. Running error

For memcmp:
[main.c] assertion 'pwd_len < MAX_LEN' failed: Invalid argument
Aborted

#GP issue

[  126.282402] general protection fault: 0031 [#1] SMP PTI
[  126.282433] Modules linked in: sgx_step(OE) msr ccm pci_stub vboxpci(OE) vboxnetadp(OE) vboxnetflt(OE) vboxdrv(OE) bnep snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic joydev hid_multitouch dell_rbtn dell_laptop dell_smm_hwmon intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp kvm_intel kvm irqbypass crct10dif_pclmul arc4 nls_iso8859_1 crc32_pclmul ghash_clmulni_intel pcbc aesni_intel aes_x86_64 crypto_simd glue_helper cryptd intel_cstate intel_rapl_perf iwlmvm mac80211 iwlwifi cfg80211 snd_soc_skl snd_soc_skl_ipc snd_soc_sst_ipc snd_soc_sst_dsp snd_hda_ext_core snd_soc_sst_match rtsx_pci_ms snd_soc_core memstick snd_compress ac97_bus snd_pcm_dmaengine snd_hda_intel snd_hda_codec snd_hda_core snd_hwdep input_leds serio_raw snd_pcm dell_wmi dell_smbios dcdbas snd_seq_midi snd_seq_midi_event
[  126.282755]  wmi_bmof snd_rawmidi snd_seq snd_seq_device snd_timer snd soundcore uvcvideo videobuf2_vmalloc videobuf2_memops videobuf2_v4l2 videobuf2_core videodev media btusb btrtl idma64 virt_dma shpchp mei_me mei intel_pch_thermal intel_lpss_pci ucsi_acpi processor_thermal_device intel_soc_dts_iosf typec_ucsi typec hci_uart btbcm serdev btqca btintel bluetooth ecdh_generic intel_lpss_acpi intel_lpss int3403_thermal intel_hid int3400_thermal acpi_thermal_rel int340x_thermal_zone sparse_keymap acpi_pad tpm_crb mac_hid acpi_als kfifo_buf industrialio isgx(OE) parport_pc ppdev lp parport autofs4 i915 rtsx_pci_sdmmc e1000e i2c_algo_bit drm_kms_helper ptp pps_core syscopyarea sysfillrect sysimgblt fb_sys_fops rtsx_pci ahci drm libahci wmi i2c_hid hid video pinctrl_sunrisepoint pinctrl_intel
[  126.283050] CPU: 1 PID: 3287 Comm: app Tainted: G           OE   4.13.0-45-generic #50~16.04.1-Ubuntu
[  126.283086] Hardware name: Dell Inc. Latitude 7490/0KP0FT, BIOS 1.1.6 11/10/2017
[  126.283115] task: ffff9615a8f0c740 task.stack: ffffb2d143f5c000
[  126.283144] RIP: 0010:do_general_protection+0x71/0x150
[  126.283165] RSP: 0000:ffffb2d143f5ff30 EFLAGS: 00010202
[  126.283188] RAX: ffffb2d143f5ff58 RBX: 0000000000000000 RCX: 0000000000000000
[  126.283216] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffb2d143f5ff58
[  126.283244] RBP: ffffb2d143f5ff48 R08: 0000000000000000 R09: 0000000000000000
[  126.283273] R10: 0000000000000000 R11: 0000000000000000 R12: ffffb2d143f5ff58
[  126.283301] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
[  126.283329] FS:  00007fd927249740(0000) GS:ffff9615c1480000(0000) knlGS:0000000000000000
[  126.283361] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  126.283385] CR2: 00007fd924803000 CR3: 000000046585e005 CR4: 00000000003606e0
[  126.283413] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[  126.283441] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[  126.283469] Call Trace:
[  126.283485]  ? general_protection+0x36/0x60
[  126.283504]  general_protection+0x4c/0x60
[  126.283522] RIP: 0033:0x403bbc
[  126.283536] RSP: 002b:00007ffd913bb120 EFLAGS: 00000202
[  126.283558] RAX: 0000000000000003 RBX: 00007fd924c7f000 RCX: 0000000000403bbc
[  126.283586] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
[  126.283614] RBP: 00007ffd913bb5f0 R08: 0000000000000000 R09: 0000000000000000
[  126.283642] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
[  126.283670] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
[  126.283699] Code: 00 00 00 85 c0 0f 85 83 00 00 00 48 89 da be 01 00 00 00 bf 0b 00 00 00 e8 8d b3 06 00 5b 41 5c 41 5d 5d c3 fb 66 0f 1f 44 00 00 <eb> aa be 0d 00 00 00 4c 89 e7 e8 80 52 04 00 85 c0 75 df 4c 89 
[  126.283805] RIP: do_general_protection+0x71/0x150 RSP: ffffb2d143f5ff30
[  126.293255] ---[ end trace 88011931c80a132c ]---
0000000000403bbc <sgx_step_aep_trampoline>:
  403bbc:       48 89 1c 25 c8 71 60    mov    %rbx,0x6071c8
  403bc3:       00 
  403bc4:       48 8d 04 25 c0 71 60    lea    0x6071c0,%rax
  403bcb:       00 
  403bcc:       48 85 c0                test   %rax,%rax
  403bcf:       74 02                   je     403bd3 <sgx_step_aep_trampoline+0x17>
  403bd1:       ff 10                   callq  *(%rax)
  403bd3:       48 8b 1c 25 c8 71 60    mov    0x6071c8,%rbx
  403bda:       00 
  403bdb:       48 8d 0c 25 bc 3b 40    lea    0x403bbc,%rcx
  403be2:       00 
  403be3:       0f 0d 04 25 d0 71 60    prefetch 0x6071d0
  403bea:       00 
  403beb:       0f ae f0                mfence 
  403bee:       0f 31                   rdtsc  
  403bf0:       89 04 25 d0 71 60 00    mov    %eax,0x6071d0
  403bf7:       48 c7 c0 03 00 00 00    mov    $0x3,%rax
  403bfe:       0f 01 d7                enclu  
jo@sgx-dsn:~/sgx-step/app/bench$ LAPTOP=1 NUM=10 STRLEN=1 make parse


[pt.c] /dev/sgx-step opened!
[pt.c] /dev/mem opened!

--------------------------------------------------------------------------------
[main.c] Creating enclave...
--------------------------------------------------------------------------------

[sched.c] continuing on CPU 1
==== System Settings ====
    Pstate max perf pct: 100
    Pstate min perf pct: 100
    Turbo Boost:         0
    cpu pinning:         1
    Designated cpu:      1
    Running on cpu:      1
==== Victim Enclave ====
    Base: 0x7fd924800000
    Size: 8388608
    Limit:  0x7fd925000000
    TCS:  0x7fd924c7f000
    AEP:  0x403bbc
    EDBGRD: debug
[main.c] enclave string adrs at 0x7fd924a1d000

[main.c] enclave trigger code adrs at 0x7fd924803000


--------------------------------------------------------------------------------
[main.c] Establishing user space IDT mapping
--------------------------------------------------------------------------------

[idt.c] DTR.base=0xfffffe0000000000/size=4095 (256 entries)
[idt.c] established user space IDT mapping at 0x7fd927266000
[idt.c] installed IRQ handler with target_rip=0x4013fb
[idt.c] IDT[ 45] @0x7fd9272662d0 = 0x403c01 (seg sel 0x33); p=1; dpl=3; type=15; ist=0
[file.c] reading buffer from '/dev/cpu/1/msr' (size=8)
[apic.c] established local memory mapping for APIC_BASE=0xfee00000 at 0x7fd927265000
[apic.c] apic_id is 2000000
[apic.c] APIC timer one-shot mode with division 2 (lvtt=2d/tdcr=0)
[main.c] calling enclave: attack=2; num_runs=10; timer=40
[main.c] Caught fault 11! Restoring enclave page permissions..
[main.c] ^^ enclave RIP=0x3000; ACCESSED=0
[main.c] ^^ enclave RIP=0x3000; ACCESSED=0
[main.c] ^^ enclave RIP=0x3003; ACCESSED=1

add continuous integration

eg Travis-CI to at least make sure everything compiles on an up-to-date system. This means we should also patch, build, and install the SGX-SDK.

We can also consider running at least some tests from the app directory in the CI environment.

Could sgx-step support SGX in-kernel/dcap driver?

Hi,

Currently sgx-step can only run with SGX oot-driver, does it have the capability to run on SGX in-kernel or dcap driver since those are the major drivers of SGX?
I tried sgx-step with SGX in-kernel/dcap driver, it failed to run...

periodic mode

Hi,
How could sgx-step support APIC periodic mode?

Shujie

undefined symbol: sgx_get_aep

Hi there,
I installed SGX-step by following the steps, and tried to test the samples in /app, but I always get the following errors. How could I solve it? Thanks.
./app: symbol lookup error: ./app: undefined symbol: sgx_get_aep

AEP trampoline sgx-gdb compatibility

Custom AEP trampoline seems to cause sgx-gdb to crash with a segmentation fault. Full output for the aep-redirect sample program:

GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Source directories searched: /opt/intel/sgxsdk/lib64/gdb-sgx-plugin:$cdir:$cwd
Setting environment variable "LD_PRELOAD" to null value.
Reading symbols from ./app...done.
(gdb) r
Starting program: /home/jo/write_buffer_writeup/code/sgx-step/app/aep-redirect/app 
detect urts is loaded, initializing
Function "random_stack_notify_gdb" not defined.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[main.c] Creating enclave...
add-symbol-file '/home/jo/write_buffer_writeup/code/sgx-step/app/aep-redirect/Enclave/encl.so' 0x7ffff5c00bd0 -readnow -s .interp 0x7ffff5c00238  -s .note.gnu.build-id 0x7ffff5c00254  -s .gnu.hash 0x7ffff5c00278  -s .dynsym 0x7ffff5c003d8  -s .dynstr 0x7ffff5c007c8  -s .rela.dyn 0x7ffff5c00a88  -s .plt 0x7ffff5c00bb0  -s .plt.got 0x7ffff5c00bc0  -s .nipx 0x7ffff5c12ca0  -s .rodata 0x7ffff5c134d0  -s .niprod 0x7ffff5c13c80  -s .eh_frame_hdr 0x7ffff5c144c0  -s .eh_frame 0x7ffff5c148a8  -s .fini_array 0x7ffff5e16e20  -s .data.rel.ro 0x7ffff5e16e40  -s .dynamic 0x7ffff5e16ea0  -s .got 0x7ffff5e16fe0  -s .got.plt 0x7ffff5e17000  -s .data 0x7ffff5e17020  -s .nipd 0x7ffff5e17904  -s .bss 0x7ffff5e18000 
==== Victim Enclave ====
[pt.c] /dev/sgx-step opened!
    Base:   0x7ffff5c00000
    Size:   4194304
    Limit:  0x7ffff6000000
    TCS:    0x7ffff5f7a000
    SSA:    0x7ffff5f7bf48
    AEP:    0x402c82
    EDBGRD: debug
[main.c] revoking a access rights..

Program received signal SIGSEGV, Segmentation fault.
0x00007fffffffd9c5 in ?? ()
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff79a6269 in raise (sig=11) at ../sysdeps/unix/sysv/linux/pt-raise.c:35
35	../sysdeps/unix/sysv/linux/pt-raise.c: No such file or directory.
(gdb) c
Continuing.

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
(gdb) quit

After some digging it seems this is caused by the is_eresume() function of upstream SDK, which assumes the AEP is always a single ENCLU instruction. As such, sgx-gdb compatibility will probably require another SDK patch...

https://github.com/intel/linux-sgx/blob/master/sdk/debugger_interface/linux/se_ptrace.c#L368

static int is_eresume(pid_t pid, struct user_regs_struct *regs)
{
    unsigned int instr;

    if(!se_read_process_mem(pid, (void *)regs->REG(ip), (char *)&instr, sizeof(instr), NULL))
        return FALSE;
    if((ENCLU == (instr & 0xffffff))
            && (SE_ERESUME == regs->REG(ax)))
        return TRUE;
    return FALSE;
}
```

bench compile warning with latest sgx-step version on Ubuntu 20.04

Hi,

I just tried to run bench project with your latest version of sgx-step on my new laptop. And when I compile the bench project, I got following warning:
aep_trampoline.S: Assembler messages:
aep_trampoline.S:60 Warning: no instruction mnemonic suffix given and no register operands; using default for 'add'

And I also got same warning from irq_entry.S:36 .
Then my laptop was frozen and I had to restart my laptop.(This happens whenever I run the bench project)

So far, I have tried with it on two machines which had skylake and whisky model. Both systems are ubuntu 20.04.

Would it be the problem related to ubuntu 20 ? Could you gave me some suggestions on how to fix it ?

Thanks in advance.

Regards

Compilation errors in sgx_encl.c and sgx_util.c

When I try to install SGX_driver, I get the following compilation errors.
This part should be changed to automatically choose whether to use vm_insert_pfn or vmf_insert_pfn, depending on your version of Linux Kernel.


error: implicit declaration of function ‘vm_insert_pfn’; did you mean ‘vmf_insert_pfn’? [-Werror=implicit-function-declaration]
rc = vm_insert_pfn(vma, entry->addr, PFN_DOWN(entry->epc_page->pa));
^~~~~~~~~~~~~
vmf_insert_pfn

error: implicit declaration of function ‘vm_insert_pfn’; did you mean ‘vmf_insert_pfn’? [-Werror=implicit-function-declaration]
ret = vm_insert_pfn(vma, encl_page->addr, PFN_DOWN(epc_page->pa));
^~~~~~~~~~~~~
vmf_insert_pfn

Starting with Kernel 4.20, vm_insert_pfn transitions to vmf_insert_pfn breaking backward compatibility.

http://web.ist.utl.pt/joao.leao.guerreiro/2019/04/setting-up-a-sgx-development-environment/

Thanks

SGXv2 support [SOLVED: UMIP]

Greetings,

Big fan of your work!

Just want to report that when I run app/bench with some SGXv2 machines, interesting things occurred. It said the following lines,

[main.c] Caught fault 11! Restoring enclave page permissions..
[main.c] assertion 'fault_cnt++ < 10'

However, this won't happen on machines that only support SGXv1.
Any thoughts?

FYI, all the experiments were conducted on a Ubuntu 18.04 with a Linux 4.15.0 kernel, with and without Turbo Boost enabled.

Thanks.

Questions regarding the use of unmap_alias and sim_reload

I have been trying to learn and understand SGX step and Foreshadow and while I was experimenting with it, I commented out unmap_alias and sim_reload from the program and found it didn't really change much. The exploit still worked. Could I get more context as to why those functions are in the program?
Screenshot from 2023-07-19 14-53-04

Question about why we need to redirect the output to files

Hi,

I have been using sgx-step for half a year, and this tool could really help us understand how sgx and related attacks work. And I'm very curious about why we have to redirect our output to an extra file ?

For example, when I was running bench, I got good result when redirecting the output to out.txt but sometimes got a bad result(miss some string accesses) if I print the result directly to the terminal.

I know that printing things to the terminal will reduce the accuracy of attack result, but why ? Is this because printing things to terminal cost more cycles then writing things to a file and the longer cycles influence the accuracy of single-step ?

BTW, I remembered that you mentioned this phenomenon somewhere, but now I can't find it. If you still remember where you mentioned it, it will be very helpful.

Thanks for your help.

regards
Neo

/dev/sgx-step would be uninstalled after os reboot

HW: NUC7JYJ
SW: Ubuntu Desktop 20.04

Reproducible steps:

  1. install sgx-step following the wiki Building and Running - 0, 1, check by $ls /dev/sgx-step, OK
  2. reboot os
  3. check by $ls /dev/sgx-step again, NO

Is this normal?

Restore APIC timer on ASSERT failure

To prevent system crashes, we should consider gracefully restoring the APIC timer to its default configuration when it was modified and the ASSERT macro subsequently terminates the application.

undefined symbol : sgx_get_aep

Screenshot from 2022-04-18 11-39-19
Screenshot from 2022-04-12 23-58-17
Screenshot from 2022-04-12 23-58-46
while performing make run in app/aep_redirect it shows sgx_get_aep undefined.
Tried the solution in issue #24 but error still exits.

Query regarding APIC timer interval configuration

Hi,

I'm having some trouble configuring the APIC timer interval and was hoping you could help.

lscpu output:

Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              12
On-line CPU(s) list: 0-11
Thread(s) per core:  2
Core(s) per socket:  6
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               158
Model name:          Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Stepping:            10
CPU MHz:             2508.222
CPU max MHz:         4500.0000
CPU min MHz:         800.0000
BogoMIPS:            5199.98
Virtualization:      VT-x
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            12288K
NUMA node0 CPU(s):   0-11
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 bmi2 erms invpcid rdseed adx clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d

I'm running app/bench as follows:

cd app/bench
NUM=100 make parse

The contents of out.txt are:


--------------------------------------------------------------------------------
[main.c] Creating enclave...
--------------------------------------------------------------------------------

[sched.c] continuing on CPU 1
==== System Settings ====
    Pstate max perf pct: 100
    Pstate min perf pct: 57
    Turbo Boost:         0
    cpu pinning:         1
    Designated cpu:      1
    Running on cpu:      1
[pt.c] /dev/sgx-step opened!
==== Victim Enclave ====
    Base:   0x7fa4a3000000
    Size:   8388608
    Limit:  0x7fa4a3800000
    TCS:    0x7fa4a3471000
    SSA:    0x7fa4a3472f48
    AEP:    0x55b0d19c73d1
    EDBGRD: debug
[main.c] enclave trigger code adrs at 0x7fa4a3005000

[pt.c] /dev/mem opened!

--------------------------------------------------------------------------------
[main.c] Establishing user space APIC/IDT mappings
--------------------------------------------------------------------------------

[idt.c] DTR.base=0xfffffe0000000000/size=4095 (256 entries)
[idt.c] established user space IDT mapping at 0x7fa4a5226000
[idt.c] installed ring3 IRQ handler with target_rip=0x55b0d19c4450
[idt.c] IDT[ 45] @0x7fa4a52262d0 = 0x55b0d19c741a (seg sel 0x33); p=1; dpl=3; type=15; ist=0
[file.c] reading buffer from '/dev/cpu/1/msr' (size=8)
[apic.c] established local memory mapping for APIC_BASE=0xfee00000 at 0x7fa4a5225000
[apic.c] APIC_ID=2000000; LVTT=400ec; TDCR=0
[apic.c] APIC timer one-shot mode with division 2 (lvtt=2d/tdcr=0)

--------------------------------------------------------------------------------
[main.c] Triggering user space software interrupts
--------------------------------------------------------------------------------

[main.c] calling enclave: attack=1; num_runs=100; timer=20
[main.c] Caught fault 11! Restoring enclave page permissions..
[main.c] ^^ enclave RIP=0x5500; ACCESSED=1
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
...
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[main.c] ^^ enclave RIP=0x5500; ACCESSED=0
[apic.c] Restored APIC_LVTT=400ec/TDCR=0)
[file.c] writing buffer to '/dev/cpu/1/msr' (size=8)

--------------------------------------------------------------------------------
[main.c] all done; counted 651 IRQs
--------------------------------------------------------------------------------

while the output of parse_nop.py is

parse_nop.py: found instruction slide at 0x5000 (length=100)
parse_nop.py counted tot= 0  one= 0  zero= 0  plus= 0

If my understanding is correct, at least one value in the line should be non-zero (assuming an interrupt landed while the enclave was running). I also find it strange that RIP value stays constant. Inspecting the python script, I found out that this value was always greater than INST_SLIDE_END. Also, tampering with the timer interval value didn't help much.

Any ideas?

kernel panics when single-stepping [SOLVED: KPTI #PF for kernel IRQ]

Hi, I am trying to run the single-step bench and sometimes encounter kernel bug especially when step over 1000s times. Here is an example from the kernel log:

[ 132.182650] BUG: unable to handle kernel paging request at 000055bb86c8b000
[ 132.182657] IP: 0x55bb86c8b000
[ 132.182658] PGD 80000007b65d0067 P4D 80000007b65d0067 PUD 7ad9f5067 PMD 7f8e31067 PTE 7bed47025
[ 132.182661] Oops: 0011 [#1] SMP PTI
[ 132.182663] Modules linked in: sgx_step(OE) msr thunderbolt rfcomm cmac snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic bnep intel_wmi_thunderbolt wmi_bmof arc4 intel_rapl iwlmvm x86_pkg_temp_thermal intel_powerclamp coretemp crct10dif_pclmul crc32_pclmul ghash_clmulni_intel mac80211 pcbc aesni_intel rtsx_pci_ms aes_x86_64 crypto_simd iwlwifi glue_helper memstick cryptd intel_cstate intel_rapl_perf btusb btrtl cfg80211 btbcm btintel joydev input_leds bluetooth ecdh_generic snd_hda_intel ir_rc6_decoder snd_hda_codec snd_hda_core snd_hwdep rc_rc6_mce snd_pcm ir_lirc_codec snd_seq_midi lirc_dev snd_seq_midi_event i915 snd_rawmidi ite_cir rc_core drm_kms_helper snd_seq video drm snd_seq_device snd_timer i2c_algo_bit fb_sys_fops syscopyarea acpi_pad sysfillrect mei_me snd sysimgblt wmi
[ 132.182690] mei mac_hid soundcore intel_pch_thermal sch_fq_codel binfmt_misc kvm_intel kvm isgx(OE) parport_pc ppdev lp parport ip_tables x_tables autofs4 hid_generic usbhid hid rtsx_pci_sdmmc ahci e1000e rtsx_pci libahci
[ 132.182699] CPU: 1 PID: 3739 Comm: app Tainted: G OE 4.15.18+ #3
[ 132.182700] Hardware name: Intel Corporation NUC7i7BNH/NUC7i7BNB, BIOS BNKBL357.86A.0062.2018.0222.1644 02/22/2018
[ 132.182701] RIP: 0010:0x55bb86c8b000
[ 132.182702] RSP: 0000:ffffaac644e87ee8 EFLAGS: 00010002
[ 132.182703] RAX: 0000000000000008 RBX: 0000000000000008 RCX: 0000000000000000
[ 132.182704] RDX: ffff932c01c80000 RSI: 0000000000000008 RDI: ffffaac644e87f58
[ 132.182704] RBP: ffffaac644e87f28 R08: 0000000000000000 R09: 0000000000000000
[ 132.182705] R10: 0000000000000000 R11: 0000000000000000 R12: ffffaac644e87f58
[ 132.182706] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
[ 132.182707] FS: 00007f34f50e4b80(0000) GS:ffff932c01c80000(0000) knlGS:0000000000000000
[ 132.182708] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 132.182709] CR2: 000055bb86c8b000 CR3: 00000007acf9a001 CR4: 00000000000606e0
[ 132.182709] Call Trace:
[ 132.182713] ? exit_to_usermode_loop+0x4f/0xd0
[ 132.182715] prepare_exit_to_usermode+0x83/0x90
[ 132.182718] retint_user+0x8/0x8
[ 132.182719] RIP: 0033:0x55bb86c8a2fd
[ 132.182720] RSP: 002b:00007ffd60331b60 EFLAGS: 00000202 ORIG_RAX: ffffffffffffff02
[ 132.182721] RAX: 0000000000000003 RBX: 00007f34f3a76000 RCX: 000055bb86c8a2fd
[ 132.182721] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
[ 132.182722] RBP: 00007ffd60332050 R08: 0000000000000000 R09: 0000000000000000
[ 132.182723] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
[ 132.182723] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
[ 132.182724] Code: Bad RIP value.
[ 132.182726] RIP: 0x55bb86c8b000 RSP: ffffaac644e87ee8
[ 132.182726] CR2: 000055bb86c8b000
[ 132.182728] ---[ end trace cad0a7670dc9a000 ]---
[ 132.182829] mm/pgtable-generic.c:40: bad pmd 00000000b3c05ac0(00000007b2884047)

Some info that may help to reproduce the bug:
commands: cd app/bench && NUM=10000 STRLEN=1 make run
kernel version: Ubuntu-4.15.0-135.139 (git://kernel.ubuntu.com/ubuntu/ubuntu-bionic.git)
cpu model: Intel(R) Core(TM) i7-7567U
kernel parameters: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nox2apic iomem=relaxed no_timer_check nosmep nosmap clearcpuid=514 isolcpus=1 nmi_watchdog=0"

Can you help to check and advise what is the potential causes of this? Thanks so much

Enclave creation failure

Hey, we're currently trying to build the 'foreshadow' app but when we run the makefile we get this error:

[main.c] Creating enclave...
Error calling enclave at main.c:153 (rv=0x2006)
Makefile:48: recipe for target 'run' failed
make: *** [run] Aborted

We followed the instructions from the README.md of sgx-step and then executed make run in app/foreshadow.
This is a slight time-critical issue, @jovanbulck we'd appreciate it a lot if you could help us out. Thanks!

libsgxstep/apic.c: ensure IRQ on apic_timer_deadline

Current code only configures local APIC timer in TSC deadline mode, without actually scheduling an IRQ event. As such, kernel will never regain control of the CPU (unless maybe when /dev/sgx-step is released and the wrapped handler is explicitly called). See

$ watch -n 1 cat /proc/interrupts

Kernel should be put back in control of the local APIC timer by explicitly scheduling an IRQ with wrmsr IA32_TSC_DEADLINE_MSR via an IOCTL call to the /dev/sgx-step kernel driver.

Support multithreaded enclaves

Currently, the Intel SGX-SDK patch and aep_trampoline.S use global variables to store the current TCS. This may not work in a multi-threaded environment (e.g., Gramine).

Best would be better to properly refactor to avoid the usage of a stored tcs variable in AEP interception in aep_trampoline.S and debug functionality in enclave.c.

Not able to build the apps

Hey, i'm currently trying to build the 'foreshadow' app but when i run the makefile i get this error:

[===] Enclave [===]
[GEN] sgx_edger8r encl.edl
make[1]: sgx_edger8r: Command not found
Makefile:84: recipe for target 'edger' failed
make[1]: *** [edger] Error 127
Makefile:72: recipe for target 'build-Enclave' failed
make: *** [build-Enclave] Error 2

I edited the makefile inside the 'Enclave' folder by:

  • adding the line:
    SGX_SDK ?= /opt/intel/sgxsdk
    (when i tried to print the value of SGX_SDK through "echo" i got blank output).

  • changing the EDGER variable to be
    EDGER = $(SGX_SDK)/bin/x64/sgx_edger8r

the error above seemed to be solved but then i encountered a new one:
[===] Enclave [===]
[GEN] /opt/intel/sgxsdk/bin/x64/sgx_edger8r encl.edl
[CC] encl_t.c (trusted edge)
[CC] encl.c (core)
[LD] encl.o encl_t.o -lsgx_trts encl.unsigned.so
Makefile:51: recipe for target 'encl.so' failed
make[1]: *** [encl.so] Error 127
Makefile:72: recipe for target 'build-Enclave' failed
make: *** [build-Enclave] Error 2

i followed the installation instructions inside the README, would appreciate some help.

Thanks,
Bar.

Unable to install sgx driver

Hey! I enabled bios while booting my machine but when I run ./install_SGX_driver.sh , it shows the following error:
make -C /lib/modules/5.4.0-53-generic/build M=/home/shalabh/nice/sgx-step/kernel/linux-sgx-driver modules
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-53-generic'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-53-generic'
modprobe: ERROR: could not insert 'isgx': Operation not permitted

I checked in 'dev/' but could not find isgx. What could be the case? I checked again and SGX was enabled.
Thanks

support for retrieving symbol addresses from enclave binary

A dynamic ELF parser library could easily return addresses (relative to the enclave base) for required enclave symbols (functions, data locations) etc. Together with get_enclave_base(), this way one does not have to either (i) get addresses manually using objdump or (ii) add special ecalls to get addresses at runtime for demo purposes.

./app: undefined symbol: sgx_get_aep

After SGX-Step using the latest version v2.14, step 1 and 2 succeeded,
but step 3.Build and run test applications has an error:

$ cd app/aep-redirect
$ make run

...
: note: this is the location of the previous definition
[AS] aep_trampoline.S
[AS] irq_entry.S
[AS] rtm.S
[AS] transient.S
[AR] libsgx-step.a
[CC] main.c
[LD] main.o -o app
./app: symbol lookup error: ./app: undefined symbol: sgx_get_aep
make: *** [Makefile:45: run] Error 127

And also an error:
$ cd app/bench
$ NUM=100 STRLEN=1 make parse

...
: note: this is the location of the previous definition
[AS] aep_trampoline.S
[AS] irq_entry.S
[AS] rtm.S
[AS] transient.S
[AR] libsgx-step.a
[CC] main.c
[LD] main.o -o app
./app: symbol lookup error: ./app: undefined symbol: sgx_get_aep
make: *** [Makefile:64: run] Error 127

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.