update to syscare-1.2.1-4
This commit is contained in:
parent
5e13351958
commit
23b205f1c6
@ -1,7 +1,7 @@
|
||||
From 8c09e8b3d9d59012c1019c01ac2246c770501c75 Mon Sep 17 00:00:00 2001
|
||||
From: ningyu <405888464@qq.com>
|
||||
Date: Sun, 7 Apr 2024 10:50:13 +0800
|
||||
Subject: [PATCH 01/10] upatch-hijacker: fix compile bug container_of_safe =>
|
||||
Subject: [PATCH 01/17] upatch-hijacker: fix compile bug container_of_safe =>
|
||||
container_of
|
||||
|
||||
---
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From a535e14a7db49df3c8aab017e32b92d8e5bb4087 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Wed, 10 Apr 2024 10:25:21 +0800
|
||||
Subject: [PATCH 02/10] daemon: fix 'cannot get file selinux xattr when selinux
|
||||
Subject: [PATCH 02/17] daemon: fix 'cannot get file selinux xattr when selinux
|
||||
is not enforcing' issue
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From e5294afa8135f54f44196bd92e5a32c2b09b9bda Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Wed, 10 Apr 2024 12:19:51 +0800
|
||||
Subject: [PATCH 03/10] syscared: fix 'syscare check command does not check
|
||||
Subject: [PATCH 03/17] syscared: fix 'syscare check command does not check
|
||||
symbol confiliction' issue
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From c213504c02d73738a86935fb5883f2e59d083da7 Mon Sep 17 00:00:00 2001
|
||||
From b53cb3d2903ea8ee3667f892b813648da7bc59a7 Mon Sep 17 00:00:00 2001
|
||||
From: ningyu <ningyu9@huawei.com>
|
||||
Date: Tue, 9 Apr 2024 09:21:35 +0000
|
||||
Subject: [PATCH 05/10] abi: change uuid type from string to uuid bytes
|
||||
Subject: [PATCH 04/17] Change uuid type to Uuid
|
||||
|
||||
---
|
||||
Cargo.lock | 1 +
|
||||
@ -68,7 +68,7 @@ index 55618ae..08cc2c7 100644
|
||||
pub version: String,
|
||||
pub release: u32,
|
||||
diff --git a/syscare-build/src/package/rpm/spec_builder.rs b/syscare-build/src/package/rpm/spec_builder.rs
|
||||
index 88f57d8..a24954f 100644
|
||||
index 88f57d8..5570c34 100644
|
||||
--- a/syscare-build/src/package/rpm/spec_builder.rs
|
||||
+++ b/syscare-build/src/package/rpm/spec_builder.rs
|
||||
@@ -62,7 +62,7 @@ impl RpmSpecBuilder {
|
||||
@ -85,7 +85,7 @@ index 88f57d8..a24954f 100644
|
||||
);
|
||||
let pkg_version = format!("{}-{}", patch_info.version, patch_info.release);
|
||||
- let pkg_root = Path::new(PKG_INSTALL_DIR).join(&patch_info.uuid);
|
||||
+ let pkg_root = Path::new(PKG_INSTALL_DIR).join(patch_info.uuid.to_string());
|
||||
+ let pkg_root = Path::new(PKG_INSTALL_DIR).join(&patch_info.uuid.to_string());
|
||||
|
||||
let mut spec = RpmSpecFile::new(
|
||||
pkg_name,
|
||||
39
0005-fix-clippy-warning.patch
Normal file
39
0005-fix-clippy-warning.patch
Normal file
@ -0,0 +1,39 @@
|
||||
From 41e5b9125fab50d4b3a137c5397443319e2365ec Mon Sep 17 00:00:00 2001
|
||||
From: ningyu <405888464@qq.com>
|
||||
Date: Wed, 10 Apr 2024 17:19:35 +0800
|
||||
Subject: [PATCH 05/17] fix clippy warning
|
||||
|
||||
---
|
||||
syscare-build/src/package/rpm/spec_builder.rs | 2 +-
|
||||
syscared/src/patch/driver/upatch/mod.rs | 2 +-
|
||||
2 files changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/syscare-build/src/package/rpm/spec_builder.rs b/syscare-build/src/package/rpm/spec_builder.rs
|
||||
index 5570c34..a24954f 100644
|
||||
--- a/syscare-build/src/package/rpm/spec_builder.rs
|
||||
+++ b/syscare-build/src/package/rpm/spec_builder.rs
|
||||
@@ -113,7 +113,7 @@ impl RpmSpecBuilder {
|
||||
patch_info.name
|
||||
);
|
||||
let pkg_version = format!("{}-{}", patch_info.version, patch_info.release);
|
||||
- let pkg_root = Path::new(PKG_INSTALL_DIR).join(&patch_info.uuid.to_string());
|
||||
+ let pkg_root = Path::new(PKG_INSTALL_DIR).join(patch_info.uuid.to_string());
|
||||
|
||||
let mut spec = RpmSpecFile::new(
|
||||
pkg_name,
|
||||
diff --git a/syscared/src/patch/driver/upatch/mod.rs b/syscared/src/patch/driver/upatch/mod.rs
|
||||
index 98fc54c..98b1e34 100644
|
||||
--- a/syscared/src/patch/driver/upatch/mod.rs
|
||||
+++ b/syscared/src/patch/driver/upatch/mod.rs
|
||||
@@ -38,7 +38,7 @@ mod target;
|
||||
use monitor::UserPatchMonitor;
|
||||
use target::PatchTarget;
|
||||
|
||||
-pub(self) type ActivePatchMap = Arc<Mutex<IndexMap<PathBuf, ActivePatch>>>;
|
||||
+type ActivePatchMap = Arc<Mutex<IndexMap<PathBuf, ActivePatch>>>;
|
||||
|
||||
#[derive(Default)]
|
||||
struct ActivePatch {
|
||||
--
|
||||
2.41.0
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 32c3d16175b93627504981d05a1a3e3ec603415e Mon Sep 17 00:00:00 2001
|
||||
From 729f32db079e2aace7cf355d480627b0bbf37e8c Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Wed, 10 Apr 2024 19:30:56 +0800
|
||||
Subject: [PATCH 04/10] syscared: fix 'cannot find process of dynlib patch'
|
||||
Subject: [PATCH 06/17] syscared: fix 'cannot find process of dynlib patch'
|
||||
issue
|
||||
|
||||
1. For detecting process mapped dynamic library,
|
||||
@ -21,7 +21,7 @@ Signed-off-by: renoseven <dev@renoseven.net>
|
||||
4 files changed, 270 insertions(+), 199 deletions(-)
|
||||
|
||||
diff --git a/syscared/src/patch/driver/upatch/mod.rs b/syscared/src/patch/driver/upatch/mod.rs
|
||||
index 98fc54c..a7fa154 100644
|
||||
index 98b1e34..a7fa154 100644
|
||||
--- a/syscared/src/patch/driver/upatch/mod.rs
|
||||
+++ b/syscared/src/patch/driver/upatch/mod.rs
|
||||
@@ -21,7 +21,7 @@ use std::{
|
||||
@ -37,7 +37,7 @@ index 98fc54c..a7fa154 100644
|
||||
use monitor::UserPatchMonitor;
|
||||
use target::PatchTarget;
|
||||
|
||||
-pub(self) type ActivePatchMap = Arc<Mutex<IndexMap<PathBuf, ActivePatch>>>;
|
||||
-type ActivePatchMap = Arc<Mutex<IndexMap<PathBuf, ActivePatch>>>;
|
||||
+type ElfPatchMap = Arc<Mutex<IndexMap<PathBuf, ElfPatchRecord>>>;
|
||||
|
||||
#[derive(Default)]
|
||||
@ -1,7 +1,7 @@
|
||||
From 1fbb81935c66c47a68716580878f2b983272a2bc Mon Sep 17 00:00:00 2001
|
||||
From 520e46ddd8f393125509a436134255765c5960cc Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 12 Apr 2024 11:35:57 +0800
|
||||
Subject: [PATCH 06/10] syscared: optimize patch error logic
|
||||
Subject: [PATCH 07/17] syscared: optimize patch error logic
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -1,7 +1,7 @@
|
||||
From bbf3396adbbd53709ab5a78c1035e6b9b010d549 Mon Sep 17 00:00:00 2001
|
||||
From 4ceb42b4a81cfb573aad4b4542f143be4c0ae90c Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 12 Apr 2024 11:40:25 +0800
|
||||
Subject: [PATCH 07/10] syscared: optimize transaction creation logic
|
||||
Subject: [PATCH 08/17] syscared: optimize transaction creation logic
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -1,7 +1,7 @@
|
||||
From 7c976ffc72330c85bc815bc1983dd7096778bf1b Mon Sep 17 00:00:00 2001
|
||||
From 399de1f2021ae91ee6fc1271b1ee4f2f5933eaf1 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 12 Apr 2024 11:50:59 +0800
|
||||
Subject: [PATCH 08/10] upatch-manage: optimize output
|
||||
Subject: [PATCH 09/17] upatch-manage: optimize output
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -1,7 +1,7 @@
|
||||
From 1a419fd88160f45a8fdabd8e6427811804735af1 Mon Sep 17 00:00:00 2001
|
||||
From 51aa26c1eeb7514bceb0194b601de560c6b9d74a Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 12 Apr 2024 11:35:57 +0800
|
||||
Subject: [PATCH 09/10] syscared: optimize patch error logic
|
||||
Subject: [PATCH 10/17] syscared: optimize patch error logic
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -1,7 +1,7 @@
|
||||
From 91b63792ed2b13ce8fc706df1ffa7d9fdadc31c7 Mon Sep 17 00:00:00 2001
|
||||
From 1d67bb57973cc0bc4b227c4359c15c4f31a1c82c Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 12 Apr 2024 11:40:25 +0800
|
||||
Subject: [PATCH 10/10] syscared: optimize transaction creation logic
|
||||
Subject: [PATCH 11/17] syscared: optimize transaction creation logic
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
47
0012-common-impl-CStr-from_bytes_with_next_nul.patch
Normal file
47
0012-common-impl-CStr-from_bytes_with_next_nul.patch
Normal file
@ -0,0 +1,47 @@
|
||||
From b64fa8df5ef916510e345cdd0382c32364d0c255 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Tue, 16 Apr 2024 12:44:11 +0800
|
||||
Subject: [PATCH 12/17] common: impl CStr::from_bytes_with_next_nul()
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
syscare-common/src/ffi/c_str.rs | 14 ++++++++++++--
|
||||
1 file changed, 12 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/syscare-common/src/ffi/c_str.rs b/syscare-common/src/ffi/c_str.rs
|
||||
index 060149a..4f3f26d 100644
|
||||
--- a/syscare-common/src/ffi/c_str.rs
|
||||
+++ b/syscare-common/src/ffi/c_str.rs
|
||||
@@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
use std::{
|
||||
- ffi::{CStr, OsStr, OsString},
|
||||
+ ffi::{CStr, CString, FromBytesWithNulError, OsStr, OsString},
|
||||
os::unix::{ffi::OsStringExt, prelude::OsStrExt},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
@@ -34,9 +34,19 @@ pub trait CStrExt: AsRef<CStr> {
|
||||
fn to_path_buf(&self) -> PathBuf {
|
||||
PathBuf::from(self.to_os_string())
|
||||
}
|
||||
+
|
||||
+ fn from_bytes_with_next_nul(bytes: &[u8]) -> Result<&CStr, FromBytesWithNulError> {
|
||||
+ let nul_pos = bytes.iter().position(|b| b == &b'\0').unwrap_or(0);
|
||||
+ let cstr_bytes = &bytes[..=nul_pos];
|
||||
+
|
||||
+ CStr::from_bytes_with_nul(cstr_bytes)
|
||||
+ }
|
||||
}
|
||||
|
||||
-impl<T: AsRef<CStr>> CStrExt for T {}
|
||||
+impl CStrExt for CStr {}
|
||||
+impl CStrExt for &CStr {}
|
||||
+impl CStrExt for CString {}
|
||||
+impl CStrExt for &CString {}
|
||||
|
||||
#[test]
|
||||
fn test_cstr() {
|
||||
--
|
||||
2.41.0
|
||||
|
||||
2317
0013-syscared-improve-patch-management.patch
Normal file
2317
0013-syscared-improve-patch-management.patch
Normal file
File diff suppressed because it is too large
Load Diff
237
0014-syscared-stop-activating-ignored-process-on-new-proc.patch
Normal file
237
0014-syscared-stop-activating-ignored-process-on-new-proc.patch
Normal file
@ -0,0 +1,237 @@
|
||||
From 3ee829f2156651f2284e072ba63abd196ee43294 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Wed, 17 Apr 2024 19:14:19 +0800
|
||||
Subject: [PATCH 14/17] syscared: stop activating ignored process on new
|
||||
process start
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
syscared/src/patch/driver/kpatch/mod.rs | 8 +-
|
||||
syscared/src/patch/driver/upatch/mod.rs | 109 ++++++++++++------------
|
||||
2 files changed, 58 insertions(+), 59 deletions(-)
|
||||
|
||||
diff --git a/syscared/src/patch/driver/kpatch/mod.rs b/syscared/src/patch/driver/kpatch/mod.rs
|
||||
index 45dc719..307efb5 100644
|
||||
--- a/syscared/src/patch/driver/kpatch/mod.rs
|
||||
+++ b/syscared/src/patch/driver/kpatch/mod.rs
|
||||
@@ -239,7 +239,7 @@ impl KernelPatchDriver {
|
||||
|
||||
pub fn apply(&mut self, patch: &KernelPatch) -> Result<()> {
|
||||
info!(
|
||||
- "Kpatch: Applying patch '{}' ({})",
|
||||
+ "Applying patch '{}' ({})",
|
||||
patch.uuid,
|
||||
patch.patch_file.display()
|
||||
);
|
||||
@@ -253,7 +253,7 @@ impl KernelPatchDriver {
|
||||
|
||||
pub fn remove(&mut self, patch: &KernelPatch) -> Result<()> {
|
||||
info!(
|
||||
- "Kpatch: Removing patch '{}' ({})",
|
||||
+ "Removing patch '{}' ({})",
|
||||
patch.uuid,
|
||||
patch.patch_file.display()
|
||||
);
|
||||
@@ -265,7 +265,7 @@ impl KernelPatchDriver {
|
||||
|
||||
pub fn active(&mut self, patch: &KernelPatch) -> Result<()> {
|
||||
info!(
|
||||
- "Kpatch: Activating patch '{}' ({})",
|
||||
+ "Activating patch '{}' ({})",
|
||||
patch.uuid,
|
||||
patch.patch_file.display()
|
||||
);
|
||||
@@ -277,7 +277,7 @@ impl KernelPatchDriver {
|
||||
|
||||
pub fn deactive(&mut self, patch: &KernelPatch) -> Result<()> {
|
||||
info!(
|
||||
- "Kpatch: Deactivating patch '{}' ({})",
|
||||
+ "Deactivating patch '{}' ({})",
|
||||
patch.uuid,
|
||||
patch.patch_file.display()
|
||||
);
|
||||
diff --git a/syscared/src/patch/driver/upatch/mod.rs b/syscared/src/patch/driver/upatch/mod.rs
|
||||
index dd07e9b..66eecf5 100644
|
||||
--- a/syscared/src/patch/driver/upatch/mod.rs
|
||||
+++ b/syscared/src/patch/driver/upatch/mod.rs
|
||||
@@ -237,21 +237,20 @@ impl UserPatchDriver {
|
||||
patch_entity.clean_dead_process(&process_list);
|
||||
|
||||
// Active patch
|
||||
- let need_actived = patch_entity.need_actived(&process_list);
|
||||
+ let need_ignored = patch_entity.need_ignored(&process_list);
|
||||
+
|
||||
+ let mut need_actived = patch_entity.need_actived(&process_list);
|
||||
+ need_actived.retain(|pid| !need_ignored.contains(pid));
|
||||
if !need_actived.is_empty() {
|
||||
debug!(
|
||||
- "Upatch: Activating patch '{}' ({}) for process {:?}",
|
||||
+ "Activating patch '{}' ({}) for process {:?}",
|
||||
patch_uuid,
|
||||
target_elf.display(),
|
||||
need_actived,
|
||||
);
|
||||
}
|
||||
|
||||
- let ignore_list = patch_entity.need_ignored(&process_list);
|
||||
for pid in need_actived {
|
||||
- if ignore_list.contains(&pid) {
|
||||
- continue;
|
||||
- }
|
||||
match sys::active_patch(patch_uuid, pid, target_elf, &patch_entity.patch_file) {
|
||||
Ok(_) => patch_entity.add_process(pid),
|
||||
Err(e) => {
|
||||
@@ -283,7 +282,7 @@ impl UserPatchDriver {
|
||||
|
||||
pub fn apply(&mut self, patch: &UserPatch) -> Result<()> {
|
||||
info!(
|
||||
- "Upatch: Applying patch '{}' ({})",
|
||||
+ "Applying patch '{}' ({})",
|
||||
patch.uuid,
|
||||
patch.patch_file.display()
|
||||
);
|
||||
@@ -296,7 +295,7 @@ impl UserPatchDriver {
|
||||
|
||||
pub fn remove(&mut self, patch: &UserPatch) -> Result<()> {
|
||||
info!(
|
||||
- "Upatch: Removing patch '{}' ({})",
|
||||
+ "Removing patch '{}' ({})",
|
||||
patch.uuid,
|
||||
patch.patch_file.display()
|
||||
);
|
||||
@@ -326,7 +325,7 @@ impl UserPatchDriver {
|
||||
|
||||
// Active patch
|
||||
info!(
|
||||
- "Upatch: Activating patch '{}' ({}) for {}",
|
||||
+ "Activating patch '{}' ({}) for {}",
|
||||
patch_uuid,
|
||||
patch_file.display(),
|
||||
target_elf.display(),
|
||||
@@ -342,29 +341,28 @@ impl UserPatchDriver {
|
||||
}
|
||||
|
||||
// Check results, return error if all process fails
|
||||
- match results.iter().any(|(_, result)| result.is_ok()) {
|
||||
- true => {
|
||||
- for (pid, result) in &results {
|
||||
- if let Err(e) = result {
|
||||
- warn!(
|
||||
- "Upatch: Failed to active patch '{}' for process {}, {}",
|
||||
- patch_uuid,
|
||||
- pid,
|
||||
- e.to_string().to_lowercase(),
|
||||
- );
|
||||
- }
|
||||
+ if !results.is_empty() && results.iter().all(|(_, result)| result.is_err()) {
|
||||
+ let mut err_msg = String::new();
|
||||
+
|
||||
+ writeln!(err_msg, "Upatch: Failed to active patch")?;
|
||||
+ for (pid, result) in &results {
|
||||
+ if let Err(e) = result {
|
||||
+ writeln!(err_msg, "* Process {}: {}", pid, e)?;
|
||||
}
|
||||
}
|
||||
- false => {
|
||||
- let mut err_msg = String::new();
|
||||
+ err_msg.pop();
|
||||
+ bail!(err_msg);
|
||||
+ }
|
||||
|
||||
- writeln!(err_msg, "Upatch: Failed to active patch")?;
|
||||
- for (pid, result) in &results {
|
||||
- if let Err(e) = result {
|
||||
- writeln!(err_msg, "* Process {}: {}", pid, e)?;
|
||||
- }
|
||||
- }
|
||||
- bail!(err_msg);
|
||||
+ // Print failure results
|
||||
+ for (pid, result) in &results {
|
||||
+ if let Err(e) = result {
|
||||
+ warn!(
|
||||
+ "Upatch: Failed to active patch '{}' for process {}, {}",
|
||||
+ patch_uuid,
|
||||
+ pid,
|
||||
+ e.to_string().to_lowercase(),
|
||||
+ );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,17 +405,19 @@ impl UserPatchDriver {
|
||||
|
||||
// Deactive patch
|
||||
info!(
|
||||
- "Upatch: Deactivating patch '{}' ({}) for {}",
|
||||
+ "Deactivating patch '{}' ({}) for {}",
|
||||
patch_uuid,
|
||||
patch_file.display(),
|
||||
target_elf.display(),
|
||||
);
|
||||
+
|
||||
+ let need_ignored = patch_entity.need_ignored(&process_list);
|
||||
+
|
||||
+ let mut need_deactived = patch_entity.need_deactived(&process_list);
|
||||
+ need_deactived.retain(|pid| need_ignored.contains(pid));
|
||||
+
|
||||
let mut results = Vec::new();
|
||||
- let ignore_list = patch_entity.need_ignored(&process_list);
|
||||
for pid in patch_entity.need_deactived(&process_list) {
|
||||
- if ignore_list.contains(&pid) {
|
||||
- continue;
|
||||
- }
|
||||
let result = sys::deactive_patch(patch_uuid, pid, target_elf, patch_file);
|
||||
if result.is_ok() {
|
||||
patch_entity.remove_process(pid)
|
||||
@@ -426,29 +426,28 @@ impl UserPatchDriver {
|
||||
}
|
||||
|
||||
// Check results, return error if any process failes
|
||||
- match results.iter().any(|(_, result)| result.is_err()) {
|
||||
- true => {
|
||||
- let mut err_msg = String::new();
|
||||
-
|
||||
- writeln!(err_msg, "Upatch: Failed to deactive patch")?;
|
||||
- for (pid, result) in &results {
|
||||
- if let Err(e) = result {
|
||||
- writeln!(err_msg, "* Process {}: {}", pid, e)?;
|
||||
- }
|
||||
+ if !results.is_empty() && results.iter().any(|(_, result)| result.is_err()) {
|
||||
+ let mut err_msg = String::new();
|
||||
+
|
||||
+ writeln!(err_msg, "Upatch: Failed to deactive patch")?;
|
||||
+ for (pid, result) in &results {
|
||||
+ if let Err(e) = result {
|
||||
+ writeln!(err_msg, "* Process {}: {}", pid, e)?;
|
||||
}
|
||||
- bail!(err_msg)
|
||||
}
|
||||
- false => {
|
||||
- for (pid, result) in &results {
|
||||
- if let Err(e) = result {
|
||||
- warn!(
|
||||
- "Upatch: Failed to deactive patch '{}' for process {}, {}",
|
||||
- patch_uuid,
|
||||
- pid,
|
||||
- e.to_string().to_lowercase(),
|
||||
- );
|
||||
- }
|
||||
- }
|
||||
+ err_msg.pop();
|
||||
+ bail!(err_msg);
|
||||
+ }
|
||||
+
|
||||
+ // Print failure results
|
||||
+ for (pid, result) in &results {
|
||||
+ if let Err(e) = result {
|
||||
+ warn!(
|
||||
+ "Upatch: Failed to deactive patch '{}' for process {}, {}",
|
||||
+ patch_uuid,
|
||||
+ pid,
|
||||
+ e.to_string().to_lowercase(),
|
||||
+ );
|
||||
}
|
||||
}
|
||||
|
||||
--
|
||||
2.41.0
|
||||
|
||||
35
0015-syscared-adapt-upatch-manage-exit-code-change.patch
Normal file
35
0015-syscared-adapt-upatch-manage-exit-code-change.patch
Normal file
@ -0,0 +1,35 @@
|
||||
From 96ccd901456d950761835befde8979519575778d Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 19 Apr 2024 12:02:23 +0800
|
||||
Subject: [PATCH 15/17] syscared: adapt upatch-manage exit code change
|
||||
|
||||
1. upatch driver treats EEXIST as an error
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
syscared/src/patch/driver/upatch/sys.rs | 2 --
|
||||
1 file changed, 2 deletions(-)
|
||||
|
||||
diff --git a/syscared/src/patch/driver/upatch/sys.rs b/syscared/src/patch/driver/upatch/sys.rs
|
||||
index bfeb1b8..a388bc6 100644
|
||||
--- a/syscared/src/patch/driver/upatch/sys.rs
|
||||
+++ b/syscared/src/patch/driver/upatch/sys.rs
|
||||
@@ -2,7 +2,6 @@ use std::path::Path;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use log::Level;
|
||||
-use nix::libc::EEXIST;
|
||||
use uuid::Uuid;
|
||||
|
||||
use syscare_common::process::Command;
|
||||
@@ -26,7 +25,6 @@ pub fn active_patch(uuid: &Uuid, pid: i32, target_elf: &Path, patch_file: &Path)
|
||||
|
||||
match exit_code {
|
||||
0 => Ok(()),
|
||||
- EEXIST => Ok(()),
|
||||
_ => bail!(std::io::Error::from_raw_os_error(exit_code)),
|
||||
}
|
||||
}
|
||||
--
|
||||
2.41.0
|
||||
|
||||
446
0016-upatch-manage-change-exit-code.patch
Normal file
446
0016-upatch-manage-change-exit-code.patch
Normal file
@ -0,0 +1,446 @@
|
||||
From 10dc2c5843156d032277cc0a3a85e2e8df3a5146 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 19 Apr 2024 12:01:38 +0800
|
||||
Subject: [PATCH 16/17] upatch-manage: change exit code
|
||||
|
||||
1. return more specific exit code
|
||||
2. change exit code from EEXIST to 0 when patching existing patch (uuid)
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
upatch-manage/log.h | 2 +-
|
||||
upatch-manage/upatch-elf.c | 10 ++---
|
||||
upatch-manage/upatch-manage.c | 7 ++--
|
||||
upatch-manage/upatch-patch.c | 70 ++++++++++++++++++++--------------
|
||||
upatch-manage/upatch-process.c | 15 ++------
|
||||
upatch-manage/upatch-ptrace.c | 1 +
|
||||
6 files changed, 56 insertions(+), 49 deletions(-)
|
||||
|
||||
diff --git a/upatch-manage/log.h b/upatch-manage/log.h
|
||||
index a41bfc8..32e9c56 100644
|
||||
--- a/upatch-manage/log.h
|
||||
+++ b/upatch-manage/log.h
|
||||
@@ -52,7 +52,7 @@ enum exit_status {
|
||||
/* it is time cost */
|
||||
#define log_debug(format, ...) log(DEBUG, format, ##__VA_ARGS__)
|
||||
#define log_normal(format, ...) log(NORMAL, format, ##__VA_ARGS__)
|
||||
-#define log_warn(format, ...) log(WARN, "%s: " format, logprefix, ##__VA_ARGS__)
|
||||
+#define log_warn(format, ...) log(WARN, format, ##__VA_ARGS__)
|
||||
#define log_error(format, ...) log(ERR, format, ##__VA_ARGS__)
|
||||
|
||||
#define log(level, format, ...) \
|
||||
diff --git a/upatch-manage/upatch-elf.c b/upatch-manage/upatch-elf.c
|
||||
index 165f0cf..02444eb 100644
|
||||
--- a/upatch-manage/upatch-elf.c
|
||||
+++ b/upatch-manage/upatch-elf.c
|
||||
@@ -54,20 +54,20 @@ static int open_elf(struct elf_info *einfo, const char *name)
|
||||
fd = open(name, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
ret = -errno;
|
||||
- log_error("Failed to open file '%s', ret=%d\n", name, ret);
|
||||
+ log_error("Failed to open file '%s'\n", name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = stat(name, &st);
|
||||
if (ret != 0) {
|
||||
ret = -errno;
|
||||
- log_error("Failed to stat file '%s', ret=%d\n", name, ret);
|
||||
+ log_error("Failed to stat file '%s'\n", name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = read_from_offset(fd, (void **)&einfo->patch_buff, st.st_size, 0);
|
||||
if (ret != 0) {
|
||||
- log_error("Failed to read file '%s', ret=%d\n", name, ret);
|
||||
+ log_error("Failed to read file '%s'\n", name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ int upatch_init(struct upatch_elf *uelf, const char *name)
|
||||
{
|
||||
int ret = open_elf(&uelf->info, name);
|
||||
if (ret) {
|
||||
- log_error("Failed to open elf '%s', ret=%d\n", name, ret);
|
||||
+ log_error("Failed to open file '%s'\n", name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ int binary_init(struct running_elf *relf, const char *name)
|
||||
{
|
||||
int ret = open_elf(&relf->info, name);
|
||||
if (ret) {
|
||||
- log_error("Failed to open elf '%s', ret=%d\n", name, ret);
|
||||
+ log_error("Failed to open file '%s'\n", name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
diff --git a/upatch-manage/upatch-manage.c b/upatch-manage/upatch-manage.c
|
||||
index e33eeb3..8a7ba60 100644
|
||||
--- a/upatch-manage/upatch-manage.c
|
||||
+++ b/upatch-manage/upatch-manage.c
|
||||
@@ -146,7 +146,7 @@ int patch_upatch(const char *uuid, const char *binary_path, const char *upatch_p
|
||||
|
||||
int ret = upatch_init(&uelf, upatch_path);
|
||||
if (ret) {
|
||||
- log_error("Failed to initialize patch, ret=%d\n", ret);
|
||||
+ log_error("Failed to initialize patch, pid=%d, ret=%d\n", pid, ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,6 @@ int patch_upatch(const char *uuid, const char *binary_path, const char *upatch_p
|
||||
log_error("Failed to patch process, pid=%d, ret=%d\n", pid, ret);
|
||||
goto out;
|
||||
}
|
||||
- log_normal("SUCCESS\n");
|
||||
|
||||
out:
|
||||
upatch_close(&uelf);
|
||||
@@ -173,7 +172,6 @@ int unpatch_upatch(const char *uuid, const char *binary_path, const char *upatch
|
||||
log_error("Failed to unpatch process, pid=%d, ret=%d\n", pid, ret);
|
||||
return ret;
|
||||
}
|
||||
- log_normal("SUCCESS\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -185,7 +183,6 @@ int info_upatch(const char *binary_path, const char *upatch_path, int pid)
|
||||
log_error("Failed to get patch info, pid=%d, ret=%d\n", pid, ret);
|
||||
return ret;
|
||||
}
|
||||
- log_normal("SUCCESS\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -207,6 +204,7 @@ int main(int argc, char *argv[])
|
||||
log_debug("Patch: %s\n", args.upatch);
|
||||
log_debug("Binary: %s\n", args.binary);
|
||||
|
||||
+ args.pid = args.pid & INT32_MAX;
|
||||
switch (args.cmd) {
|
||||
case PATCH:
|
||||
ret = patch_upatch(args.uuid, args.binary, args.upatch, args.pid);
|
||||
@@ -223,5 +221,6 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
|
||||
+ (ret == 0) ? log_normal("SUCCESS\n\n") : log_error("FAILED\n\n");
|
||||
return abs(ret);
|
||||
}
|
||||
diff --git a/upatch-manage/upatch-patch.c b/upatch-manage/upatch-patch.c
|
||||
index 5e16002..5a8f927 100644
|
||||
--- a/upatch-manage/upatch-patch.c
|
||||
+++ b/upatch-manage/upatch-patch.c
|
||||
@@ -291,7 +291,6 @@ static void *upatch_alloc(struct object_file *obj, size_t sz)
|
||||
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1,
|
||||
0);
|
||||
if (addr == 0) {
|
||||
- log_error("Failed to alloc remote patch memory\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -308,7 +307,7 @@ static void *upatch_alloc(struct object_file *obj, size_t sz)
|
||||
return (void *)addr;
|
||||
}
|
||||
|
||||
-static void __upatch_memfree(struct object_file *obj, void *base,
|
||||
+static void upatch_free(struct object_file *obj, void *base,
|
||||
unsigned int size)
|
||||
{
|
||||
log_debug("Free patch memory %p\n", base);
|
||||
@@ -323,14 +322,13 @@ static int __alloc_memory(struct object_file *obj_file,
|
||||
/* Do the allocs. */
|
||||
layout->base = upatch_alloc(obj_file, layout->size);
|
||||
if (!layout->base) {
|
||||
- log_error("Failed to alloc patch core layout %p\n", layout->base);
|
||||
- return -ENOMEM;
|
||||
+ return -errno;
|
||||
}
|
||||
|
||||
layout->kbase = malloc(layout->size);
|
||||
if (!layout->kbase) {
|
||||
- __upatch_memfree(obj_file, layout->base, layout->size);
|
||||
- return -ENOMEM;
|
||||
+ upatch_free(obj_file, layout->base, layout->size);
|
||||
+ return -errno;
|
||||
}
|
||||
|
||||
memset(layout->kbase, 0, layout->size);
|
||||
@@ -345,7 +343,6 @@ static int alloc_memory(struct upatch_elf *uelf, struct object_file *obj)
|
||||
/* Do the allocs. */
|
||||
ret = __alloc_memory(obj, &uelf->core_layout);
|
||||
if (ret) {
|
||||
- log_error("Failed to alloc patch memory, ret=%d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -634,11 +631,13 @@ static int upatch_apply_patches(struct upatch_process *proc,
|
||||
*/
|
||||
ret = alloc_memory(uelf, obj);
|
||||
if (ret) {
|
||||
+ log_error("Failed to alloc patch memory\n");
|
||||
goto free;
|
||||
}
|
||||
|
||||
ret = upatch_mprotect(uelf, obj);
|
||||
if (ret) {
|
||||
+ log_error("Failed to set patch memory permission\n");
|
||||
goto free;
|
||||
}
|
||||
|
||||
@@ -675,7 +674,7 @@ static int upatch_apply_patches(struct upatch_process *proc,
|
||||
|
||||
// TODO: clear
|
||||
free:
|
||||
- __upatch_memfree(obj, uelf->core_layout.base, uelf->core_layout.size);
|
||||
+ upatch_free(obj, uelf->core_layout.base, uelf->core_layout.size);
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
@@ -708,15 +707,16 @@ int process_patch(int pid, struct upatch_elf *uelf, struct running_elf *relf, co
|
||||
// 查看process的信息,pid: maps, mem, cmdline, exe
|
||||
ret = upatch_process_init(&proc, pid);
|
||||
if (ret < 0) {
|
||||
- log_error("Failed to init process %d, ret=%d\n", pid, ret);
|
||||
+ log_error("Failed to init process\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
- printf("Patch ");
|
||||
+ printf("Patch '%s' to ", uuid);
|
||||
upatch_process_print_short(&proc);
|
||||
|
||||
ret = upatch_process_mem_open(&proc, MEM_READ);
|
||||
if (ret < 0) {
|
||||
+ log_error("Failed to open process memory\n");
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
@@ -731,15 +731,19 @@ int process_patch(int pid, struct upatch_elf *uelf, struct running_elf *relf, co
|
||||
*/
|
||||
// 解析process的mem-maps,获得各个块的内存映射以及phdr
|
||||
ret = upatch_process_map_object_files(&proc, NULL);
|
||||
- if (ret < 0)
|
||||
+ if (ret < 0) {
|
||||
+ log_error("Failed to read process memory mapping\n");
|
||||
goto out_free;
|
||||
+ }
|
||||
ret = upatch_process_uuid_exist(&proc, uuid);
|
||||
if (ret != 0) {
|
||||
+ ret = 0;
|
||||
+ log_error("Patch '%s' already exists\n", uuid);
|
||||
goto out_free;
|
||||
}
|
||||
ret = binary_init(relf, binary_path);
|
||||
if (ret) {
|
||||
- log_error("Failed to load binary, ret=%d\n", ret);
|
||||
+ log_error("Failed to load binary\n");
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
@@ -750,24 +754,27 @@ int process_patch(int pid, struct upatch_elf *uelf, struct running_elf *relf, co
|
||||
|
||||
/* Finally, attach to process */
|
||||
ret = upatch_process_attach(&proc);
|
||||
- if (ret < 0)
|
||||
+ if (ret < 0) {
|
||||
+ log_error("Failed to attach process\n");
|
||||
goto out_free;
|
||||
+ }
|
||||
|
||||
// TODO: 栈解析
|
||||
// 应用
|
||||
ret = upatch_apply_patches(&proc, uelf, uuid);
|
||||
- if (ret < 0)
|
||||
+ if (ret < 0) {
|
||||
+ log_error("Failed to apply patch\n");
|
||||
goto out_free;
|
||||
-
|
||||
- ret = 0;
|
||||
+ }
|
||||
|
||||
out_free:
|
||||
upatch_process_detach(&proc);
|
||||
+ gettimeofday(&end_tv, NULL);
|
||||
+
|
||||
upatch_process_destroy(&proc);
|
||||
|
||||
out:
|
||||
if (is_calc_time) {
|
||||
- gettimeofday(&end_tv, NULL);
|
||||
frozen_time = GET_MICROSECONDS(end_tv, start_tv);
|
||||
log_normal("Process %d frozen time is %ld microsecond(s)\n",
|
||||
pid, frozen_time);
|
||||
@@ -800,7 +807,7 @@ static int upatch_unapply_patches(struct upatch_process *proc, const char *uuid)
|
||||
}
|
||||
|
||||
log_debug("munmap upatch layout core:\n");
|
||||
- __upatch_memfree(obj,
|
||||
+ upatch_free(obj,
|
||||
(void *)patch->uinfo->start,
|
||||
patch->uinfo->end - patch->uinfo->start
|
||||
);
|
||||
@@ -810,7 +817,7 @@ static int upatch_unapply_patches(struct upatch_process *proc, const char *uuid)
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
- log_debug("can't found patch info memory\n");
|
||||
+ log_warn("Patch '%s' is not found\n", uuid);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -831,16 +838,18 @@ int process_unpatch(int pid, const char *uuid)
|
||||
// 查看process的信息,pid: maps, mem, cmdline, exe
|
||||
ret = upatch_process_init(&proc, pid);
|
||||
if (ret < 0) {
|
||||
- log_error("Failed to init process %d, ret=%d\n", pid, ret);
|
||||
+ log_error("Failed to init process\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
- printf("Unpatch ");
|
||||
+ printf("Unpatch '%s' from ", uuid);
|
||||
upatch_process_print_short(&proc);
|
||||
|
||||
ret = upatch_process_mem_open(&proc, MEM_READ);
|
||||
- if (ret < 0)
|
||||
+ if (ret < 0) {
|
||||
+ log_error("Failed to open process memory\n");
|
||||
goto out_free;
|
||||
+ }
|
||||
|
||||
// use uprobe to hack function. the program has been executed to the entry
|
||||
// point
|
||||
@@ -853,8 +862,10 @@ int process_unpatch(int pid, const char *uuid)
|
||||
*/
|
||||
// 解析process的mem-maps,获得各个块的内存映射以及phdr
|
||||
ret = upatch_process_map_object_files(&proc, NULL);
|
||||
- if (ret < 0)
|
||||
+ if (ret < 0) {
|
||||
+ log_error("Failed to read process memory mapping\n");
|
||||
goto out_free;
|
||||
+ }
|
||||
|
||||
is_calc_time = true;
|
||||
gettimeofday(&start_tv, NULL);
|
||||
@@ -862,24 +873,25 @@ int process_unpatch(int pid, const char *uuid)
|
||||
/* Finally, attach to process */
|
||||
ret = upatch_process_attach(&proc);
|
||||
if (ret < 0) {
|
||||
+ log_error("Failed to attach process\n");
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
// 应用
|
||||
ret = upatch_unapply_patches(&proc, uuid);
|
||||
if (ret < 0) {
|
||||
+ log_error("Failed to remove patch\n");
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
- ret = 0;
|
||||
-
|
||||
out_free:
|
||||
upatch_process_detach(&proc);
|
||||
+ gettimeofday(&end_tv, NULL);
|
||||
+
|
||||
upatch_process_destroy(&proc);
|
||||
|
||||
out:
|
||||
if (is_calc_time) {
|
||||
- gettimeofday(&end_tv, NULL);
|
||||
frozen_time = GET_MICROSECONDS(end_tv, start_tv);
|
||||
log_normal("Process %d frozen time is %ld microsecond(s)\n",
|
||||
pid, frozen_time);
|
||||
@@ -924,23 +936,25 @@ int process_info(int pid)
|
||||
// 查看process的信息,pid: maps, mem, cmdline, exe
|
||||
ret = upatch_process_init(&proc, pid);
|
||||
if (ret < 0) {
|
||||
- log_error("Failed to init process %d, ret=%d\n", pid, ret);
|
||||
+ log_error("Failed to init process\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = upatch_process_mem_open(&proc, MEM_READ);
|
||||
if (ret < 0) {
|
||||
+ log_error("Failed to open process memory\n");
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
ret = upatch_process_map_object_files(&proc, NULL);
|
||||
if (ret < 0) {
|
||||
+ log_error("Failed to read process memory mapping\n");
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
ret = upatch_info(&proc);
|
||||
if (ret) {
|
||||
- status = "active";
|
||||
+ status = "actived";
|
||||
}
|
||||
else {
|
||||
status = "removed";
|
||||
diff --git a/upatch-manage/upatch-process.c b/upatch-manage/upatch-process.c
|
||||
index cd3f7e0..c368165 100644
|
||||
--- a/upatch-manage/upatch-process.c
|
||||
+++ b/upatch-manage/upatch-process.c
|
||||
@@ -57,7 +57,7 @@ static int lock_process(int pid)
|
||||
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
- log_error("Failed to open '%s'\n", path);
|
||||
+ log_error("Failed to open file '%s'\n", path);
|
||||
return -1;
|
||||
}
|
||||
log_debug("OK\n");
|
||||
@@ -204,7 +204,7 @@ static void process_print_cmdline(struct upatch_process *proc)
|
||||
snprintf(buf, PATH_MAX, "/proc/%d/cmdline", proc->pid);
|
||||
int fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
- log_error("Failed to open %s", buf);
|
||||
+ log_error("Failed to open file '%s'\n", buf);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ int upatch_process_mem_open(struct upatch_process *proc, int mode)
|
||||
snprintf(path, sizeof(path), "/proc/%d/mem", proc->pid);
|
||||
proc->memfd = open(path, mode == MEM_WRITE ? O_RDWR : O_RDONLY);
|
||||
if (proc->memfd < 0) {
|
||||
- log_error("Failed to open %s", path);
|
||||
+ log_error("Failed to open file '%s'\n", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -560,16 +560,9 @@ error:
|
||||
int upatch_process_map_object_files(struct upatch_process *proc,
|
||||
const char *patch_id)
|
||||
{
|
||||
- int ret;
|
||||
-
|
||||
- ret = upatch_process_parse_proc_maps(proc);
|
||||
- if (ret < 0)
|
||||
- return -1;
|
||||
-
|
||||
// we can get plt/got table from mem's elf_segments
|
||||
// Now we read them from the running file
|
||||
-
|
||||
- return ret;
|
||||
+ return upatch_process_parse_proc_maps(proc);
|
||||
}
|
||||
|
||||
// static int process_has_thread_pid(struct upatch_proces *proc, int pid)
|
||||
diff --git a/upatch-manage/upatch-ptrace.c b/upatch-manage/upatch-ptrace.c
|
||||
index 39e8f59..1309a6e 100644
|
||||
--- a/upatch-manage/upatch-ptrace.c
|
||||
+++ b/upatch-manage/upatch-ptrace.c
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
+#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
--
|
||||
2.41.0
|
||||
|
||||
140
0017-upatch-manage-change-the-way-to-calculate-frozen-tim.patch
Normal file
140
0017-upatch-manage-change-the-way-to-calculate-frozen-tim.patch
Normal file
@ -0,0 +1,140 @@
|
||||
From ce0702b2da3820a3e872fd6563d5ce9e51cab130 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 19 Apr 2024 14:19:27 +0800
|
||||
Subject: [PATCH 17/17] upatch-manage: change the way to calculate frozen time
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
upatch-manage/upatch-patch.c | 58 +++++++++++++++++++-----------------
|
||||
1 file changed, 31 insertions(+), 27 deletions(-)
|
||||
|
||||
diff --git a/upatch-manage/upatch-patch.c b/upatch-manage/upatch-patch.c
|
||||
index 5a8f927..ab972ac 100644
|
||||
--- a/upatch-manage/upatch-patch.c
|
||||
+++ b/upatch-manage/upatch-patch.c
|
||||
@@ -679,6 +679,31 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
+static void upatch_time_tick(int pid) {
|
||||
+ static struct timeval start_tv;
|
||||
+ static struct timeval end_tv;
|
||||
+
|
||||
+ if ((end_tv.tv_sec != 0) || (end_tv.tv_usec != 0)) {
|
||||
+ memset(&start_tv, 0, sizeof(struct timeval));
|
||||
+ memset(&end_tv, 0, sizeof(struct timeval));
|
||||
+ }
|
||||
+
|
||||
+ if ((start_tv.tv_sec == 0) && (start_tv.tv_usec == 0)) {
|
||||
+ gettimeofday(&start_tv, NULL);
|
||||
+ } else {
|
||||
+ gettimeofday(&end_tv, NULL);
|
||||
+ }
|
||||
+
|
||||
+ if ((start_tv.tv_sec == 0) || (start_tv.tv_usec == 0) ||
|
||||
+ (end_tv.tv_sec == 0) || (end_tv.tv_usec == 0)) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ unsigned long frozen_time = GET_MICROSECONDS(end_tv, start_tv);
|
||||
+ log_normal("Process %d frozen time is %ld microsecond(s)\n",
|
||||
+ pid, frozen_time);
|
||||
+}
|
||||
+
|
||||
int upatch_process_uuid_exist(struct upatch_process *proc, const char *uuid)
|
||||
{
|
||||
struct object_file *obj;
|
||||
@@ -698,14 +723,10 @@ int upatch_process_uuid_exist(struct upatch_process *proc, const char *uuid)
|
||||
|
||||
int process_patch(int pid, struct upatch_elf *uelf, struct running_elf *relf, const char *uuid, const char *binary_path)
|
||||
{
|
||||
- int ret;
|
||||
- bool is_calc_time = false;
|
||||
- struct timeval start_tv, end_tv;
|
||||
- unsigned long frozen_time;
|
||||
struct upatch_process proc;
|
||||
|
||||
// 查看process的信息,pid: maps, mem, cmdline, exe
|
||||
- ret = upatch_process_init(&proc, pid);
|
||||
+ int ret = upatch_process_init(&proc, pid);
|
||||
if (ret < 0) {
|
||||
log_error("Failed to init process\n");
|
||||
goto out;
|
||||
@@ -748,9 +769,7 @@ int process_patch(int pid, struct upatch_elf *uelf, struct running_elf *relf, co
|
||||
}
|
||||
|
||||
uelf->relf = relf;
|
||||
-
|
||||
- is_calc_time = true;
|
||||
- gettimeofday(&start_tv, NULL);
|
||||
+ upatch_time_tick(pid);
|
||||
|
||||
/* Finally, attach to process */
|
||||
ret = upatch_process_attach(&proc);
|
||||
@@ -769,16 +788,11 @@ int process_patch(int pid, struct upatch_elf *uelf, struct running_elf *relf, co
|
||||
|
||||
out_free:
|
||||
upatch_process_detach(&proc);
|
||||
- gettimeofday(&end_tv, NULL);
|
||||
+ upatch_time_tick(pid);
|
||||
|
||||
upatch_process_destroy(&proc);
|
||||
|
||||
out:
|
||||
- if (is_calc_time) {
|
||||
- frozen_time = GET_MICROSECONDS(end_tv, start_tv);
|
||||
- log_normal("Process %d frozen time is %ld microsecond(s)\n",
|
||||
- pid, frozen_time);
|
||||
- }
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -827,16 +841,12 @@ out:
|
||||
|
||||
int process_unpatch(int pid, const char *uuid)
|
||||
{
|
||||
- int ret;
|
||||
- bool is_calc_time = false;
|
||||
- struct timeval start_tv, end_tv;
|
||||
- unsigned long frozen_time;
|
||||
struct upatch_process proc;
|
||||
|
||||
// TODO: check build id
|
||||
// TODO: 栈解析
|
||||
// 查看process的信息,pid: maps, mem, cmdline, exe
|
||||
- ret = upatch_process_init(&proc, pid);
|
||||
+ int ret = upatch_process_init(&proc, pid);
|
||||
if (ret < 0) {
|
||||
log_error("Failed to init process\n");
|
||||
goto out;
|
||||
@@ -867,8 +877,7 @@ int process_unpatch(int pid, const char *uuid)
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
- is_calc_time = true;
|
||||
- gettimeofday(&start_tv, NULL);
|
||||
+ upatch_time_tick(pid);
|
||||
|
||||
/* Finally, attach to process */
|
||||
ret = upatch_process_attach(&proc);
|
||||
@@ -886,16 +895,11 @@ int process_unpatch(int pid, const char *uuid)
|
||||
|
||||
out_free:
|
||||
upatch_process_detach(&proc);
|
||||
- gettimeofday(&end_tv, NULL);
|
||||
+ upatch_time_tick(pid);
|
||||
|
||||
upatch_process_destroy(&proc);
|
||||
|
||||
out:
|
||||
- if (is_calc_time) {
|
||||
- frozen_time = GET_MICROSECONDS(end_tv, start_tv);
|
||||
- log_normal("Process %d frozen time is %ld microsecond(s)\n",
|
||||
- pid, frozen_time);
|
||||
- }
|
||||
return ret;
|
||||
}
|
||||
|
||||
--
|
||||
2.41.0
|
||||
|
||||
30
syscare.spec
30
syscare.spec
@ -11,7 +11,7 @@
|
||||
############################################
|
||||
Name: syscare
|
||||
Version: 1.2.1
|
||||
Release: 3
|
||||
Release: 4
|
||||
Summary: System hot-fix service
|
||||
License: MulanPSL-2.0 and GPL-2.0-only
|
||||
URL: https://gitee.com/openeuler/syscare
|
||||
@ -20,13 +20,20 @@ Source0: %{name}-%{version}.tar.gz
|
||||
Patch0001: 0001-upatch-hijacker-fix-compile-bug.patch
|
||||
Patch0002: 0002-daemon-fix-cannot-get-file-selinux-xattr-when-selinu.patch
|
||||
Patch0003: 0003-syscared-fix-syscare-check-command-does-not-check-sy.patch
|
||||
Patch0004: 0004-syscared-fix-cannot-find-process-of-dynlib-patch-iss.patch
|
||||
Patch0005: 0005-abi-change-uuid-type-from-string-to-uuid-bytes.patch
|
||||
Patch0006: 0006-syscared-optimize-patch-error-logic.patch
|
||||
Patch0007: 0007-syscared-optimize-transaction-creation-logic.patch
|
||||
Patch0008: 0008-upatch-manage-optimize-output.patch
|
||||
Patch0009: 0009-syscared-optimize-patch-error-logic.patch
|
||||
Patch0010: 0010-syscared-optimize-transaction-creation-logic.patch
|
||||
Patch0004: 0004-Change-uuid-type-to-Uuid.patch
|
||||
Patch0005: 0005-fix-clippy-warning.patch
|
||||
Patch0006: 0006-syscared-fix-cannot-find-process-of-dynlib-patch-iss.patch
|
||||
Patch0007: 0007-syscared-optimize-patch-error-logic.patch
|
||||
Patch0008: 0008-syscared-optimize-transaction-creation-logic.patch
|
||||
Patch0009: 0009-upatch-manage-optimize-output.patch
|
||||
Patch0010: 0010-syscared-optimize-patch-error-logic.patch
|
||||
Patch0011: 0011-syscared-optimize-transaction-creation-logic.patch
|
||||
Patch0012: 0012-common-impl-CStr-from_bytes_with_next_nul.patch
|
||||
Patch0013: 0013-syscared-improve-patch-management.patch
|
||||
Patch0014: 0014-syscared-stop-activating-ignored-process-on-new-proc.patch
|
||||
Patch0015: 0015-syscared-adapt-upatch-manage-exit-code-change.patch
|
||||
Patch0016: 0016-upatch-manage-change-exit-code.patch
|
||||
Patch0017: 0017-upatch-manage-change-the-way-to-calculate-frozen-tim.patch
|
||||
|
||||
BuildRequires: cmake >= 3.14 make
|
||||
BuildRequires: rust >= 1.51 cargo >= 1.51
|
||||
@ -177,6 +184,13 @@ fi
|
||||
################ Change log ################
|
||||
############################################
|
||||
%changelog
|
||||
* Fri Apr 19 2024 ningyu<ningyu9@huawei.com> - 1.2.1-4
|
||||
- common: impl CStr::from_bytes_with_next_nul()
|
||||
- syscared: improve patch management
|
||||
- syscared: stop activating ignored process on new process start
|
||||
- syscared: adapt upatch-manage exit code change
|
||||
- upatch-manage: change exit code
|
||||
- upatch-manage: change the way to calculate frozen time
|
||||
* Fri Apr 12 2024 ningyu<ningyu9@huawei.com> - 1.2.1-3
|
||||
- upatch-hijacker: fix compile bug
|
||||
- daemon: fix 'cannot get file selinux xattr when selinux is not enforcing' issue
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user