GeezerVison is showing github.com — feat: 新增防止冻结进程 · VVeakee/SKRoot-linuxKernelRoot@02efc71
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard Collapse file Copy file name to clipboardExpand all lines: patch_kernel_root/patch_avc_denied.cpp +7-40Lines changed: 7 additions & 40 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #include "patch_avc_denied.h" | 2 | 2 | #include "analyze/ARM_asm.h" | 3 | 3 | PatchAvcDenied::PatchAvcDenied(const std::vector<char>& file_buf, const KernelSymbolOffset& sym, | 4 | | - const AnalyzeKernel& analyze_kernel) : m_file_buf(file_buf), m_sym(sym), m_analyze_kernel(analyze_kernel) { | | 4 | + const AnalyzeKernel& analyze_kernel) : PatchBase(file_buf, sym, analyze_kernel) { | 5 | 5 |
| 6 | 6 | } | 7 | 7 |
| 8 | 8 | PatchAvcDenied::~PatchAvcDenied() | 9 | 9 | { | 10 | 10 | } | 11 | 11 |
| 12 | | -int PatchAvcDenied::get_atomic_usage_len() { | 13 | | - int len = 8; | 14 | | - if (m_analyze_kernel.is_kernel_version_less("6.6.0")) { | 15 | | - len = 4; | 16 | | - } | 17 | | - return len; | 18 | | -} | 19 | | - | 20 | | -int PatchAvcDenied::get_securebits_padding() { | 21 | | - if (get_atomic_usage_len() == 8) { | 22 | | - return 4; | 23 | | - } | 24 | | - return 0; | 25 | | -} | 26 | | - | 27 | | -std::string PatchAvcDenied::get_cap_ability_max() { | 28 | | - std::string cap; | 29 | | - if (m_analyze_kernel.is_kernel_version_less("5.8.0")) { | 30 | | - cap = "0x3FFFFFFFFF"; | 31 | | - } | 32 | | - else if (m_analyze_kernel.is_kernel_version_less("5.9.0")) { | 33 | | - cap = "0xFFFFFFFFFF"; | 34 | | - } | 35 | | - else { | 36 | | - cap = "0x1FFFFFFFFFF"; | 37 | | - } | 38 | | - return cap; | 39 | | -} | 40 | | - | 41 | | -int PatchAvcDenied::get_need_write_cap_cnt() { | 42 | | - int cnt = 0; | 43 | | - if (m_analyze_kernel.is_kernel_version_less("4.3.0")) { | | 12 | +int PatchAvcDenied::get_need_read_cap_cnt() { | | 13 | + int cnt = get_cap_cnt(); | | 14 | + if (cnt < 5) { | 44 | 15 | cnt = 3; | 45 | 16 | } | 46 | | - else { | 47 | | - cnt = 5; | 48 | | - } | 49 | 17 | return cnt; | 50 | 18 | } | 51 | 19 |
| 52 | 20 |
| 53 | 21 | size_t PatchAvcDenied::patch_avc_denied(size_t hook_func_start_addr, const std::vector<size_t>& task_struct_offset_cred, | 54 | 22 | std::vector<patch_bytes_data>& vec_out_patch_bytes_data) { | 55 | 23 | size_t avc_denied_addr = m_sym.avc_denied; | 56 | | - int atomic_usage_len = get_atomic_usage_len(); | 57 | | - int securebits_padding = get_securebits_padding(); | | 24 | + int atomic_usage_len = get_cred_atomic_usage_len(); | | 25 | + int securebits_padding = get_cred_securebits_padding(); | 58 | 26 | std::string cap_ability_max = get_cap_ability_max(); | 59 | | - int cap_cnt = get_need_write_cap_cnt(); | | 27 | + int cap_cnt = get_need_read_cap_cnt(); | 60 | 28 |
| 61 | 29 | size_t avc_denied_entry_hook_jump_back_addr = avc_denied_addr + 4; | 62 | 30 | auto next_asm_line_bytes_cnt = (task_struct_offset_cred.size() - 1) * 4; | 63 | 31 | std::stringstream sstrAsm; | 64 | 32 | sstrAsm | 65 | 33 | << "STP X7, X8, [sp, #-16]!" << std::endl | 66 | 34 | << "STP X9, X10, [sp, #-16]!" << std::endl; | 67 | | - | 68 | 35 | sstrAsm << "MRS X7, SP_EL0" << std::endl; | 69 | 36 | for (auto x = 0; x < task_struct_offset_cred.size(); x++) { | 70 | 37 | if (x != task_struct_offset_cred.size() - 1) { | |
Collapse file Copy file name to clipboard +3-10Lines changed: 3 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #pragma once | 2 | 2 | #include <iostream> | 3 | 3 | #include <vector> | 4 | | -#include "patch_kernel_root.h" | 5 | | -#include "analyze/analyze_kernel.h" | 6 | | -class PatchAvcDenied | | 4 | +#include "patch_base.h" | | 5 | +class PatchAvcDenied : public PatchBase | 7 | 6 | { | 8 | 7 | public: | 9 | 8 | PatchAvcDenied(const std::vector<char>& file_buf, const KernelSymbolOffset& sym, | @@ -14,11 +13,5 @@ class PatchAvcDenied | 14 | 13 | std::vector<patch_bytes_data>& vec_out_patch_bytes_data); | 15 | 14 |
| 16 | 15 | private: | 17 | | - int get_atomic_usage_len(); | 18 | | - int get_securebits_padding(); | 19 | | - std::string get_cap_ability_max(); | 20 | | - int get_need_write_cap_cnt(); | 21 | | - const std::vector<char>& m_file_buf; | 22 | | - const KernelSymbolOffset& m_sym; | 23 | | - const AnalyzeKernel& m_analyze_kernel; | | 16 | + int get_need_read_cap_cnt(); | 24 | 17 | }; |
Collapse file Copy file name to clipboard +49Lines changed: 49 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +#include "patch_base.h" | | 2 | +#include "analyze/ARM_asm.h" | | 3 | +PatchBase::PatchBase(const std::vector<char>& file_buf, const KernelSymbolOffset& sym, | | 4 | + const AnalyzeKernel& analyze_kernel) : m_file_buf(file_buf), m_sym(sym), m_analyze_kernel(analyze_kernel) { | | 5 | + | | 6 | +} | | 7 | + | | 8 | +PatchBase::~PatchBase() | | 9 | +{ | | 10 | +} | | 11 | + | | 12 | +int PatchBase::get_cred_atomic_usage_len() { | | 13 | + int len = 8; | | 14 | + if (m_analyze_kernel.is_kernel_version_less("6.6.0")) { | | 15 | + len = 4; | | 16 | + } | | 17 | + return len; | | 18 | +} | | 19 | + | | 20 | +int PatchBase::get_cred_securebits_padding() { | | 21 | + if (get_cred_atomic_usage_len() == 8) { | | 22 | + return 4; | | 23 | + } | | 24 | + return 0; | | 25 | +} | | 26 | + | | 27 | +std::string PatchBase::get_cap_ability_max() { | | 28 | + std::string cap; | | 29 | + if (m_analyze_kernel.is_kernel_version_less("5.8.0")) { | | 30 | + cap = "0x3FFFFFFFFF"; | | 31 | + } | | 32 | + else if (m_analyze_kernel.is_kernel_version_less("5.9.0")) { | | 33 | + cap = "0xFFFFFFFFFF"; | | 34 | + } | | 35 | + else { | | 36 | + cap = "0x1FFFFFFFFFF"; | | 37 | + } | | 38 | + return cap; | | 39 | +} | | 40 | + | | 41 | +int PatchBase::get_cap_cnt() { | | 42 | + int cnt = 0; | | 43 | + if (m_analyze_kernel.is_kernel_version_less("4.3.0")) { | | 44 | + cnt = 4; | | 45 | + } else { | | 46 | + cnt = 5; | | 47 | + } | | 48 | + return cnt; | | 49 | +} |
Collapse file Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +#pragma once | | 2 | +#include <iostream> | | 3 | +#include <vector> | | 4 | +#include "patch_kernel_root.h" | | 5 | +#include "analyze/analyze_kernel.h" | | 6 | +class PatchBase | | 7 | +{ | | 8 | +public: | | 9 | + PatchBase(const std::vector<char>& file_buf, const KernelSymbolOffset& sym, | | 10 | + const AnalyzeKernel& analyze_kernel); | | 11 | + ~PatchBase(); | | 12 | +protected: | | 13 | + int get_cred_atomic_usage_len(); | | 14 | + int get_cred_securebits_padding(); | | 15 | + std::string get_cap_ability_max(); | | 16 | + int get_cap_cnt(); | | 17 | + const std::vector<char>& m_file_buf; | | 18 | + const KernelSymbolOffset& m_sym; | | 19 | + const AnalyzeKernel& m_analyze_kernel; | | 20 | +}; |
Collapse file Copy file name to clipboardExpand all lines: patch_kernel_root/patch_do_execve.cpp +4-37Lines changed: 4 additions & 37 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | #include "patch_do_execve.h" | 3 | 3 | #include "analyze/ARM_asm.h" | 4 | 4 | PatchDoExecve::PatchDoExecve(const std::vector<char>& file_buf, const KernelSymbolOffset& sym, | 5 | | - const AnalyzeKernel& analyze_kernel) : m_file_buf(file_buf), m_sym(sym), m_analyze_kernel(analyze_kernel) { | | 5 | + const AnalyzeKernel& analyze_kernel) : PatchBase(file_buf, sym, analyze_kernel) { | 6 | 6 |
| 7 | 7 | } | 8 | 8 | PatchDoExecve::~PatchDoExecve() {} | @@ -39,41 +39,8 @@ std::pair<size_t, size_t> PatchDoExecve::get_do_execve_param() { | 39 | 39 | return { do_execve_addr, do_execve_key_reg}; | 40 | 40 | } | 41 | 41 |
| 42 | | -int PatchDoExecve::get_atomic_usage_len() { | 43 | | - int len = 8; | 44 | | - if (m_analyze_kernel.is_kernel_version_less("6.6.0")) { | 45 | | - len = 4; | 46 | | - } | 47 | | - return len; | 48 | | -} | 49 | | - | 50 | | -int PatchDoExecve::get_securebits_padding() { | 51 | | - if (get_atomic_usage_len() == 8) { | 52 | | - return 4; | 53 | | - } | 54 | | - return 0; | 55 | | -} | 56 | | - | 57 | | -std::string PatchDoExecve::get_cap_ability_max() { | 58 | | - std::string cap; | 59 | | - if (m_analyze_kernel.is_kernel_version_less("5.8.0")) { | 60 | | - cap = "0x3FFFFFFFFF"; | 61 | | - } else if (m_analyze_kernel.is_kernel_version_less("5.9.0")) { | 62 | | - cap = "0xFFFFFFFFFF"; | 63 | | - } else { | 64 | | - cap = "0x1FFFFFFFFFF"; | 65 | | - } | 66 | | - return cap; | 67 | | -} | 68 | | - | 69 | 42 | int PatchDoExecve::get_need_write_cap_cnt() { | 70 | | - int cnt = 0; | 71 | | - if (m_analyze_kernel.is_kernel_version_less("4.3.0")) { | 72 | | - cnt = 4; | 73 | | - } else { | 74 | | - cnt = 5; | 75 | | - } | 76 | | - return cnt; | | 43 | + return get_cap_cnt(); | 77 | 44 | } | 78 | 45 |
| 79 | 46 | size_t PatchDoExecve::patch_do_execve(const std::string& str_root_key, size_t hook_func_start_addr, | @@ -82,8 +49,8 @@ size_t PatchDoExecve::patch_do_execve(const std::string& str_root_key, size_t ho | 82 | 49 | std::vector<patch_bytes_data>& vec_out_patch_bytes_data) { | 83 | 50 |
| 84 | 51 | auto [do_execve_addr, do_execve_key_reg] = get_do_execve_param(); | 85 | | - int atomic_usage_len = get_atomic_usage_len(); | 86 | | - int securebits_padding = get_securebits_padding(); | | 52 | + int atomic_usage_len = get_cred_atomic_usage_len(); | | 53 | + int securebits_padding = get_cred_securebits_padding(); | 87 | 54 | std::string cap_ability_max = get_cap_ability_max(); | 88 | 55 | int cap_cnt = get_need_write_cap_cnt(); | 89 | 56 |
| |
Collapse file Copy file name to clipboard +2-9Lines changed: 2 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #pragma once | 2 | 2 | #include <iostream> | 3 | 3 | #include <vector> | 4 | | -#include "patch_kernel_root.h" | 5 | | -#include "analyze/analyze_kernel.h" | 6 | | -class PatchDoExecve | | 4 | +#include "patch_base.h" | | 5 | +class PatchDoExecve : public PatchBase | 7 | 6 | { | 8 | 7 | public: | 9 | 8 | PatchDoExecve(const std::vector<char>& file_buf, const KernelSymbolOffset& sym, | @@ -17,11 +16,5 @@ class PatchDoExecve | 17 | 16 |
| 18 | 17 | private: | 19 | 18 | std::pair<size_t, size_t> get_do_execve_param(); | 20 | | - int get_atomic_usage_len(); | 21 | | - int get_securebits_padding(); | 22 | | - std::string get_cap_ability_max(); | 23 | 19 | int get_need_write_cap_cnt(); | 24 | | - const std::vector<char>& m_file_buf; | 25 | | - const KernelSymbolOffset & m_sym; | 26 | | - const AnalyzeKernel& m_analyze_kernel; | 27 | 20 | }; |
Collapse file Copy file name to clipboardExpand all lines: patch_kernel_root/patch_filldir64.cpp +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #include "patch_filldir64.h" | 2 | 2 | #include "analyze/ARM_asm.h" | 3 | 3 | PatchFilldir64::PatchFilldir64(const std::vector<char>& file_buf, const KernelSymbolOffset& sym, | 4 | | - const AnalyzeKernel& analyze_kernel) : m_file_buf(file_buf), m_sym(sym), m_analyze_kernel(analyze_kernel) { | | 4 | + const AnalyzeKernel& analyze_kernel) : PatchBase(file_buf, sym, analyze_kernel) { | 5 | 5 |
| 6 | 6 | } | 7 | 7 |
| @@ -46,7 +46,6 @@ size_t PatchFilldir64::patch_filldir64(size_t root_key_addr_offset, size_t hook_ | 46 | 46 | return 0; | 47 | 47 | } | 48 | 48 | size_t nHookFuncSize = strBytes.length() / 2; | 49 | | - | 50 | 49 | char hookOrigCmd[4] = { 0 }; | 51 | 50 | memcpy(&hookOrigCmd, (void*)((size_t)&m_file_buf[0] + filldir64_addr), sizeof(hookOrigCmd)); | 52 | 51 | std::string strHookOrigCmd = bytes_2_hex_str((const unsigned char*)hookOrigCmd, sizeof(hookOrigCmd)); | |
Collapse file Copy file name to clipboard +2-8Lines changed: 2 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #pragma once | 2 | 2 | #include <iostream> | 3 | 3 | #include <vector> | 4 | | -#include "patch_kernel_root.h" | 5 | | -#include "analyze/analyze_kernel.h" | 6 | | -class PatchFilldir64 | | 4 | +#include "patch_base.h" | | 5 | +class PatchFilldir64 : public PatchBase | 7 | 6 | { | 8 | 7 | public: | 9 | 8 | PatchFilldir64(const std::vector<char>& file_buf, const KernelSymbolOffset& sym, | 10 | 9 | const AnalyzeKernel& analyze_kernel); | 11 | 10 | ~PatchFilldir64(); | 12 | 11 |
| 13 | 12 | size_t patch_filldir64(size_t root_key_addr_offset, size_t hook_func_start_addr, std::vector<patch_bytes_data>& vec_out_patch_bytes_data); | 14 | | - | 15 | | -private: | 16 | | - const std::vector<char>& m_file_buf; | 17 | | - const KernelSymbolOffset& m_sym; | 18 | | - const AnalyzeKernel& m_analyze_kernel; | 19 | 13 | }; |
|