Skip to content

Commit e3a3bbe

Browse files
rchatrehansendc
authored andcommitted
x86/sgx: Ensure no data in PCMD page after truncate
A PCMD (Paging Crypto MetaData) page contains the PCMD structures of enclave pages that have been encrypted and moved to the shmem backing store. When all enclave pages sharing a PCMD page are loaded in the enclave, there is no need for the PCMD page and it can be truncated from the backing store. A few issues appeared around the truncation of PCMD pages. The known issues have been addressed but the PCMD handling code could be made more robust by loudly complaining if any new issue appears in this area. Add a check that will complain with a warning if the PCMD page is not actually empty after it has been truncated. There should never be data in the PCMD page at this point since it is was just checked to be empty and truncated with enclave mutex held and is updated with the enclave mutex held. Suggested-by: Dave Hansen <[email protected]> Signed-off-by: Reinette Chatre <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Tested-by: Haitao Huang <[email protected]> Link: https://lkml.kernel.org/r/6495120fed43fafc1496d09dd23df922b9a32709.1652389823.git.reinette.chatre@intel.com
1 parent af11783 commit e3a3bbe

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

arch/x86/kernel/cpu/sgx/encl.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,20 @@ static int __sgx_encl_eldu(struct sgx_encl_page *encl_page,
187187
kunmap_atomic(pcmd_page);
188188
kunmap_atomic((void *)(unsigned long)pginfo.contents);
189189

190+
get_page(b.pcmd);
190191
sgx_encl_put_backing(&b);
191192

192193
sgx_encl_truncate_backing_page(encl, page_index);
193194

194-
if (pcmd_page_empty && !reclaimer_writing_to_pcmd(encl, pcmd_first_page))
195+
if (pcmd_page_empty && !reclaimer_writing_to_pcmd(encl, pcmd_first_page)) {
195196
sgx_encl_truncate_backing_page(encl, PFN_DOWN(page_pcmd_off));
197+
pcmd_page = kmap_atomic(b.pcmd);
198+
if (memchr_inv(pcmd_page, 0, PAGE_SIZE))
199+
pr_warn("PCMD page not empty after truncate.\n");
200+
kunmap_atomic(pcmd_page);
201+
}
202+
203+
put_page(b.pcmd);
196204

197205
return ret;
198206
}

0 commit comments

Comments
 (0)