]> www.infradead.org Git - users/dwmw2/linux.git/commit
selftests/sgx: Fix NULL-pointer-dereference upon early test failure
authorReinette Chatre <reinette.chatre@intel.com>
Tue, 8 Feb 2022 21:48:39 +0000 (13:48 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 11:57:33 +0000 (13:57 +0200)
commitbc72277b7541756d91c07afee6d768ec97777651
treec26a8c41e8e5551f0841509d42a43c9f9814ae7b
parent704404dab53465c2deeeff6cf64869a42d8f2c56
selftests/sgx: Fix NULL-pointer-dereference upon early test failure

[ Upstream commit 2d03861e0d1d1ee81efc59338101cdd86a7474f6 ]

== Background ==

The SGX selftests track parts of the enclave binaries in an array:
encl->segment_tbl[]. That array is dynamically allocated early
(but not first) in the test's lifetime. The array is referenced
at the end of the test in encl_delete().

== Problem ==

encl->segment_tbl[] can be NULL if the test fails before its
allocation. That leads to a NULL-pointer-dereference in encl_delete().
This is triggered during early failures of the selftest like if the
enclave binary ("test_encl.elf") is deleted.

== Solution ==

Ensure encl->segment_tbl[] is valid before attempting to access
its members. The offset with which it is accessed, encl->nr_segments,
is initialized before encl->segment_tbl[] and thus considered valid
to use after the encl->segment_tbl[] check succeeds.

Fixes: 3200505d4de6 ("selftests/sgx: Create a heap for the test enclave")
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Link: https://lkml.kernel.org/r/90a31dfd640ea756fa324712e7cbab4a90fa7518.1644355600.git.reinette.chatre@intel.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/sgx/load.c