A RISC-V Extension to Minimize Privileges of Enclave Runtimes
Neelu Kalani and Edouard Bugnion
1
Neelu Kalani and Edouard Bugnion
Sneak Peek
2
SM
OS
EApp
TRTS
App
Enclave
TRTS Utils
SBOS
RISC-V Physical Memory Protection
Address Range | RWX |
Our Proposal: �RISC-V PMP-extension to enforce
the least privilege principle for TRTS.�Keystone-LP.
Lack of enforcement of least privilege principle on the TRTS!
Outline
3
SM
OS
EApp
TRTS
App
Enclave
TRTS Utils
SBOS
RISC-V Physical Memory Protection
Address Range | RWX |
Our Proposal: �RISC-V PMP-extension to enforce
the least privilege principle for TRTS.�Keystone-LP.
Lack of enforcement of least privilege principle on the TRTS!
Trusted Execution Environments (TEEs)
4
SM
Host OS
EApp
TRTS
App
Enclave
TRTS Utils
SBOS
EApp = Enclave Application
Requires confidentiality and �integrity guarantees
SM = Security Monitor
Provides security guarantees
TRTS = Trusted Runtime System/� Shielding Runtime
Mediate OS and EApp interactions
TRTS = Shield
5
Host OS
EApp
TRTS
TRTS Utils
The TRTS shields the EApp from the untrusted host �and is in the EApp’s TCB!
TRTS Software is Large
6
EApp
Keystone �Runtime Eyrie
5 kLoC
Graphene/�Overshadow Runtimes�13-22 kLoC
CURE Runtime�(Linux kernel)/Haven LibOS�Millions of LoC
SCONE�Shielding�Library�180 kLoC
Iago attacks!
Memory leaked or corrupted!
Impersonation attacks!
Linux kernel CVEs!
TRTS Mediated Interactions Between EApp and OS
The enclave address space contains memory shared with the untrusted OS!
7
EApp �Memory
Str[100]
Address X
SBOS
Str[0-49]
“EApp secret”
Address X + 100
copy_from_user(Y , X, 50)
ret = ocall(write, Y)
//OS performed write syscall
bytes_written += ret
Address Y
While (bytes_written < len) {
X += ret //X + 50
}
Str[50-99]
TRTS Code
print(Str)
TRTS = Confused Deputy
The untrusted OS abuses the TRTS into acting as a confused deputy�and leak secret EApp data through the shared communication channel.
8
Str[100]
Address X
SBOS
Str[0-49]
“EApp secret”
Address X + 100
copy_from_user(Y , X, 50)
ret = ocall(write, Y)
//OS performed write syscall
X += ret // X + 100
Address Y
While (bytes_written < len) {
bytes_written += ret
}
Str[50-99]
//Malicious OS returns an unexpected value
TRTS Code
EApp �Memory
“EApp Secret”
The TRTS
How do we protect the EApp from trusted software?
9
Our Goal: Rethink the Trust Model in TEEs
10
SM
Host OS
EApp
TRTS
App
Enclave
TRTS Utils
SBOS
Our Goal: Rethink the Trust Model in TEEs
11
SM
Host OS
EApp
TRTS
App
Enclave
TRTS Utils
SBOS
Str[100]
Address X
SBOS
“EApp secret”
Address X + 100
EApp �Memory
Key Takeaways
12
Outline
13
SM
OS
EApp
TRTS
App
Enclave
TRTS Utils
SBOS
RISC-V Physical Memory Protection
Address Range | RWX |
Our Proposal: �RISC-V PMP-extension to enforce
the least privilege principle for TRTS.�Keystone-LP.
Lack of enforcement of least privilege principle on the TRTS!
RISC-V Physical Memory Protection (PMP)
Protect contiguous physical memory address ranges
14
Address Range | RWX |
| |
| |
| |
PMP0
PMP1
PMP7
RISC-V Physical Memory Protection (PMP)
Priority based mechanism
15
Address Range | RWX |
| |
| |
| |
Decreasing
priority
PMP0
PMP1
PMP7
RISC-V PMP: Who Protects Physical Memory From Whom?
16
Firmware
OS
App
M-mode
RISC-V Privilege Modes
S-mode
U-mode
App
PMP rules are �configured by M-mode
PMP rules are applied to U-mode and S-mode
PMP Enforcement during Address Translation
17
TLB
1) Address translation request
(virtual address, request.RWX)
2) TLB Miss
PTW
PMP
3) Translation successful�(physical address, PTE.RWX)
Check PMP
4) Match with pmpaddr, �TLB.RWX = PTE.RWX & pmpcfg.RWX
5) TLB fill with �TLB.RWX
2) TLB Hit,�No need for a PMP check
5) PMP.RWX & request.RWX = 0, �PMP check fail,�access fault
V | Tag | PA | RWX | U |
Addr. | RWX |
Can PMP be Leveraged by the SM in TEEs?
18
Can PMP be Leveraged by the SM in TEEs?
19
Decreasing
priority
PMP0
RWX = 000 |
|
|
RWX = 111 |
PMP1
PMP7
SM
Executing�OS
Physical �Memory
Can PMP be Leveraged by the SM in TEEs?
20
Decreasing
priority
PMP0
RWX = 000 |
|
|
|
PMP1
PMP7
TRTS + EApp
RWX = 000 |
|
|
|
SM
Executing�Enclave
Executing�OS
Physical �Memory
RWX = 111
RWX = 111
RWX = 000
RWX = 000
This is how open source TEE framework Keystone also uses PMP!
Can we use RISC-V PMP to achieve our goal?
Inefficient choice.
21
RISC-V SSTATUS.SUM Bit
Does not prevent TRTS from leaking EApp secrets!
22
Key Takeaways
23
Outline
24
SM
OS
EApp
TRTS
App
Enclave
TRTS Utils
SBOS
RISC-V Physical Memory Protection
Address Range | RWX |
Our Proposal: �RISC-V PMP-extension to enforce
the least privilege principle for TRTS.�Keystone-LP.
Lack of enforcement of least privilege principle on the TRTS!
RISC-V PMP Extension
AS bit: Allow Supervisor access to User Pages.
M-mode governed equivalent of SUM bit in the PMP.
25
Address Range | RWX + AS bit |
| |
| |
| |
PMP0
PMP1
PMP7
AS bit in the TLB
1 additional bit per TLB entry.
26
TLB
1) Address translation request
(virtual address, request.RWX)
2) TLB Miss
PTW
PMP
3) Translation successful�(physical address, PTE.RWX)
Check PMP
4) Match with pmpaddr, �TLB.RWX = PTE.RWX & pmpcfg.RWX�TLB.AS = pmpcfg.AS
5) TLB fill with �TLB.RWX and TLB.AS bit
2) TLB Hit,�No need for a PMP check
5) PMP check fail,�access fault
V | Tag | PA | RWX | U | AS |
Addr. | RWX | AS |
Keystone-LP: How can the SM use PMP extension?
27
Decreasing
priority
PMP0
RWX = 000 |
|
|
|
PMP1
PMP7
TRTS + EApp
RWX = 000 |
|
|
|
SM
Executing�Enclave
Executing�OS
Physical �Memory
RWX = 111
RWX = 111
RWX = 000
RWX = 000
RECAP:
Keystone-LP: How can the SM use PMP extension?
2 PMP entries per enclave.�Number of simultaneous enclaves = (Number of PMP entries - 2)/2
28
Decreasing
priority
PMP0
PMP1
PMP7
RWX = 000, AS = 0 |
|
|
|
|
Executing�Enclave
Executing�OS
RWX = 000, AS = 0 |
|
|
|
|
TRTS
SM
Physical �Memory
EApp
SBTRTS
PMP2
RWX = 111, AS = 0
RWX = 111, AS = 1
RWX = 000, AS = 0
RWX = 111, AS = 1
RWX = 000, AS = 0
RWX = 000, AS = 0
SBTRTS = Shared buffer between TRTS and EApp
TRTS = Confused deputy
29
Str[100]
Address X
SBOS
Str[0-49]
“EApp secret”
Address X + 100
Address Y
Str[50-99]
EApp �Memory
“EApp Secret”
Yet again, TRTS = Confused deputy
The SBTRTS allows the EApp to expose selected data to the TRTS.
Even if the TRTS has vulnerabilities, it doesn’t have direct access to EApp data anymore!
30
Str[100]
Address X
SBTRTS
“EApp secret”
Address X + 100
Address Y
EApp �Memory
SBOS
Address Z
Str[100]
Is the risk eliminated completely?
Our mechanism raises the bar to exploit TRTS vulnerabilities to leak sensitive EApp data!
31
Key Takeaways
32
Summary
33
34
35