1
2
3
4
5
6
7
8
9
10#include <signal.h>
11#include <ucontext.h>
12
13#include "test_signals_utils.h"
14#include "testcases.h"
15
16struct fake_sigframe sf;
17
18#define MIN_SZ_ALIGN 16
19
20static int fake_sigreturn_bad_size_run(struct tdescr *td,
21 siginfo_t *si, ucontext_t *uc)
22{
23 size_t resv_sz, need_sz, offset;
24 struct _aarch64_ctx *shead = GET_SF_RESV_HEAD(sf), *head;
25
26
27 if (!get_current_context(td, &sf.uc))
28 return 1;
29
30 resv_sz = GET_SF_RESV_SIZE(sf);
31
32 need_sz = sizeof(struct esr_context) + HDR_SZ;
33 head = get_starting_head(shead, need_sz, resv_sz, &offset);
34 if (!head)
35 return 0;
36
37
38
39
40
41
42
43
44
45 head->magic = ESR_MAGIC;
46 head->size = sizeof(struct esr_context);
47
48 write_terminator_record(GET_RESV_NEXT_HEAD(head));
49 ASSERT_GOOD_CONTEXT(&sf.uc);
50
51
52
53
54
55
56
57
58
59
60 head->size = (resv_sz - offset - need_sz + MIN_SZ_ALIGN) & ~0xfUL;
61
62 head->size += MIN_SZ_ALIGN;
63
64 write_terminator_record(GET_RESV_NEXT_HEAD(head));
65 ASSERT_BAD_CONTEXT(&sf.uc);
66 fake_sigreturn(&sf, sizeof(sf), 0);
67
68 return 1;
69}
70
71struct tdescr tde = {
72 .name = "FAKE_SIGRETURN_BAD_SIZE",
73 .descr = "Triggers a sigreturn with a overrun __reserved area",
74 .sig_ok = SIGSEGV,
75 .timeout = 3,
76 .run = fake_sigreturn_bad_size_run,
77};
78