x86/sgx: Simplify struct sgx_enclave_restrict_permissions
Jarkko Sakkinen
maintainerRFC PATCH 1/1 x86/sgx: Simplify struct sgx_enclave_restrict_permissions
The reasoning to change SECINFO to simply flags is stated in this inline comment:
/*
* Return valid permission fields from a secinfo structure provided by
* user space. The secinfo structure is required to only have bits in
* the permission fields set.
*/
It is better to simply change the parameter type than require to use a malformed version of a data structure.
---
Only compile-tested.
arch/x86/include/uapi/asm/sgx.h | 5 ++- arch/x86/kernel/cpu/sgx/ioctl.c | 57 ++++++--------------------------- 2 files changed, 12 insertions(+), 50 deletions(-)
arch/x86/include/uapi/asm/sgx.h +2 -3
@@ -88,15 +88,14 @@ struct sgx_enclave_provision {* @offset: starting page offset (page aligned relative to enclave base * address defined in SECS) * @length: length of memory (multiple of the page size) -* @secinfo: address for the SECINFO data containing the new permission bits -* for pages in range described by @offset and @length +* @flags: flags field of the SECINFO data * @result: (output) SGX result code of ENCLS[EMODPR] function * @count: (output) bytes successfully changed (multiple of page size) */ struct sgx_enclave_restrict_permissions {__u64 offset;__u64 length; -__u64 secinfo; +__u64 flags;__u64 result;__u64 count; };
arch/x86/kernel/cpu/sgx/ioctl.c +10 -47
95 lines not on this page · raw message
Signature · 1 line
2.35.1
Hi Jarkko,
Quoted 11 lines · Jarkko Sakkinen
The reasoning to change SECINFO to simply flags is stated in this inline comment:
/*
* Return valid permission fields from a secinfo structure provided by
* user space. The secinfo structure is required to only have bits in
* the permission fields set.
*/It is better to simply change the parameter type than require to use a malformed version of a data structure.
Could you please elaborate what is malformed?
Quoted 21 lines
Signed-off-by Jarkko Sakkinen <[email protected]>---
Only compile-tested.arch/x86/include/uapi/asm/sgx.h | 5 ++- arch/x86/kernel/cpu/sgx/ioctl.c | 57 ++++++--------------------------- 2 files changed, 12 insertions(+), 50 deletions(-)arch/x86/include/uapi/asm/sgx.h +1
-2@@ -88,15 +88,14 @@ struct sgx_enclave_provision {* @offset: starting page offset (page aligned relative to enclave base * address defined in SECS) * @length: length of memory (multiple of the page size) -* @secinfo: address for the SECINFO data containing the new permission bits -* for pages in range described by @offset and @length +* @flags: flags field of the SECINFO data * @result: (output) SGX result code of ENCLS[EMODPR] function
arch/x86/include/uapi/asm/sgx.h struct sgx_enclave_provision { · line 101
Quoted 10 lines
arch/x86/include/uapi/asm/sgx.h +1
-1* @count: (output) bytes successfully changed (multiple of page size) */ struct sgx_enclave_restrict_permissions {__u64 offset;__u64 length; -__u64 secinfo; +__u64 flags;__u64 result;__u64 count; };
What is the motivation for using the flags field of the SECINFO data? If the goal is to only provide necessary information, why not just provide the permission bits since none of the other bits are used? If the goal is to make room for future SECINFO changes/demands, why not include the reserved field of SECINFO where future changes are most likely to reside?
Reinette
Jarkko Sakkinen
maintainerQuoted 12 lines · Reinette Chatre
Hi Jarkko,
Quoted 9 lines · Jarkko Sakkinen
The reasoning to change SECINFO to simply flags is stated in this inline comment:
/*
* Return valid permission fields from a secinfo structure provided by
* user space. The secinfo structure is required to only have bits in
* the permission fields set.
*/
Quoted 4 lines
Quoted 2 lines
It is better to simply change the parameter type than require to use a malformed version of a data structure.
Could you please elaborate what is malformed?
The structure that is accepted by the API. According to SDM permission changes are done with a structure where PT_REG is set, which gives -EINVAL. I categorize it as a bug.
BR, Jarkko
Hi Jarkko,
Quoted 13 lines · Jarkko Sakkinen
Quoted 12 lines · Reinette Chatre
Hi Jarkko,
Quoted 9 lines · Jarkko Sakkinen
The reasoning to change SECINFO to simply flags is stated in this inline comment:
/*
* Return valid permission fields from a secinfo structure provided by
* user space. The secinfo structure is required to only have bits in
* the permission fields set.
*/
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
It is better to simply change the parameter type than require to use a malformed version of a data structure.
Could you please elaborate what is malformed?
The structure that is accepted by the API. According to SDM permission changes are done with a structure where
PT_REGis set, which gives-EINVAL. I categorize it as a bug.
I assume that you are referring to this line from the SDM:
IF (EPCM(DS:RCX).PT is not PT_REG)
THEN #PF(DS:RCX); FI;
Please note that the above tests the PT bit of the EPCM entry, not the PT field in the provided SECINFO.
Reinette