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 badly sized terminator
6  * record: on sigreturn Kernel must spot this attempt and the test case
7  * 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_size_for_magic0_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 	/* at least HDR_SZ for the badly sized terminator. */
28 	head = get_starting_head(shead, HDR_SZ, GET_SF_RESV_SIZE(sf), NULL);
29 	if (!head)
30 		return 0;
31 
32 	head->magic = 0;
33 	head->size = HDR_SZ;
34 	ASSERT_BAD_CONTEXT(&sf.uc);
35 	fake_sigreturn(&sf, sizeof(sf), 0);
36 
37 	return 1;
38 }
39 
40 struct tdescr tde = {
41 		.name = "FAKE_SIGRETURN_BAD_SIZE_FOR_TERMINATOR",
42 		.descr = "Trigger a sigreturn using non-zero size terminator",
43 		.sig_ok = SIGSEGV,
44 		.timeout = 3,
45 		.run = fake_sigreturn_bad_size_for_magic0_run,
46 };
47