syscare/0035-security-sanitize-sensitive-code.patch
renoseven aaca4c9c5f update to 1.2.1-10
Signed-off-by: renoseven <dev@renoseven.net>
2024-08-16 16:44:21 +08:00

1990 lines
67 KiB
Diff

From 3dffc94e5bf110785c9fe96dc96f16dba10c8ac8 Mon Sep 17 00:00:00 2001
From: liuxiaobo <liuxiaobo19@huawei.com>
Date: Fri, 7 Jun 2024 16:25:53 +0800
Subject: [PATCH] security: sanitize sensitive code
1. rename 'upatch_hijacker' to 'upatch_helper'
2. sanitize all 'hijacker' in source code
Signed-off-by: liuxiaobo <liuxiaobo19@huawei.com>
---
CMakeLists.txt | 2 +-
upatch-build/src/{hijacker.rs => helper.rs} | 31 ++++---
upatch-build/src/main.rs | 11 +--
upatch-build/src/project.rs | 2 +-
upatch-build/src/rpc/proxy.rs | 4 +-
.../CMakeLists.txt | 2 +-
upatch-helper/helper/CMakeLists.txt | 35 ++++++++
.../helper/gnu-as-helper.c | 18 ++--
.../helper/gnu-compiler-helper.c | 16 ++--
.../helper/helper.h | 12 +--
upatch-helper/ko/CMakeLists.txt | 32 +++++++
{upatch-hijacker => upatch-helper}/ko/LICENSE | 0
.../ko/Makefile | 2 +-
{upatch-hijacker => upatch-helper}/ko/cache.c | 4 +-
{upatch-hijacker => upatch-helper}/ko/cache.h | 8 +-
.../ko/context.c | 60 ++++++-------
.../ko/context.h | 16 ++--
{upatch-hijacker => upatch-helper}/ko/ioctl.c | 82 ++++++++---------
{upatch-hijacker => upatch-helper}/ko/ioctl.h | 22 ++---
{upatch-hijacker => upatch-helper}/ko/log.h | 8 +-
{upatch-hijacker => upatch-helper}/ko/main.c | 12 +--
{upatch-hijacker => upatch-helper}/ko/map.c | 2 +-
{upatch-hijacker => upatch-helper}/ko/map.h | 8 +-
.../ko/records.c | 12 +--
.../ko/records.h | 16 ++--
.../ko/uprobe.c | 16 ++--
.../ko/uprobe.h | 8 +-
{upatch-hijacker => upatch-helper}/ko/utils.h | 8 +-
upatch-hijacker/hijacker/CMakeLists.txt | 35 --------
upatch-hijacker/ko/CMakeLists.txt | 32 -------
upatch-manage/upatch-patch.c | 4 +-
upatchd/src/config.rs | 4 +-
upatchd/src/{hijacker => helper}/config.rs | 24 ++---
.../src/{hijacker => helper}/elf_resolver.rs | 0
upatchd/src/{hijacker => helper}/ioctl.rs | 28 +++---
upatchd/src/{hijacker => helper}/kmod.rs | 8 +-
upatchd/src/{hijacker => helper}/mod.rs | 87 ++++++++++---------
upatchd/src/main.rs | 4 +-
upatchd/src/rpc/skeleton.rs | 8 +-
upatchd/src/rpc/skeleton_impl.rs | 30 +++----
40 files changed, 359 insertions(+), 354 deletions(-)
rename upatch-build/src/{hijacker.rs => helper.rs} (69%)
rename {upatch-hijacker => upatch-helper}/CMakeLists.txt (81%)
create mode 100644 upatch-helper/helper/CMakeLists.txt
rename upatch-hijacker/hijacker/gnu-as-hijacker.c => upatch-helper/helper/gnu-as-helper.c (89%)
rename upatch-hijacker/hijacker/gnu-compiler-hijacker.c => upatch-helper/helper/gnu-compiler-helper.c (85%)
rename upatch-hijacker/hijacker/hijacker.h => upatch-helper/helper/helper.h (83%)
create mode 100644 upatch-helper/ko/CMakeLists.txt
rename {upatch-hijacker => upatch-helper}/ko/LICENSE (100%)
rename {upatch-hijacker => upatch-helper}/ko/Makefile (94%)
rename {upatch-hijacker => upatch-helper}/ko/cache.c (94%)
rename {upatch-hijacker => upatch-helper}/ko/cache.h (86%)
rename {upatch-hijacker => upatch-helper}/ko/context.c (70%)
rename {upatch-hijacker => upatch-helper}/ko/context.h (73%)
rename {upatch-hijacker => upatch-helper}/ko/ioctl.c (64%)
rename {upatch-hijacker => upatch-helper}/ko/ioctl.h (69%)
rename {upatch-hijacker => upatch-helper}/ko/log.h (87%)
rename {upatch-hijacker => upatch-helper}/ko/main.c (86%)
rename {upatch-hijacker => upatch-helper}/ko/map.c (99%)
rename {upatch-hijacker => upatch-helper}/ko/map.h (90%)
rename {upatch-hijacker => upatch-helper}/ko/records.c (90%)
rename {upatch-hijacker => upatch-helper}/ko/records.h (80%)
rename {upatch-hijacker => upatch-helper}/ko/uprobe.c (89%)
rename {upatch-hijacker => upatch-helper}/ko/uprobe.h (86%)
rename {upatch-hijacker => upatch-helper}/ko/utils.h (90%)
delete mode 100644 upatch-hijacker/hijacker/CMakeLists.txt
delete mode 100644 upatch-hijacker/ko/CMakeLists.txt
rename upatchd/src/{hijacker => helper}/config.rs (70%)
rename upatchd/src/{hijacker => helper}/elf_resolver.rs (100%)
rename upatchd/src/{hijacker => helper}/ioctl.rs (80%)
rename upatchd/src/{hijacker => helper}/kmod.rs (95%)
rename upatchd/src/{hijacker => helper}/mod.rs (52%)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4858ba5..659222f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,7 +66,7 @@ set(CMAKE_EXE_LINKER_FLAGS "${LINK_FLAGS}")
# Subdirectories
add_subdirectory(upatch-diff)
add_subdirectory(upatch-manage)
-add_subdirectory(upatch-hijacker)
+add_subdirectory(upatch-helper)
add_subdirectory(misc)
# Build rust executables
diff --git a/upatch-build/src/hijacker.rs b/upatch-build/src/helper.rs
similarity index 69%
rename from upatch-build/src/hijacker.rs
rename to upatch-build/src/helper.rs
index 3060495..7ce3323 100644
--- a/upatch-build/src/hijacker.rs
+++ b/upatch-build/src/helper.rs
@@ -9,13 +9,13 @@ use crate::rpc::{RpcRemote, UpatchProxy};
const UPATCHD_SOCKET_NAME: &str = "upatchd.sock";
-pub struct Hijacker<'a> {
+pub struct UpatchHelper<'a> {
proxy: UpatchProxy,
programs: IndexSet<&'a Path>,
finished: Vec<&'a Path>,
}
-impl<'a> Hijacker<'a> {
+impl<'a> UpatchHelper<'a> {
pub fn new<I, P>(compilers: I, work_dir: P) -> Result<Self>
where
I: IntoIterator<Item = &'a Compiler>,
@@ -36,20 +36,20 @@ impl<'a> Hijacker<'a> {
programs,
finished: vec![],
};
- instance.hijack()?;
+ instance.enable()?;
Ok(instance)
}
}
-impl Hijacker<'_> {
- fn hijack(&mut self) -> Result<()> {
- info!("Hijacking compiler(s)");
+impl UpatchHelper<'_> {
+ fn enable(&mut self) -> Result<()> {
+ info!("Hooking compiler(s)");
for exec_path in &self.programs {
info!("- {}", exec_path.display());
self.proxy
- .enable_hijack(exec_path)
- .with_context(|| format!("Failed to hijack {}", exec_path.display()))?;
+ .hook_compiler(exec_path)
+ .with_context(|| format!("Failed to hook compiler {}", exec_path.display()))?;
self.finished.push(exec_path);
}
@@ -57,14 +57,13 @@ impl Hijacker<'_> {
Ok(())
}
- fn unhack(&mut self) {
- info!("Releasing compiler(s)");
+ fn disable(&mut self) {
+ info!("Unhooking compiler(s)");
while let Some(exec_path) = self.finished.pop() {
info!("- {}", exec_path.display());
- let result = self
- .proxy
- .disable_hijack(exec_path)
- .with_context(|| format!("Failed to release {}", exec_path.display()));
+ let result = self.proxy.unhook_compiler(exec_path).with_context(|| {
+ format!("Failed to unhook compiler helper {}", exec_path.display())
+ });
if let Err(e) = result {
error!("{:?}", e);
@@ -73,8 +72,8 @@ impl Hijacker<'_> {
}
}
-impl Drop for Hijacker<'_> {
+impl Drop for UpatchHelper<'_> {
fn drop(&mut self) {
- self.unhack()
+ self.disable()
}
}
diff --git a/upatch-build/src/main.rs b/upatch-build/src/main.rs
index 473b0a7..769cc6c 100644
--- a/upatch-build/src/main.rs
+++ b/upatch-build/src/main.rs
@@ -36,7 +36,7 @@ mod compiler;
mod dwarf;
mod elf;
mod file_relation;
-mod hijacker;
+mod helper;
mod pattern_path;
mod project;
mod resolve;
@@ -47,7 +47,7 @@ use build_root::BuildRoot;
use compiler::Compiler;
use dwarf::Dwarf;
use file_relation::FileRelation;
-use hijacker::Hijacker;
+use helper::UpatchHelper;
use project::Project;
const CLI_NAME: &str = "upatch build";
@@ -401,7 +401,8 @@ impl UpatchBuild {
}
let mut files = FileRelation::new();
- let hijacker = Hijacker::new(&compilers, work_dir).context("Failed to hack compilers")?;
+ let upatch_helper =
+ UpatchHelper::new(&compilers, work_dir).context("Failed to hook compilers")?;
info!("Preparing {}", project);
project
@@ -435,8 +436,8 @@ impl UpatchBuild {
info!("Collecting file relations");
files.collect_patched_build(object_dir, patched_dir)?;
- // Unhack compilers
- drop(hijacker);
+ // Restore compilers
+ drop(upatch_helper);
let build_info = BuildInfo {
linker,
diff --git a/upatch-build/src/project.rs b/upatch-build/src/project.rs
index b36c26b..8b2a7b6 100644
--- a/upatch-build/src/project.rs
+++ b/upatch-build/src/project.rs
@@ -28,7 +28,7 @@ use syscare_common::{fs, process::Command};
use crate::{args::Arguments, build_root::BuildRoot};
const PATCH_BIN: &str = "patch";
-const COMPILER_CMD_ENV: &str = "UPATCH_HIJACKER";
+const COMPILER_CMD_ENV: &str = "UPATCH_HELPER";
const PREPARE_SCRIPT_NAME: &str = "prepare.sh";
const BUILD_SCRIPT_NAME: &str = "build.sh";
diff --git a/upatch-build/src/rpc/proxy.rs b/upatch-build/src/rpc/proxy.rs
index e249fa5..f63d681 100644
--- a/upatch-build/src/rpc/proxy.rs
+++ b/upatch-build/src/rpc/proxy.rs
@@ -30,7 +30,7 @@ impl UpatchProxy {
}
#[named]
- pub fn enable_hijack<P: AsRef<Path>>(&self, exec_path: P) -> Result<()> {
+ pub fn hook_compiler<P: AsRef<Path>>(&self, exec_path: P) -> Result<()> {
self.remote.call_with_args(
function_name!(),
RpcArguments::new().arg(exec_path.as_ref().to_path_buf()),
@@ -38,7 +38,7 @@ impl UpatchProxy {
}
#[named]
- pub fn disable_hijack<P: AsRef<Path>>(&self, exec_path: P) -> Result<()> {
+ pub fn unhook_compiler<P: AsRef<Path>>(&self, exec_path: P) -> Result<()> {
self.remote.call_with_args(
function_name!(),
RpcArguments::new().arg(exec_path.as_ref().to_path_buf()),
diff --git a/upatch-hijacker/CMakeLists.txt b/upatch-helper/CMakeLists.txt
similarity index 81%
rename from upatch-hijacker/CMakeLists.txt
rename to upatch-helper/CMakeLists.txt
index 77d1010..bcd7295 100644
--- a/upatch-hijacker/CMakeLists.txt
+++ b/upatch-helper/CMakeLists.txt
@@ -3,4 +3,4 @@ include_directories(${CMAKE_CURRENT_LIST_DIR})
# Build components
add_subdirectory(ko)
-add_subdirectory(hijacker)
+add_subdirectory(helper)
diff --git a/upatch-helper/helper/CMakeLists.txt b/upatch-helper/helper/CMakeLists.txt
new file mode 100644
index 0000000..fefcebe
--- /dev/null
+++ b/upatch-helper/helper/CMakeLists.txt
@@ -0,0 +1,35 @@
+# Build helpers
+add_executable(gnu-as-helper gnu-as-helper.c)
+add_executable(gnu-compiler-helper gnu-compiler-helper.c)
+
+# Generate helpers
+add_custom_target(generate-upatch-helpers ALL
+ COMMENT "Generating upatch helpers..."
+ COMMAND ln -f gnu-as-helper as-helper
+ COMMAND ln -f gnu-compiler-helper gcc-helper
+ COMMAND ln -f gnu-compiler-helper g++-helper
+ COMMAND ln -f gnu-compiler-helper cc-helper
+ COMMAND ln -f gnu-compiler-helper c++-helper
+ DEPENDS
+ gnu-as-helper
+ gnu-compiler-helper
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+# Install helpers
+install(
+ PROGRAMS
+ ${CMAKE_CURRENT_BINARY_DIR}/gnu-as-helper
+ ${CMAKE_CURRENT_BINARY_DIR}/gnu-compiler-helper
+ ${CMAKE_CURRENT_BINARY_DIR}/as-helper
+ ${CMAKE_CURRENT_BINARY_DIR}/gcc-helper
+ ${CMAKE_CURRENT_BINARY_DIR}/g++-helper
+ ${CMAKE_CURRENT_BINARY_DIR}/cc-helper
+ ${CMAKE_CURRENT_BINARY_DIR}/c++-helper
+ PERMISSIONS
+ OWNER_EXECUTE OWNER_WRITE OWNER_READ
+ GROUP_EXECUTE GROUP_READ
+ WORLD_READ WORLD_EXECUTE
+ DESTINATION
+ ${SYSCARE_LIBEXEC_DIR}
+)
diff --git a/upatch-hijacker/hijacker/gnu-as-hijacker.c b/upatch-helper/helper/gnu-as-helper.c
similarity index 89%
rename from upatch-hijacker/hijacker/gnu-as-hijacker.c
rename to upatch-helper/helper/gnu-as-helper.c
index 886420e..05246c3 100644
--- a/upatch-hijacker/hijacker/gnu-as-hijacker.c
+++ b/upatch-helper/helper/gnu-as-helper.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Mulan PSL v2
/*
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
- * gnu-as-hijacker is licensed under Mulan PSL v2.
+ * gnu-as-helper is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
@@ -20,7 +20,7 @@
#include <sys/stat.h>
#include <sys/syscall.h>
-#include "hijacker.h"
+#include "helper.h"
#ifndef SYS_gettid
#error "SYS_gettid is unavailable on this system"
@@ -39,8 +39,8 @@ static char g_new_output_file[PATH_MAX] = { 0 };
/*
* The whole part:
* 1. Someone called execve() to run a compiler (inode).
- * 2. If the inode was registered, under layer would rewrite argv[0] to hijacker path.
- * 3. Hijacker would add some arguments and calls execve() again.
+ * 2. If the inode was registered, under layer would rewrite argv[0] to helper path.
+ * 3. Helper would add some arguments and calls execve() again.
* 4. Under layer redirects argv[0] to original path.
* Pid would keep same.
*/
@@ -53,27 +53,27 @@ int main(int argc, char *argv[], char *envp[])
return -ENOENT;
}
- // If there is no env, stop hijack
- const char *output_dir = get_hijacker_env();
+ // If there is no env, stop helper
+ const char *output_dir = get_helper_env();
if (output_dir == NULL) {
return execve(filename, argv, envp);
}
- // If output dir is not a directory, stop hijack
+ // If output dir is not a directory, stop helper
struct stat output_dir_stat;
if ((stat(output_dir, &output_dir_stat) != 0) ||
(!S_ISDIR(output_dir_stat.st_mode))) {
return execve(filename, argv, envp);
}
- // If there is no output, stop hijack
+ // If there is no output, stop helper
int output_index = find_output_flag(argc, argv);
if (output_index < 0) {
return execve(filename, argv, envp);
}
output_index += 1;
- // If the output is null device, stop hijack
+ // If the output is null device, stop helper
const char *output_file = argv[output_index];
if (strncmp(output_file, NULL_DEV_PATH, strlen(NULL_DEV_PATH)) == 0) {
return execve(filename, argv, envp);
diff --git a/upatch-hijacker/hijacker/gnu-compiler-hijacker.c b/upatch-helper/helper/gnu-compiler-helper.c
similarity index 85%
rename from upatch-hijacker/hijacker/gnu-compiler-hijacker.c
rename to upatch-helper/helper/gnu-compiler-helper.c
index d868467..507d709 100644
--- a/upatch-hijacker/hijacker/gnu-compiler-hijacker.c
+++ b/upatch-helper/helper/gnu-compiler-helper.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Mulan PSL v2
/*
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
- * gnu-compiler-hijacker is licensed under Mulan PSL v2.
+ * gnu-compiler-helper is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
@@ -14,7 +14,7 @@
#include <stdio.h>
-#include "hijacker.h"
+#include "helper.h"
static char* APPEND_ARGS[] = {
"-gdwarf", /* obatain debug information */
@@ -27,8 +27,8 @@ static const int APPEND_ARG_LEN = (int)(sizeof(APPEND_ARGS) / sizeof(char *));
/*
* The whole part:
* 1. Someone called execve() to run a compiler (inode).
- * 2. If the inode was registered, under layer would rewrite argv[0] to hijacker path.
- * 3. Hijacker would add some arguments and calls execve() again.
+ * 2. If the inode was registered, under layer would rewrite argv[0] to helper path.
+ * 3. Helper would add some arguments and calls execve() again.
* 4. Under layer redirects argv[0] to original path.
* Pid would keep same.
*/
@@ -40,13 +40,13 @@ int main(int argc, char *argv[], char *envp[])
return -ENOENT;
}
- // If there is no env, stop hijack
- const char *hijacker_env = get_hijacker_env();
- if (hijacker_env == NULL) {
+ // If there is no env, stop helper
+ const char *helper_env = get_helper_env();
+ if (helper_env == NULL) {
return execve(filename, argv, envp);
}
- // If there is no output, stop hijack
+ // If there is no output, stop helper
if (find_output_flag(argc, argv) < 0) {
return execve(filename, argv, envp);
}
diff --git a/upatch-hijacker/hijacker/hijacker.h b/upatch-helper/helper/helper.h
similarity index 83%
rename from upatch-hijacker/hijacker/hijacker.h
rename to upatch-helper/helper/helper.h
index cc820ee..67a895c 100644
--- a/upatch-hijacker/hijacker/hijacker.h
+++ b/upatch-helper/helper/helper.h
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Mulan PSL v2
/*
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
- * gnu-compiler-hijacker is licensed under Mulan PSL v2.
+ * gnu-compiler-helper is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
@@ -12,8 +12,8 @@
* See the Mulan PSL v2 for more details.
*/
-#ifndef __UPATCH_HIJACKER_COMMON_H
-#define __UPATCH_HIJACKER_COMMON_H
+#ifndef __UPATCH_HELPER_COMMON_H
+#define __UPATCH_HELPER_COMMON_H
#include <errno.h>
#include <stdlib.h>
@@ -22,7 +22,7 @@
#include <linux/limits.h>
-static const char *UPATCH_ENV_NAME = "UPATCH_HIJACKER";
+static const char *UPATCH_ENV_NAME = "UPATCH_HELPER";
static const char *EXEC_SELF_PATH = "/proc/self/exe";
static const char *OUTPUT_FLAG_NAME = "-o";
@@ -39,7 +39,7 @@ static inline char* get_current_exec(void)
return (char *)g_filename;
}
-static inline const char* get_hijacker_env(void)
+static inline const char* get_helper_env(void)
{
return getenv(UPATCH_ENV_NAME);
}
@@ -58,4 +58,4 @@ static inline int find_output_flag(int argc, char* const argv[])
return -EINVAL;
}
-#endif /* __UPATCH_HIJACKER_COMMON_H */
+#endif /* __UPATCH_HELPER_COMMON_H */
diff --git a/upatch-helper/ko/CMakeLists.txt b/upatch-helper/ko/CMakeLists.txt
new file mode 100644
index 0000000..2a5b980
--- /dev/null
+++ b/upatch-helper/ko/CMakeLists.txt
@@ -0,0 +1,32 @@
+# Build upatch-helper kernel module
+
+# Set target
+set(UPATCH_HELPER_KMOD "upatch_helper.ko")
+
+# Detect kernel source path
+if (DEFINED KERNEL_VERSION)
+ set(KERNEL_SOURCE_PATH "/lib/modules/${KERNEL_VERSION}/build")
+ set(UPATCH_HELPER_KMOD_BUILD_CMD make module_version=${BUILD_VERSION} kernel=${KERNEL_SOURCE_PATH})
+else()
+ set(UPATCH_HELPER_KMOD_BUILD_CMD make module_version=${BUILD_VERSION})
+endif()
+
+# Build kernel module
+add_custom_target(upatch-helper-kmod ALL
+ COMMENT "Building kernel module upatch_helper..."
+ BYPRODUCTS ${UPATCH_HELPER_KMOD}
+ COMMAND ${UPATCH_HELPER_KMOD_BUILD_CMD}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+# Install kernel module
+install(
+ FILES
+ ${UPATCH_HELPER_KMOD}
+ PERMISSIONS
+ OWNER_WRITE OWNER_READ
+ GROUP_READ
+ WORLD_READ
+ DESTINATION
+ ${SYSCARE_LIBEXEC_DIR}
+)
diff --git a/upatch-hijacker/ko/LICENSE b/upatch-helper/ko/LICENSE
similarity index 100%
rename from upatch-hijacker/ko/LICENSE
rename to upatch-helper/ko/LICENSE
diff --git a/upatch-hijacker/ko/Makefile b/upatch-helper/ko/Makefile
similarity index 94%
rename from upatch-hijacker/ko/Makefile
rename to upatch-helper/ko/Makefile
index ebf6314..6ea3b72 100644
--- a/upatch-hijacker/ko/Makefile
+++ b/upatch-helper/ko/Makefile
@@ -1,4 +1,4 @@
-module_name ?= upatch_hijacker
+module_name ?= upatch_helper
module_version ?= "1.0-dev"
kernel ?= /lib/modules/$(shell uname -r)/build
diff --git a/upatch-hijacker/ko/cache.c b/upatch-helper/ko/cache.c
similarity index 94%
rename from upatch-hijacker/ko/cache.c
rename to upatch-helper/ko/cache.c
index b5af6bf..4a5994f 100644
--- a/upatch-hijacker/ko/cache.c
+++ b/upatch-helper/ko/cache.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -24,7 +24,7 @@
#include "log.h"
-static const char *CACHE_SLAB_NAME = "upatch_hijacker";
+static const char *CACHE_SLAB_NAME = "upatch_helper";
static struct kmem_cache *g_path_cache = NULL;
diff --git a/upatch-hijacker/ko/cache.h b/upatch-helper/ko/cache.h
similarity index 86%
rename from upatch-hijacker/ko/cache.h
rename to upatch-helper/ko/cache.h
index e26a49c..b9bdcc4 100644
--- a/upatch-hijacker/ko/cache.h
+++ b/upatch-helper/ko/cache.h
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -18,8 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef _UPATCH_HIJACKER_KO_CACHE_H
-#define _UPATCH_HIJACKER_KO_CACHE_H
+#ifndef _UPATCH_HELPER_KO_CACHE_H
+#define _UPATCH_HELPER_KO_CACHE_H
int cache_init(void);
void cache_exit(void);
@@ -27,4 +27,4 @@ void cache_exit(void);
char *path_buf_alloc(void);
void path_buf_free(char *buff);
-#endif /* _UPATCH_HIJACKER_KO_CACHE_H */
+#endif /* _UPATCH_HELPER_KO_CACHE_H */
diff --git a/upatch-hijacker/ko/context.c b/upatch-helper/ko/context.c
similarity index 70%
rename from upatch-hijacker/ko/context.c
rename to upatch-helper/ko/context.c
index 2e406f4..3a6c920 100644
--- a/upatch-hijacker/ko/context.c
+++ b/upatch-helper/ko/context.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -34,34 +34,34 @@
struct context {
struct pid_namespace *ns;
struct uprobe_record *uprobe;
- struct map *hijacker_map;
+ struct map *helper_map;
};
-static bool find_hijacker_context(const struct context *context,
+static bool find_helper_context(const struct context *context,
const struct pid_namespace *ns);
-static void free_hijacker_context(struct context *context);
+static void free_helper_context(struct context *context);
-static const struct map_ops HIJACK_MAP_OPS = {
- .find_value = (find_value_fn)find_hijacker_record,
- .free_value = (free_value_fn)free_hijacker_record,
+static const struct map_ops HELPER_MAP_OPS = {
+ .find_value = (find_value_fn)find_helper_record,
+ .free_value = (free_value_fn)free_helper_record,
};
static const struct map_ops CONTEXT_MAP_OPS = {
- .find_value = (find_value_fn)find_hijacker_context,
- .free_value = (free_value_fn)free_hijacker_context,
+ .find_value = (find_value_fn)find_helper_context,
+ .free_value = (free_value_fn)free_helper_context,
};
static const size_t MAX_CONTEXT_NUM = 1024;
-static const size_t HIJACKER_PER_CONTEXT = 16;
+static const size_t HELPER_PER_CONTEXT = 16;
static struct map *g_context_map = NULL;
/* Context private interface */
-static int create_hijacker_context(struct context **context,
+static int create_helper_context(struct context **context,
struct pid_namespace *ns, const char *path, loff_t offset)
{
struct context *new_context = NULL;
struct uprobe_record *uprobe = NULL;
- struct map *hijacker_map = NULL;
+ struct map *helper_map = NULL;
int ret = 0;
new_context = kzalloc(sizeof(struct context), GFP_KERNEL);
@@ -70,9 +70,9 @@ static int create_hijacker_context(struct context **context,
return -ENOMEM;
}
- ret = new_map(&hijacker_map, HIJACKER_PER_CONTEXT, &HIJACK_MAP_OPS);
+ ret = new_map(&helper_map, HELPER_PER_CONTEXT, &HELPER_MAP_OPS);
if (ret != 0) {
- pr_err("failed to create hijacker map, ret=%d\n", ret);
+ pr_err("failed to create helper map, ret=%d\n", ret);
kfree(new_context);
return ret;
}
@@ -80,7 +80,7 @@ static int create_hijacker_context(struct context **context,
ret = new_uprobe_record(&uprobe, handle_uprobe, path, offset);
if (ret != 0) {
pr_err("failed to create uprobe record, ret=%d\n", ret);
- free_map(hijacker_map);
+ free_map(helper_map);
kfree(new_context);
return ret;
}
@@ -90,20 +90,20 @@ static int create_hijacker_context(struct context **context,
pr_err("failed to register uprobe, inode=%lu, offset=0x%llx, ret=%d\n",
uprobe->inode->i_ino, uprobe->offset, ret);
free_uprobe_record(uprobe);
- free_map(hijacker_map);
+ free_map(helper_map);
kfree(new_context);
return ret;
}
new_context->ns = get_pid_ns(ns);
new_context->uprobe = uprobe;
- new_context->hijacker_map = hijacker_map;
+ new_context->helper_map = helper_map;
*context = new_context;
return 0;
}
-static void free_hijacker_context(struct context *context)
+static void free_helper_context(struct context *context)
{
if (context == NULL) {
return;
@@ -114,11 +114,11 @@ static void free_hijacker_context(struct context *context)
put_pid_ns(context->ns);
free_uprobe_record(context->uprobe);
- free_map(context->hijacker_map);
+ free_map(context->helper_map);
kfree(context);
}
-static bool find_hijacker_context(const struct context *context,
+static bool find_helper_context(const struct context *context,
const struct pid_namespace *ns)
{
return ns_equal(context->ns, ns);
@@ -143,7 +143,7 @@ void context_exit(void)
free_map(g_context_map);
}
-int build_hijacker_context(const char *path, loff_t offset)
+int build_helper_context(const char *path, loff_t offset)
{
struct pid_namespace *ns = task_active_pid_ns(current);
struct context *context = NULL;
@@ -153,37 +153,37 @@ int build_hijacker_context(const char *path, loff_t offset)
return -EINVAL;
}
- ret = create_hijacker_context(&context, ns, path, offset);
+ ret = create_helper_context(&context, ns, path, offset);
if (ret != 0) {
- pr_err("failed to create hijacker context, ret=%d\n", ret);
+ pr_err("failed to create helper context, ret=%d\n", ret);
return ret;
}
- pr_debug("hijacker context, addr=0x%lx\n", (unsigned long)context);
+ pr_debug("helper context, addr=0x%lx\n", (unsigned long)context);
ret = map_insert(g_context_map, context);
if (ret != 0) {
- pr_err("failed to register hijacker context, ret=%d\n", ret);
+ pr_err("failed to register helper context, ret=%d\n", ret);
return ret;
}
return 0;
}
-void destroy_hijacker_context(void)
+void destroy_helper_context(void)
{
- pr_debug("destroy hijacker context\n");
+ pr_debug("destroy helper context\n");
map_remove(g_context_map, task_active_pid_ns(current));
}
-size_t hijacker_context_count(void)
+size_t helper_context_count(void)
{
return map_size(g_context_map);
}
-struct map *get_hijacker_map(void)
+struct map *get_helper_map(void)
{
struct pid_namespace *ns = task_active_pid_ns(current);
struct context *context = (struct context *)map_get(g_context_map, ns);
- return (context != NULL) ? context->hijacker_map : NULL;
+ return (context != NULL) ? context->helper_map : NULL;
}
diff --git a/upatch-hijacker/ko/context.h b/upatch-helper/ko/context.h
similarity index 73%
rename from upatch-hijacker/ko/context.h
rename to upatch-helper/ko/context.h
index 6b5a50f..2054b75 100644
--- a/upatch-hijacker/ko/context.h
+++ b/upatch-helper/ko/context.h
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -18,8 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef _UPATCH_HIJACKER_KO_CONTEXT_H
-#define _UPATCH_HIJACKER_KO_CONTEXT_H
+#ifndef _UPATCH_HELPER_KO_CONTEXT_H
+#define _UPATCH_HELPER_KO_CONTEXT_H
#include <linux/types.h>
@@ -28,10 +28,10 @@ struct map;
int context_init(void);
void context_exit(void);
-int build_hijacker_context(const char *path, loff_t offset);
-void destroy_hijacker_context(void);
-size_t hijacker_context_count(void);
+int build_helper_context(const char *path, loff_t offset);
+void destroy_helper_context(void);
+size_t helper_context_count(void);
-struct map *get_hijacker_map(void);
+struct map *get_helper_map(void);
-#endif /* _UPATCH_HIJACKER_KO_CONTEXT_H */
+#endif /* _UPATCH_HELPER_KO_CONTEXT_H */
diff --git a/upatch-hijacker/ko/ioctl.c b/upatch-helper/ko/ioctl.c
similarity index 64%
rename from upatch-hijacker/ko/ioctl.c
rename to upatch-helper/ko/ioctl.c
index f76b5fb..500e7d4 100644
--- a/upatch-hijacker/ko/ioctl.c
+++ b/upatch-helper/ko/ioctl.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -32,19 +32,19 @@
#include "context.h"
#include "utils.h"
-static const struct file_operations HIJACKER_DEV_FOPS = {
+static const struct file_operations HELPER_DEV_FOPS = {
.owner = THIS_MODULE,
.unlocked_ioctl = handle_ioctl,
};
-static struct miscdevice g_hijacker_dev = {
+static struct miscdevice g_helper_dev = {
.minor = MISC_DYNAMIC_MINOR,
- .mode = UPATCH_HIJACKER_DEV_MODE,
- .name = UPATCH_HIJACKER_DEV_NAME,
- .fops = &HIJACKER_DEV_FOPS,
+ .mode = UPATCH_HELPER_DEV_MODE,
+ .name = UPATCH_HELPER_DEV_NAME,
+ .fops = &HELPER_DEV_FOPS,
};
-static inline int handle_enable_hijacker(void __user *arg)
+static inline int handle_enable_helper(void __user *arg)
{
int ret = 0;
upatch_enable_request_t *msg = NULL;
@@ -62,10 +62,10 @@ static inline int handle_enable_hijacker(void __user *arg)
return -EFAULT;
}
- pr_debug("enable hijacker, path=%s, offset=0x%llx\n", msg->path, msg->offset);
- ret = build_hijacker_context(msg->path, msg->offset);
+ pr_debug("enable helper, path=%s, offset=0x%llx\n", msg->path, msg->offset);
+ ret = build_helper_context(msg->path, msg->offset);
if (ret != 0) {
- pr_err("failed to build hijacker context, ret=%d\n", ret);
+ pr_err("failed to build helper context, ret=%d\n", ret);
kfree(msg);
}
@@ -73,21 +73,21 @@ static inline int handle_enable_hijacker(void __user *arg)
return 0;
}
-static inline void handle_disable_hijacker(void)
+static inline void handle_disable_helper(void)
{
- pr_debug("disable hijacker\n");
- destroy_hijacker_context();
+ pr_debug("disable helper\n");
+ destroy_helper_context();
}
-static inline int handle_register_hijacker(void __user *arg)
+static inline int handle_register_helper(void __user *arg)
{
upatch_register_request_t *msg = NULL;
- struct map *hijacker_map = get_hijacker_map();
- struct hijacker_record *record = NULL;
+ struct map *helper_map = get_helper_map();
+ struct helper_record *record = NULL;
int ret = 0;
- if (hijacker_map == NULL) {
- pr_err("failed to get hijacker map\n");
+ if (helper_map == NULL) {
+ pr_err("failed to get helper map\n");
return -EFAULT;
}
@@ -104,21 +104,21 @@ static inline int handle_register_hijacker(void __user *arg)
return -EFAULT;
}
- ret = create_hijacker_record(&record, msg->exec_path, msg->jump_path);
+ ret = create_helper_record(&record, msg->exec_path, msg->jump_path);
if (ret != 0) {
- pr_err("failed to create hijacker record [%s -> %s], ret=%d\n",
+ pr_err("failed to create helper record [%s -> %s], ret=%d\n",
msg->exec_path, msg->jump_path, ret);
kfree(msg);
return ret;
}
- pr_debug("register hijacker, inode=%lu, addr=0x%lx\n",
+ pr_debug("register helper, inode=%lu, addr=0x%lx\n",
record->exec_inode->i_ino, (unsigned long)record);
- ret = map_insert(get_hijacker_map(), record);
+ ret = map_insert(get_helper_map(), record);
if (ret != 0) {
- pr_err("failed to register hijacker record [%s -> %s], ret=%d\n",
+ pr_err("failed to register helper record [%s -> %s], ret=%d\n",
msg->exec_path, msg->jump_path, ret);
- free_hijacker_record(record);
+ free_helper_record(record);
kfree(msg);
return ret;
}
@@ -127,16 +127,16 @@ static inline int handle_register_hijacker(void __user *arg)
return 0;
}
-static inline int handle_unregister_hijacker(void __user *arg)
+static inline int handle_unregister_helper(void __user *arg)
{
upatch_register_request_t *msg = NULL;
- struct map *hijacker_map = get_hijacker_map();
+ struct map *helper_map = get_helper_map();
struct inode *inode = NULL;
int ret = 0;
- if (hijacker_map == NULL) {
- pr_err("failed to get hijacker map\n");
+ if (helper_map == NULL) {
+ pr_err("failed to get helper map\n");
return -EFAULT;
}
@@ -161,8 +161,8 @@ static inline int handle_unregister_hijacker(void __user *arg)
return -ENOENT;
}
- pr_debug("remove hijacker, inode=%lu\n", inode->i_ino);
- map_remove(hijacker_map, inode);
+ pr_debug("remove helper, inode=%lu\n", inode->i_ino);
+ map_remove(helper_map, inode);
kfree(msg);
return 0;
@@ -172,7 +172,7 @@ int ioctl_init(void)
{
int ret = 0;
- ret = misc_register(&g_hijacker_dev);
+ ret = misc_register(&g_helper_dev);
if (ret != 0) {
pr_err("failed to register misc device, ret=%d\n", ret);
}
@@ -182,7 +182,7 @@ int ioctl_init(void)
void ioctl_exit(void)
{
- misc_deregister(&g_hijacker_dev);
+ misc_deregister(&g_helper_dev);
}
long handle_ioctl(struct file *file,
@@ -190,23 +190,23 @@ long handle_ioctl(struct file *file,
{
int ret = 0;
- if (_IOC_TYPE(cmd) != UPATCH_HIJACKER_IOC_MAGIC) {
+ if (_IOC_TYPE(cmd) != UPATCH_HELPER_IOC_MAGIC) {
pr_info("invalid command\n");
return -EBADMSG;
}
switch (cmd) {
- case UPATCH_HIJACKER_ENABLE:
- ret = handle_enable_hijacker((void __user *)arg);
+ case UPATCH_HELPER_ENABLE:
+ ret = handle_enable_helper((void __user *)arg);
break;
- case UPATCH_HIJACKER_DISABLE:
- handle_disable_hijacker();
+ case UPATCH_HELPER_DISABLE:
+ handle_disable_helper();
break;
- case UPATCH_HIJACKER_REGISTER:
- ret = handle_register_hijacker((void __user *)arg);
+ case UPATCH_HELPER_REGISTER:
+ ret = handle_register_helper((void __user *)arg);
break;
- case UPATCH_HIJACKER_UNREGISTER:
- ret = handle_unregister_hijacker((void __user *)arg);
+ case UPATCH_HELPER_UNREGISTER:
+ ret = handle_unregister_helper((void __user *)arg);
break;
default:
ret = -EBADMSG;
diff --git a/upatch-hijacker/ko/ioctl.h b/upatch-helper/ko/ioctl.h
similarity index 69%
rename from upatch-hijacker/ko/ioctl.h
rename to upatch-helper/ko/ioctl.h
index dbcd12e..fd49961 100644
--- a/upatch-hijacker/ko/ioctl.h
+++ b/upatch-helper/ko/ioctl.h
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -18,22 +18,22 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef _UPATCH_HIJACKER_KO_IOCTL_H
-#define _UPATCH_HIJACKER_KO_IOCTL_H
+#ifndef _UPATCH_HELPER_KO_IOCTL_H
+#define _UPATCH_HELPER_KO_IOCTL_H
#include <linux/types.h>
#include <linux/limits.h>
-#define UPATCH_HIJACKER_DEV_NAME "upatch-hijacker"
-#define UPATCH_HIJACKER_DEV_MODE 0600
+#define UPATCH_HELPER_DEV_NAME "upatch-helper"
+#define UPATCH_HELPER_DEV_MODE 0600
-#define UPATCH_HIJACKER_IOC_MAGIC 0xE5
-#define UPATCH_HIJACKER_ENABLE _IOW(UPATCH_HIJACKER_IOC_MAGIC, 0x1, \
+#define UPATCH_HELPER_IOC_MAGIC 0xE5
+#define UPATCH_HELPER_ENABLE _IOW(UPATCH_HELPER_IOC_MAGIC, 0x1, \
upatch_enable_request_t)
-#define UPATCH_HIJACKER_DISABLE _IO(UPATCH_HIJACKER_IOC_MAGIC, 0x2)
-#define UPATCH_HIJACKER_REGISTER _IOW(UPATCH_HIJACKER_IOC_MAGIC, 0x3, \
+#define UPATCH_HELPER_DISABLE _IO(UPATCH_HELPER_IOC_MAGIC, 0x2)
+#define UPATCH_HELPER_REGISTER _IOW(UPATCH_HELPER_IOC_MAGIC, 0x3, \
upatch_register_request_t)
-#define UPATCH_HIJACKER_UNREGISTER _IOW(UPATCH_HIJACKER_IOC_MAGIC, 0x4, \
+#define UPATCH_HELPER_UNREGISTER _IOW(UPATCH_HELPER_IOC_MAGIC, 0x4, \
upatch_register_request_t)
typedef struct {
@@ -52,4 +52,4 @@ int ioctl_init(void);
void ioctl_exit(void);
long handle_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
-#endif /* _UPATCH_HIJACKER_KO_IOCTL_H */
+#endif /* _UPATCH_HELPER_KO_IOCTL_H */
diff --git a/upatch-hijacker/ko/log.h b/upatch-helper/ko/log.h
similarity index 87%
rename from upatch-hijacker/ko/log.h
rename to upatch-helper/ko/log.h
index 2aede01..5341d10 100644
--- a/upatch-hijacker/ko/log.h
+++ b/upatch-helper/ko/log.h
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -18,8 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef _UPATCH_HIJACKER_KO_LOG_H
-#define _UPATCH_HIJACKER_KO_LOG_H
+#ifndef _UPATCH_HELPER_KO_LOG_H
+#define _UPATCH_HELPER_KO_LOG_H
#include <linux/module.h>
#include <linux/printk.h>
@@ -30,4 +30,4 @@
#define pr_fmt(fmt) "%s: " fmt, THIS_MODULE->name
-#endif /* _UPATCH_HIJACKER_KO_LOG_H */
+#endif /* _UPATCH_HELPER_KO_LOG_H */
diff --git a/upatch-hijacker/ko/main.c b/upatch-helper/ko/main.c
similarity index 86%
rename from upatch-hijacker/ko/main.c
rename to upatch-helper/ko/main.c
index e14796e..52f0b86 100644
--- a/upatch-hijacker/ko/main.c
+++ b/upatch-helper/ko/main.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -26,7 +26,7 @@
#include "context.h"
#include "ioctl.h"
-static int __init upatch_hijacker_init(void)
+static int __init upatch_helper_init(void)
{
int ret = 0;
@@ -52,17 +52,17 @@ static int __init upatch_hijacker_init(void)
return 0;
}
-static void __exit upatch_hijacker_exit(void)
+static void __exit upatch_helper_exit(void)
{
ioctl_exit();
cache_exit();
context_exit();
}
-module_init(upatch_hijacker_init);
-module_exit(upatch_hijacker_exit);
+module_init(upatch_helper_init);
+module_exit(upatch_helper_exit);
MODULE_AUTHOR("renoseven (dev@renoseven.net)");
-MODULE_DESCRIPTION("upatch compiler hijacker");
+MODULE_DESCRIPTION("upatch compiler helper");
MODULE_LICENSE("GPL");
MODULE_VERSION(BUILD_VERSION);
diff --git a/upatch-hijacker/ko/map.c b/upatch-helper/ko/map.c
similarity index 99%
rename from upatch-hijacker/ko/map.c
rename to upatch-helper/ko/map.c
index 3049556..7771e8c 100644
--- a/upatch-hijacker/ko/map.c
+++ b/upatch-helper/ko/map.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
diff --git a/upatch-hijacker/ko/map.h b/upatch-helper/ko/map.h
similarity index 90%
rename from upatch-hijacker/ko/map.h
rename to upatch-helper/ko/map.h
index 37b522b..0e5a790 100644
--- a/upatch-hijacker/ko/map.h
+++ b/upatch-helper/ko/map.h
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -18,8 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef _UPATCH_HIJACKER_KO_MAP_H
-#define _UPATCH_HIJACKER_KO_MAP_H
+#ifndef _UPATCH_HELPER_KO_MAP_H
+#define _UPATCH_HELPER_KO_MAP_H
#include <linux/types.h>
@@ -40,4 +40,4 @@ void map_remove(struct map *map, const void *param);
void *map_get(struct map *map, const void *param);
size_t map_size(const struct map *map);
-#endif /* _UPATCH_HIJACKER_KO_MAP_H */
+#endif /* _UPATCH_HELPER_KO_MAP_H */
diff --git a/upatch-hijacker/ko/records.c b/upatch-helper/ko/records.c
similarity index 90%
rename from upatch-hijacker/ko/records.c
rename to upatch-helper/ko/records.c
index ef1e3fd..079240d 100644
--- a/upatch-hijacker/ko/records.c
+++ b/upatch-helper/ko/records.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -76,10 +76,10 @@ void free_uprobe_record(struct uprobe_record *record)
kfree(record);
}
-int create_hijacker_record(struct hijacker_record **record,
+int create_helper_record(struct helper_record **record,
const char *exec_path, const char *jump_path)
{
- struct hijacker_record *new_record = NULL;
+ struct helper_record *new_record = NULL;
struct inode *exec_inode = NULL;
struct inode *jump_inode = NULL;
@@ -99,7 +99,7 @@ int create_hijacker_record(struct hijacker_record **record,
return -ENOENT;
}
- new_record = kzalloc(sizeof(struct hijacker_record), GFP_KERNEL);
+ new_record = kzalloc(sizeof(struct helper_record), GFP_KERNEL);
if (record == NULL) {
return -ENOMEM;
}
@@ -113,7 +113,7 @@ int create_hijacker_record(struct hijacker_record **record,
return 0;
}
-void free_hijacker_record(struct hijacker_record *record)
+void free_helper_record(struct helper_record *record)
{
if (record == NULL) {
return;
@@ -124,7 +124,7 @@ void free_hijacker_record(struct hijacker_record *record)
kfree(record);
}
-bool find_hijacker_record(const struct hijacker_record *record,
+bool find_helper_record(const struct helper_record *record,
const struct inode *inode)
{
return (inode_equal(record->exec_inode, inode) ||
diff --git a/upatch-hijacker/ko/records.h b/upatch-helper/ko/records.h
similarity index 80%
rename from upatch-hijacker/ko/records.h
rename to upatch-helper/ko/records.h
index 759ed5e..e9c8553 100644
--- a/upatch-hijacker/ko/records.h
+++ b/upatch-helper/ko/records.h
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -18,8 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef _UPATCH_HIJACKER_KO_ENTITY_H
-#define _UPATCH_HIJACKER_KO_ENTITY_H
+#ifndef _UPATCH_HELPER_KO_ENTITY_H
+#define _UPATCH_HELPER_KO_ENTITY_H
#include <linux/types.h>
#include <linux/limits.h>
@@ -36,7 +36,7 @@ struct uprobe_record {
struct uprobe_consumer *uc;
};
-struct hijacker_record {
+struct helper_record {
struct inode *exec_inode;
struct inode *jump_inode;
char exec_path[PATH_MAX];
@@ -47,10 +47,10 @@ int new_uprobe_record(struct uprobe_record **record,
uprobe_handler handler, const char *path, loff_t offset);
void free_uprobe_record(struct uprobe_record *record);
-int create_hijacker_record(struct hijacker_record **record,
+int create_helper_record(struct helper_record **record,
const char *exec_path, const char *jump_path);
-void free_hijacker_record(struct hijacker_record *record);
-bool find_hijacker_record(const struct hijacker_record *record,
+void free_helper_record(struct helper_record *record);
+bool find_helper_record(const struct helper_record *record,
const struct inode *inode);
-#endif /* _UPATCH_HIJACKER_KO_ENTITY_H */
+#endif /* _UPATCH_HELPER_KO_ENTITY_H */
diff --git a/upatch-hijacker/ko/uprobe.c b/upatch-helper/ko/uprobe.c
similarity index 89%
rename from upatch-hijacker/ko/uprobe.c
rename to upatch-helper/ko/uprobe.c
index bc3c639..ab3513c 100644
--- a/upatch-hijacker/ko/uprobe.c
+++ b/upatch-helper/ko/uprobe.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -74,7 +74,7 @@ static inline const char __user *new_user_str(const char *src, size_t len)
return (const char __user *)addr;
}
-static inline const char *select_jump_path(const struct hijacker_record *record,
+static inline const char *select_jump_path(const struct helper_record *record,
const struct inode *inode)
{
if (inode_equal(inode, record->exec_inode)) {
@@ -92,8 +92,8 @@ int handle_uprobe(struct uprobe_consumer *self, struct pt_regs *regs)
const char __user *argv0 = (const char __user *)_reg_argv0;
const char __user *new_argv0 = NULL;
- struct map *hijacker_map = get_hijacker_map();
- const struct hijacker_record *record = NULL;
+ struct map *helper_map = get_helper_map();
+ const struct helper_record *record = NULL;
const char *elf_path = NULL;
const char *jump_path = NULL;
@@ -102,11 +102,11 @@ int handle_uprobe(struct uprobe_consumer *self, struct pt_regs *regs)
char *path_buff = NULL;
size_t path_len = 0;
- if ((argv0 == NULL) || (hijacker_context_count() == 0)) {
+ if ((argv0 == NULL) || (helper_context_count() == 0)) {
return 0;
}
- if (map_size(hijacker_map) == 0) {
+ if (map_size(helper_map) == 0) {
return 0;
}
@@ -129,7 +129,7 @@ int handle_uprobe(struct uprobe_consumer *self, struct pt_regs *regs)
return 0;
}
- record = (const struct hijacker_record *)map_get(hijacker_map, inode);
+ record = (const struct helper_record *)map_get(helper_map, inode);
if (record == NULL) {
pr_debug("record not found, elf_path=%s\n", elf_path);
path_buf_free(path_buff);
@@ -143,7 +143,7 @@ int handle_uprobe(struct uprobe_consumer *self, struct pt_regs *regs)
return 0;
}
path_len = strnlen(jump_path, PATH_MAX) + 1;
- pr_debug("[hijacked] elf_path=%s, jump_path=%s\n", elf_path, jump_path);
+ pr_debug("[helped] elf_path=%s, jump_path=%s\n", elf_path, jump_path);
new_argv0 = new_user_str(jump_path, path_len);
if (new_argv0 == NULL) {
diff --git a/upatch-hijacker/ko/uprobe.h b/upatch-helper/ko/uprobe.h
similarity index 86%
rename from upatch-hijacker/ko/uprobe.h
rename to upatch-helper/ko/uprobe.h
index 06564d5..39bc11d 100644
--- a/upatch-hijacker/ko/uprobe.h
+++ b/upatch-helper/ko/uprobe.h
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -18,8 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef _UPATCH_HIJACKER_KO_UPROBE_H
-#define _UPATCH_HIJACKER_KO_UPROBE_H
+#ifndef _UPATCH_HELPER_KO_UPROBE_H
+#define _UPATCH_HELPER_KO_UPROBE_H
#include <linux/types.h>
@@ -28,4 +28,4 @@ struct pt_regs;
int handle_uprobe(struct uprobe_consumer *self, struct pt_regs *regs);
-#endif /* _UPATCH_HIJACKER_KO_UPROBE_H */
+#endif /* _UPATCH_HELPER_KO_UPROBE_H */
diff --git a/upatch-hijacker/ko/utils.h b/upatch-helper/ko/utils.h
similarity index 90%
rename from upatch-hijacker/ko/utils.h
rename to upatch-helper/ko/utils.h
index 5e2f7ed..2add3e6 100644
--- a/upatch-hijacker/ko/utils.h
+++ b/upatch-helper/ko/utils.h
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * upatch-hijacker kernel module
+ * upatch-helper kernel module
* Copyright (C) 2024 Huawei Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -18,8 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef _UPATCH_HIJACKER_KO_UTILS_H
-#define _UPATCH_HIJACKER_KO_UTILS_H
+#ifndef _UPATCH_HELPER_KO_UTILS_H
+#define _UPATCH_HELPER_KO_UTILS_H
#include <linux/fs.h>
#include <linux/namei.h>
@@ -47,4 +47,4 @@ static inline bool ns_equal(const struct pid_namespace *lhs,
return (lhs->ns.inum == rhs->ns.inum);
}
-#endif /* _UPATCH_HIJACKER_KO_UTILS_H */
+#endif /* _UPATCH_HELPER_KO_UTILS_H */
diff --git a/upatch-hijacker/hijacker/CMakeLists.txt b/upatch-hijacker/hijacker/CMakeLists.txt
deleted file mode 100644
index e42ffb3..0000000
--- a/upatch-hijacker/hijacker/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-# Build hijackers
-add_executable(gnu-as-hijacker gnu-as-hijacker.c)
-add_executable(gnu-compiler-hijacker gnu-compiler-hijacker.c)
-
-# Generate hijackers
-add_custom_target(generate-upatch-hijackers ALL
- COMMENT "Generating upatch hijackers..."
- COMMAND ln -f gnu-as-hijacker as-hijacker
- COMMAND ln -f gnu-compiler-hijacker gcc-hijacker
- COMMAND ln -f gnu-compiler-hijacker g++-hijacker
- COMMAND ln -f gnu-compiler-hijacker cc-hijacker
- COMMAND ln -f gnu-compiler-hijacker c++-hijacker
- DEPENDS
- gnu-as-hijacker
- gnu-compiler-hijacker
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-)
-
-# Install hijackers
-install(
- PROGRAMS
- ${CMAKE_CURRENT_BINARY_DIR}/gnu-as-hijacker
- ${CMAKE_CURRENT_BINARY_DIR}/gnu-compiler-hijacker
- ${CMAKE_CURRENT_BINARY_DIR}/as-hijacker
- ${CMAKE_CURRENT_BINARY_DIR}/gcc-hijacker
- ${CMAKE_CURRENT_BINARY_DIR}/g++-hijacker
- ${CMAKE_CURRENT_BINARY_DIR}/cc-hijacker
- ${CMAKE_CURRENT_BINARY_DIR}/c++-hijacker
- PERMISSIONS
- OWNER_EXECUTE OWNER_WRITE OWNER_READ
- GROUP_EXECUTE GROUP_READ
- WORLD_READ WORLD_EXECUTE
- DESTINATION
- ${SYSCARE_LIBEXEC_DIR}
-)
diff --git a/upatch-hijacker/ko/CMakeLists.txt b/upatch-hijacker/ko/CMakeLists.txt
deleted file mode 100644
index 9d3c67c..0000000
--- a/upatch-hijacker/ko/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-# Build upatch-hijacker kernel module
-
-# Set target
-set(UPATCH_HIJACKER_KMOD "upatch_hijacker.ko")
-
-# Detect kernel source path
-if (DEFINED KERNEL_VERSION)
- set(KERNEL_SOURCE_PATH "/lib/modules/${KERNEL_VERSION}/build")
- set(UPATCH_HIJACKER_KMOD_BUILD_CMD make module_version=${BUILD_VERSION} kernel=${KERNEL_SOURCE_PATH})
-else()
- set(UPATCH_HIJACKER_KMOD_BUILD_CMD make module_version=${BUILD_VERSION})
-endif()
-
-# Build kernel module
-add_custom_target(upatch-hijacker-kmod ALL
- COMMENT "Building kernel module upatch-hijacker..."
- BYPRODUCTS ${UPATCH_HIJACKER_KMOD}
- COMMAND ${UPATCH_HIJACKER_KMOD_BUILD_CMD}
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-)
-
-# Install kernel module
-install(
- FILES
- ${UPATCH_HIJACKER_KMOD}
- PERMISSIONS
- OWNER_WRITE OWNER_READ
- GROUP_READ
- WORLD_READ
- DESTINATION
- ${SYSCARE_LIBEXEC_DIR}
-)
diff --git a/upatch-manage/upatch-patch.c b/upatch-manage/upatch-patch.c
index cbdbbe1..8a1ad41 100644
--- a/upatch-manage/upatch-patch.c
+++ b/upatch-manage/upatch-patch.c
@@ -730,7 +730,7 @@ int process_patch(int pid, struct upatch_elf *uelf, struct running_elf *relf, co
goto out_free;
}
- // use uprobe to hack function. the program has been executed to the entry
+ // use uprobe to interpose function. the program has been executed to the entry
// point
/*
@@ -850,7 +850,7 @@ int process_unpatch(int pid, const char *uuid)
goto out_free;
}
- // use uprobe to hack function. the program has been executed to the entry
+ // use uprobe to interpose function. the program has been executed to the entry
// point
/*
diff --git a/upatchd/src/config.rs b/upatchd/src/config.rs
index 125770d..2ddb011 100644
--- a/upatchd/src/config.rs
+++ b/upatchd/src/config.rs
@@ -18,7 +18,7 @@ use anyhow::{anyhow, Result};
use serde::{Deserialize, Serialize};
use syscare_common::fs;
-use crate::hijacker::HijackerConfig;
+use crate::helper::UpatchHelperConfig;
const DEFAULT_SOCKET_UID: u32 = 0;
const DEFAULT_SOCKET_GID: u32 = 0;
@@ -46,7 +46,7 @@ pub struct DaemonConfig {
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Config {
pub daemon: DaemonConfig,
- pub hijacker: HijackerConfig,
+ pub helper: UpatchHelperConfig,
}
impl Config {
diff --git a/upatchd/src/hijacker/config.rs b/upatchd/src/helper/config.rs
similarity index 70%
rename from upatchd/src/hijacker/config.rs
rename to upatchd/src/helper/config.rs
index 5f97fb1..e8eaefc 100644
--- a/upatchd/src/hijacker/config.rs
+++ b/upatchd/src/helper/config.rs
@@ -23,26 +23,26 @@ const GCC_BINARY: &str = "/usr/bin/gcc";
const GXX_BINARY: &str = "/usr/bin/g++";
const AS_BINARY: &str = "/usr/bin/as";
-const CC_HIJACKER: &str = "/usr/libexec/syscare/cc-hijacker";
-const CXX_HIJACKER: &str = "/usr/libexec/syscare/c++-hijacker";
-const GCC_HIJACKER: &str = "/usr/libexec/syscare/gcc-hijacker";
-const GXX_HIJACKER: &str = "/usr/libexec/syscare/g++-hijacker";
-const AS_HIJACKER: &str = "/usr/libexec/syscare/as-hijacker";
+const CC_HELPER: &str = "/usr/libexec/syscare/cc-helper";
+const CXX_HELPER: &str = "/usr/libexec/syscare/c++-helper";
+const GCC_HELPER: &str = "/usr/libexec/syscare/gcc-helper";
+const GXX_HELPER: &str = "/usr/libexec/syscare/g++-helper";
+const AS_HELPER: &str = "/usr/libexec/syscare/as-helper";
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-pub struct HijackerConfig {
+pub struct UpatchHelperConfig {
pub mapping: IndexMap<PathBuf, PathBuf>,
}
-impl Default for HijackerConfig {
+impl Default for UpatchHelperConfig {
fn default() -> Self {
Self {
mapping: indexmap! {
- PathBuf::from(CC_BINARY) => PathBuf::from(CC_HIJACKER),
- PathBuf::from(CXX_BINARY) => PathBuf::from(CXX_HIJACKER),
- PathBuf::from(GCC_BINARY) => PathBuf::from(GCC_HIJACKER),
- PathBuf::from(GXX_BINARY) => PathBuf::from(GXX_HIJACKER),
- PathBuf::from(AS_BINARY) => PathBuf::from(AS_HIJACKER),
+ PathBuf::from(CC_BINARY) => PathBuf::from(CC_HELPER),
+ PathBuf::from(CXX_BINARY) => PathBuf::from(CXX_HELPER),
+ PathBuf::from(GCC_BINARY) => PathBuf::from(GCC_HELPER),
+ PathBuf::from(GXX_BINARY) => PathBuf::from(GXX_HELPER),
+ PathBuf::from(AS_BINARY) => PathBuf::from(AS_HELPER),
},
}
}
diff --git a/upatchd/src/hijacker/elf_resolver.rs b/upatchd/src/helper/elf_resolver.rs
similarity index 100%
rename from upatchd/src/hijacker/elf_resolver.rs
rename to upatchd/src/helper/elf_resolver.rs
diff --git a/upatchd/src/hijacker/ioctl.rs b/upatchd/src/helper/ioctl.rs
similarity index 80%
rename from upatchd/src/hijacker/ioctl.rs
rename to upatchd/src/helper/ioctl.rs
index b187979..0efbab4 100644
--- a/upatchd/src/hijacker/ioctl.rs
+++ b/upatchd/src/helper/ioctl.rs
@@ -21,20 +21,20 @@ use syscare_common::{ffi::OsStrExt, fs};
const KMOD_IOCTL_MAGIC: u16 = 0xE5;
ioctl_write_ptr!(
- ioctl_enable_hijacker,
+ ioctl_enable_hook,
KMOD_IOCTL_MAGIC,
0x1,
UpatchEnableRequest
);
-ioctl_none!(ioctl_disable_hijacker, KMOD_IOCTL_MAGIC, 0x2);
+ioctl_none!(ioctl_disable_hook, KMOD_IOCTL_MAGIC, 0x2);
ioctl_write_ptr!(
- ioctl_register_hijacker,
+ ioctl_register_hooker,
KMOD_IOCTL_MAGIC,
0x3,
UpatchRegisterRequest
);
ioctl_write_ptr!(
- ioctl_unregister_hijacker,
+ ioctl_unregister_hooker,
KMOD_IOCTL_MAGIC,
0x4,
UpatchRegisterRequest
@@ -51,18 +51,18 @@ pub struct UpatchRegisterRequest {
jump_path: [u8; PATH_MAX as usize],
}
-pub struct HijackerIoctl {
+pub struct UpatchHelperIoctl {
dev: File,
}
-impl HijackerIoctl {
+impl UpatchHelperIoctl {
pub fn new<P: AsRef<Path>>(dev_path: P) -> Result<Self> {
Ok(Self {
dev: fs::open_file(dev_path)?,
})
}
- pub fn enable_hijacker<P: AsRef<Path>>(&self, lib_path: P, offset: u64) -> Result<()> {
+ pub fn enable_hook<P: AsRef<Path>>(&self, lib_path: P, offset: u64) -> Result<()> {
let mut msg = UpatchEnableRequest {
path: [0; PATH_MAX as usize],
offset: 0,
@@ -74,23 +74,23 @@ impl HijackerIoctl {
msg.offset = offset;
unsafe {
- ioctl_enable_hijacker(self.dev.as_raw_fd(), &msg)
+ ioctl_enable_hook(self.dev.as_raw_fd(), &msg)
.map_err(|e| anyhow!("Ioctl error, ret={}", e))?
};
Ok(())
}
- pub fn disable_hijacker(&self) -> Result<()> {
+ pub fn disable_hook(&self) -> Result<()> {
unsafe {
- ioctl_disable_hijacker(self.dev.as_raw_fd())
+ ioctl_disable_hook(self.dev.as_raw_fd())
.map_err(|e| anyhow!("Ioctl error, ret={}", e))?
};
Ok(())
}
- pub fn register_hijacker<P, Q>(&self, exec_path: P, jump_path: Q) -> Result<()>
+ pub fn register_hooker<P, Q>(&self, exec_path: P, jump_path: Q) -> Result<()>
where
P: AsRef<Path>,
Q: AsRef<Path>,
@@ -108,14 +108,14 @@ impl HijackerIoctl {
.write_all(jump_path.as_ref().to_cstring()?.to_bytes_with_nul())?;
unsafe {
- ioctl_register_hijacker(self.dev.as_raw_fd(), &msg)
+ ioctl_register_hooker(self.dev.as_raw_fd(), &msg)
.map_err(|e| anyhow!("Ioctl error, {}", e.desc()))?
};
Ok(())
}
- pub fn unregister_hijacker<P, Q>(&self, exec_path: P, jump_path: Q) -> Result<()>
+ pub fn unregister_hooker<P, Q>(&self, exec_path: P, jump_path: Q) -> Result<()>
where
P: AsRef<Path>,
Q: AsRef<Path>,
@@ -133,7 +133,7 @@ impl HijackerIoctl {
.write_all(jump_path.as_ref().to_cstring()?.to_bytes_with_nul())?;
unsafe {
- ioctl_unregister_hijacker(self.dev.as_raw_fd(), &msg)
+ ioctl_unregister_hooker(self.dev.as_raw_fd(), &msg)
.map_err(|e| anyhow!("Ioctl error, {}", e.desc()))?
};
diff --git a/upatchd/src/hijacker/kmod.rs b/upatchd/src/helper/kmod.rs
similarity index 95%
rename from upatchd/src/hijacker/kmod.rs
rename to upatchd/src/helper/kmod.rs
index fc89f5f..59b7ede 100644
--- a/upatchd/src/hijacker/kmod.rs
+++ b/upatchd/src/helper/kmod.rs
@@ -25,13 +25,13 @@ use syscare_common::{fs, os};
const KMOD_SYS_PATH: &str = "/sys/module";
/// An RAII guard of the kernel module.
-pub struct HijackerKmodGuard {
+pub struct UpatchHelperKmodGuard {
kmod_name: String,
kmod_path: PathBuf,
sys_path: PathBuf,
}
-impl HijackerKmodGuard {
+impl UpatchHelperKmodGuard {
pub fn new<S: AsRef<str>, P: AsRef<Path>>(name: S, kmod_path: P) -> Result<Self> {
let instance = Self {
kmod_name: name.as_ref().to_string(),
@@ -45,7 +45,7 @@ impl HijackerKmodGuard {
}
}
-impl HijackerKmodGuard {
+impl UpatchHelperKmodGuard {
fn selinux_relabel_kmod(&self) -> Result<()> {
const KMOD_SECURITY_TYPE: &str = "modules_object_t";
@@ -92,7 +92,7 @@ impl HijackerKmodGuard {
}
}
-impl Drop for HijackerKmodGuard {
+impl Drop for UpatchHelperKmodGuard {
fn drop(&mut self) {
if let Err(e) = self.remove_kmod() {
error!("{:?}", e);
diff --git a/upatchd/src/hijacker/mod.rs b/upatchd/src/helper/mod.rs
similarity index 52%
rename from upatchd/src/hijacker/mod.rs
rename to upatchd/src/helper/mod.rs
index d0f2c4d..85245d0 100644
--- a/upatchd/src/hijacker/mod.rs
+++ b/upatchd/src/helper/mod.rs
@@ -24,24 +24,24 @@ mod elf_resolver;
mod ioctl;
mod kmod;
-pub use config::HijackerConfig;
+pub use config::UpatchHelperConfig;
use elf_resolver::ElfResolver;
-use ioctl::HijackerIoctl;
-use kmod::HijackerKmodGuard;
+use ioctl::UpatchHelperIoctl;
+use kmod::UpatchHelperKmodGuard;
-const KMOD_NAME: &str = "upatch_hijacker";
-const KMOD_DEV_PATH: &str = "/dev/upatch-hijacker";
-const KMOD_PATH: &str = "/usr/libexec/syscare/upatch_hijacker.ko";
+const KMOD_NAME: &str = "upatch_helper";
+const KMOD_DEV_PATH: &str = "/dev/upatch-helper";
+const KMOD_PATH: &str = "/usr/libexec/syscare/upatch_helper.ko";
-const HIJACK_SYMBOL_NAME: &str = "execve";
+const TARGET_SYMBOL_NAME: &str = "execve";
-pub struct Hijacker {
- config: HijackerConfig,
- ioctl: HijackerIoctl,
- _kmod: HijackerKmodGuard, // need to ensure this drops last
+pub struct UpatchHelper {
+ config: UpatchHelperConfig,
+ ioctl: UpatchHelperIoctl,
+ _kmod: UpatchHelperKmodGuard, // need to ensure this drops last
}
-impl Hijacker {
+impl UpatchHelper {
fn find_symbol_addr(symbol_name: &str) -> Result<(PathBuf, u64)> {
let exec_file = MappedFile::open(os::process::path())?;
let exec_resolver = ElfResolver::new(exec_file.as_bytes())?;
@@ -59,61 +59,66 @@ impl Hijacker {
}
}
-impl Hijacker {
- pub fn new(config: HijackerConfig) -> Result<Self> {
- debug!("Initializing hijacker kernel module...");
- let kmod = HijackerKmodGuard::new(KMOD_NAME, KMOD_PATH)?;
+impl UpatchHelper {
+ pub fn new(config: UpatchHelperConfig) -> Result<Self> {
+ debug!("Initializing upatch kernel module...");
+ let kmod = UpatchHelperKmodGuard::new(KMOD_NAME, KMOD_PATH)?;
- debug!("Initializing hijacker ioctl channel...");
- let ioctl = HijackerIoctl::new(KMOD_DEV_PATH)?;
+ debug!("Initializing upatch ioctl channel...");
+ let ioctl = UpatchHelperIoctl::new(KMOD_DEV_PATH)?;
- debug!("Initializing hijacker hooks...");
- let (lib_path, offset) = Self::find_symbol_addr(HIJACK_SYMBOL_NAME)?;
+ debug!("Initializing upatch hooks...");
+ let (lib_path, offset) = Self::find_symbol_addr(TARGET_SYMBOL_NAME)?;
info!(
"Hooking library: {}, offset: {:#x}",
lib_path.display(),
offset
);
- ioctl.enable_hijacker(lib_path, offset)?;
+ ioctl.enable_hook(lib_path, offset)?;
Ok(Self {
config,
- _kmod: kmod,
ioctl,
+ _kmod: kmod,
})
}
-}
-impl Hijacker {
- fn get_hijacker<P: AsRef<Path>>(&self, exec_path: P) -> Result<&Path> {
- let hijacker = self
- .config
- .mapping
- .get(exec_path.as_ref())
- .with_context(|| format!("Cannot find hijacker for {}", exec_path.as_ref().display()))?
- .as_path();
+ pub fn register_hooker<P: AsRef<Path>>(&self, elf_path: P) -> Result<()> {
+ let exec_path = elf_path.as_ref();
+ let jump_path = self.jump_path(exec_path)?;
- Ok(hijacker)
+ self.ioctl.register_hooker(exec_path, jump_path)
}
- pub fn register<P: AsRef<Path>>(&self, elf_path: P) -> Result<()> {
+ pub fn unregister_hooker<P: AsRef<Path>>(&self, elf_path: P) -> Result<()> {
let exec_path = elf_path.as_ref();
- let jump_path = self.get_hijacker(exec_path)?;
+ let jump_path = self.jump_path(exec_path)?;
- self.ioctl.register_hijacker(exec_path, jump_path)
+ self.ioctl.unregister_hooker(exec_path, jump_path)
}
+}
- pub fn unregister<P: AsRef<Path>>(&self, elf_path: P) -> Result<()> {
- let exec_path = elf_path.as_ref();
- let jump_path = self.get_hijacker(exec_path)?;
+impl UpatchHelper {
+ fn jump_path<P: AsRef<Path>>(&self, exec_path: P) -> Result<&Path> {
+ let jump_path = self
+ .config
+ .mapping
+ .get(exec_path.as_ref())
+ .with_context(|| {
+ format!(
+ "Cannot find hook program for {}",
+ exec_path.as_ref().display()
+ )
+ })?
+ .as_path();
- self.ioctl.unregister_hijacker(exec_path, jump_path)
+ Ok(jump_path)
}
}
-impl Drop for Hijacker {
+impl Drop for UpatchHelper {
fn drop(&mut self) {
- if let Err(e) = self.ioctl.disable_hijacker() {
+ if let Err(e) = self.ioctl.disable_hook() {
error!("{:?}", e);
}
}
diff --git a/upatchd/src/main.rs b/upatchd/src/main.rs
index 066e53e..8141679 100644
--- a/upatchd/src/main.rs
+++ b/upatchd/src/main.rs
@@ -30,7 +30,7 @@ use syscare_common::{fs, os};
mod args;
mod config;
-mod hijacker;
+mod helper;
mod rpc;
use args::Arguments;
@@ -175,7 +175,7 @@ impl Daemon {
}
fn initialize_skeleton(&self) -> Result<IoHandler> {
- let config = self.config.hijacker.clone();
+ let config = self.config.helper.clone();
let methods = SkeletonImpl::new(config)?.to_delegate();
let mut io_handler = IoHandler::new();
diff --git a/upatchd/src/rpc/skeleton.rs b/upatchd/src/rpc/skeleton.rs
index 9972fc1..a6891e1 100644
--- a/upatchd/src/rpc/skeleton.rs
+++ b/upatchd/src/rpc/skeleton.rs
@@ -18,9 +18,9 @@ use super::function::{rpc, RpcResult};
#[rpc(server)]
pub trait Skeleton {
- #[rpc(name = "enable_hijack")]
- fn enable_hijack(&self, exec_path: PathBuf) -> RpcResult<()>;
+ #[rpc(name = "hook_compiler")]
+ fn hook_compiler(&self, exec_path: PathBuf) -> RpcResult<()>;
- #[rpc(name = "disable_hijack")]
- fn disable_hijack(&self, exec_path: PathBuf) -> RpcResult<()>;
+ #[rpc(name = "unhook_compiler")]
+ fn unhook_compiler(&self, exec_path: PathBuf) -> RpcResult<()>;
}
diff --git a/upatchd/src/rpc/skeleton_impl.rs b/upatchd/src/rpc/skeleton_impl.rs
index d725166..c5085ae 100644
--- a/upatchd/src/rpc/skeleton_impl.rs
+++ b/upatchd/src/rpc/skeleton_impl.rs
@@ -17,7 +17,7 @@ use std::path::PathBuf;
use anyhow::{Context, Result};
use log::{debug, info};
-use crate::hijacker::{Hijacker, HijackerConfig};
+use crate::helper::{UpatchHelper, UpatchHelperConfig};
use super::{
function::{RpcFunction, RpcResult},
@@ -25,34 +25,34 @@ use super::{
};
pub struct SkeletonImpl {
- hijacker: Hijacker,
+ helper: UpatchHelper,
}
impl SkeletonImpl {
- pub fn new(config: HijackerConfig) -> Result<Self> {
- debug!("Initializing hijacker...");
+ pub fn new(config: UpatchHelperConfig) -> Result<Self> {
+ debug!("Initializing upatch helper...");
Ok(Self {
- hijacker: Hijacker::new(config).context("Failed to initialize hijacker")?,
+ helper: UpatchHelper::new(config).context("Failed to initialize upatch helper")?,
})
}
}
impl Skeleton for SkeletonImpl {
- fn enable_hijack(&self, elf_path: PathBuf) -> RpcResult<()> {
+ fn hook_compiler(&self, elf_path: PathBuf) -> RpcResult<()> {
RpcFunction::call(|| {
- info!("Enable hijack: {}", elf_path.display());
- self.hijacker
- .register(&elf_path)
- .with_context(|| format!("Failed to register hijack {}", elf_path.display()))
+ info!("Hook compiler: {}", elf_path.display());
+ self.helper
+ .register_hooker(&elf_path)
+ .with_context(|| format!("Failed to hook helper {}", elf_path.display()))
})
}
- fn disable_hijack(&self, elf_path: PathBuf) -> RpcResult<()> {
+ fn unhook_compiler(&self, elf_path: PathBuf) -> RpcResult<()> {
RpcFunction::call(|| {
- info!("Disable hijack: {}", elf_path.display());
- self.hijacker
- .unregister(&elf_path)
- .with_context(|| format!("Failed to unregister hijack {}", elf_path.display()))
+ info!("Unhook compiler: {}", elf_path.display());
+ self.helper
+ .unregister_hooker(&elf_path)
+ .with_context(|| format!("Failed to unhook compiler {}", elf_path.display()))
})
}
}
--
2.34.1