Both mmap() calls could fail without being checked, leading to undefined behavior on memcpy or dereference. Use err() on failure, consistent with the rest of the test.
Signed-off-by: Hongfu Li <[email protected]> --- tools/testing/selftests/x86/fsgsbase.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c index 0a75252d31b6..5ff54d12d40e 100644 --- a/tools/testing/selftests/x86/fsgsbase.c +++ b/tools/testing/selftests/x86/fsgsbase.c @@ -252,6 +252,10 @@ static unsigned short load_gs(void) NULL, sizeof(desc), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0); + + if (low_desc == MAP_FAILED) + err(1, "mmap"); + memcpy(low_desc, &desc, sizeof(desc)); low_desc->entry_number = set_thread_area_entry_number; @@ -572,6 +576,8 @@ int main() shared_scratch = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); + if (shared_scratch == MAP_FAILED) + err(1, "mmap"); /* Do these tests before we have an LDT. */ test_ptrace_write_gs_read_base(); -- 2.54.0

