1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (C) 2019 ARM Limited 4 * 5 * Place a fake sigframe on the stack including a BAD Unknown magic 6 * record: on sigreturn Kernel must spot this attempt and the test 7 * case is expected to be terminated via SEGV. 8 */ 9 10 #include <signal.h> 11 #include <ucontext.h> 12 13 #include "test_signals_utils.h" 14 #include "testcases.h" 15 16 struct fake_sigframe sf; 17 18 static int fake_sigreturn_bad_magic_run(struct tdescr *td, 19 siginfo_t *si, ucontext_t *uc) 20 { 21 struct _aarch64_ctx *shead = GET_SF_RESV_HEAD(sf), *head; 22 23 /* just to fill the ucontext_t with something real */ 24 if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) 25 return 1; 26 27 /* need at least 2*HDR_SZ space: KSFT_BAD_MAGIC + terminator. */ 28 head = get_starting_head(shead, HDR_SZ * 2, GET_SF_RESV_SIZE(sf), NULL); 29 if (!head) 30 return 0; 31 32 /* 33 * use a well known NON existent bad magic...something 34 * we should pretty sure won't be ever defined in Kernel 35 */ 36 head->magic = KSFT_BAD_MAGIC; 37 head->size = HDR_SZ; 38 write_terminator_record(GET_RESV_NEXT_HEAD(head)); 39 40 ASSERT_BAD_CONTEXT(&sf.uc); 41 fake_sigreturn(&sf, sizeof(sf), 0); 42 43 return 1; 44 } 45 46 struct tdescr tde = { 47 .name = "FAKE_SIGRETURN_BAD_MAGIC", 48 .descr = "Trigger a sigreturn with a sigframe with a bad magic", 49 .sig_ok = SIGSEGV, 50 .timeout = 3, 51 .run = fake_sigreturn_bad_magic_run, 52 }; 53