1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2019 ARM Limited
4 *
5 * Try to mangle the ucontext from inside a signal handler, mangling the
6 * DAIF bits in an illegal manner: this attempt must be spotted by Kernel
7 * and the test case is expected to be terminated via SEGV.
8 *
9 */
10
11 #include "test_signals_utils.h"
12 #include "testcases.h"
13
mangle_invalid_pstate_run(struct tdescr * td,siginfo_t * si,ucontext_t * uc)14 static int mangle_invalid_pstate_run(struct tdescr *td, siginfo_t *si,
15 ucontext_t *uc)
16 {
17 ASSERT_GOOD_CONTEXT(uc);
18
19 /*
20 * This config should trigger a SIGSEGV by Kernel when it checks
21 * the sigframe consistency in valid_user_regs() routine.
22 */
23 uc->uc_mcontext.pstate |= PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT;
24
25 return 1;
26 }
27
28 struct tdescr tde = {
29 .sanity_disabled = true,
30 .name = "MANGLE_PSTATE_INVALID_DAIF_BITS",
31 .descr = "Mangling uc_mcontext with INVALID DAIF_BITS",
32 .sig_trig = SIGUSR1,
33 .sig_ok = SIGSEGV,
34 .run = mangle_invalid_pstate_run,
35 };
36