Skip to content

Commit 11b09f8

Browse files
bmax121bmax
andauthored
fix: hook functions starts with pac (#222)
* added BTI in trampoline head for support hook "BR/BLR -> PACIXSP" * 0.12.3 --------- Co-authored-by: bmax <[email protected]>
1 parent 8eebc2e commit 11b09f8

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

kernel/base/hook.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,17 @@ hook_err_t hook_prepare(hook_t *hook)
566566
if (is_bad_address((void *)hook->relo_addr)) return -HOOK_BAD_ADDRESS;
567567

568568
// backup origin instruction
569-
for (int i = 0; i < TRAMPOLINE_NUM; i++) {
569+
for (int i = 0; i < TRAMPOLINE_MAX_NUM; i++) {
570570
hook->origin_insts[i] = *((uint32_t *)hook->origin_addr + i);
571571
}
572572
// trampline to replace_addr
573-
hook->tramp_insts_num = branch_from_to(hook->tramp_insts, hook->origin_addr, hook->replace_addr);
573+
if (hook->origin_insts[0] == ARM64_PACIASP || hook->origin_insts[0] == ARM64_PACIBSP) {
574+
hook->tramp_insts_num = branch_from_to(&hook->tramp_insts[1], hook->origin_addr, hook->replace_addr);
575+
hook->tramp_insts[0] = ARM64_BTI_JC;
576+
hook->tramp_insts_num++;
577+
} else {
578+
hook->tramp_insts_num = branch_from_to(hook->tramp_insts, hook->origin_addr, hook->replace_addr);
579+
}
574580

575581
// relocate
576582
for (int i = 0; i < sizeof(hook->relo_insts) / sizeof(hook->relo_insts[0]); i++) {

kernel/include/hook.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ typedef int8_t chain_item_state;
4040
#define local_container_of(ptr, type, member) ({ (type *)((char *)(ptr) - local_offsetof(type, member)); })
4141

4242
#define HOOK_MEM_REGION_NUM 4
43-
#define TRAMPOLINE_NUM 4
44-
#define RELOCATE_INST_NUM (TRAMPOLINE_NUM * 8 + 8)
43+
#define TRAMPOLINE_MAX_NUM 6
44+
#define RELOCATE_INST_NUM (TRAMPOLINE_MAX_NUM * 8 + 8)
4545

4646
#define HOOK_CHAIN_NUM 0x10
4747
#define TRANSIT_INST_NUM 0x60
@@ -52,6 +52,8 @@ typedef int8_t chain_item_state;
5252
#define ARM64_BTI_C 0xd503245f
5353
#define ARM64_BTI_J 0xd503249f
5454
#define ARM64_BTI_JC 0xd50324df
55+
#define ARM64_PACIASP 0xd503233f
56+
#define ARM64_PACIBSP 0xd503237f
5557

5658
typedef struct
5759
{
@@ -63,8 +65,8 @@ typedef struct
6365
// out
6466
int32_t tramp_insts_num;
6567
int32_t relo_insts_num;
66-
uint32_t origin_insts[TRAMPOLINE_NUM] __attribute__((aligned(8)));
67-
uint32_t tramp_insts[TRAMPOLINE_NUM] __attribute__((aligned(8)));
68+
uint32_t origin_insts[TRAMPOLINE_MAX_NUM] __attribute__((aligned(8)));
69+
uint32_t tramp_insts[TRAMPOLINE_MAX_NUM] __attribute__((aligned(8)));
6870
uint32_t relo_insts[RELOCATE_INST_NUM] __attribute__((aligned(8)));
6971
} hook_t __attribute__((aligned(8)));
7072

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#define MAJOR 0
22
#define MINOR 12
3-
#define PATCH 2
3+
#define PATCH 3

0 commit comments

Comments
 (0)