代码拉取完成,页面将自动刷新
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。