1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2019 ARM Limited
4 *
5 * Place a fake sigframe on the stack at a misaligned SP: on sigreturn
6 * Kernel must spot this attempt and the test case is expected to be
7 * 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
fake_sigreturn_misaligned_run(struct tdescr * td,siginfo_t * si,ucontext_t * uc)18 static int fake_sigreturn_misaligned_run(struct tdescr *td,
19 siginfo_t *si, ucontext_t *uc)
20 {
21 /* just to fill the ucontext_t with something real */
22 if (!get_current_context(td, &sf.uc, sizeof(sf.uc)))
23 return 1;
24
25 /* Forcing sigframe on misaligned SP (16 + 3) */
26 fake_sigreturn(&sf, sizeof(sf), 3);
27
28 return 1;
29 }
30
31 struct tdescr tde = {
32 .name = "FAKE_SIGRETURN_MISALIGNED_SP",
33 .descr = "Triggers a sigreturn with a misaligned sigframe",
34 .sig_ok = SIGSEGV,
35 .timeout = 3,
36 .run = fake_sigreturn_misaligned_run,
37 };
38