Skip to contentSkip to conversation

x86/sgx: Allow RW for TCS pages

PATCH In review Jarkko Sakkinen 2 participants 3 messages Mar 19, 2022 – Mar 30, 2022

Subsystems (2)
lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH 1/1 x86/sgx: Allow RW for TCS pages

Not allowing to set RW for added TCS pages leads only to a special case to be handled in the user space run-time. Thus, allow permissions to be set RW. Originally, it would have probably made more sense to check up that the permissions are RW.

---
 arch/x86/kernel/cpu/sgx/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/sgx/ioctl.c +1 -1
index 83df20e3e633..f79761ad0400 100644
@@ -215,7 +215,7 @@ static int sgx_validate_secinfo(struct sgx_secinfo *secinfo)
 	 * CPU will silently overwrite the permissions as zero, which means
 	 * that we need to validate it ourselves.
 	 */
-	if (pt == SGX_SECINFO_TCS && perm)
+	if (pt == SGX_SECINFO_TCS && (perm != 0 || perm != (PROT_READ | PROT_WRITE)))
 		return -EINVAL;
 
 	if (secinfo->flags & SGX_SECINFO_RESERVED_MASK)
Signature · 1 line
2.35.1
#1 lore raw

Hi Jarkko,

Quoted 15 lines · Jarkko Sakkinen

Not allowing to set RW for added TCS pages leads only to a special case to be handled in the user space run-time. Thus, allow permissions to be set RW. Originally, it would have probably made more sense to check up that the permissions are RW.

---
 arch/x86/kernel/cpu/sgx/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/sgx/ioctl.c +0 -0
index 83df20e3e633..f79761ad0400 100644

arch/x86/kernel/cpu/sgx/ioctl.c static int sgx_validate_secinfo(struct sgx_secinfo *secinfo) · line 221

Quoted 8 lines
arch/x86/kernel/cpu/sgx/ioctl.c +1 -1
@@ -215,7 +215,7 @@ static int sgx_validate_secinfo(struct sgx_secinfo *secinfo)
 	 * CPU will silently overwrite the permissions as zero, which means
 	 * that we need to validate it ourselves.
 	 */
-	if (pt == SGX_SECINFO_TCS && perm)
+	if (pt == SGX_SECINFO_TCS && (perm != 0 || perm != (PROT_READ | PROT_WRITE)))
 		return -EINVAL;
 
 	if (secinfo->flags & SGX_SECINFO_RESERVED_MASK)

The comments above sgx_ioc_enclave_add_pages() seem to indicate that zero permissions are required:

"A SECINFO for a TCS is required to always contain zero permissions because
CPU silently zeros them. Allowing anything else would cause a mismatch in the measurement."

Reinette

author maintainer
#2 lore raw
Quoted 25 lines · Reinette Chatre

Hi Jarkko,

Quoted 22 lines · Jarkko Sakkinen

Not allowing to set RW for added TCS pages leads only to a special case to be handled in the user space run-time. Thus, allow permissions to be set RW. Originally, it would have probably made more sense to check up that the permissions are RW.

---
 arch/x86/kernel/cpu/sgx/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/sgx/ioctl.c +1 -1
index 83df20e3e633..f79761ad0400 100644
@@ -215,7 +215,7 @@ static int sgx_validate_secinfo(struct sgx_secinfo *secinfo)
 	 * CPU will silently overwrite the permissions as zero, which means
 	 * that we need to validate it ourselves.
 	 */
-	if (pt == SGX_SECINFO_TCS && perm)
+	if (pt == SGX_SECINFO_TCS && (perm != 0 || perm != (PROT_READ | PROT_WRITE)))
 		return -EINVAL;
 
Quoted 8 lines

arch/x86/kernel/cpu/sgx/ioctl.c static int sgx_validate_secinfo(struct sgx_secinfo *secinfo) · line 221

Quoted 1 line
arch/x86/kernel/cpu/sgx/ioctl.c +0 -0
 	if (secinfo->flags & SGX_SECINFO_RESERVED_MASK)

The comments above sgx_ioc_enclave_add_pages() seem to indicate that zero permissions are required:

"A SECINFO for a TCS is required to always contain zero permissions because
CPU silently zeros them. Allowing anything else would cause a mismatch in the measurement."

I think this can be left out for now but fixing the relative addressing is an obvious fix.

BR, Jarkko