update to 1.2.1-9
Signed-off-by: renoseven <dev@renoseven.net>
This commit is contained in:
parent
ee9a0e3756
commit
e33abf2f0a
@ -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/13] upatch-hijacker: fix compile bug container_of_safe =>
|
||||
Subject: [PATCH] upatch-hijacker: fix compile bug container_of_safe =>
|
||||
container_of
|
||||
|
||||
---
|
||||
@ -29,5 +29,5 @@ index a9c18ba..3049556 100644
|
||||
\ No newline at end of file
|
||||
+}
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
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/13] daemon: fix 'cannot get file selinux xattr when selinux
|
||||
is not enforcing' issue
|
||||
Subject: [PATCH] daemon: fix 'cannot get file selinux xattr when selinux is
|
||||
not enforcing' issue
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -215,5 +215,5 @@ index 028a4c8..8ac12e7 100644
|
||||
debug!("Initializing hijacker ioctl channel...");
|
||||
let ioctl = HijackerIoctl::new(KMOD_DEV_PATH)?;
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
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/13] syscared: fix 'syscare check command does not check
|
||||
symbol confiliction' issue
|
||||
Subject: [PATCH] syscared: fix 'syscare check command does not check symbol
|
||||
confiliction' issue
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -381,5 +381,5 @@ index b353bdf..f633567 100644
|
||||
}
|
||||
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
From 32c3d16175b93627504981d05a1a3e3ec603415e Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Wed, 10 Apr 2024 19:30:56 +0800
|
||||
Subject: [PATCH 04/13] syscared: fix 'cannot find process of dynlib patch'
|
||||
issue
|
||||
Subject: [PATCH] syscared: fix 'cannot find process of dynlib patch' issue
|
||||
|
||||
1. For detecting process mapped dynamic library,
|
||||
we use /proc/$pid/map_files instead.
|
||||
@ -683,5 +682,5 @@ index bab2974..f0745f0 100644
|
||||
|
||||
Ok(())
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From a61958c837b70c0c530d32ee58b616ab9ad01f4b Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 12 Apr 2024 11:35:57 +0800
|
||||
Subject: [PATCH 05/13] syscared: optimize patch error logic
|
||||
Subject: [PATCH] syscared: optimize patch error logic
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -99,5 +99,5 @@ index f0745f0..1908520 100644
|
||||
.exit_code();
|
||||
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 211e4549324a9209dc982b7426af8b832410b619 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 12 Apr 2024 11:40:25 +0800
|
||||
Subject: [PATCH 06/13] syscared: optimize transaction creation logic
|
||||
Subject: [PATCH] syscared: optimize transaction creation logic
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -108,5 +108,5 @@ index 98494b1..b009d46 100644
|
||||
})
|
||||
}
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From a32e9f39965579064dbd504246f13c6431ffed33 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 12 Apr 2024 11:50:59 +0800
|
||||
Subject: [PATCH 07/13] upatch-manage: optimize output
|
||||
Subject: [PATCH] upatch-manage: optimize output
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -132,5 +132,5 @@ index 0d57238..cd3f7e0 100644
|
||||
}
|
||||
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From cc090b31139bb9aa0158e50a8a620fc41b23231c Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Tue, 16 Apr 2024 12:44:11 +0800
|
||||
Subject: [PATCH 08/13] common: impl CStr::from_bytes_with_next_nul()
|
||||
Subject: [PATCH] common: impl CStr::from_bytes_with_next_nul()
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -43,5 +43,5 @@ index 060149a..4f3f26d 100644
|
||||
#[test]
|
||||
fn test_cstr() {
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 354e0888188d4cabd9fff9912fa0935e4e1b4b52 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Tue, 16 Apr 2024 14:20:27 +0800
|
||||
Subject: [PATCH 09/13] syscared: improve patch management
|
||||
Subject: [PATCH] syscared: improve patch management
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -2315,5 +2315,5 @@ index 507bf8e..985b8f1 100644
|
||||
Ok(Patch::UserPatch(patch))
|
||||
}
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
From a83410a74713c4f191aeb31bc9ea87b9e9f4bcc6 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Wed, 17 Apr 2024 19:14:19 +0800
|
||||
Subject: [PATCH 10/13] syscared: stop activating ignored process on new
|
||||
process start
|
||||
Subject: [PATCH] syscared: stop activating ignored process on new process
|
||||
start
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -233,5 +233,5 @@ index dd07e9b..66eecf5 100644
|
||||
}
|
||||
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 4ad0b0369cd039b64635d2c405fa244b6c6afb59 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 19 Apr 2024 12:02:23 +0800
|
||||
Subject: [PATCH 11/13] syscared: adapt upatch-manage exit code change
|
||||
Subject: [PATCH] syscared: adapt upatch-manage exit code change
|
||||
|
||||
1. upatch driver treats EEXIST as an error
|
||||
|
||||
@ -31,5 +31,5 @@ index bfeb1b8..a388bc6 100644
|
||||
}
|
||||
}
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From e04ce4a7539a469091fef8c1566a85fe6050f728 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 19 Apr 2024 12:01:38 +0800
|
||||
Subject: [PATCH 12/13] upatch-manage: change exit code
|
||||
Subject: [PATCH] upatch-manage: change exit code
|
||||
|
||||
1. return more specific exit code
|
||||
2. change exit code from EEXIST to 0 when patching existing patch (uuid)
|
||||
@ -442,5 +442,5 @@ index 39e8f59..1309a6e 100644
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From ff07e664cb475fa74b4f6531d8e709a5dd9b55dd Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 19 Apr 2024 14:19:27 +0800
|
||||
Subject: [PATCH 13/13] upatch-manage: change the way to calculate frozen time
|
||||
Subject: [PATCH] upatch-manage: change the way to calculate frozen time
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -136,5 +136,5 @@ index 5a8f927..ab972ac 100644
|
||||
}
|
||||
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
From 35ee9283c60a2d3e7d5ae2bcb9db31c71856d645 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Thu, 9 May 2024 18:49:29 +0800
|
||||
Subject: [PATCH 14/21] upatch-build: fix 'file detection cause build failure'
|
||||
issue
|
||||
Subject: [PATCH] upatch-build: fix 'file detection cause build failure' issue
|
||||
|
||||
File relation detection does not work as we expected sometimes.
|
||||
We changed the way to parse file relations from parsing dwarf info
|
||||
@ -553,5 +552,5 @@ index a34f713..9927ece 100644
|
||||
e.source()
|
||||
.map(|e| e.to_string())
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 2a4df8e1c7418c49fbad06e20b2a6af100b1ed16 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Sat, 11 May 2024 08:26:33 +0800
|
||||
Subject: [PATCH 15/21] upatch-diff: optimize log output
|
||||
Subject: [PATCH] upatch-diff: optimize log output
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -465,5 +465,5 @@ index 2f7c777..b2d038b 100644
|
||||
unsigned char bind;
|
||||
unsigned char type;
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 4626c401b541c46debd18e1a326a323f4f85f69d Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Sat, 11 May 2024 08:28:48 +0800
|
||||
Subject: [PATCH 16/21] security: change directory permission
|
||||
Subject: [PATCH] security: change directory permission
|
||||
|
||||
1. config_dir /etc/syscare drwx------.
|
||||
2. data_dir /usr/lib/syscare drwx------.
|
||||
@ -95,5 +95,5 @@ index 86e2052..1007ebb 100644
|
||||
Ok(server)
|
||||
}
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From bb21560c6ab6217c06533ea85dd7db5a40379e5b Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Sat, 11 May 2024 10:21:58 +0800
|
||||
Subject: [PATCH 17/21] security: change daemon socket permission
|
||||
Subject: [PATCH] security: change daemon socket permission
|
||||
|
||||
1. add socket uid & gid to config file
|
||||
default uid: 0
|
||||
@ -822,5 +822,5 @@ index a334120..d725166 100644
|
||||
}
|
||||
}
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
From 270b6e91dc659aa52bde54facbc744d35fc67de4 Mon Sep 17 00:00:00 2001
|
||||
From: ningyu <ningyu9@huawei.com>
|
||||
Date: Sat, 11 May 2024 08:06:58 +0000
|
||||
Subject: [PATCH 18/21] upatch-manage: Fixed the core dump issue after applying
|
||||
hot patches to nginx on x86_64 architecture.
|
||||
Subject: [PATCH] upatch-manage: Fixed the core dump issue after applying hot
|
||||
patches to nginx on x86_64 architecture.
|
||||
|
||||
For non-dynamic library elf, do not place the global variables in the GOT table
|
||||
---
|
||||
@ -128,5 +128,5 @@ index fe68b7e..481fec9 100644
|
||||
|
||||
/* load bias, used to handle ASLR */
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From e7baf4fef5dfa7ccbb0d639628a910a8099735ec Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Sat, 11 May 2024 17:31:46 +0800
|
||||
Subject: [PATCH 19/21] upatch-diff: fix 'lookup_relf failed' issue
|
||||
Subject: [PATCH] upatch-diff: fix 'lookup_relf failed' issue
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
@ -140,5 +140,5 @@ index 037f5fc..3bb35e7 100644
|
||||
+ return (result->symbol != NULL);
|
||||
}
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From d3a4f6a47f2151e9828bdfd805ff2af927c80ed9 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Mon, 13 May 2024 21:27:13 +0800
|
||||
Subject: [PATCH 20/21] upatch-diff: only check changed file symbols
|
||||
Subject: [PATCH] upatch-diff: only check changed file symbols
|
||||
|
||||
1. sync compare results (SAME/NEW/CHANGED) to correlated objects
|
||||
2. mark file changes by looking up symbol changes
|
||||
@ -161,5 +161,5 @@ index 3bb35e7..676880f 100644
|
||||
|
||||
return (result->symbol != NULL);
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 8103b361db40350131bdb7b01124ce1d0f23e09a Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Tue, 14 May 2024 14:10:05 +0800
|
||||
Subject: [PATCH 21/21] upatch-diff: remove rela check while build rebuilding
|
||||
Subject: [PATCH] upatch-diff: remove rela check while build rebuilding
|
||||
.eh_frame
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
@ -23,5 +23,5 @@ index 6b5fc53..f9c5327 100644
|
||||
|
||||
/*
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
From cf5217d55b2a603cfa0a852d876809c536835f18 Mon Sep 17 00:00:00 2001
|
||||
From 5f9ef3e5d565fc31c809f57635c3619b4a2e6582 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Fri, 17 May 2024 14:46:30 +0800
|
||||
Subject: [PATCH] syscared: fix 'apply kernel module patch failure' issue
|
||||
@ -23,5 +23,5 @@ index 307efb5..970da92 100644
|
||||
current_kernel == patch_target,
|
||||
"Kpatch: Patch is incompatible",
|
||||
--
|
||||
2.41.0
|
||||
2.34.1
|
||||
|
||||
|
||||
241
0023-all-finding-executable-from-environment-variables.patch
Normal file
241
0023-all-finding-executable-from-environment-variables.patch
Normal file
@ -0,0 +1,241 @@
|
||||
From c0c8df3bdb7986925570279f3085425d9e6a87cc Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Wed, 29 May 2024 22:06:09 +0800
|
||||
Subject: [PATCH] all: finding executable from environment variables
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
syscare-build/src/main.rs | 10 ++++++++--
|
||||
syscare-build/src/patch/user_patch/upatch_builder.rs | 2 +-
|
||||
syscare/src/executor/build.rs | 7 +++----
|
||||
syscare/src/main.rs | 10 ++++++++--
|
||||
syscared/src/main.rs | 10 ++++++++--
|
||||
syscared/src/patch/driver/upatch/sys.rs | 2 +-
|
||||
upatch-build/src/main.rs | 9 ++++++++-
|
||||
7 files changed, 37 insertions(+), 13 deletions(-)
|
||||
|
||||
diff --git a/syscare-build/src/main.rs b/syscare-build/src/main.rs
|
||||
index 8928218..1faa803 100644
|
||||
--- a/syscare-build/src/main.rs
|
||||
+++ b/syscare-build/src/main.rs
|
||||
@@ -12,7 +12,7 @@
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
-use std::{process, sync::Arc};
|
||||
+use std::{env, process, sync::Arc};
|
||||
|
||||
use anyhow::{bail, ensure, Context, Result};
|
||||
use flexi_logger::{
|
||||
@@ -22,7 +22,7 @@ use lazy_static::lazy_static;
|
||||
use log::{error, info, LevelFilter, Record};
|
||||
|
||||
use syscare_abi::{PackageInfo, PackageType, PatchInfo, PatchType};
|
||||
-use syscare_common::{fs, os};
|
||||
+use syscare_common::{concat_os, fs, os};
|
||||
|
||||
mod args;
|
||||
mod build_params;
|
||||
@@ -44,6 +44,9 @@ const CLI_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
const CLI_ABOUT: &str = env!("CARGO_PKG_DESCRIPTION");
|
||||
const CLI_UMASK: u32 = 0o022;
|
||||
|
||||
+const PATH_ENV_NAME: &str = "PATH";
|
||||
+const PATH_ENV_VALUE: &str = "/usr/libexec/syscare";
|
||||
+
|
||||
const LOG_FILE_NAME: &str = "build";
|
||||
const KERNEL_PKG_NAME: &str = "kernel";
|
||||
|
||||
@@ -70,6 +73,9 @@ impl SyscareBuild {
|
||||
fn new() -> Result<Self> {
|
||||
// Initialize arguments & prepare environments
|
||||
os::umask::set_umask(CLI_UMASK);
|
||||
+ if let Some(path_env) = env::var_os(PATH_ENV_NAME) {
|
||||
+ env::set_var(PATH_ENV_NAME, concat_os!(PATH_ENV_VALUE, ":", path_env));
|
||||
+ }
|
||||
|
||||
let args = Arguments::new()?;
|
||||
let build_root = BuildRoot::new(&args.build_root)?;
|
||||
diff --git a/syscare-build/src/patch/user_patch/upatch_builder.rs b/syscare-build/src/patch/user_patch/upatch_builder.rs
|
||||
index ad8710b..ca56515 100644
|
||||
--- a/syscare-build/src/patch/user_patch/upatch_builder.rs
|
||||
+++ b/syscare-build/src/patch/user_patch/upatch_builder.rs
|
||||
@@ -34,7 +34,7 @@ use crate::{build_params::BuildParameters, package::PackageImpl, patch::PatchBui
|
||||
|
||||
use super::{elf_relation::ElfRelation, DEBUGINFO_FILE_EXT};
|
||||
|
||||
-const UPATCH_BUILD_BIN: &str = "/usr/libexec/syscare/upatch-build";
|
||||
+const UPATCH_BUILD_BIN: &str = "upatch-build";
|
||||
const RPMBUILD_BIN: &str = "rpmbuild";
|
||||
|
||||
struct UBuildParameters {
|
||||
diff --git a/syscare/src/executor/build.rs b/syscare/src/executor/build.rs
|
||||
index f9027c7..6d3866f 100644
|
||||
--- a/syscare/src/executor/build.rs
|
||||
+++ b/syscare/src/executor/build.rs
|
||||
@@ -19,22 +19,21 @@ use anyhow::{bail, Context, Result};
|
||||
use super::CommandExecutor;
|
||||
use crate::args::SubCommand;
|
||||
|
||||
-const SYSCARE_BUILD_PATH: &str = "/usr/libexec/syscare/syscare-build";
|
||||
+const SYSCARE_BUILD_BIN: &str = "syscare-build";
|
||||
|
||||
pub struct BuildCommandExecutor;
|
||||
|
||||
impl CommandExecutor for BuildCommandExecutor {
|
||||
fn invoke(&self, command: &SubCommand) -> Result<Option<i32>> {
|
||||
if let SubCommand::Build { args } = command {
|
||||
- let e = Command::new(SYSCARE_BUILD_PATH).args(args).exec();
|
||||
+ let e = Command::new(SYSCARE_BUILD_BIN).args(args).exec();
|
||||
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::NotFound => {
|
||||
bail!("Package syscare-build is not installed");
|
||||
}
|
||||
_ => {
|
||||
- return Err(e)
|
||||
- .with_context(|| format!("Failed to start {}", SYSCARE_BUILD_PATH))
|
||||
+ return Err(e).with_context(|| format!("Failed to start {}", SYSCARE_BUILD_BIN))
|
||||
}
|
||||
}
|
||||
}
|
||||
diff --git a/syscare/src/main.rs b/syscare/src/main.rs
|
||||
index c709f6a..dea5717 100644
|
||||
--- a/syscare/src/main.rs
|
||||
+++ b/syscare/src/main.rs
|
||||
@@ -12,7 +12,7 @@
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
-use std::{process, rc::Rc};
|
||||
+use std::{env, process, rc::Rc};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use flexi_logger::{DeferredNow, LogSpecification, Logger, LoggerHandle, WriteMode};
|
||||
@@ -25,13 +25,16 @@ mod rpc;
|
||||
use args::Arguments;
|
||||
use executor::{build::BuildCommandExecutor, patch::PatchCommandExecutor, CommandExecutor};
|
||||
use rpc::{RpcProxy, RpcRemote};
|
||||
-use syscare_common::os;
|
||||
+use syscare_common::{concat_os, os};
|
||||
|
||||
pub const CLI_NAME: &str = env!("CARGO_PKG_NAME");
|
||||
pub const CLI_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const CLI_ABOUT: &str = env!("CARGO_PKG_DESCRIPTION");
|
||||
const CLI_UMASK: u32 = 0o077;
|
||||
|
||||
+const PATH_ENV_NAME: &str = "PATH";
|
||||
+const PATH_ENV_VALUE: &str = "/usr/libexec/syscare";
|
||||
+
|
||||
const SOCKET_FILE_NAME: &str = "syscared.sock";
|
||||
const PATCH_OP_LOCK_NAME: &str = "patch_op.lock";
|
||||
|
||||
@@ -52,6 +55,9 @@ impl SyscareCLI {
|
||||
fn new() -> Result<Self> {
|
||||
// Initialize arguments & prepare environments
|
||||
os::umask::set_umask(CLI_UMASK);
|
||||
+ if let Some(path_env) = env::var_os(PATH_ENV_NAME) {
|
||||
+ env::set_var(PATH_ENV_NAME, concat_os!(PATH_ENV_VALUE, ":", path_env));
|
||||
+ }
|
||||
|
||||
let args = Arguments::new()?;
|
||||
|
||||
diff --git a/syscared/src/main.rs b/syscared/src/main.rs
|
||||
index b840abf..5c60ecf 100644
|
||||
--- a/syscared/src/main.rs
|
||||
+++ b/syscared/src/main.rs
|
||||
@@ -12,7 +12,7 @@
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
-use std::{fs::Permissions, os::unix::fs::PermissionsExt, panic, process, sync::Arc};
|
||||
+use std::{env, fs::Permissions, os::unix::fs::PermissionsExt, panic, process, sync::Arc};
|
||||
|
||||
use anyhow::{ensure, Context, Result};
|
||||
use daemonize::Daemonize;
|
||||
@@ -28,7 +28,7 @@ use parking_lot::RwLock;
|
||||
use patch::manager::PatchManager;
|
||||
use signal_hook::{consts::TERM_SIGNALS, iterator::Signals, low_level::signal_name};
|
||||
|
||||
-use syscare_common::{fs, os};
|
||||
+use syscare_common::{concat_os, fs, os};
|
||||
|
||||
mod args;
|
||||
mod config;
|
||||
@@ -49,6 +49,9 @@ const DAEMON_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
const DAEMON_ABOUT: &str = env!("CARGO_PKG_DESCRIPTION");
|
||||
const DAEMON_UMASK: u32 = 0o077;
|
||||
|
||||
+const PATH_ENV_NAME: &str = "PATH";
|
||||
+const PATH_ENV_VALUE: &str = "/usr/libexec/syscare";
|
||||
+
|
||||
const CONFIG_FILE_NAME: &str = "syscared.yaml";
|
||||
const PID_FILE_NAME: &str = "syscared.pid";
|
||||
const SOCKET_FILE_NAME: &str = "syscared.sock";
|
||||
@@ -107,6 +110,9 @@ impl Daemon {
|
||||
|
||||
// Initialize arguments & prepare environments
|
||||
os::umask::set_umask(DAEMON_UMASK);
|
||||
+ if let Some(path_env) = env::var_os(PATH_ENV_NAME) {
|
||||
+ env::set_var(PATH_ENV_NAME, concat_os!(PATH_ENV_VALUE, ":", path_env));
|
||||
+ }
|
||||
|
||||
let args = Arguments::new()?;
|
||||
fs::create_dir_all(&args.config_dir)?;
|
||||
diff --git a/syscared/src/patch/driver/upatch/sys.rs b/syscared/src/patch/driver/upatch/sys.rs
|
||||
index a388bc6..1990289 100644
|
||||
--- a/syscared/src/patch/driver/upatch/sys.rs
|
||||
+++ b/syscared/src/patch/driver/upatch/sys.rs
|
||||
@@ -6,7 +6,7 @@ use uuid::Uuid;
|
||||
|
||||
use syscare_common::process::Command;
|
||||
|
||||
-const UPATCH_MANAGE_BIN: &str = "/usr/libexec/syscare/upatch-manage";
|
||||
+const UPATCH_MANAGE_BIN: &str = "upatch-manage";
|
||||
|
||||
pub fn active_patch(uuid: &Uuid, pid: i32, target_elf: &Path, patch_file: &Path) -> Result<()> {
|
||||
let exit_code = Command::new(UPATCH_MANAGE_BIN)
|
||||
diff --git a/upatch-build/src/main.rs b/upatch-build/src/main.rs
|
||||
index b5c14a8..473b0a7 100644
|
||||
--- a/upatch-build/src/main.rs
|
||||
+++ b/upatch-build/src/main.rs
|
||||
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
|
||||
use std::{
|
||||
+ env,
|
||||
ffi::OsStr,
|
||||
fs::Permissions,
|
||||
os::unix::fs::PermissionsExt,
|
||||
@@ -54,6 +55,9 @@ const CLI_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
const CLI_ABOUT: &str = env!("CARGO_PKG_DESCRIPTION");
|
||||
const CLI_UMASK: u32 = 0o022;
|
||||
|
||||
+const PATH_ENV_NAME: &str = "PATH";
|
||||
+const PATH_ENV_VALUE: &str = "/usr/libexec/syscare";
|
||||
+
|
||||
const LOG_FILE_NAME: &str = "build";
|
||||
|
||||
struct BuildInfo {
|
||||
@@ -83,6 +87,9 @@ impl UpatchBuild {
|
||||
fn new() -> Result<Self> {
|
||||
// Initialize arguments & prepare environments
|
||||
os::umask::set_umask(CLI_UMASK);
|
||||
+ if let Some(path_env) = env::var_os(PATH_ENV_NAME) {
|
||||
+ env::set_var(PATH_ENV_NAME, concat_os!(PATH_ENV_VALUE, ":", path_env));
|
||||
+ }
|
||||
|
||||
let args = Arguments::new()?;
|
||||
let build_root = BuildRoot::new(&args.build_root)?;
|
||||
@@ -196,7 +203,7 @@ impl UpatchBuild {
|
||||
output_dir: &Path,
|
||||
verbose: bool,
|
||||
) -> Result<()> {
|
||||
- const UPATCH_DIFF_BIN: &str = "/usr/libexec/syscare/upatch-diff";
|
||||
+ const UPATCH_DIFF_BIN: &str = "upatch-diff";
|
||||
|
||||
let ouput_name = original_object.file_name().with_context(|| {
|
||||
format!(
|
||||
--
|
||||
2.34.1
|
||||
|
||||
901
0024-all-remove-redundant-code.patch
Normal file
901
0024-all-remove-redundant-code.patch
Normal file
@ -0,0 +1,901 @@
|
||||
From 5956424c9bc00a722dd6227de1b85e65a5e23b25 Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Tue, 21 May 2024 15:01:48 +0800
|
||||
Subject: [PATCH] all: remove redundant code
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
syscare-build/src/build_root/mod.rs | 20 +-
|
||||
syscare-build/src/build_root/package_root.rs | 6 -
|
||||
syscare-build/src/build_root/patch_root.rs | 6 -
|
||||
syscare-build/src/package/dependency.rs | 10 -
|
||||
syscare-build/src/package/mod.rs | 1 -
|
||||
syscare-build/src/package/rpm/mod.rs | 4 -
|
||||
syscare-common/src/os/disk.rs | 64 ----
|
||||
syscare-common/src/os/grub.rs | 312 ------------------
|
||||
syscare-common/src/os/kernel.rs | 43 +--
|
||||
syscare-common/src/os/mod.rs | 2 -
|
||||
syscare-common/src/util/digest.rs | 7 -
|
||||
syscared/src/fast_reboot/manager.rs | 123 -------
|
||||
syscared/src/fast_reboot/mod.rs | 17 -
|
||||
syscared/src/main.rs | 7 +-
|
||||
syscared/src/rpc/skeleton/fast_reboot.rs | 21 --
|
||||
syscared/src/rpc/skeleton/mod.rs | 2 -
|
||||
syscared/src/rpc/skeleton_impl/fast_reboot.rs | 42 ---
|
||||
syscared/src/rpc/skeleton_impl/mod.rs | 2 -
|
||||
18 files changed, 3 insertions(+), 686 deletions(-)
|
||||
delete mode 100644 syscare-build/src/package/dependency.rs
|
||||
delete mode 100644 syscare-common/src/os/disk.rs
|
||||
delete mode 100644 syscare-common/src/os/grub.rs
|
||||
delete mode 100644 syscared/src/fast_reboot/manager.rs
|
||||
delete mode 100644 syscared/src/fast_reboot/mod.rs
|
||||
delete mode 100644 syscared/src/rpc/skeleton/fast_reboot.rs
|
||||
delete mode 100644 syscared/src/rpc/skeleton_impl/fast_reboot.rs
|
||||
|
||||
diff --git a/syscare-build/src/build_root/mod.rs b/syscare-build/src/build_root/mod.rs
|
||||
index 81de6b2..6a12788 100644
|
||||
--- a/syscare-build/src/build_root/mod.rs
|
||||
+++ b/syscare-build/src/build_root/mod.rs
|
||||
@@ -12,11 +12,7 @@
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
-use std::{
|
||||
- ffi::OsStr,
|
||||
- ops::Deref,
|
||||
- path::{Path, PathBuf},
|
||||
-};
|
||||
+use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::Result;
|
||||
use syscare_common::fs;
|
||||
@@ -61,17 +57,3 @@ impl BuildRoot {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
-
|
||||
-impl Deref for BuildRoot {
|
||||
- type Target = Path;
|
||||
-
|
||||
- fn deref(&self) -> &Self::Target {
|
||||
- &self.path
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-impl AsRef<OsStr> for BuildRoot {
|
||||
- fn as_ref(&self) -> &OsStr {
|
||||
- self.as_os_str()
|
||||
- }
|
||||
-}
|
||||
diff --git a/syscare-build/src/build_root/package_root.rs b/syscare-build/src/build_root/package_root.rs
|
||||
index abb7a86..724a42b 100644
|
||||
--- a/syscare-build/src/build_root/package_root.rs
|
||||
+++ b/syscare-build/src/build_root/package_root.rs
|
||||
@@ -50,9 +50,3 @@ impl PackageRoot {
|
||||
})
|
||||
}
|
||||
}
|
||||
-
|
||||
-impl AsRef<Path> for PackageRoot {
|
||||
- fn as_ref(&self) -> &Path {
|
||||
- &self.path
|
||||
- }
|
||||
-}
|
||||
diff --git a/syscare-build/src/build_root/patch_root.rs b/syscare-build/src/build_root/patch_root.rs
|
||||
index b780e32..af8ec6b 100644
|
||||
--- a/syscare-build/src/build_root/patch_root.rs
|
||||
+++ b/syscare-build/src/build_root/patch_root.rs
|
||||
@@ -44,9 +44,3 @@ impl PatchRoot {
|
||||
})
|
||||
}
|
||||
}
|
||||
-
|
||||
-impl AsRef<Path> for PatchRoot {
|
||||
- fn as_ref(&self) -> &Path {
|
||||
- &self.path
|
||||
- }
|
||||
-}
|
||||
diff --git a/syscare-build/src/package/dependency.rs b/syscare-build/src/package/dependency.rs
|
||||
deleted file mode 100644
|
||||
index 37bdf92..0000000
|
||||
--- a/syscare-build/src/package/dependency.rs
|
||||
+++ /dev/null
|
||||
@@ -1,10 +0,0 @@
|
||||
-pub struct PackageDependency {
|
||||
- requires: HashSet<String>,
|
||||
- conflicts: HashSet<String>,
|
||||
- suggests: HashSet<String>,
|
||||
- recommends: HashSet<String>,
|
||||
-}
|
||||
-
|
||||
-impl PackageDependency {
|
||||
-
|
||||
-}
|
||||
\ No newline at end of file
|
||||
diff --git a/syscare-build/src/package/mod.rs b/syscare-build/src/package/mod.rs
|
||||
index 9ba29a1..72b555a 100644
|
||||
--- a/syscare-build/src/package/mod.rs
|
||||
+++ b/syscare-build/src/package/mod.rs
|
||||
@@ -33,7 +33,6 @@ pub use spec_writer::*;
|
||||
pub use tar::*;
|
||||
|
||||
trait Package {
|
||||
- fn extension(&self) -> &'static str;
|
||||
fn parse_package_info(&self, pkg_path: &Path) -> Result<PackageInfo>;
|
||||
fn query_package_files(&self, pkg_path: &Path) -> Result<Vec<PathBuf>>;
|
||||
fn extract_package(&self, pkg_path: &Path, output_dir: &Path) -> Result<()>;
|
||||
diff --git a/syscare-build/src/package/rpm/mod.rs b/syscare-build/src/package/rpm/mod.rs
|
||||
index 5b4bf07..0e9f77c 100644
|
||||
--- a/syscare-build/src/package/rpm/mod.rs
|
||||
+++ b/syscare-build/src/package/rpm/mod.rs
|
||||
@@ -60,10 +60,6 @@ impl RpmPackage {
|
||||
}
|
||||
|
||||
impl Package for RpmPackage {
|
||||
- fn extension(&self) -> &'static str {
|
||||
- PKG_FILE_EXT
|
||||
- }
|
||||
-
|
||||
fn parse_package_info(&self, pkg_path: &Path) -> Result<PackageInfo> {
|
||||
let query_result = Self::query_package_info(
|
||||
pkg_path,
|
||||
diff --git a/syscare-common/src/os/disk.rs b/syscare-common/src/os/disk.rs
|
||||
deleted file mode 100644
|
||||
index 7ace804..0000000
|
||||
--- a/syscare-common/src/os/disk.rs
|
||||
+++ /dev/null
|
||||
@@ -1,64 +0,0 @@
|
||||
-// SPDX-License-Identifier: Mulan PSL v2
|
||||
-/*
|
||||
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
||||
- * syscare-common 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
|
||||
- *
|
||||
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
- * See the Mulan PSL v2 for more details.
|
||||
- */
|
||||
-
|
||||
-use std::ffi::OsStr;
|
||||
-use std::path::{Path, PathBuf};
|
||||
-
|
||||
-use crate::fs;
|
||||
-
|
||||
-#[inline(always)]
|
||||
-fn find_disk<P: AsRef<Path>, S: AsRef<OsStr>>(directory: P, name: S) -> std::io::Result<PathBuf> {
|
||||
- #[inline(always)]
|
||||
- fn __find_disk(directory: &Path, name: &OsStr) -> std::io::Result<PathBuf> {
|
||||
- let dev = fs::find_symlink(
|
||||
- directory,
|
||||
- name,
|
||||
- fs::FindOptions {
|
||||
- fuzz: false,
|
||||
- recursive: false,
|
||||
- },
|
||||
- )?;
|
||||
- fs::canonicalize(dev)
|
||||
- }
|
||||
-
|
||||
- __find_disk(directory.as_ref(), name.as_ref()).map_err(|_| {
|
||||
- std::io::Error::new(
|
||||
- std::io::ErrorKind::NotFound,
|
||||
- format!(
|
||||
- "Cannot find block device by label \"{}\"",
|
||||
- name.as_ref().to_string_lossy()
|
||||
- ),
|
||||
- )
|
||||
- })
|
||||
-}
|
||||
-
|
||||
-pub fn find_by_id<S: AsRef<OsStr>>(name: S) -> std::io::Result<PathBuf> {
|
||||
- find_disk("/dev/disk/by-id", name)
|
||||
-}
|
||||
-
|
||||
-pub fn find_by_label<S: AsRef<OsStr>>(name: S) -> std::io::Result<PathBuf> {
|
||||
- find_disk("/dev/disk/by-label", name)
|
||||
-}
|
||||
-
|
||||
-pub fn find_by_uuid<S: AsRef<OsStr>>(name: S) -> std::io::Result<PathBuf> {
|
||||
- find_disk("/dev/disk/by-uuid", name)
|
||||
-}
|
||||
-
|
||||
-pub fn find_by_partuuid<S: AsRef<OsStr>>(name: S) -> std::io::Result<PathBuf> {
|
||||
- find_disk("/dev/disk/by-partuuid", name)
|
||||
-}
|
||||
-
|
||||
-pub fn find_by_path<S: AsRef<OsStr>>(name: S) -> std::io::Result<PathBuf> {
|
||||
- find_disk("/dev/disk/by-path", name)
|
||||
-}
|
||||
diff --git a/syscare-common/src/os/grub.rs b/syscare-common/src/os/grub.rs
|
||||
deleted file mode 100644
|
||||
index 54299d8..0000000
|
||||
--- a/syscare-common/src/os/grub.rs
|
||||
+++ /dev/null
|
||||
@@ -1,312 +0,0 @@
|
||||
-// SPDX-License-Identifier: Mulan PSL v2
|
||||
-/*
|
||||
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
||||
- * syscare-common 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
|
||||
- *
|
||||
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
- * See the Mulan PSL v2 for more details.
|
||||
- */
|
||||
-
|
||||
-use std::collections::HashMap;
|
||||
-use std::ffi::{OsStr, OsString};
|
||||
-use std::io::{BufRead, BufReader};
|
||||
-use std::os::unix::prelude::OsStrExt as StdOsStrExt;
|
||||
-use std::path::{Path, PathBuf};
|
||||
-
|
||||
-use lazy_static::lazy_static;
|
||||
-use log::debug;
|
||||
-use regex::bytes::Regex;
|
||||
-
|
||||
-use super::{disk, proc_mounts};
|
||||
-use crate::{
|
||||
- ffi::OsStrExt,
|
||||
- fs,
|
||||
- io::{BufReadOsLines, OsLines},
|
||||
-};
|
||||
-
|
||||
-#[derive(Debug, Clone, Copy)]
|
||||
-enum BootType {
|
||||
- Csm,
|
||||
- Uefi,
|
||||
-}
|
||||
-
|
||||
-#[derive(Debug)]
|
||||
-pub struct GrubMenuEntry {
|
||||
- name: OsString,
|
||||
- root: PathBuf,
|
||||
- kernel: PathBuf,
|
||||
- initrd: PathBuf,
|
||||
-}
|
||||
-
|
||||
-impl GrubMenuEntry {
|
||||
- pub fn get_name(&self) -> &OsStr {
|
||||
- &self.name
|
||||
- }
|
||||
-
|
||||
- pub fn get_root(&self) -> &Path {
|
||||
- &self.root
|
||||
- }
|
||||
-
|
||||
- pub fn get_kernel(&self) -> PathBuf {
|
||||
- // Path is stripped by regular expression, thus, it would always start with '/'
|
||||
- self.root.join(self.kernel.strip_prefix("/").unwrap())
|
||||
- }
|
||||
-
|
||||
- pub fn get_initrd(&self) -> PathBuf {
|
||||
- // Path is stripped by regular expression, thus, it would always start with '/'
|
||||
- self.root.join(self.initrd.strip_prefix("/").unwrap())
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-struct GrubConfigParser<R> {
|
||||
- lines: OsLines<R>,
|
||||
- is_matching: bool,
|
||||
- entry_name: Option<OsString>,
|
||||
- entry_root: Option<PathBuf>,
|
||||
- entry_kernel: Option<PathBuf>,
|
||||
- entry_initrd: Option<PathBuf>,
|
||||
-}
|
||||
-
|
||||
-impl<R: BufRead> GrubConfigParser<R> {
|
||||
- pub fn new(buf: R) -> Self {
|
||||
- Self {
|
||||
- lines: buf.os_lines(),
|
||||
- is_matching: false,
|
||||
- entry_name: None,
|
||||
- entry_root: None,
|
||||
- entry_kernel: None,
|
||||
- entry_initrd: None,
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- #[inline(always)]
|
||||
- fn parse_name(str: &OsStr) -> Option<OsString> {
|
||||
- lazy_static! {
|
||||
- static ref RE: Regex = Regex::new(r"'([^']*)'").unwrap();
|
||||
- }
|
||||
- RE.captures(str.as_bytes())
|
||||
- .and_then(|captures| captures.get(1))
|
||||
- .map(|matched| OsStr::from_bytes(matched.as_bytes()).to_os_string())
|
||||
- }
|
||||
-
|
||||
- #[inline(always)]
|
||||
- fn parse_uuid(str: &OsStr) -> Option<OsString> {
|
||||
- str.split_whitespace()
|
||||
- .filter_map(|str| {
|
||||
- let arg = str.trim();
|
||||
- if arg != OsStr::new("search") && !arg.starts_with("--") {
|
||||
- return Some(arg.to_os_string());
|
||||
- }
|
||||
- None
|
||||
- })
|
||||
- .next()
|
||||
- }
|
||||
-
|
||||
- #[inline(always)]
|
||||
- fn parse_path(str: &OsStr) -> Option<PathBuf> {
|
||||
- lazy_static! {
|
||||
- static ref RE: Regex = Regex::new(r"/\.?\w+([\w\-\.])*").unwrap();
|
||||
- }
|
||||
- RE.find(str.as_bytes())
|
||||
- .map(|matched| PathBuf::from(OsStr::from_bytes(matched.as_bytes())))
|
||||
- }
|
||||
-
|
||||
- #[inline(always)]
|
||||
- fn parse_mount_point(str: &OsStr) -> Option<PathBuf> {
|
||||
- let find_dev = Self::parse_uuid(str).and_then(|uuid| disk::find_by_uuid(uuid).ok());
|
||||
- if let (Some(dev_name), Ok(mounts)) = (find_dev, proc_mounts::Mounts::new()) {
|
||||
- for mount in mounts {
|
||||
- if mount.mount_source == dev_name {
|
||||
- return Some(mount.mount_point);
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
- None
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-impl<R: BufRead> Iterator for GrubConfigParser<R> {
|
||||
- type Item = GrubMenuEntry;
|
||||
-
|
||||
- fn next(&mut self) -> Option<Self::Item> {
|
||||
- for line in (&mut self.lines).flatten() {
|
||||
- if line.starts_with("#") {
|
||||
- continue;
|
||||
- }
|
||||
-
|
||||
- let str = line.trim();
|
||||
- if str.is_empty() {
|
||||
- continue;
|
||||
- }
|
||||
-
|
||||
- if !self.is_matching {
|
||||
- if str.starts_with("menuentry '") {
|
||||
- self.entry_name = Self::parse_name(str);
|
||||
- self.is_matching = true;
|
||||
- }
|
||||
- continue;
|
||||
- }
|
||||
- if str.starts_with("search") {
|
||||
- self.entry_root = Self::parse_mount_point(str);
|
||||
- } else if str.starts_with("linux") {
|
||||
- self.entry_kernel = Self::parse_path(str);
|
||||
- } else if str.starts_with("initrd") {
|
||||
- self.entry_initrd = Self::parse_path(str);
|
||||
- } else if str.starts_with("}") {
|
||||
- let entry = match (
|
||||
- &self.entry_name,
|
||||
- &self.entry_root,
|
||||
- &self.entry_kernel,
|
||||
- &self.entry_initrd,
|
||||
- ) {
|
||||
- (Some(name), Some(root), Some(kernel), Some(initrd)) => Some(GrubMenuEntry {
|
||||
- name: name.to_os_string(),
|
||||
- root: root.to_path_buf(),
|
||||
- kernel: kernel.to_path_buf(),
|
||||
- initrd: initrd.to_path_buf(),
|
||||
- }),
|
||||
- _ => None,
|
||||
- };
|
||||
- self.is_matching = false;
|
||||
- self.entry_name = None;
|
||||
- self.entry_root = None;
|
||||
- self.entry_kernel = None;
|
||||
- self.entry_initrd = None;
|
||||
-
|
||||
- return entry;
|
||||
- }
|
||||
- }
|
||||
- None
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-struct GrubEnvParser<R> {
|
||||
- lines: OsLines<R>,
|
||||
-}
|
||||
-
|
||||
-impl<R: BufRead> GrubEnvParser<R> {
|
||||
- pub fn new(buf: R) -> Self {
|
||||
- Self {
|
||||
- lines: buf.os_lines(),
|
||||
- }
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-impl<R: BufRead> Iterator for GrubEnvParser<R> {
|
||||
- type Item = (OsString, OsString);
|
||||
-
|
||||
- fn next(&mut self) -> Option<Self::Item> {
|
||||
- for line in (&mut self.lines).flatten() {
|
||||
- if line.starts_with("#") {
|
||||
- continue;
|
||||
- }
|
||||
-
|
||||
- let str = line.trim();
|
||||
- if str.is_empty() {
|
||||
- continue;
|
||||
- }
|
||||
-
|
||||
- let mut kv = line.split('=');
|
||||
- if let (Some(key), Some(value)) = (kv.next(), kv.next()) {
|
||||
- return Some((key.trim().to_os_string(), value.trim().to_os_string()));
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- None
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-fn get_boot_type() -> BootType {
|
||||
- const UEFI_SYS_INTERFACE: &str = "/sys/firmware/efi";
|
||||
-
|
||||
- match fs::metadata(UEFI_SYS_INTERFACE) {
|
||||
- Ok(_) => BootType::Uefi,
|
||||
- Err(_) => BootType::Csm,
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-fn get_grub_path(boot_type: BootType) -> PathBuf {
|
||||
- const CSM_GRUB_PATH: &str = "/boot/grub2";
|
||||
- const UEFI_GRUB_PATH: &str = "/boot/efi/EFI";
|
||||
-
|
||||
- match boot_type {
|
||||
- BootType::Csm => PathBuf::from(CSM_GRUB_PATH),
|
||||
- BootType::Uefi => PathBuf::from(UEFI_GRUB_PATH),
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-fn find_grub_config<P: AsRef<Path>>(grub_root: P) -> std::io::Result<PathBuf> {
|
||||
- const GRUB_CFG_NAME: &str = "grub.cfg";
|
||||
-
|
||||
- fs::find_file(
|
||||
- grub_root,
|
||||
- GRUB_CFG_NAME,
|
||||
- fs::FindOptions {
|
||||
- fuzz: false,
|
||||
- recursive: true,
|
||||
- },
|
||||
- )
|
||||
-}
|
||||
-
|
||||
-fn find_grub_env<P: AsRef<Path>>(grub_root: P) -> std::io::Result<PathBuf> {
|
||||
- const GRUB_ENV_NAME: &str = "grubenv";
|
||||
-
|
||||
- fs::find_file(
|
||||
- grub_root,
|
||||
- GRUB_ENV_NAME,
|
||||
- fs::FindOptions {
|
||||
- fuzz: false,
|
||||
- recursive: true,
|
||||
- },
|
||||
- )
|
||||
-}
|
||||
-
|
||||
-pub fn read_menu_entries<P: AsRef<Path>>(grub_root: P) -> std::io::Result<Vec<GrubMenuEntry>> {
|
||||
- let grub_config = find_grub_config(grub_root)?;
|
||||
-
|
||||
- let result = GrubConfigParser::new(BufReader::new(fs::open_file(grub_config)?)).collect();
|
||||
-
|
||||
- Ok(result)
|
||||
-}
|
||||
-
|
||||
-pub fn read_grub_env<P: AsRef<Path>>(grub_root: P) -> std::io::Result<HashMap<OsString, OsString>> {
|
||||
- let grub_env = find_grub_env(grub_root).unwrap();
|
||||
-
|
||||
- let result = GrubEnvParser::new(BufReader::new(fs::open_file(grub_env)?)).collect();
|
||||
-
|
||||
- Ok(result)
|
||||
-}
|
||||
-
|
||||
-pub fn get_boot_entry() -> std::io::Result<GrubMenuEntry> {
|
||||
- let boot_type = get_boot_type();
|
||||
- let grub_root = get_grub_path(boot_type);
|
||||
- debug!("Boot type: {:?}", boot_type);
|
||||
-
|
||||
- let menu_entries = read_menu_entries(&grub_root)?;
|
||||
- debug!("Boot entries: {:#?}", menu_entries);
|
||||
-
|
||||
- let grub_env = read_grub_env(&grub_root)?;
|
||||
- let default_entry_name = grub_env.get(OsStr::new("saved_entry")).ok_or_else(|| {
|
||||
- std::io::Error::new(
|
||||
- std::io::ErrorKind::Other,
|
||||
- "Cannot read grub default entry name",
|
||||
- )
|
||||
- })?;
|
||||
- debug!("Default entry: {:?}", default_entry_name);
|
||||
-
|
||||
- for entry in menu_entries {
|
||||
- if entry.get_name() == default_entry_name {
|
||||
- return Ok(entry);
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- Err(std::io::Error::new(
|
||||
- std::io::ErrorKind::Other,
|
||||
- format!("Cannot find grub default entry {:?}", default_entry_name),
|
||||
- ))
|
||||
-}
|
||||
diff --git a/syscare-common/src/os/kernel.rs b/syscare-common/src/os/kernel.rs
|
||||
index b89850b..a29e663 100644
|
||||
--- a/syscare-common/src/os/kernel.rs
|
||||
+++ b/syscare-common/src/os/kernel.rs
|
||||
@@ -12,51 +12,10 @@
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
-use std::{ffi::OsStr, path::Path};
|
||||
-
|
||||
-use anyhow::Result;
|
||||
-
|
||||
-const KEXEC_PATH: &str = "kexec";
|
||||
-const SYSTEMCTL_PATH: &str = "systemctl";
|
||||
+use std::ffi::OsStr;
|
||||
|
||||
use super::platform;
|
||||
-use crate::{concat_os, process::Command};
|
||||
|
||||
pub fn version() -> &'static OsStr {
|
||||
platform::release()
|
||||
}
|
||||
-
|
||||
-pub fn load<P, Q>(kernel: P, initramfs: Q) -> Result<()>
|
||||
-where
|
||||
- P: AsRef<Path>,
|
||||
- Q: AsRef<Path>,
|
||||
-{
|
||||
- Command::new(KEXEC_PATH)
|
||||
- .arg("--load")
|
||||
- .arg(kernel.as_ref())
|
||||
- .arg(concat_os!("--initrd=", initramfs.as_ref()))
|
||||
- .arg("--reuse-cmdline")
|
||||
- .run_with_output()?
|
||||
- .exit_ok()
|
||||
-}
|
||||
-
|
||||
-pub fn unload() -> Result<()> {
|
||||
- Command::new(KEXEC_PATH)
|
||||
- .arg("--unload")
|
||||
- .run_with_output()?
|
||||
- .exit_ok()
|
||||
-}
|
||||
-
|
||||
-pub fn systemd_exec() -> Result<()> {
|
||||
- Command::new(SYSTEMCTL_PATH)
|
||||
- .arg("kexec")
|
||||
- .run_with_output()?
|
||||
- .exit_ok()
|
||||
-}
|
||||
-
|
||||
-pub fn force_exec() -> Result<()> {
|
||||
- Command::new(KEXEC_PATH)
|
||||
- .arg("--exec")
|
||||
- .run_with_output()?
|
||||
- .exit_ok()
|
||||
-}
|
||||
diff --git a/syscare-common/src/os/mod.rs b/syscare-common/src/os/mod.rs
|
||||
index 8e6d5c1..6a93a20 100644
|
||||
--- a/syscare-common/src/os/mod.rs
|
||||
+++ b/syscare-common/src/os/mod.rs
|
||||
@@ -13,8 +13,6 @@
|
||||
*/
|
||||
|
||||
pub mod cpu;
|
||||
-pub mod disk;
|
||||
-pub mod grub;
|
||||
pub mod kernel;
|
||||
pub mod platform;
|
||||
pub mod proc_maps;
|
||||
diff --git a/syscare-common/src/util/digest.rs b/syscare-common/src/util/digest.rs
|
||||
index bb879cb..086b636 100644
|
||||
--- a/syscare-common/src/util/digest.rs
|
||||
+++ b/syscare-common/src/util/digest.rs
|
||||
@@ -45,10 +45,3 @@ where
|
||||
|
||||
Ok(format!("{:#x}", hasher.finalize()))
|
||||
}
|
||||
-
|
||||
-pub fn dir<P: AsRef<Path>>(directory: P) -> std::io::Result<String> {
|
||||
- file_list(fs::list_files(
|
||||
- directory,
|
||||
- fs::TraverseOptions { recursive: true },
|
||||
- )?)
|
||||
-}
|
||||
diff --git a/syscared/src/fast_reboot/manager.rs b/syscared/src/fast_reboot/manager.rs
|
||||
deleted file mode 100644
|
||||
index 8a4a928..0000000
|
||||
--- a/syscared/src/fast_reboot/manager.rs
|
||||
+++ /dev/null
|
||||
@@ -1,123 +0,0 @@
|
||||
-// SPDX-License-Identifier: Mulan PSL v2
|
||||
-/*
|
||||
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
||||
- * syscared 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
|
||||
- *
|
||||
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
- * See the Mulan PSL v2 for more details.
|
||||
- */
|
||||
-
|
||||
-use std::path::PathBuf;
|
||||
-
|
||||
-use anyhow::{Context, Result};
|
||||
-use lazy_static::lazy_static;
|
||||
-use log::{error, info};
|
||||
-
|
||||
-use syscare_common::{
|
||||
- fs,
|
||||
- os::{grub, kernel},
|
||||
-};
|
||||
-
|
||||
-lazy_static! {
|
||||
- static ref BOOT_DIRECTORY: PathBuf = PathBuf::from("/boot");
|
||||
-}
|
||||
-
|
||||
-pub enum RebootOption {
|
||||
- Normal,
|
||||
- Forced,
|
||||
-}
|
||||
-
|
||||
-struct LoadKernelOption {
|
||||
- name: String,
|
||||
- kernel: PathBuf,
|
||||
- initramfs: PathBuf,
|
||||
-}
|
||||
-
|
||||
-pub struct KExecManager;
|
||||
-
|
||||
-impl KExecManager {
|
||||
- fn find_kernel(kernel_version: &str) -> Result<LoadKernelOption> {
|
||||
- info!("Finding kernel {}...", kernel_version);
|
||||
- let kernel_file_name = format!("vmlinuz-{}", kernel_version);
|
||||
- let kernel_file = fs::find_file(
|
||||
- BOOT_DIRECTORY.as_path(),
|
||||
- kernel_file_name,
|
||||
- fs::FindOptions {
|
||||
- fuzz: false,
|
||||
- recursive: false,
|
||||
- },
|
||||
- )
|
||||
- .with_context(|| format!("Cannot find kernel {}", kernel_version))?;
|
||||
-
|
||||
- info!("Finding initramfs...");
|
||||
- let initramfs_file_name = format!("initramfs-{}.img", kernel_version);
|
||||
- let initramfs_file = fs::find_file(
|
||||
- BOOT_DIRECTORY.as_path(),
|
||||
- initramfs_file_name,
|
||||
- fs::FindOptions {
|
||||
- fuzz: false,
|
||||
- recursive: false,
|
||||
- },
|
||||
- )
|
||||
- .with_context(|| format!("Cannot find kernel {} initramfs", kernel_version))?;
|
||||
-
|
||||
- Ok(LoadKernelOption {
|
||||
- name: kernel_version.to_owned(),
|
||||
- kernel: kernel_file,
|
||||
- initramfs: initramfs_file,
|
||||
- })
|
||||
- }
|
||||
-
|
||||
- fn find_kernel_by_grub() -> Result<LoadKernelOption> {
|
||||
- info!("Parsing grub configuration...");
|
||||
- let entry = grub::get_boot_entry().context("Failed to read grub boot entry")?;
|
||||
- let entry_name = entry
|
||||
- .get_name()
|
||||
- .to_str()
|
||||
- .context("Failed to parse grub entry name")?;
|
||||
-
|
||||
- Ok(LoadKernelOption {
|
||||
- name: entry_name.to_owned(),
|
||||
- kernel: entry.get_kernel(),
|
||||
- initramfs: entry.get_initrd(),
|
||||
- })
|
||||
- }
|
||||
-
|
||||
- pub fn load_kernel(kernel_version: Option<String>) -> Result<()> {
|
||||
- let load_option = match kernel_version {
|
||||
- Some(version) => Self::find_kernel(&version),
|
||||
- None => Self::find_kernel_by_grub().or_else(|e| {
|
||||
- error!("{:?}", e);
|
||||
- let version: &str = kernel::version()
|
||||
- .to_str()
|
||||
- .context("Failed to parse current kernel version")?;
|
||||
-
|
||||
- Self::find_kernel(version)
|
||||
- }),
|
||||
- }?;
|
||||
-
|
||||
- kernel::unload().context("Failed to unload kernel")?;
|
||||
-
|
||||
- let name = load_option.name;
|
||||
- let kernel = load_option.kernel;
|
||||
- let initramfs = load_option.initramfs;
|
||||
- info!("Loading {:?}", name);
|
||||
- info!("Using kernel: {:?}", kernel);
|
||||
- info!("Using initrd: {:?}", initramfs);
|
||||
-
|
||||
- kernel::load(&kernel, &initramfs).context("Failed to load kernel")
|
||||
- }
|
||||
-
|
||||
- pub fn execute(option: RebootOption) -> Result<()> {
|
||||
- match option {
|
||||
- RebootOption::Normal => kernel::systemd_exec(),
|
||||
- RebootOption::Forced => kernel::force_exec(),
|
||||
- }
|
||||
- .context("Failed to execute kernel")
|
||||
- }
|
||||
-}
|
||||
diff --git a/syscared/src/fast_reboot/mod.rs b/syscared/src/fast_reboot/mod.rs
|
||||
deleted file mode 100644
|
||||
index 8c40eb9..0000000
|
||||
--- a/syscared/src/fast_reboot/mod.rs
|
||||
+++ /dev/null
|
||||
@@ -1,17 +0,0 @@
|
||||
-// SPDX-License-Identifier: Mulan PSL v2
|
||||
-/*
|
||||
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
||||
- * syscared 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
|
||||
- *
|
||||
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
- * See the Mulan PSL v2 for more details.
|
||||
- */
|
||||
-
|
||||
-mod manager;
|
||||
-
|
||||
-pub use manager::*;
|
||||
diff --git a/syscared/src/main.rs b/syscared/src/main.rs
|
||||
index 5c60ecf..f13a9f8 100644
|
||||
--- a/syscared/src/main.rs
|
||||
+++ b/syscared/src/main.rs
|
||||
@@ -32,17 +32,13 @@ use syscare_common::{concat_os, fs, os};
|
||||
|
||||
mod args;
|
||||
mod config;
|
||||
-mod fast_reboot;
|
||||
mod patch;
|
||||
mod rpc;
|
||||
|
||||
use args::Arguments;
|
||||
use config::Config;
|
||||
use patch::monitor::PatchMonitor;
|
||||
-use rpc::{
|
||||
- skeleton::{FastRebootSkeleton, PatchSkeleton},
|
||||
- skeleton_impl::{FastRebootSkeletonImpl, PatchSkeletonImpl},
|
||||
-};
|
||||
+use rpc::{skeleton::PatchSkeleton, skeleton_impl::PatchSkeletonImpl};
|
||||
|
||||
const DAEMON_NAME: &str = env!("CARGO_PKG_NAME");
|
||||
const DAEMON_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
@@ -195,7 +191,6 @@ impl Daemon {
|
||||
let mut io_handler = IoHandler::new();
|
||||
|
||||
io_handler.extend_with(PatchSkeletonImpl::new(patch_manager).to_delegate());
|
||||
- io_handler.extend_with(FastRebootSkeletonImpl.to_delegate());
|
||||
|
||||
Ok(io_handler)
|
||||
}
|
||||
diff --git a/syscared/src/rpc/skeleton/fast_reboot.rs b/syscared/src/rpc/skeleton/fast_reboot.rs
|
||||
deleted file mode 100644
|
||||
index 1a7b496..0000000
|
||||
--- a/syscared/src/rpc/skeleton/fast_reboot.rs
|
||||
+++ /dev/null
|
||||
@@ -1,21 +0,0 @@
|
||||
-// SPDX-License-Identifier: Mulan PSL v2
|
||||
-/*
|
||||
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
||||
- * syscared 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
|
||||
- *
|
||||
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
- * See the Mulan PSL v2 for more details.
|
||||
- */
|
||||
-
|
||||
-use super::function::{rpc, RpcResult};
|
||||
-
|
||||
-#[rpc(server)]
|
||||
-pub trait FastRebootSkeleton {
|
||||
- #[rpc(name = "fast_reboot")]
|
||||
- fn fast_reboot(&self, kernel_version: Option<String>, force: bool) -> RpcResult<()>;
|
||||
-}
|
||||
diff --git a/syscared/src/rpc/skeleton/mod.rs b/syscared/src/rpc/skeleton/mod.rs
|
||||
index 74456ca..6fa6b60 100644
|
||||
--- a/syscared/src/rpc/skeleton/mod.rs
|
||||
+++ b/syscared/src/rpc/skeleton/mod.rs
|
||||
@@ -14,8 +14,6 @@
|
||||
|
||||
use super::function;
|
||||
|
||||
-mod fast_reboot;
|
||||
mod patch;
|
||||
|
||||
-pub use fast_reboot::*;
|
||||
pub use patch::*;
|
||||
diff --git a/syscared/src/rpc/skeleton_impl/fast_reboot.rs b/syscared/src/rpc/skeleton_impl/fast_reboot.rs
|
||||
deleted file mode 100644
|
||||
index aeab458..0000000
|
||||
--- a/syscared/src/rpc/skeleton_impl/fast_reboot.rs
|
||||
+++ /dev/null
|
||||
@@ -1,42 +0,0 @@
|
||||
-// SPDX-License-Identifier: Mulan PSL v2
|
||||
-/*
|
||||
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
||||
- * syscared 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
|
||||
- *
|
||||
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
- * See the Mulan PSL v2 for more details.
|
||||
- */
|
||||
-
|
||||
-use anyhow::{Context, Result};
|
||||
-
|
||||
-use crate::fast_reboot::{KExecManager, RebootOption};
|
||||
-use log::info;
|
||||
-
|
||||
-use super::{
|
||||
- function::{RpcFunction, RpcResult},
|
||||
- skeleton::FastRebootSkeleton,
|
||||
-};
|
||||
-
|
||||
-pub struct FastRebootSkeletonImpl;
|
||||
-
|
||||
-impl FastRebootSkeleton for FastRebootSkeletonImpl {
|
||||
- fn fast_reboot(&self, kernel_version: Option<String>, force: bool) -> RpcResult<()> {
|
||||
- RpcFunction::call(move || -> Result<()> {
|
||||
- info!("Rebooting system...");
|
||||
-
|
||||
- KExecManager::load_kernel(kernel_version)
|
||||
- .and_then(|_| {
|
||||
- KExecManager::execute(match force {
|
||||
- true => RebootOption::Forced,
|
||||
- false => RebootOption::Normal,
|
||||
- })
|
||||
- })
|
||||
- .context("Failed to reboot system")
|
||||
- })
|
||||
- }
|
||||
-}
|
||||
diff --git a/syscared/src/rpc/skeleton_impl/mod.rs b/syscared/src/rpc/skeleton_impl/mod.rs
|
||||
index a238df4..7037946 100644
|
||||
--- a/syscared/src/rpc/skeleton_impl/mod.rs
|
||||
+++ b/syscared/src/rpc/skeleton_impl/mod.rs
|
||||
@@ -15,8 +15,6 @@
|
||||
use super::function;
|
||||
use super::skeleton;
|
||||
|
||||
-mod fast_reboot;
|
||||
mod patch;
|
||||
|
||||
-pub use fast_reboot::*;
|
||||
pub use patch::*;
|
||||
--
|
||||
2.34.1
|
||||
|
||||
2283
0025-all-add-c-rust-compilation-options.patch
Normal file
2283
0025-all-add-c-rust-compilation-options.patch
Normal file
File diff suppressed because it is too large
Load Diff
32
0026-common-fix-failed-to-set-selinux-status-issue.patch
Normal file
32
0026-common-fix-failed-to-set-selinux-status-issue.patch
Normal file
@ -0,0 +1,32 @@
|
||||
From 28eee5483aa283ee6e2ca50a3e141d21a0e9cb4b Mon Sep 17 00:00:00 2001
|
||||
From: liuxiaobo <liuxiaobo19@huawei.com>
|
||||
Date: Wed, 5 Jun 2024 10:52:44 +0800
|
||||
Subject: [PATCH] common: fix 'failed to set selinux status' issue
|
||||
|
||||
Signed-off-by: liuxiaobo <liuxiaobo19@huawei.com>
|
||||
---
|
||||
syscare-common/src/os/selinux.rs | 8 +++++++-
|
||||
1 file changed, 7 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/syscare-common/src/os/selinux.rs b/syscare-common/src/os/selinux.rs
|
||||
index cf3b5b2..bb9864c 100644
|
||||
--- a/syscare-common/src/os/selinux.rs
|
||||
+++ b/syscare-common/src/os/selinux.rs
|
||||
@@ -59,7 +59,13 @@ pub fn set_status(value: Status) -> Result<()> {
|
||||
if (value != Status::Permissive) && (value != Status::Enforcing) {
|
||||
bail!("Status {} is invalid", value);
|
||||
}
|
||||
- fs::write(SELINUX_SYS_FILE, value.to_string())?;
|
||||
+ fs::write(
|
||||
+ SELINUX_SYS_FILE,
|
||||
+ match value {
|
||||
+ Status::Enforcing => "1",
|
||||
+ _ => "0",
|
||||
+ },
|
||||
+ )?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
--
|
||||
2.34.1
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
From ca2c36855f39d95d95f18024633e155a9cf220ff Mon Sep 17 00:00:00 2001
|
||||
From: ningyu <ningyu9@huawei.com>
|
||||
Date: Mon, 27 May 2024 10:34:00 +0000
|
||||
Subject: [PATCH] upatch-diff: exit with error when any tls var included
|
||||
|
||||
Signed-off-by: ningyu <ningyu9@huawei.com>
|
||||
---
|
||||
upatch-diff/create-diff-object.c | 17 +++++++++++++++++
|
||||
1 file changed, 17 insertions(+)
|
||||
|
||||
diff --git a/upatch-diff/create-diff-object.c b/upatch-diff/create-diff-object.c
|
||||
index 6474b22..5ec6f31 100644
|
||||
--- a/upatch-diff/create-diff-object.c
|
||||
+++ b/upatch-diff/create-diff-object.c
|
||||
@@ -847,6 +847,19 @@ static void include_debug_sections(struct upatch_elf *uelf)
|
||||
/* currently, there si no special section need to be handled */
|
||||
static void process_special_sections(void) {}
|
||||
|
||||
+static bool has_tls_included(struct upatch_elf *uelf)
|
||||
+{
|
||||
+ struct symbol *sym;
|
||||
+
|
||||
+ list_for_each_entry(sym, &uelf->symbols, list) {
|
||||
+ if (sym->include == 1 && sym->type == STT_TLS) {
|
||||
+ log_normal("TLS symbol '%s' included, but it's not supported", sym->name);
|
||||
+ return true;
|
||||
+ }
|
||||
+ }
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
static void verify_patchability(struct upatch_elf *uelf)
|
||||
{
|
||||
struct section *sec;
|
||||
@@ -878,6 +891,10 @@ static void verify_patchability(struct upatch_elf *uelf)
|
||||
|
||||
if (errs)
|
||||
DIFF_FATAL("%d, Unsupported section changes", errs);
|
||||
+
|
||||
+ if (has_tls_included(uelf)) {
|
||||
+ DIFF_FATAL("Unsupported symbol included");
|
||||
+ }
|
||||
}
|
||||
|
||||
static void migrate_included_elements(struct upatch_elf *uelf_patched, struct upatch_elf *uelf_out)
|
||||
--
|
||||
2.34.1
|
||||
|
||||
34
0028-upatch-diff-fix-lookup_relf-duplicate-failure.patch
Normal file
34
0028-upatch-diff-fix-lookup_relf-duplicate-failure.patch
Normal file
@ -0,0 +1,34 @@
|
||||
From 598fcd5fc70ffb1f17c00ef03bcd67d8c42c06df Mon Sep 17 00:00:00 2001
|
||||
From: ningyu <ningyu9@huawei.com>
|
||||
Date: Mon, 27 May 2024 11:16:26 +0000
|
||||
Subject: [PATCH] upatch-diff: fix lookup_relf duplicate failure
|
||||
|
||||
Signed-off-by: ningyu <ningyu9@huawei.com>
|
||||
---
|
||||
upatch-diff/running-elf.c | 8 +++++++-
|
||||
1 file changed, 7 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/upatch-diff/running-elf.c b/upatch-diff/running-elf.c
|
||||
index 25b72b7..18ff095 100644
|
||||
--- a/upatch-diff/running-elf.c
|
||||
+++ b/upatch-diff/running-elf.c
|
||||
@@ -125,9 +125,15 @@ bool lookup_relf(struct running_elf *relf,
|
||||
symbol = &relf->obj_syms[i];
|
||||
sympos++;
|
||||
|
||||
- if (strcmp(symbol->name, lookup_sym->name) != 0) {
|
||||
+ if (result->symbol != NULL && symbol->type == STT_FILE) {
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ if (strcmp(symbol->name, lookup_sym->name) != 0 ||
|
||||
+ symbol->bind != lookup_sym->bind) {
|
||||
continue;
|
||||
}
|
||||
+
|
||||
if ((result->symbol != NULL) &&
|
||||
(result->symbol->bind == symbol->bind)) {
|
||||
ERROR("Found duplicate symbol '%s' in %s",
|
||||
--
|
||||
2.34.1
|
||||
|
||||
611
0029-upatch-diff-fix-memory-leak.patch
Normal file
611
0029-upatch-diff-fix-memory-leak.patch
Normal file
@ -0,0 +1,611 @@
|
||||
From 70ba20b8a6b5e7fdb05b79aeada4882a6fd2ca1e Mon Sep 17 00:00:00 2001
|
||||
From: liuxiaobo <liuxiaobo19@huawei.com>
|
||||
Date: Thu, 27 Jun 2024 14:22:53 +0800
|
||||
Subject: [PATCH] upatch-diff: fix memory leak
|
||||
|
||||
Signed-off-by: liuxiaobo <liuxiaobo19@huawei.com>
|
||||
---
|
||||
upatch-diff/create-diff-object.c | 34 +++++---
|
||||
upatch-diff/elf-correlate.c | 10 +--
|
||||
upatch-diff/elf-create.c | 83 ++++++++++++--------
|
||||
upatch-diff/elf-debug.c | 7 +-
|
||||
upatch-diff/running-elf.c | 2 +-
|
||||
upatch-diff/running-elf.h | 2 +-
|
||||
upatch-diff/upatch-elf.c | 128 ++++++++++++++++++++++---------
|
||||
upatch-diff/upatch-elf.h | 14 +++-
|
||||
8 files changed, 191 insertions(+), 89 deletions(-)
|
||||
|
||||
diff --git a/upatch-diff/create-diff-object.c b/upatch-diff/create-diff-object.c
|
||||
index 5ec6f31..8830956 100644
|
||||
--- a/upatch-diff/create-diff-object.c
|
||||
+++ b/upatch-diff/create-diff-object.c
|
||||
@@ -836,8 +836,10 @@ static void include_debug_sections(struct upatch_elf *uelf)
|
||||
|
||||
list_for_each_entry_safe(rela, saferela, &sec->relas, list)
|
||||
// The shndex of symbol is SHN_COMMON, there is no related section
|
||||
- if (rela->sym && !rela->sym->include)
|
||||
+ if (rela->sym && !rela->sym->include) {
|
||||
list_del(&rela->list);
|
||||
+ free(rela);
|
||||
+ }
|
||||
}
|
||||
|
||||
if (eh_sec)
|
||||
@@ -993,15 +995,20 @@ int main(int argc, char*argv[])
|
||||
mark_ignored_functions_same();
|
||||
mark_ignored_sections_same();
|
||||
|
||||
- upatch_elf_teardown(&uelf_source);
|
||||
- upatch_elf_free(&uelf_source);
|
||||
-
|
||||
include_standard_elements(&uelf_patched);
|
||||
|
||||
num_changed = include_changed_functions(&uelf_patched);
|
||||
new_globals_exist = include_new_globals(&uelf_patched);
|
||||
if (!num_changed && !new_globals_exist) {
|
||||
log_normal("No functional changes\n");
|
||||
+ upatch_elf_destroy(&uelf_source);
|
||||
+ upatch_elf_destroy(&uelf_patched);
|
||||
+
|
||||
+ upatch_elf_close(&uelf_source);
|
||||
+ upatch_elf_close(&uelf_patched);
|
||||
+
|
||||
+ relf_close(&relf);
|
||||
+
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1019,9 +1026,6 @@ int main(int argc, char*argv[])
|
||||
|
||||
migrate_included_elements(&uelf_patched, &uelf_out);
|
||||
|
||||
- /* since out elf still point to it, we only destroy it, not free it */
|
||||
- upatch_elf_teardown(&uelf_patched);
|
||||
-
|
||||
upatch_create_strings_elements(&uelf_out);
|
||||
|
||||
upatch_create_patches_sections(&uelf_out, &relf);
|
||||
@@ -1060,11 +1064,19 @@ int main(int argc, char*argv[])
|
||||
|
||||
upatch_write_output_elf(&uelf_out, uelf_patched.elf, arguments.output_obj, 0664);
|
||||
|
||||
- relf_destroy(&relf);
|
||||
- upatch_elf_free(&uelf_patched);
|
||||
- upatch_elf_teardown(&uelf_out);
|
||||
- upatch_elf_free(&uelf_out);
|
||||
+ upatch_elf_destroy(&uelf_source);
|
||||
+ upatch_elf_destroy(&uelf_patched);
|
||||
+ upatch_elf_destroy(&uelf_out);
|
||||
+
|
||||
+ upatch_elf_close(&uelf_source);
|
||||
+ upatch_elf_close(&uelf_patched);
|
||||
+ upatch_elf_close(&uelf_out);
|
||||
+
|
||||
+ relf_close(&relf);
|
||||
|
||||
log_normal("Done\n");
|
||||
+ fflush(stdout);
|
||||
+ fflush(stderr);
|
||||
+
|
||||
return 0;
|
||||
}
|
||||
diff --git a/upatch-diff/elf-correlate.c b/upatch-diff/elf-correlate.c
|
||||
index 3e3a536..cc3b925 100644
|
||||
--- a/upatch-diff/elf-correlate.c
|
||||
+++ b/upatch-diff/elf-correlate.c
|
||||
@@ -36,9 +36,8 @@ static void correlate_symbol(struct symbol *sym_orig, struct symbol *sym_patched
|
||||
sym_orig->status = sym_patched->status = SAME;
|
||||
if (strcmp(sym_orig->name, sym_patched->name)) {
|
||||
log_debug("renaming symbol %s to %s \n", sym_patched->name, sym_orig->name);
|
||||
- sym_patched->name = strdup(sym_orig->name);
|
||||
- if (!sym_patched->name)
|
||||
- ERROR("strdup");
|
||||
+ sym_patched->name = sym_orig->name;
|
||||
+ sym_patched->name_source = DATA_SOURCE_REF;
|
||||
}
|
||||
if (sym_orig->relf_sym && !sym_patched->relf_sym)
|
||||
sym_patched->relf_sym = sym_orig->relf_sym;
|
||||
@@ -98,9 +97,8 @@ static void __correlate_section(struct section *sec_orig, struct section *sec_pa
|
||||
/* Make sure these two sections have the same name */
|
||||
if (strcmp(sec_orig->name, sec_patched->name)) {
|
||||
log_debug("renaming section %s to %s \n", sec_patched->name, sec_orig->name);
|
||||
- sec_patched->name = strdup(sec_orig->name);
|
||||
- if (!sec_patched->name)
|
||||
- ERROR("strdup");
|
||||
+ sec_patched->name = sec_orig->name;
|
||||
+ sec_patched->name_source = DATA_SOURCE_REF;
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/upatch-diff/elf-create.c b/upatch-diff/elf-create.c
|
||||
index 8ac212a..bd7edf0 100644
|
||||
--- a/upatch-diff/elf-create.c
|
||||
+++ b/upatch-diff/elf-create.c
|
||||
@@ -41,10 +41,12 @@ static struct section *create_section_pair(struct upatch_elf *uelf, char *name,
|
||||
{
|
||||
char *relaname;
|
||||
struct section *sec, *relasec;
|
||||
+ size_t size = strlen(name) + strlen(".rela") + 1;
|
||||
|
||||
- relaname = malloc(strlen(name) + strlen(".rela") + 1);
|
||||
- if (!relaname)
|
||||
+ relaname = calloc(1, size);
|
||||
+ if (!relaname) {
|
||||
ERROR("relaname malloc failed.");
|
||||
+ }
|
||||
|
||||
strcpy(relaname, ".rela");
|
||||
strcat(relaname, name);
|
||||
@@ -52,13 +54,17 @@ static struct section *create_section_pair(struct upatch_elf *uelf, char *name,
|
||||
/* allocate text section resourcce */
|
||||
ALLOC_LINK(sec, &uelf->sections);
|
||||
sec->name = name;
|
||||
- sec->data = malloc(sizeof(*sec->data));
|
||||
- if (!sec->data)
|
||||
+ sec->data = calloc(1, sizeof(Elf_Data));
|
||||
+ if (!sec->data) {
|
||||
ERROR("section data malloc failed.");
|
||||
+ }
|
||||
+ sec->data_source = DATA_SOURCE_ALLOC;
|
||||
|
||||
sec->data->d_buf = calloc(nr, entsize);
|
||||
- if (!sec->data->d_buf)
|
||||
+ if (!sec->data->d_buf) {
|
||||
ERROR("d_buf of section data malloc failed.");
|
||||
+ }
|
||||
+ sec->dbuf_source = DATA_SOURCE_ALLOC;
|
||||
|
||||
sec->data->d_size = entsize * nr;
|
||||
sec->data->d_type = ELF_T_BYTE;
|
||||
@@ -73,12 +79,15 @@ static struct section *create_section_pair(struct upatch_elf *uelf, char *name,
|
||||
/* set relocation section */
|
||||
ALLOC_LINK(relasec, &uelf->sections);
|
||||
relasec->name = relaname;
|
||||
+ relasec->name_source = DATA_SOURCE_ALLOC;
|
||||
INIT_LIST_HEAD(&relasec->relas);
|
||||
|
||||
/* buffers will be generated by upatch_rebuild_rela_section_data */
|
||||
- relasec->data = malloc(sizeof(*relasec->data));
|
||||
- if (!relasec->data)
|
||||
+ relasec->data = calloc(1, sizeof(Elf_Data));
|
||||
+ if (!relasec->data) {
|
||||
ERROR("relasec data malloc failed.");
|
||||
+ }
|
||||
+ relasec->data_source = DATA_SOURCE_ALLOC;
|
||||
|
||||
relasec->data->d_type = ELF_T_RELA;
|
||||
|
||||
@@ -103,9 +112,12 @@ void upatch_create_strings_elements(struct upatch_elf *uelf)
|
||||
ALLOC_LINK(sec, &uelf->sections);
|
||||
sec->name = ".upatch.strings";
|
||||
|
||||
- sec->data = malloc(sizeof(*sec->data));
|
||||
- if (!sec->data)
|
||||
+ sec->data = calloc(1, sizeof(Elf_Data));
|
||||
+ if (!sec->data) {
|
||||
ERROR("section data malloc failed");
|
||||
+ }
|
||||
+ sec->data_source = DATA_SOURCE_ALLOC;
|
||||
+
|
||||
sec->data->d_type = ELF_T_BYTE;
|
||||
|
||||
/* set section header */
|
||||
@@ -310,12 +322,14 @@ void upatch_build_strings_section_data(struct upatch_elf *uelf)
|
||||
size += strlen(string->name) + 1;
|
||||
|
||||
/* allocate section resources */
|
||||
- strtab = malloc(size);
|
||||
- if (!strtab)
|
||||
+ strtab = calloc(1, size);
|
||||
+ if (!strtab) {
|
||||
ERROR("strtab malloc failed.");
|
||||
+ }
|
||||
|
||||
sec->data->d_buf = strtab;
|
||||
sec->data->d_size = size;
|
||||
+ sec->dbuf_source = DATA_SOURCE_ALLOC;
|
||||
|
||||
/* populate strings section data */
|
||||
list_for_each_entry(string, &uelf->strings, list) {
|
||||
@@ -407,13 +421,15 @@ static void rebuild_rela_section_data(struct section *sec)
|
||||
nr++;
|
||||
|
||||
size = nr * sizeof(*relas);
|
||||
- relas = malloc(size);
|
||||
- if (!relas)
|
||||
+ relas = calloc(1, size);
|
||||
+ if (!relas) {
|
||||
ERROR("relas malloc failed.");
|
||||
+ }
|
||||
|
||||
sec->data->d_buf = relas;
|
||||
sec->data->d_size = size;
|
||||
sec->sh.sh_size = size;
|
||||
+ sec->dbuf_source = DATA_SOURCE_ALLOC;
|
||||
|
||||
list_for_each_entry(rela, &sec->relas, list) {
|
||||
relas[index].r_offset = rela->offset;
|
||||
@@ -469,18 +485,19 @@ void upatch_create_shstrtab(struct upatch_elf *uelf)
|
||||
char *buf;
|
||||
|
||||
shstrtab = find_section_by_name(&uelf->sections, ".shstrtab");
|
||||
- if (!shstrtab)
|
||||
+ if (!shstrtab) {
|
||||
ERROR("find_section_by_name failed.");
|
||||
+ }
|
||||
|
||||
/* determine size of string table */
|
||||
size = 1;
|
||||
list_for_each_entry(sec, &uelf->sections, list)
|
||||
size += strlen(sec->name) + 1;
|
||||
|
||||
- buf = malloc(size);
|
||||
- if (!buf)
|
||||
+ buf = calloc(1, size);
|
||||
+ if (!buf) {
|
||||
ERROR("malloc shstrtab failed.");
|
||||
- memset(buf, 0, size);
|
||||
+ }
|
||||
|
||||
offset = 1;
|
||||
list_for_each_entry(sec, &uelf->sections, list) {
|
||||
@@ -490,11 +507,14 @@ void upatch_create_shstrtab(struct upatch_elf *uelf)
|
||||
offset += len;
|
||||
}
|
||||
|
||||
- if (offset != size)
|
||||
+ if (offset != size) {
|
||||
+ free(buf);
|
||||
ERROR("shstrtab size mismatch.");
|
||||
+ }
|
||||
|
||||
shstrtab->data->d_buf = buf;
|
||||
shstrtab->data->d_size = size;
|
||||
+ shstrtab->dbuf_source = DATA_SOURCE_ALLOC;
|
||||
|
||||
log_debug("shstrtab: ");
|
||||
print_strtab(buf, size);
|
||||
@@ -506,25 +526,24 @@ void upatch_create_shstrtab(struct upatch_elf *uelf)
|
||||
|
||||
void upatch_create_strtab(struct upatch_elf *uelf)
|
||||
{
|
||||
- struct section *strtab;
|
||||
- struct symbol *sym;
|
||||
size_t size = 0, offset = 0, len = 0;
|
||||
- char *buf;
|
||||
|
||||
- strtab = find_section_by_name(&uelf->sections, ".strtab");
|
||||
- if (!strtab)
|
||||
+ struct section *strtab = find_section_by_name(&uelf->sections, ".strtab");
|
||||
+ if (!strtab) {
|
||||
ERROR("find section failed in create strtab.");
|
||||
+ }
|
||||
|
||||
+ struct symbol *sym = NULL;
|
||||
list_for_each_entry(sym, &uelf->symbols, list) {
|
||||
if (sym->type == STT_SECTION)
|
||||
continue;
|
||||
size += strlen(sym->name) + 1;
|
||||
}
|
||||
|
||||
- buf = malloc(size);
|
||||
- if (!buf)
|
||||
+ char *buf = calloc(1, size);
|
||||
+ if (!buf) {
|
||||
ERROR("malloc buf failed in create strtab");
|
||||
- memset(buf, 0, size);
|
||||
+ }
|
||||
|
||||
list_for_each_entry(sym, &uelf->symbols, list) {
|
||||
if (sym->type == STT_SECTION) {
|
||||
@@ -537,11 +556,14 @@ void upatch_create_strtab(struct upatch_elf *uelf)
|
||||
offset += len;
|
||||
}
|
||||
|
||||
- if (offset != size)
|
||||
+ if (offset != size) {
|
||||
+ free(buf);
|
||||
ERROR("shstrtab size mismatch.");
|
||||
+ }
|
||||
|
||||
strtab->data->d_buf = buf;
|
||||
strtab->data->d_size = size;
|
||||
+ strtab->dbuf_source = DATA_SOURCE_ALLOC;
|
||||
|
||||
log_debug("strtab: ");
|
||||
print_strtab(buf, size);
|
||||
@@ -569,10 +591,10 @@ void upatch_create_symtab(struct upatch_elf *uelf)
|
||||
nr++;
|
||||
|
||||
size = nr * symtab->sh.sh_entsize;
|
||||
- buf = malloc(size);
|
||||
- if (!buf)
|
||||
+ buf = calloc(1, size);
|
||||
+ if (!buf) {
|
||||
ERROR("malloc buf failed in create symtab.");
|
||||
- memset(buf, 0, size);
|
||||
+ }
|
||||
|
||||
offset = 0;
|
||||
list_for_each_entry(sym, &uelf->symbols, list) {
|
||||
@@ -585,6 +607,7 @@ void upatch_create_symtab(struct upatch_elf *uelf)
|
||||
|
||||
symtab->data->d_buf = buf;
|
||||
symtab->data->d_size = size;
|
||||
+ symtab->dbuf_source = DATA_SOURCE_ALLOC;
|
||||
|
||||
/* update symtab section header */
|
||||
strtab = find_section_by_name(&uelf->sections, ".strtab");
|
||||
diff --git a/upatch-diff/elf-debug.c b/upatch-diff/elf-debug.c
|
||||
index eaabfa1..0490f86 100644
|
||||
--- a/upatch-diff/elf-debug.c
|
||||
+++ b/upatch-diff/elf-debug.c
|
||||
@@ -129,9 +129,10 @@ void upatch_rebuild_eh_frame(struct section *sec)
|
||||
|
||||
/* in this time, some relcation entries may have been deleted */
|
||||
frame_size = 0;
|
||||
- eh_frame = malloc(sec->data->d_size);
|
||||
- if (!eh_frame)
|
||||
+ eh_frame = calloc(1, sec->data->d_size);
|
||||
+ if (!eh_frame) {
|
||||
ERROR("malloc eh_frame failed \n");
|
||||
+ }
|
||||
|
||||
/* 8 is the offset of PC begin */
|
||||
current_offset = 8;
|
||||
@@ -191,5 +192,7 @@ void upatch_rebuild_eh_frame(struct section *sec)
|
||||
|
||||
sec->data->d_buf = eh_frame;
|
||||
sec->data->d_size = frame_size;
|
||||
+ sec->dbuf_source = DATA_SOURCE_ALLOC;
|
||||
+
|
||||
sec->sh.sh_size = frame_size;
|
||||
}
|
||||
diff --git a/upatch-diff/running-elf.c b/upatch-diff/running-elf.c
|
||||
index 18ff095..c99b395 100644
|
||||
--- a/upatch-diff/running-elf.c
|
||||
+++ b/upatch-diff/running-elf.c
|
||||
@@ -101,7 +101,7 @@ void relf_init(char *elf_name, struct running_elf *relf)
|
||||
}
|
||||
}
|
||||
|
||||
-int relf_destroy(struct running_elf *relf)
|
||||
+int relf_close(struct running_elf *relf)
|
||||
{
|
||||
free(relf->obj_syms);
|
||||
elf_end(relf->elf);
|
||||
diff --git a/upatch-diff/running-elf.h b/upatch-diff/running-elf.h
|
||||
index 0646780..b02c8e2 100644
|
||||
--- a/upatch-diff/running-elf.h
|
||||
+++ b/upatch-diff/running-elf.h
|
||||
@@ -58,7 +58,7 @@ struct running_elf {
|
||||
|
||||
void relf_init(char *, struct running_elf *);
|
||||
|
||||
-int relf_destroy(struct running_elf *);
|
||||
+int relf_close(struct running_elf *);
|
||||
|
||||
bool lookup_relf(struct running_elf *, struct symbol *, struct lookup_result *);
|
||||
|
||||
diff --git a/upatch-diff/upatch-elf.c b/upatch-diff/upatch-elf.c
|
||||
index ee38efc..171e88e 100644
|
||||
--- a/upatch-diff/upatch-elf.c
|
||||
+++ b/upatch-diff/upatch-elf.c
|
||||
@@ -67,11 +67,14 @@ static void create_section_list(struct upatch_elf *uelf)
|
||||
sec->name = elf_strptr(uelf->elf, shstrndx, sec->sh.sh_name);
|
||||
if (!sec->name)
|
||||
ERROR("elf_strptr with error %s", elf_errmsg(0));
|
||||
-
|
||||
sec->data = elf_getdata(scn, NULL);
|
||||
if (!sec->data)
|
||||
ERROR("elf_getdata with error %s", elf_errmsg(0));
|
||||
|
||||
+ sec->name_source = DATA_SOURCE_ELF;
|
||||
+ sec->data_source = DATA_SOURCE_ELF;
|
||||
+ sec->dbuf_source = DATA_SOURCE_ELF;
|
||||
+
|
||||
sec->index = (unsigned int)elf_ndxscn(scn);
|
||||
/* found extended section header */
|
||||
if (sec->sh.sh_type == SHT_SYMTAB_SHNDX)
|
||||
@@ -157,6 +160,8 @@ static void create_rela_list(struct upatch_elf *uelf, struct section *relasec)
|
||||
struct rela *rela;
|
||||
int index = 0, skip = 0;
|
||||
|
||||
+ INIT_LIST_HEAD(&relasec->relas);
|
||||
+
|
||||
/* for relocation sections, sh_info is the index which these informations apply */
|
||||
relasec->base = find_section_by_index(&uelf->sections, relasec->sh.sh_info);
|
||||
if (!relasec->base)
|
||||
@@ -215,10 +220,86 @@ static void create_rela_list(struct upatch_elf *uelf, struct section *relasec)
|
||||
}
|
||||
}
|
||||
|
||||
+static void destroy_rela_list(struct section *relasec)
|
||||
+{
|
||||
+ struct rela *rela = NULL, *saferela = NULL;
|
||||
+
|
||||
+ list_for_each_entry_safe(rela, saferela, &relasec->relas, list) {
|
||||
+ list_del(&rela->list);
|
||||
+ free(rela);
|
||||
+ }
|
||||
+
|
||||
+ INIT_LIST_HEAD(&relasec->relas);
|
||||
+}
|
||||
+
|
||||
+static void destroy_section_list(struct upatch_elf *uelf)
|
||||
+{
|
||||
+ struct section *sec = NULL, *safesec = NULL;
|
||||
+
|
||||
+ list_for_each_entry_safe(sec, safesec, &uelf->sections, list) {
|
||||
+ if (sec->twin) {
|
||||
+ sec->twin->twin = NULL;
|
||||
+ }
|
||||
+
|
||||
+ if ((sec->name != NULL) && (sec->name_source == DATA_SOURCE_ALLOC)) {
|
||||
+ free(sec->name);
|
||||
+ sec->name = NULL;
|
||||
+ }
|
||||
+
|
||||
+ if (sec->data != NULL) {
|
||||
+ if (sec->dbuf_source == DATA_SOURCE_ALLOC) {
|
||||
+ free(sec->data->d_buf);
|
||||
+ sec->data->d_buf = NULL;
|
||||
+ }
|
||||
+ if (sec->data_source == DATA_SOURCE_ALLOC) {
|
||||
+ free(sec->data);
|
||||
+ sec->data = NULL;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (is_rela_section(sec)) {
|
||||
+ destroy_rela_list(sec);
|
||||
+ }
|
||||
+
|
||||
+ list_del(&sec->list);
|
||||
+ free(sec);
|
||||
+ }
|
||||
+
|
||||
+ INIT_LIST_HEAD(&uelf->sections);
|
||||
+}
|
||||
+
|
||||
+static void destroy_symbol_list(struct upatch_elf *uelf)
|
||||
+{
|
||||
+ struct symbol *sym = NULL, *safesym = NULL;
|
||||
+
|
||||
+ list_for_each_entry_safe(sym, safesym, &uelf->symbols, list) {
|
||||
+ if (sym->twin) {
|
||||
+ sym->twin->twin = NULL;
|
||||
+ }
|
||||
+
|
||||
+ list_del(&sym->list);
|
||||
+ free(sym);
|
||||
+ }
|
||||
+
|
||||
+ INIT_LIST_HEAD(&uelf->symbols);
|
||||
+}
|
||||
+
|
||||
+static void destroy_string_list(struct upatch_elf *uelf)
|
||||
+{
|
||||
+ struct string *str = NULL, *safestr = NULL;
|
||||
+
|
||||
+ list_for_each_entry_safe(str, safestr, &uelf->strings, list) {
|
||||
+ list_del(&str->list);
|
||||
+ free(str);
|
||||
+ }
|
||||
+
|
||||
+ INIT_LIST_HEAD(&uelf->strings);
|
||||
+}
|
||||
+
|
||||
void upatch_elf_open(struct upatch_elf *uelf, const char *name)
|
||||
{
|
||||
GElf_Ehdr ehdr;
|
||||
- struct section *relasec;
|
||||
+ struct section *sec;
|
||||
Elf *elf = NULL;
|
||||
int fd = 1;
|
||||
|
||||
@@ -264,46 +345,21 @@ void upatch_elf_open(struct upatch_elf *uelf, const char *name)
|
||||
create_section_list(uelf);
|
||||
create_symbol_list(uelf);
|
||||
|
||||
- list_for_each_entry(relasec, &uelf->sections, list) {
|
||||
- if (!is_rela_section(relasec))
|
||||
- continue;
|
||||
- INIT_LIST_HEAD(&relasec->relas);
|
||||
-
|
||||
- create_rela_list(uelf, relasec);
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-void upatch_elf_teardown(struct upatch_elf *uelf)
|
||||
-{
|
||||
- struct section *sec, *safesec;
|
||||
- struct symbol *sym, *safesym;
|
||||
- struct rela *rela, *saferela;
|
||||
-
|
||||
- list_for_each_entry_safe(sec, safesec, &uelf->sections, list) {
|
||||
- if (sec->twin)
|
||||
- sec->twin->twin = NULL;
|
||||
+ list_for_each_entry(sec, &uelf->sections, list) {
|
||||
if (is_rela_section(sec)) {
|
||||
- list_for_each_entry_safe(rela, saferela, &sec->relas, list) {
|
||||
- memset(rela, 0, sizeof(*rela));
|
||||
- free(rela);
|
||||
- }
|
||||
+ create_rela_list(uelf, sec);
|
||||
}
|
||||
- memset(sec, 0, sizeof(*sec));
|
||||
- free(sec);
|
||||
- }
|
||||
-
|
||||
- list_for_each_entry_safe(sym, safesym, &uelf->symbols, list) {
|
||||
- if (sym->twin)
|
||||
- sym->twin->twin = NULL;
|
||||
- memset(sym, 0, sizeof(*sym));
|
||||
- free(sym);
|
||||
}
|
||||
+}
|
||||
|
||||
- INIT_LIST_HEAD(&uelf->sections);
|
||||
- INIT_LIST_HEAD(&uelf->symbols);
|
||||
+void upatch_elf_destroy(struct upatch_elf *uelf)
|
||||
+{
|
||||
+ destroy_section_list(uelf);
|
||||
+ destroy_symbol_list(uelf);
|
||||
+ destroy_string_list(uelf);
|
||||
}
|
||||
|
||||
-void upatch_elf_free(struct upatch_elf *uelf)
|
||||
+void upatch_elf_close(struct upatch_elf *uelf)
|
||||
{
|
||||
elf_end(uelf->elf);
|
||||
close(uelf->fd);
|
||||
diff --git a/upatch-diff/upatch-elf.h b/upatch-diff/upatch-elf.h
|
||||
index 3cbb59b..6c62c93 100644
|
||||
--- a/upatch-diff/upatch-elf.h
|
||||
+++ b/upatch-diff/upatch-elf.h
|
||||
@@ -39,6 +39,12 @@ struct section;
|
||||
struct rela;
|
||||
struct symbol;
|
||||
|
||||
+enum data_source {
|
||||
+ DATA_SOURCE_ELF,
|
||||
+ DATA_SOURCE_REF,
|
||||
+ DATA_SOURCE_ALLOC,
|
||||
+};
|
||||
+
|
||||
enum status {
|
||||
NEW,
|
||||
CHANGED,
|
||||
@@ -61,6 +67,9 @@ struct section {
|
||||
struct section *twin;
|
||||
char *name;
|
||||
Elf_Data *data;
|
||||
+ enum data_source name_source;
|
||||
+ enum data_source data_source;
|
||||
+ enum data_source dbuf_source;
|
||||
GElf_Shdr sh;
|
||||
int ignore;
|
||||
int include;
|
||||
@@ -102,6 +111,7 @@ struct symbol {
|
||||
struct section *sec;
|
||||
GElf_Sym sym;
|
||||
char *name;
|
||||
+ enum data_source name_source;
|
||||
struct debug_symbol *relf_sym;
|
||||
unsigned int index;
|
||||
unsigned char bind;
|
||||
@@ -132,8 +142,8 @@ struct upatch_elf {
|
||||
void upatch_elf_open(struct upatch_elf *, const char *);
|
||||
|
||||
// Destory upatch_elf struct
|
||||
-void upatch_elf_teardown(struct upatch_elf *);
|
||||
+void upatch_elf_destroy(struct upatch_elf *);
|
||||
|
||||
-void upatch_elf_free(struct upatch_elf *);
|
||||
+void upatch_elf_close(struct upatch_elf *);
|
||||
|
||||
#endif
|
||||
--
|
||||
2.34.1
|
||||
|
||||
43
0030-upatch-hijacker-fix-memory-leak.patch
Normal file
43
0030-upatch-hijacker-fix-memory-leak.patch
Normal file
@ -0,0 +1,43 @@
|
||||
From 41322f2b7a234f91ca6e8e29cfdee2f77356dd8c Mon Sep 17 00:00:00 2001
|
||||
From: liuxiaobo <liuxiaobo19@huawei.com>
|
||||
Date: Thu, 27 Jun 2024 16:22:26 +0800
|
||||
Subject: [PATCH] upatch-hijacker: fix memory leak
|
||||
|
||||
Signed-off-by: liuxiaobo <liuxiaobo19@huawei.com>
|
||||
---
|
||||
upatch-hijacker/hijacker/gnu-as-hijacker.c | 11 +++++++++--
|
||||
1 file changed, 9 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/upatch-hijacker/hijacker/gnu-as-hijacker.c b/upatch-hijacker/hijacker/gnu-as-hijacker.c
|
||||
index 860a84f..886420e 100644
|
||||
--- a/upatch-hijacker/hijacker/gnu-as-hijacker.c
|
||||
+++ b/upatch-hijacker/hijacker/gnu-as-hijacker.c
|
||||
@@ -48,6 +48,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
// Try to get executable path
|
||||
const char *filename = get_current_exec();
|
||||
+
|
||||
if (filename == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
@@ -111,9 +112,15 @@ int main(int argc, char *argv[], char *envp[])
|
||||
(void)unlink(output_file);
|
||||
}
|
||||
|
||||
+ int ret = 0;
|
||||
if (symlink(new_output_file, output_file) != 0) {
|
||||
- return execve(filename, argv, envp);
|
||||
+ ret = execve(filename, argv, envp);
|
||||
+ goto out;
|
||||
}
|
||||
|
||||
- return execve(filename, (char* const*)new_argv, envp);
|
||||
+ ret = execve(filename, (char* const*)new_argv, envp);
|
||||
+out:
|
||||
+ free(new_argv);
|
||||
+
|
||||
+ return ret;
|
||||
}
|
||||
--
|
||||
2.34.1
|
||||
|
||||
113
0031-upatch-manage-fix-memory-leak.patch
Normal file
113
0031-upatch-manage-fix-memory-leak.patch
Normal file
@ -0,0 +1,113 @@
|
||||
From 22e9b146b485735389b71e9b71a3f31ea151477c Mon Sep 17 00:00:00 2001
|
||||
From: liuxiaobo <liuxiaobo19@huawei.com>
|
||||
Date: Thu, 27 Jun 2024 16:22:02 +0800
|
||||
Subject: [PATCH] upatch-manage: fix memory leak
|
||||
|
||||
Signed-off-by: liuxiaobo <liuxiaobo19@huawei.com>
|
||||
---
|
||||
upatch-manage/arch/x86_64/ptrace.c | 7 ++--
|
||||
upatch-manage/upatch-process.c | 61 ++++++++++++++++++------------
|
||||
2 files changed, 39 insertions(+), 29 deletions(-)
|
||||
|
||||
diff --git a/upatch-manage/arch/x86_64/ptrace.c b/upatch-manage/arch/x86_64/ptrace.c
|
||||
index 3d6dd72..95e2710 100644
|
||||
--- a/upatch-manage/arch/x86_64/ptrace.c
|
||||
+++ b/upatch-manage/arch/x86_64/ptrace.c
|
||||
@@ -173,9 +173,8 @@ size_t get_upatch_addr_len()
|
||||
return UPATCH_ADDR_LEN;
|
||||
}
|
||||
|
||||
-
|
||||
unsigned long get_new_insn(void)
|
||||
{
|
||||
- char jmp_insn[] = { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00};
|
||||
- return *(unsigned long *)jmp_insn;
|
||||
-}
|
||||
\ No newline at end of file
|
||||
+ // ASM: jmp word ptr [di] (FF25 0000 0000 0000)
|
||||
+ return 0x25FF;
|
||||
+}
|
||||
diff --git a/upatch-manage/upatch-process.c b/upatch-manage/upatch-process.c
|
||||
index 3b8db3b..84ec030 100644
|
||||
--- a/upatch-manage/upatch-process.c
|
||||
+++ b/upatch-manage/upatch-process.c
|
||||
@@ -385,6 +385,40 @@ process_new_object(struct upatch_process *proc, dev_t dev, ino_t inode,
|
||||
return o;
|
||||
}
|
||||
|
||||
+static int add_upatch_object(struct upatch_process *proc,
|
||||
+ struct object_file *o, unsigned long src, unsigned char *header_buf)
|
||||
+{
|
||||
+ struct object_patch *opatch;
|
||||
+
|
||||
+ opatch = malloc(sizeof(struct object_patch));
|
||||
+ if (opatch == NULL) {
|
||||
+ log_error("malloc opatch failed\n");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ opatch->uinfo = malloc(sizeof(struct upatch_info));
|
||||
+ if (opatch->uinfo == NULL) {
|
||||
+ log_error("malloc opatch->uinfo failed\n");
|
||||
+ free(opatch);
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ memcpy(opatch->uinfo, header_buf, sizeof(struct upatch_info));
|
||||
+ opatch->funcs = malloc(opatch->uinfo->changed_func_num *
|
||||
+ sizeof(struct upatch_info_func));
|
||||
+ if (upatch_process_mem_read(proc, src, opatch->funcs,
|
||||
+ opatch->uinfo->changed_func_num * sizeof(struct upatch_info_func))) {
|
||||
+ log_error("can't read patch funcs at 0x%lx\n", src);
|
||||
+ free(opatch->uinfo);
|
||||
+ free(opatch);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ list_add(&opatch->list, &o->applied_patch);
|
||||
+ o->num_applied_patch++;
|
||||
+ o->is_patch = 1;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
/**
|
||||
* Returns: 0 if everything is ok, -1 on error.
|
||||
*/
|
||||
@@ -420,33 +454,10 @@ static int process_add_object_vma(struct upatch_process *proc, dev_t dev,
|
||||
}
|
||||
|
||||
if (object_type == OBJECT_UPATCH) {
|
||||
- struct object_patch *opatch;
|
||||
-
|
||||
- opatch = malloc(sizeof(struct object_patch));
|
||||
- if (opatch == NULL) {
|
||||
- return -1;
|
||||
- }
|
||||
-
|
||||
- opatch->uinfo = malloc(sizeof(struct upatch_info));
|
||||
- if (opatch->uinfo == NULL) {
|
||||
- return -1;
|
||||
- }
|
||||
-
|
||||
- memcpy(opatch->uinfo, header_buf, sizeof(struct upatch_info));
|
||||
- opatch->funcs = malloc(opatch->uinfo->changed_func_num *
|
||||
- sizeof(struct upatch_info_func));
|
||||
- if (upatch_process_mem_read(
|
||||
- proc, vma->start + sizeof(struct upatch_info),
|
||||
- opatch->funcs,
|
||||
- opatch->uinfo->changed_func_num *
|
||||
- sizeof(struct upatch_info_func))) {
|
||||
- log_error("can't read patch funcs at 0x%lx\n",
|
||||
- vma->start + sizeof(struct upatch_info));
|
||||
+ unsigned long src = vma->start + sizeof(struct upatch_info);
|
||||
+ if (add_upatch_object(proc, o, src, header_buf) != 0) {
|
||||
return -1;
|
||||
}
|
||||
- list_add(&opatch->list, &o->applied_patch);
|
||||
- o->num_applied_patch++;
|
||||
- o->is_patch = 1;
|
||||
}
|
||||
if (object_type == OBJECT_ELF) {
|
||||
o->is_elf = 1;
|
||||
--
|
||||
2.34.1
|
||||
|
||||
1989
0032-security-sanitize-sensitive-code.patch
Normal file
1989
0032-security-sanitize-sensitive-code.patch
Normal file
File diff suppressed because it is too large
Load Diff
242
0033-all-implement-asan-gcov-build-type.patch
Normal file
242
0033-all-implement-asan-gcov-build-type.patch
Normal file
@ -0,0 +1,242 @@
|
||||
From eeb3f8b656839a374564572d19f675dc56d65ead Mon Sep 17 00:00:00 2001
|
||||
From: liuxiaobo <liuxiaobo19@huawei.com>
|
||||
Date: Mon, 17 Jun 2024 16:22:08 +0800
|
||||
Subject: [PATCH] all: implement asan & gcov build type
|
||||
|
||||
Signed-off-by: liuxiaobo <liuxiaobo19@huawei.com>
|
||||
---
|
||||
CMakeLists.txt | 127 ++++++++++++++++++++--------
|
||||
upatch-diff/CMakeLists.txt | 4 +-
|
||||
upatch-helper/helper/CMakeLists.txt | 4 +-
|
||||
upatch-manage/CMakeLists.txt | 5 +-
|
||||
4 files changed, 99 insertions(+), 41 deletions(-)
|
||||
|
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index 659222f..04872b1 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -8,7 +8,12 @@ project(syscare)
|
||||
include(GNUInstallDirs)
|
||||
find_package(Git QUIET)
|
||||
|
||||
-# Version
|
||||
+# Build type
|
||||
+if(NOT CMAKE_BUILD_TYPE)
|
||||
+ set(CMAKE_BUILD_TYPE RelWithDebInfo)
|
||||
+endif()
|
||||
+
|
||||
+# Build version
|
||||
if(NOT DEFINED BUILD_VERSION)
|
||||
execute_process(
|
||||
COMMAND sh -c "cat syscare/Cargo.toml | grep -F 'version' | head -n 1 | awk -F '\"' '{print $2}'"
|
||||
@@ -27,12 +32,55 @@ if(GIT_FOUND)
|
||||
ERROR_QUIET
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
- set(BUILD_VERSION "${BUILD_VERSION}-g${GIT_VERSION}")
|
||||
+ set(PROJECT_BUILD_VERSION "${BUILD_VERSION}-g${GIT_VERSION}")
|
||||
else()
|
||||
- set(BUILD_VERSION "${BUILD_VERSION}")
|
||||
+ set(PROJECT_BUILD_VERSION "${BUILD_VERSION}")
|
||||
+endif()
|
||||
+
|
||||
+# Build configurations
|
||||
+if(ENABLE_ASAN)
|
||||
+ set(PROJECT_BUILD_VERSION "${PROJECT_BUILD_VERSION}-asan")
|
||||
+ list(APPEND PROJECT_C_BUILD_FLAGS -fsanitize=address -fno-omit-frame-pointer)
|
||||
+ list(APPEND PROJECT_C_LIBRARIES asan)
|
||||
endif()
|
||||
|
||||
-# Set install directories
|
||||
+if(ENABLE_GCOV)
|
||||
+ set(PROJECT_BUILD_VERSION "${PROJECT_BUILD_VERSION}-gcov")
|
||||
+ list(APPEND PROJECT_C_BUILD_FLAGS -ftest-coverage -fprofile-arcs)
|
||||
+ list(APPEND PROJECT_RUST_FLAGS -C instrument-coverage)
|
||||
+ list(APPEND PROJECT_C_LIBRARIES gcov)
|
||||
+endif()
|
||||
+
|
||||
+# Build flags
|
||||
+list(APPEND PROJECT_C_BUILD_FLAGS
|
||||
+ -std=gnu99 -g -Wall -O2 -Werror -Wextra
|
||||
+ -DBUILD_VERSION="${PROJECT_BUILD_VERSION}" -D_FORTIFY_SOURCE=2
|
||||
+ -Wtrampolines -Wformat=2 -Wstrict-prototypes -Wdate-time
|
||||
+ -Wstack-usage=8192 -Wfloat-equal -Wswitch-default
|
||||
+ -Wshadow -Wconversion -Wcast-qual -Wcast-align -Wunused -Wundef
|
||||
+ -funsigned-char -fstack-protector-all -fpic -fpie -ftrapv
|
||||
+ -fstack-check -freg-struct-return -fno-canonical-system-headers
|
||||
+ -pipe -fdebug-prefix-map=old=new
|
||||
+)
|
||||
+list(APPEND PROJECT_RUST_FLAGS
|
||||
+ --cfg unsound_local_offset
|
||||
+ -C relocation_model=pic
|
||||
+ -D warnings
|
||||
+ -C link-arg=-s
|
||||
+ -C overflow_checks
|
||||
+ -W rust_2021_incompatible_closure_captures
|
||||
+)
|
||||
+
|
||||
+# Link flags
|
||||
+list(APPEND PROJECT_C_LINK_FLAGS
|
||||
+ -pie
|
||||
+ -Wl,-z,relro,-z,now
|
||||
+ -Wl,-z,noexecstack -rdynamic
|
||||
+ -Wl,-Bsymbolic
|
||||
+ -Wl,-no-undefined
|
||||
+)
|
||||
+
|
||||
+# Install directories
|
||||
set(SYSCARE_BINARY_DIR "${CMAKE_INSTALL_FULL_BINDIR}")
|
||||
set(SYSCARE_LIBEXEC_DIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/syscare")
|
||||
set(SYSCARE_SERVICE_DIR "${CMAKE_INSTALL_PREFIX}/lib/systemd/system")
|
||||
@@ -46,48 +94,53 @@ message("╚════██║ ╚██╔╝ ╚════██║█
|
||||
message("███████║ ██║ ███████║╚██████╗██║ ██║██║ ██║███████╗")
|
||||
message("╚══════╝ ╚═╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝")
|
||||
message("---------------------------------------------------------")
|
||||
-message("-- Verion: ${BUILD_VERSION}")
|
||||
+message("-- Verion: ${PROJECT_BUILD_VERSION}")
|
||||
+message("-- Rust flags: ${PROJECT_RUST_FLAGS}")
|
||||
+message("-- Build flags: ${PROJECT_C_BUILD_FLAGS}")
|
||||
+message("-- Link flags: ${PROJECT_C_LINK_FLAGS}")
|
||||
+message("-- Link libraries: ${PROJECT_C_LIBRARIES}")
|
||||
message("-- Binary directory: ${SYSCARE_BINARY_DIR}")
|
||||
message("-- Libexec directory: ${SYSCARE_LIBEXEC_DIR}")
|
||||
message("-- Service directory: ${SYSCARE_SERVICE_DIR}")
|
||||
message("---------------------------------------------------------")
|
||||
|
||||
-# Compile options
|
||||
-add_compile_options(-DBUILD_VERSION="${BUILD_VERSION}")
|
||||
-add_compile_options(-std=gnu99 -g -Wall -D_FORTIFY_SOURCE=2 -O2 -Werror -Wextra
|
||||
- -Wtrampolines -Wformat=2 -Wstrict-prototypes -Wdate-time -Wstack-usage=8192
|
||||
- -Wfloat-equal -Wswitch-default -Wshadow -Wconversion -Wcast-qual -Wcast-align
|
||||
- -Wunused -Wundef -funsigned-char -fstack-protector-all -fpic -fpie -ftrapv
|
||||
- -fstack-check -freg-struct-return -fno-canonical-system-headers -pipe
|
||||
- -fdebug-prefix-map=old=new)
|
||||
-set(LINK_FLAGS "-pie -Wl,-z,relro,-z,now -Wl,-z,noexecstack -rdynamic -Wl,-Bsymbolic -Wl,-no-undefined")
|
||||
-set(CMAKE_SHARED_LINKER_FLAGS "${LINK_FLAGS}")
|
||||
-set(CMAKE_EXE_LINKER_FLAGS "${LINK_FLAGS}")
|
||||
-# Subdirectories
|
||||
-add_subdirectory(upatch-diff)
|
||||
-add_subdirectory(upatch-manage)
|
||||
-add_subdirectory(upatch-helper)
|
||||
-add_subdirectory(misc)
|
||||
+# Apply all flags
|
||||
+add_compile_options(${PROJECT_C_BUILD_FLAGS})
|
||||
+add_link_options(${PROJECT_C_LINK_FLAGS})
|
||||
+link_libraries(${PROJECT_C_LIBRARIES})
|
||||
|
||||
# Build rust executables
|
||||
-add_custom_target(rust-executables ALL
|
||||
+foreach(FLAG IN LISTS PROJECT_RUST_FLAGS)
|
||||
+ set(RUSTFLAGS "${RUSTFLAGS} ${FLAG}")
|
||||
+endforeach()
|
||||
+
|
||||
+add_custom_target(rust-build ALL
|
||||
COMMENT "Building rust executables..."
|
||||
COMMAND ${CMAKE_COMMAND} -E env
|
||||
- "BUILD_VERSION=${BUILD_VERSION}"
|
||||
- "RUSTFLAGS=--cfg unsound_local_offset -C relocation_model=pic -D warnings -C link-arg=-s -C overflow_checks -W rust_2021_incompatible_closure_captures"
|
||||
- cargo build --release --target-dir ${CMAKE_CURRENT_BINARY_DIR}
|
||||
+ "BUILD_VERSION=${PROJECT_BUILD_VERSION}"
|
||||
+ "RUSTFLAGS=${RUSTFLAGS}"
|
||||
+ cargo build --release --target-dir "${CMAKE_CURRENT_BINARY_DIR}/rust"
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
# Install rust binaries
|
||||
install(
|
||||
PROGRAMS
|
||||
- ${CMAKE_CURRENT_BINARY_DIR}/release/upatchd
|
||||
- ${CMAKE_CURRENT_BINARY_DIR}/release/syscared
|
||||
- ${CMAKE_CURRENT_BINARY_DIR}/release/syscare
|
||||
+ ${CMAKE_CURRENT_BINARY_DIR}/rust/release/upatchd
|
||||
+ ${CMAKE_CURRENT_BINARY_DIR}/rust/release/syscared
|
||||
+ PERMISSIONS
|
||||
+ OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
+ GROUP_READ GROUP_EXECUTE
|
||||
+ DESTINATION
|
||||
+ ${SYSCARE_BINARY_DIR}
|
||||
+)
|
||||
+
|
||||
+install(
|
||||
+ PROGRAMS
|
||||
+ ${CMAKE_CURRENT_BINARY_DIR}/rust/release/syscare
|
||||
PERMISSIONS
|
||||
- OWNER_EXECUTE OWNER_WRITE OWNER_READ
|
||||
- GROUP_EXECUTE GROUP_READ
|
||||
+ OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
+ GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE
|
||||
DESTINATION
|
||||
${SYSCARE_BINARY_DIR}
|
||||
@@ -95,12 +148,18 @@ install(
|
||||
|
||||
install(
|
||||
PROGRAMS
|
||||
- ${CMAKE_CURRENT_BINARY_DIR}/release/upatch-build
|
||||
- ${CMAKE_CURRENT_BINARY_DIR}/release/syscare-build
|
||||
+ ${CMAKE_CURRENT_BINARY_DIR}/rust/release/upatch-build
|
||||
+ ${CMAKE_CURRENT_BINARY_DIR}/rust/release/syscare-build
|
||||
PERMISSIONS
|
||||
- OWNER_EXECUTE OWNER_WRITE OWNER_READ
|
||||
- GROUP_EXECUTE GROUP_READ
|
||||
+ OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
+ GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE
|
||||
DESTINATION
|
||||
${SYSCARE_LIBEXEC_DIR}
|
||||
)
|
||||
+
|
||||
+# Build other components
|
||||
+add_subdirectory(upatch-diff)
|
||||
+add_subdirectory(upatch-manage)
|
||||
+add_subdirectory(upatch-helper)
|
||||
+add_subdirectory(misc)
|
||||
diff --git a/upatch-diff/CMakeLists.txt b/upatch-diff/CMakeLists.txt
|
||||
index 45091fc..a1c8688 100644
|
||||
--- a/upatch-diff/CMakeLists.txt
|
||||
+++ b/upatch-diff/CMakeLists.txt
|
||||
@@ -18,8 +18,8 @@ install(
|
||||
TARGETS
|
||||
upatch-diff
|
||||
PERMISSIONS
|
||||
- OWNER_EXECUTE OWNER_WRITE OWNER_READ
|
||||
- GROUP_EXECUTE GROUP_READ
|
||||
+ OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
+ GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE
|
||||
DESTINATION
|
||||
${SYSCARE_LIBEXEC_DIR}
|
||||
diff --git a/upatch-helper/helper/CMakeLists.txt b/upatch-helper/helper/CMakeLists.txt
|
||||
index fefcebe..700722b 100644
|
||||
--- a/upatch-helper/helper/CMakeLists.txt
|
||||
+++ b/upatch-helper/helper/CMakeLists.txt
|
||||
@@ -27,8 +27,8 @@ install(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/cc-helper
|
||||
${CMAKE_CURRENT_BINARY_DIR}/c++-helper
|
||||
PERMISSIONS
|
||||
- OWNER_EXECUTE OWNER_WRITE OWNER_READ
|
||||
- GROUP_EXECUTE GROUP_READ
|
||||
+ OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
+ GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE
|
||||
DESTINATION
|
||||
${SYSCARE_LIBEXEC_DIR}
|
||||
diff --git a/upatch-manage/CMakeLists.txt b/upatch-manage/CMakeLists.txt
|
||||
index 850a308..e09aa9c 100644
|
||||
--- a/upatch-manage/CMakeLists.txt
|
||||
+++ b/upatch-manage/CMakeLists.txt
|
||||
@@ -25,9 +25,8 @@ install(
|
||||
TARGETS
|
||||
${UPATCH_MANAGE}
|
||||
PERMISSIONS
|
||||
- OWNER_EXECUTE OWNER_WRITE OWNER_READ
|
||||
- GROUP_EXECUTE GROUP_READ
|
||||
- WORLD_READ WORLD_EXECUTE
|
||||
+ OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
+ GROUP_READ GROUP_EXECUTE
|
||||
DESTINATION
|
||||
${SYSCARE_LIBEXEC_DIR}
|
||||
)
|
||||
--
|
||||
2.34.1
|
||||
|
||||
2484
0034-all-clean-code.patch
Normal file
2484
0034-all-clean-code.patch
Normal file
File diff suppressed because it is too large
Load Diff
62
0035-syscare-abi-remove-display-limit-of-patch_info.patch
Normal file
62
0035-syscare-abi-remove-display-limit-of-patch_info.patch
Normal file
@ -0,0 +1,62 @@
|
||||
From ee2c289262c2677abb57d41534b927fc755d86e8 Mon Sep 17 00:00:00 2001
|
||||
From: Zhao Mengmeng <zhaomengmeng@kylinos.cn>
|
||||
Date: Mon, 17 Jun 2024 16:18:20 +0800
|
||||
Subject: [PATCH] syscare-abi: remove display limit of patch_info
|
||||
|
||||
When executing with `syscare info xxx`, show all the patches
|
||||
it contains.
|
||||
|
||||
Signed-off-by: Zhao Mengmeng <zhaomengmeng@kylinos.cn>
|
||||
---
|
||||
syscare-abi/src/patch_info.rs | 21 +++------------------
|
||||
1 file changed, 3 insertions(+), 18 deletions(-)
|
||||
|
||||
diff --git a/syscare-abi/src/patch_info.rs b/syscare-abi/src/patch_info.rs
|
||||
index 659755d..65f7664 100644
|
||||
--- a/syscare-abi/src/patch_info.rs
|
||||
+++ b/syscare-abi/src/patch_info.rs
|
||||
@@ -69,8 +69,6 @@ impl PatchInfo {
|
||||
|
||||
impl std::fmt::Display for PatchInfo {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
- const LIST_DISPLAY_LIMIT: usize = 9;
|
||||
-
|
||||
writeln!(f, "name: {}", self.name)?;
|
||||
writeln!(f, "version: {}", self.version)?;
|
||||
writeln!(f, "release: {}", self.release)?;
|
||||
@@ -82,10 +80,6 @@ impl std::fmt::Display for PatchInfo {
|
||||
if !self.entities.is_empty() {
|
||||
writeln!(f, "entities:")?;
|
||||
for (entity_idx, entity) in self.entities.iter().enumerate() {
|
||||
- if entity_idx >= LIST_DISPLAY_LIMIT {
|
||||
- writeln!(f, "* ......")?;
|
||||
- break;
|
||||
- }
|
||||
writeln!(f, "* {}", entity.patch_name.to_string_lossy())?;
|
||||
}
|
||||
}
|
||||
@@ -94,18 +88,9 @@ impl std::fmt::Display for PatchInfo {
|
||||
writeln!(f, "patches:")?;
|
||||
let last_idx = self.patches.len() - 1;
|
||||
for (patch_idx, patch_file) in self.patches.iter().enumerate() {
|
||||
- if patch_idx != last_idx {
|
||||
- if patch_idx >= LIST_DISPLAY_LIMIT {
|
||||
- writeln!(f, "* ......")?;
|
||||
- break;
|
||||
- }
|
||||
- writeln!(f, "* {}", patch_file.name.to_string_lossy())?
|
||||
- } else {
|
||||
- if patch_idx >= LIST_DISPLAY_LIMIT {
|
||||
- write!(f, "* ......")?;
|
||||
- break;
|
||||
- }
|
||||
- write!(f, "* {}", patch_file.name.to_string_lossy())?
|
||||
+ match patch_idx == last_idx {
|
||||
+ false => writeln!(f, "* {}", patch_file.name.to_string_lossy())?,
|
||||
+ true => write!(f, "* {}", patch_file.name.to_string_lossy())?,
|
||||
}
|
||||
}
|
||||
}
|
||||
--
|
||||
2.34.1
|
||||
|
||||
49
0036-syscare-abi-fix-clippy-warnings.patch
Normal file
49
0036-syscare-abi-fix-clippy-warnings.patch
Normal file
@ -0,0 +1,49 @@
|
||||
From 855794af7d0b932a704b1498a30e7c7f9d009eeb Mon Sep 17 00:00:00 2001
|
||||
From: renoseven <dev@renoseven.net>
|
||||
Date: Sat, 29 Jun 2024 17:03:30 +0800
|
||||
Subject: [PATCH] syscare-abi: fix clippy warnings
|
||||
|
||||
Signed-off-by: renoseven <dev@renoseven.net>
|
||||
---
|
||||
syscare-abi/src/patch_info.rs | 24 ++++++++++--------------
|
||||
1 file changed, 10 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/syscare-abi/src/patch_info.rs b/syscare-abi/src/patch_info.rs
|
||||
index 65f7664..9108a89 100644
|
||||
--- a/syscare-abi/src/patch_info.rs
|
||||
+++ b/syscare-abi/src/patch_info.rs
|
||||
@@ -77,21 +77,17 @@ impl std::fmt::Display for PatchInfo {
|
||||
writeln!(f, "target: {}", self.target.short_name())?;
|
||||
writeln!(f, "license: {}", self.target.license)?;
|
||||
writeln!(f, "description: {}", self.description)?;
|
||||
- if !self.entities.is_empty() {
|
||||
- writeln!(f, "entities:")?;
|
||||
- for (entity_idx, entity) in self.entities.iter().enumerate() {
|
||||
- writeln!(f, "* {}", entity.patch_name.to_string_lossy())?;
|
||||
- }
|
||||
+ writeln!(f, "entities:")?;
|
||||
+ for entity in &self.entities {
|
||||
+ writeln!(f, "* {}", entity.patch_name.to_string_lossy())?;
|
||||
}
|
||||
-
|
||||
- if !self.patches.is_empty() {
|
||||
- writeln!(f, "patches:")?;
|
||||
- let last_idx = self.patches.len() - 1;
|
||||
- for (patch_idx, patch_file) in self.patches.iter().enumerate() {
|
||||
- match patch_idx == last_idx {
|
||||
- false => writeln!(f, "* {}", patch_file.name.to_string_lossy())?,
|
||||
- true => write!(f, "* {}", patch_file.name.to_string_lossy())?,
|
||||
- }
|
||||
+ writeln!(f, "patches:")?;
|
||||
+ let last_idx = self.patches.len() - 1;
|
||||
+ for (idx, patch) in self.patches.iter().enumerate() {
|
||||
+ if idx == last_idx {
|
||||
+ write!(f, "* {}", patch.name.to_string_lossy())?
|
||||
+ } else {
|
||||
+ writeln!(f, "* {}", patch.name.to_string_lossy())?
|
||||
}
|
||||
}
|
||||
|
||||
--
|
||||
2.34.1
|
||||
|
||||
64
syscare.spec
64
syscare.spec
@ -1,17 +1,13 @@
|
||||
%define build_version %{version}-%{release}
|
||||
%define kernel_devel_rpm %(echo $(rpm -q kernel-devel | head -n 1))
|
||||
%define kernel_version %(echo $(rpm -q --qf "\%%{VERSION}" %{kernel_devel_rpm}))
|
||||
%define kernel_name %(echo $(rpm -q --qf "\%%{VERSION}-\%%{RELEASE}.\%%{ARCH}" %{kernel_devel_rpm}))
|
||||
|
||||
%define pkg_kmod %{name}-kmod
|
||||
%define pkg_build %{name}-build
|
||||
|
||||
############################################
|
||||
############ Package syscare ###############
|
||||
############################################
|
||||
Name: syscare
|
||||
Version: 1.2.1
|
||||
Release: 8
|
||||
Release: 9
|
||||
Summary: System hot-fix service
|
||||
License: MulanPSL-2.0 and GPL-2.0-only
|
||||
URL: https://gitee.com/openeuler/syscare
|
||||
@ -39,6 +35,20 @@ Patch0019: 0019-upatch-diff-fix-lookup_relf-failed-issue.patch
|
||||
Patch0020: 0020-upatch-diff-only-check-changed-file-symbols.patch
|
||||
Patch0021: 0021-upatch-diff-remove-rela-check-while-build-rebuilding.patch
|
||||
Patch0022: 0022-syscared-fix-apply-kernel-module-patch-failure-issue.patch
|
||||
Patch0023: 0023-all-finding-executable-from-environment-variables.patch
|
||||
Patch0024: 0024-all-remove-redundant-code.patch
|
||||
Patch0025: 0025-all-add-c-rust-compilation-options.patch
|
||||
Patch0026: 0026-common-fix-failed-to-set-selinux-status-issue.patch
|
||||
Patch0027: 0027-upatch-diff-exit-with-error-when-any-tls-var-include.patch
|
||||
Patch0028: 0028-upatch-diff-fix-lookup_relf-duplicate-failure.patch
|
||||
Patch0029: 0029-upatch-diff-fix-memory-leak.patch
|
||||
Patch0030: 0030-upatch-hijacker-fix-memory-leak.patch
|
||||
Patch0031: 0031-upatch-manage-fix-memory-leak.patch
|
||||
Patch0032: 0032-security-sanitize-sensitive-code.patch
|
||||
Patch0033: 0033-all-implement-asan-gcov-build-type.patch
|
||||
Patch0034: 0034-all-clean-code.patch
|
||||
Patch0035: 0035-syscare-abi-remove-display-limit-of-patch_info.patch
|
||||
Patch0036: 0036-syscare-abi-fix-clippy-warnings.patch
|
||||
|
||||
BuildRequires: cmake >= 3.14 make
|
||||
BuildRequires: rust >= 1.51 cargo >= 1.51
|
||||
@ -111,12 +121,12 @@ fi
|
||||
|
||||
################## Files ###################
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
%defattr(-,root,root,0555)
|
||||
%dir /usr/libexec/syscare
|
||||
%attr(550,root,root) /usr/lib/systemd/system/syscare.service
|
||||
%attr(550,root,root) /usr/bin/syscared
|
||||
%attr(555,root,root) /usr/bin/syscare
|
||||
%attr(550,root,root) /usr/libexec/syscare/upatch-manage
|
||||
%attr(0555,root,root) /usr/bin/syscare
|
||||
%attr(0550,root,root) /usr/bin/syscared
|
||||
%attr(0550,root,root) /usr/lib/systemd/system/syscare.service
|
||||
%attr(0550,root,root) /usr/libexec/syscare/upatch-manage
|
||||
|
||||
############################################
|
||||
########## Package syscare-build ###########
|
||||
@ -168,26 +178,40 @@ fi
|
||||
|
||||
################## Files ###################
|
||||
%files build
|
||||
%defattr(-,root,root,-)
|
||||
%defattr(-,root,root,0555)
|
||||
%dir /usr/libexec/syscare
|
||||
%attr(550,root,root) /usr/lib/systemd/system/upatch.service
|
||||
%attr(550,root,root) /usr/bin/upatchd
|
||||
%attr(555,root,root) /usr/libexec/syscare/syscare-build
|
||||
%attr(555,root,root) /usr/libexec/syscare/upatch-build
|
||||
%attr(555,root,root) /usr/libexec/syscare/upatch-diff
|
||||
%attr(555,root,root) /usr/libexec/syscare/as-hijacker
|
||||
%attr(555,root,root) /usr/libexec/syscare/cc-hijacker
|
||||
%attr(555,root,root) /usr/libexec/syscare/c++-hijacker
|
||||
%attr(555,root,root) /usr/libexec/syscare/gcc-hijacker
|
||||
%attr(555,root,root) /usr/libexec/syscare/g++-hijacker
|
||||
%attr(555,root,root) /usr/libexec/syscare/gnu-as-hijacker
|
||||
%attr(555,root,root) /usr/libexec/syscare/gnu-compiler-hijacker
|
||||
%attr(440,root,root) /usr/libexec/syscare/upatch_hijacker.ko
|
||||
%attr(555,root,root) /usr/libexec/syscare/as-helper
|
||||
%attr(555,root,root) /usr/libexec/syscare/cc-helper
|
||||
%attr(555,root,root) /usr/libexec/syscare/c++-helper
|
||||
%attr(555,root,root) /usr/libexec/syscare/gcc-helper
|
||||
%attr(555,root,root) /usr/libexec/syscare/g++-helper
|
||||
%attr(555,root,root) /usr/libexec/syscare/gnu-as-helper
|
||||
%attr(555,root,root) /usr/libexec/syscare/gnu-compiler-helper
|
||||
%attr(440,root,root) /usr/libexec/syscare/upatch_helper.ko
|
||||
%attr(550,root,root) /usr/lib/systemd/system/upatch.service
|
||||
|
||||
############################################
|
||||
################ Change log ################
|
||||
############################################
|
||||
%changelog
|
||||
* Mon Jul 1 2024 renoseven<dev@renoseven.net> - 1.2.1-9
|
||||
- abi: remove display limit of patch info
|
||||
- all: clean code
|
||||
- all: implement asan gcov build type
|
||||
- security: sanitize sensitive code
|
||||
- upatch-manage: fix memory leak
|
||||
- upatch-helper: fix memory leak
|
||||
- upatch-diff: fix memory leak
|
||||
- upatch-diff: fix find duplicate symbol issue
|
||||
- upatch-diff: prevent tls variable modification
|
||||
- common: fix failed to set selinux status issue
|
||||
- all: add compile options
|
||||
- all: remove redundant code
|
||||
- all: finding executable from environment variables
|
||||
* Mon May 20 2024 ningyu<ningyu9@huawei.com> - 1.2.1-8
|
||||
- syscared: fix apply kernel module patch failure issue
|
||||
* Tue May 14 2024 ningyu<ningyu9@huawei.com> - 1.2.1-7
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user