1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2019 ARM Limited
4 *
5 * Place a fake sigframe on the stack including an additional FPSIMD
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
fake_sigreturn_duplicated_fpsimd_run(struct tdescr * td,siginfo_t * si,ucontext_t * uc)18 static int fake_sigreturn_duplicated_fpsimd_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 head = get_starting_head(shead, sizeof(struct fpsimd_context) + HDR_SZ,
28 GET_SF_RESV_SIZE(sf), NULL);
29 if (!head)
30 return 0;
31
32 /* Add a spurious fpsimd_context */
33 head->magic = FPSIMD_MAGIC;
34 head->size = sizeof(struct fpsimd_context);
35 /* and terminate */
36 write_terminator_record(GET_RESV_NEXT_HEAD(head));
37
38 ASSERT_BAD_CONTEXT(&sf.uc);
39 fake_sigreturn(&sf, sizeof(sf), 0);
40
41 return 1;
42 }
43
44 struct tdescr tde = {
45 .name = "FAKE_SIGRETURN_DUPLICATED_FPSIMD",
46 .descr = "Triggers a sigreturn including two fpsimd_context",
47 .sig_ok = SIGSEGV,
48 .timeout = 3,
49 .run = fake_sigreturn_duplicated_fpsimd_run,
50 };
51