1192811Srmacklem// SPDX-License-Identifier: GPL-2.0
2192811Srmacklem/*
3192811Srmacklem * Copyright (C) 2019 ARM Limited
4192811Srmacklem *
5192811Srmacklem * Try to mangle the ucontext from inside a signal handler, mangling the
6192811Srmacklem * DAIF bits in an illegal manner: this attempt must be spotted by Kernel
7192811Srmacklem * and the test case is expected to be terminated via SEGV.
8192811Srmacklem *
9192811Srmacklem */
10192811Srmacklem
11192811Srmacklem#include "test_signals_utils.h"
12192811Srmacklem#include "testcases.h"
13192811Srmacklem
14192811Srmacklemstatic int mangle_invalid_pstate_run(struct tdescr *td, siginfo_t *si,
15192811Srmacklem				     ucontext_t *uc)
16192811Srmacklem{
17192811Srmacklem	ASSERT_GOOD_CONTEXT(uc);
18192811Srmacklem
19192811Srmacklem	/*
20192811Srmacklem	 * This config should trigger a SIGSEGV by Kernel when it checks
21192811Srmacklem	 * the sigframe consistency in valid_user_regs() routine.
22192811Srmacklem	 */
23192811Srmacklem	uc->uc_mcontext.pstate |= PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT;
24192811Srmacklem
25192811Srmacklem	return 1;
26192811Srmacklem}
27192811Srmacklem
28192811Srmacklemstruct tdescr tde = {
29192811Srmacklem		.sanity_disabled = true,
30192811Srmacklem		.name = "MANGLE_PSTATE_INVALID_DAIF_BITS",
31192811Srmacklem		.descr = "Mangling uc_mcontext with INVALID DAIF_BITS",
32192811Srmacklem		.sig_trig = SIGUSR1,
33192811Srmacklem		.sig_ok = SIGSEGV,
34192811Srmacklem		.run = mangle_invalid_pstate_run,
35192811Srmacklem};
36192811Srmacklem