@@ -519,8 +519,6 @@ static int sgx_encl_add_page(struct sgx_encl *encl, unsigned long addr,
struct sgx_va_page *va_page;
int ret;
- if (sgx_validate_secinfo(secinfo))
- return -EINVAL;
if (page_type == SGX_SECINFO_TCS) {
ret = sgx_validate_tcs(encl, data);
if (ret)
@@ -635,6 +633,9 @@ static long sgx_ioc_enclave_add_page(struct file *filep, void __user *arg)
sizeof(secinfo)))
return -EFAULT;
+ if (sgx_validate_secinfo(&secinfo))
+ return -EINVAL;
+
data_page = alloc_page(GFP_HIGHUSER);
if (!data_page)
return -ENOMEM;
When adding pages to the encalve, verify the SECINFO flags provided by userspace are valid prior to consuming the protection bits and to avoid allocating a page when SECINFO is invalid. Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> --- arch/x86/kernel/cpu/sgx/driver/ioctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)