210 lines
6.3 KiB
Diff
210 lines
6.3 KiB
Diff
From fef290b506eb5aad0afab0183b577567d0d4d5ac Mon Sep 17 00:00:00 2001
|
|
From: Huaxin Lu <luhuaxin1@huawei.com>
|
|
Date: Tue, 13 Feb 2024 21:33:21 +0800
|
|
Subject: [PATCH 16/26] Optimize Makefile
|
|
|
|
1. Support to set the compile macro for different measure methods.
|
|
2. Support the "make test" command
|
|
---
|
|
Makefile | 13 +++++++++++++
|
|
src/Makefile | 40 ++++++++++++++++++++-------------------
|
|
test/Makefile | 11 +++++++++++
|
|
test/common.sh | 6 +++---
|
|
test/test_dim_core.sh | 2 +-
|
|
test/test_module/Makefile | 16 ++++++++--------
|
|
6 files changed, 57 insertions(+), 31 deletions(-)
|
|
create mode 100644 Makefile
|
|
create mode 100644 test/Makefile
|
|
|
|
diff --git a/Makefile b/Makefile
|
|
new file mode 100644
|
|
index 0000000..4ac7c58
|
|
--- /dev/null
|
|
+++ b/Makefile
|
|
@@ -0,0 +1,13 @@
|
|
+# Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
|
|
+
|
|
+.PHONY: all test clean
|
|
+
|
|
+all:
|
|
+ make -C src/
|
|
+
|
|
+test:
|
|
+ make -C test/
|
|
+
|
|
+clean:
|
|
+ make -C src/ clean
|
|
+ make -C test/ clean
|
|
\ No newline at end of file
|
|
diff --git a/src/Makefile b/src/Makefile
|
|
index af058d9..8f4dce8 100644
|
|
--- a/src/Makefile
|
|
+++ b/src/Makefile
|
|
@@ -9,17 +9,21 @@ dim_core-objs += core/dim_core_mem_pool.o
|
|
dim_core-objs += core/dim_core_measure.o
|
|
dim_core-objs += core/dim_core_symbol.o
|
|
dim_core-objs += core/dim_core_sig.o
|
|
-dim_core-objs += core/static_baseline/dim_core_static_baseline.o
|
|
-dim_core-objs += core/static_baseline/dim_core_static_baseline_complex.o
|
|
+
|
|
dim_core-objs += core/tasks/dim_core_measure_kernel.o
|
|
dim_core-objs += core/tasks/dim_core_measure_module.o
|
|
+dim_core-objs += core/tasks/dim_core_measure_process/dim_vm_hash.o
|
|
+dim_core-objs += core/tasks/dim_core_measure_process/dim_core_measure_process.o
|
|
+ifeq ($(DIM_CORE_MEASURE_PROCESS_ELF), y)
|
|
dim_core-objs += core/tasks/dim_core_measure_process/dim_core_measure_process_elf.o
|
|
+ccflags-y += -DDIM_CORE_MEASURE_PROCESS_ELF
|
|
+else
|
|
dim_core-objs += core/tasks/dim_core_measure_process/dim_core_measure_process_vma.o
|
|
-dim_core-objs += core/tasks/dim_core_measure_process/dim_core_measure_process.o
|
|
-dim_core-objs += core/tasks/dim_core_measure_process/dim_vm_hash.o
|
|
+endif
|
|
|
|
dim_core-objs += core/policy/dim_core_policy.o
|
|
dim_core-objs += core/policy/dim_core_policy_complex.o
|
|
+
|
|
dim_core-objs += core/static_baseline/dim_core_static_baseline.o
|
|
dim_core-objs += core/static_baseline/dim_core_static_baseline_complex.o
|
|
|
|
@@ -40,6 +44,10 @@ dim_monitor-objs += monitor/dim_monitor_main.o
|
|
dim_monitor-objs += monitor/dim_monitor_fs.o
|
|
dim_monitor-objs += monitor/dim_monitor_measure.o
|
|
dim_monitor-objs += monitor/dim_monitor_symbol.o
|
|
+
|
|
+dim_monitor-objs += monitor/measure_task/dim_monitor_measure_data.o
|
|
+dim_monitor-objs += monitor/measure_task/dim_monitor_measure_text.o
|
|
+
|
|
dim_monitor-objs += common/dim_entry.o
|
|
dim_monitor-objs += common/dim_hash.o
|
|
dim_monitor-objs += common/dim_utils.o
|
|
@@ -52,8 +60,6 @@ dim_monitor-objs += measure/dim_measure_baseline.o
|
|
dim_monitor-objs += measure/dim_measure_task.o
|
|
dim_monitor-objs += measure/dim_measure_utils.o
|
|
dim_monitor-objs += measure/dim_measure_status.o
|
|
-dim_monitor-objs += monitor/measure_task/dim_monitor_measure_data.o
|
|
-dim_monitor-objs += monitor/measure_task/dim_monitor_measure_text.o
|
|
|
|
ccflags-y := -I$(src)/core
|
|
ccflags-y += -I$(src)/core/static_baseline
|
|
@@ -65,24 +71,20 @@ ccflags-y += -I$(src)/monitor/measure_task
|
|
ccflags-y += -I$(src)/common
|
|
ccflags-y += -I$(src)/measure
|
|
|
|
-EXTRA_CFLAGS += -Wall -Werror -D_FORTIFY_SOURCE=2 -O2 -fstack-protector-strong
|
|
+ccflags-y += -Wall -Werror -D_FORTIFY_SOURCE=2 -O2 -fstack-protector-strong
|
|
|
|
KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build
|
|
PWD := $(shell pwd)
|
|
|
|
-.PHONY: install test clean
|
|
+.PHONY: all modules modules_install clean
|
|
|
|
-all:
|
|
- $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules KCPPFLAGS="${cflags-y}"
|
|
+all: modules
|
|
|
|
-clean:
|
|
- $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean
|
|
+modules:
|
|
+ $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules
|
|
|
|
-install:
|
|
- rmmod -f dim_monitor || :
|
|
- rmmod -f dim_core || :
|
|
- insmod dim_core.ko
|
|
- insmod dim_monitor.ko
|
|
+modules_install:
|
|
+ $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules_install
|
|
|
|
-test:
|
|
- cd ../test && { sh test_dim_core.sh; sh test_dim_monitor.sh; }
|
|
+clean:
|
|
+ $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean
|
|
diff --git a/test/Makefile b/test/Makefile
|
|
new file mode 100644
|
|
index 0000000..4a61307
|
|
--- /dev/null
|
|
+++ b/test/Makefile
|
|
@@ -0,0 +1,11 @@
|
|
+# Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
|
|
+
|
|
+.PHONY: test
|
|
+
|
|
+test:
|
|
+ sh test_dim_core.sh
|
|
+ sh test_dim_monitor.sh
|
|
+
|
|
+clean:
|
|
+ rm -f log
|
|
+ make -C test_module/ clean
|
|
\ No newline at end of file
|
|
diff --git a/test/common.sh b/test/common.sh
|
|
index 3bd8ced..a16c564 100644
|
|
--- a/test/common.sh
|
|
+++ b/test/common.sh
|
|
@@ -6,8 +6,8 @@ TEST_DEMO_DIR=/opt/dim/demo
|
|
TEST_DEMO_BPRM=$TEST_DEMO_DIR/dim_test_demo
|
|
|
|
TEST_LOG=log
|
|
-DIM_CORE_PATH=/root/dim/dim_core.ko
|
|
-DIM_MONITOR_PATH=/root/dim/dim_monitor.ko
|
|
+DIM_CORE_PATH=../src/dim_core.ko
|
|
+DIM_MONITOR_PATH=../src/dim_monitor.ko
|
|
|
|
DIM_BASELINE_DIR_PATH=/etc/dim/digest_list
|
|
DIM_POLICY_PATH=/etc/dim/policy
|
|
@@ -144,7 +144,7 @@ DIM_BASELINE_DIR_ALL=("/usr/bin" "/usr/sbin" "/usr/lib64" "/usr/libexec" "/usr/l
|
|
|
|
dim_gen_baseline_all() {
|
|
if [ $1 ]; then
|
|
- digest_algorithm="-a sm3"
|
|
+ digest_algorithm="-a$1"
|
|
else
|
|
digest_algorithm=""
|
|
fi
|
|
diff --git a/test/test_dim_core.sh b/test/test_dim_core.sh
|
|
index 01fa2b9..8d707cc 100644
|
|
--- a/test/test_dim_core.sh
|
|
+++ b/test/test_dim_core.sh
|
|
@@ -88,7 +88,7 @@ test_measure_all_text_normal() {
|
|
}
|
|
|
|
test_measure_all_text_normal_sm3() {
|
|
- dim_gen_baseline_all 1
|
|
+ dim_gen_baseline_all sm3
|
|
dim_gen_policy_all
|
|
load_dim_modules "measure_hash=sm3"
|
|
check_dim_core_log_normal
|
|
diff --git a/test/test_module/Makefile b/test/test_module/Makefile
|
|
index 4255525..240e73e 100644
|
|
--- a/test/test_module/Makefile
|
|
+++ b/test/test_module/Makefile
|
|
@@ -2,15 +2,15 @@
|
|
|
|
obj-m := dim_test_module_demo.o
|
|
|
|
-KERNEL := $(DESTDIR)/lib/modules/$(shell uname -r)/build
|
|
-CONFIG_MODULE_SIG=n
|
|
-
|
|
+KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build
|
|
PWD := $(shell pwd)
|
|
|
|
-modules :
|
|
- $(MAKE) -C $(KERNEL) M=$(PWD) modules
|
|
+.PHONY: all modules clean
|
|
+
|
|
+all: modules
|
|
|
|
-.PHONEY:clean
|
|
+modules:
|
|
+ $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules
|
|
|
|
-clean :
|
|
- $(MAKE) -C $(KERNEL) SUBDIRS=$(PWD) clean
|
|
+clean:
|
|
+ $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean
|
|
\ No newline at end of file
|
|
--
|
|
2.33.0
|
|
|