Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/sgx: Fix uninitialized pointer dereferences in encl_get_entry

Ensure sym_tab and sym_names are zero-initialized and add an early-out
condition in the unlikely (erroneous) case that the enclave ELF file would
not contain a symbol table.

This addresses -Werror=maybe-uninitialized compiler warnings for gcc -O2.

Fixes: 33c5aac3bf32 ("selftests/sgx: Test complete changing of page type flow")
Signed-off-by: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lore.kernel.org/all/20231005153854.25566-3-jo.vanbulck%40cs.kuleuven.be

authored by

Jo Van Bulck and committed by
Dave Hansen
b84fc2e0 79eba8c9

+6 -3
+6 -3
tools/testing/selftests/sgx/load.c
··· 136 136 */ 137 137 uint64_t encl_get_entry(struct encl *encl, const char *symbol) 138 138 { 139 + Elf64_Sym *symtab = NULL; 140 + char *sym_names = NULL; 139 141 Elf64_Shdr *sections; 140 - Elf64_Sym *symtab; 141 142 Elf64_Ehdr *ehdr; 142 - char *sym_names; 143 - int num_sym; 143 + int num_sym = 0; 144 144 int i; 145 145 146 146 ehdr = encl->bin; ··· 160 160 break; 161 161 } 162 162 } 163 + 164 + if (!symtab || !sym_names) 165 + return 0; 163 166 164 167 for (i = 0; i < num_sym; i++) { 165 168 Elf64_Sym *sym = &symtab[i];