backport patchs to fix memory leak Signed-off-by: hurricane618 <hurricane618@hotmail.com>
65 lines
2.1 KiB
Diff
65 lines
2.1 KiB
Diff
From aaed2290507cac0878c93aa550664875d5875a6b Mon Sep 17 00:00:00 2001
|
|
From: hurricane618 <hurricane618@hotmail.com>
|
|
Date: Wed, 20 Dec 2023 20:17:33 +0800
|
|
Subject: [PATCH] fix memory leak in program_action
|
|
|
|
1. free path data
|
|
2. free pi in error branch
|
|
|
|
Signed-off-by: hurricane618 <hurricane618@hotmail.com>
|
|
---
|
|
.../cases/program_action/secDetector_program_action.c | 9 +++++++++
|
|
1 file changed, 9 insertions(+)
|
|
|
|
diff --git a/kerneldriver/cases/program_action/secDetector_program_action.c b/kerneldriver/cases/program_action/secDetector_program_action.c
|
|
index 1f0749a..f571c08 100644
|
|
--- a/kerneldriver/cases/program_action/secDetector_program_action.c
|
|
+++ b/kerneldriver/cases/program_action/secDetector_program_action.c
|
|
@@ -177,6 +177,9 @@ static struct process_info *get_common_process_info(struct task_struct *tsk, str
|
|
if (get_task_root(tsk, &root) == 0) {
|
|
pi->root = d_path(&root, pi->rootbuf, PATH_LEN);
|
|
}
|
|
+
|
|
+ path_put(&root);
|
|
+
|
|
if (IS_ERR_OR_NULL(pi->root)) {
|
|
pi->root = "invalid";
|
|
}
|
|
@@ -184,6 +187,9 @@ static struct process_info *get_common_process_info(struct task_struct *tsk, str
|
|
if (get_task_cwd(tsk, &cwd) == 0) {
|
|
pi->cwd = d_path(&cwd, pi->cwdbuf, PATH_LEN);
|
|
}
|
|
+
|
|
+ path_put(&cwd);
|
|
+
|
|
if (IS_ERR_OR_NULL(pi->cwd)) {
|
|
pi->cwd = "invalid";
|
|
}
|
|
@@ -258,6 +264,7 @@ static int ptrace_attach_pre_handler(struct secDetector_workflow *wf,
|
|
#endif
|
|
if (!attach_task) {
|
|
pr_err("ptrace_attach input task_struct error or arch don't support\n");
|
|
+ put_common_process_info(pi);
|
|
return 0;
|
|
}
|
|
|
|
@@ -269,6 +276,7 @@ static int ptrace_attach_pre_handler(struct secDetector_workflow *wf,
|
|
if (!log.report_data.text) {
|
|
pr_err("log.report_data.text kzalloc failed!\n");
|
|
kfree(timestamp);
|
|
+ put_common_process_info(pi);
|
|
return 0;
|
|
}
|
|
snprintf(log.report_data.text, BUF_SIZE,
|
|
@@ -304,6 +312,7 @@ static int do_pipe2_pre_handler(struct secDetector_workflow *wf,
|
|
if (!log.report_data.text) {
|
|
pr_err("log.report_data.text kzalloc failed!\n");
|
|
kfree(timestamp);
|
|
+ put_common_process_info(pi);
|
|
return 0;
|
|
}
|
|
snprintf(log.report_data.text, BUF_SIZE,
|
|
--
|
|
2.33.0
|
|
|