80 lines
2.8 KiB
Diff
80 lines
2.8 KiB
Diff
From 89d0f0762a2241b518e55b45337c1874f74e2520 Mon Sep 17 00:00:00 2001
|
|
From: jinlun <jinlun@huawei.com>
|
|
Date: Mon, 17 Jun 2024 14:51:46 +0800
|
|
Subject: [PATCH 01/14] Fix calculating ELF trampoline address
|
|
|
|
---
|
|
.../dim_core_measure_process_elf.c | 14 ++++++++------
|
|
1 file changed, 8 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/src/core/tasks/dim_core_measure_process/dim_core_measure_process_elf.c b/src/core/tasks/dim_core_measure_process/dim_core_measure_process_elf.c
|
|
index 76d1560..12040e2 100644
|
|
--- a/src/core/tasks/dim_core_measure_process/dim_core_measure_process_elf.c
|
|
+++ b/src/core/tasks/dim_core_measure_process/dim_core_measure_process_elf.c
|
|
@@ -233,6 +233,7 @@ static int get_elf_measure_area(struct file *elf_file,
|
|
}
|
|
|
|
static int measure_elf_trampoline(struct vm_area_struct *vma,
|
|
+ unsigned long base,
|
|
struct elf_shdr *shdr_trampoline,
|
|
struct task_measure_ctx *ctx)
|
|
{
|
|
@@ -243,7 +244,7 @@ static int measure_elf_trampoline(struct vm_area_struct *vma,
|
|
.algo = ctx->m->hash.algo,
|
|
};
|
|
|
|
- addr_trampoline = vma->vm_start + shdr_trampoline->sh_addr;
|
|
+ addr_trampoline = base + shdr_trampoline->sh_addr;
|
|
vma_trampoline = find_vma(vma->vm_mm, addr_trampoline);
|
|
if (vma_trampoline == NULL || !vma_is_text(vma_trampoline) ||
|
|
vma_trampoline->vm_start != addr_trampoline)
|
|
@@ -259,6 +260,7 @@ static int measure_elf_trampoline(struct vm_area_struct *vma,
|
|
}
|
|
|
|
static int measure_elf_text(struct vm_area_struct *vma,
|
|
+ unsigned long base,
|
|
struct elf_phdr *phdrs_text,
|
|
unsigned int phdrs_text_num,
|
|
struct task_measure_ctx *ctx)
|
|
@@ -266,7 +268,6 @@ static int measure_elf_text(struct vm_area_struct *vma,
|
|
int ret = 0;
|
|
unsigned int i = 0;
|
|
unsigned long addr = 0;
|
|
- unsigned long base = 0;
|
|
struct elf_phdr *phdr = NULL;
|
|
struct dim_digest digest = {
|
|
.algo = ctx->m->hash.algo,
|
|
@@ -278,8 +279,6 @@ static int measure_elf_text(struct vm_area_struct *vma,
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
- base = vma->vm_start - phdrs_text[0].p_vaddr;
|
|
-
|
|
for (; i < phdrs_text_num; i++) {
|
|
phdr = &phdrs_text[i];
|
|
addr = base + phdr->p_vaddr;
|
|
@@ -322,7 +321,10 @@ int measure_process_module_text_elf(struct vm_area_struct *vma,
|
|
return ret;
|
|
}
|
|
|
|
- ret = measure_elf_text(vma, phdrs_text, phdrs_text_num, ctx);
|
|
+ /* the vma is the first file-mapping text segment */
|
|
+ base = vma->vm_start - phdrs_text[0].p_vaddr;
|
|
+
|
|
+ ret = measure_elf_text(vma, base, phdrs_text, phdrs_text_num, ctx);
|
|
dim_kfree(phdrs_text);
|
|
if (ret < 0) {
|
|
dim_err("failed to measure elf text: %d\n", ret);
|
|
@@ -330,7 +332,7 @@ int measure_process_module_text_elf(struct vm_area_struct *vma,
|
|
}
|
|
|
|
if (shdr_trampoline_find) {
|
|
- ret = measure_elf_trampoline(vma, &shdr_trampoline, ctx);
|
|
+ ret = measure_elf_trampoline(vma, base, &shdr_trampoline, ctx);
|
|
if (ret < 0) {
|
|
dim_err("failed to measure elf trampoline: %d\n", ret);
|
|
return ret;
|
|
--
|
|
2.33.0
|
|
|