1 Star 0 Fork 10

jinlun/dim_9

forked from src-openEuler/dim 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-Fix-calculating-ELF-trampoline-address.patch 2.85 KB
一键复制 编辑 原始数据 按行查看 历史
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jinlun123123/dim_9.git
git@gitee.com:jinlun123123/dim_9.git
jinlun123123
dim_9
dim_9
master

搜索帮助