From 319677ac07cad830e4620b37aa25896816fdb280 Mon Sep 17 00:00:00 2001 From: fundavid Date: Fri, 10 Jan 2025 09:57:59 +0800 Subject: [PATCH] remove cfi bypass Signed-off-by: fundavid --- bundle.json | 3 +- interfaces/inner_api/jit_code_sign/BUILD.gn | 20 +- .../include/jit_buffer_integrity.h | 31 ++-- ...t_code_signer_base.h => jit_code_signer.h} | 16 +- .../include/jit_code_signer_factory.h | 44 ----- .../include/jit_code_signer_hybrid.h | 47 ----- .../include/jit_code_signer_single.h | 40 ---- ...de_signer_base.cpp => jit_code_signer.cpp} | 91 +++++++++- .../src/jit_code_signer_factory.cpp | 63 ------- .../src/jit_code_signer_hybrid.cpp | 171 ------------------ .../src/jit_code_signer_single.cpp | 102 ----------- test/unittest/BUILD.gn | 4 +- test/unittest/jit_code_sign_test.cpp | 87 ++++----- 13 files changed, 158 insertions(+), 561 deletions(-) rename interfaces/inner_api/jit_code_sign/include/{jit_code_signer_base.h => jit_code_signer.h} (80%) delete mode 100644 interfaces/inner_api/jit_code_sign/include/jit_code_signer_factory.h delete mode 100644 interfaces/inner_api/jit_code_sign/include/jit_code_signer_hybrid.h delete mode 100644 interfaces/inner_api/jit_code_sign/include/jit_code_signer_single.h rename interfaces/inner_api/jit_code_sign/src/{jit_code_signer_base.cpp => jit_code_signer.cpp} (57%) delete mode 100644 interfaces/inner_api/jit_code_sign/src/jit_code_signer_factory.cpp delete mode 100644 interfaces/inner_api/jit_code_sign/src/jit_code_signer_hybrid.cpp delete mode 100644 interfaces/inner_api/jit_code_sign/src/jit_code_signer_single.cpp diff --git a/bundle.json b/bundle.json index b599c18..b344930 100644 --- a/bundle.json +++ b/bundle.json @@ -88,8 +88,7 @@ "header": { "header_files": [ "jit_buffer_integrity.h", - "jit_code_signer_base.h", - "jit_code_signer_factory.h", + "jit_code_signer.h", "jit_fort_helper.h" ], "header_base": "//base/security/code_signature/interfaces/inner_api/jit_code_sign/include" diff --git a/interfaces/inner_api/jit_code_sign/BUILD.gn b/interfaces/inner_api/jit_code_sign/BUILD.gn index 2a28441..9f96c86 100644 --- a/interfaces/inner_api/jit_code_sign/BUILD.gn +++ b/interfaces/inner_api/jit_code_sign/BUILD.gn @@ -35,10 +35,10 @@ ohos_source_set("pac_sign_feature") { ":public_jit_code_sign_configs", "${code_signature_root_dir}:common_public_config", ] - configs = [ - ":private_jit_code_sign_configs", - "${code_signature_root_dir}:common_utils_config", - ] + configs = [ "${code_signature_root_dir}:common_utils_config" ] + if (jit_code_sign_enable) { + configs += [ ":private_jit_code_sign_configs" ] + } external_deps = [ "bounds_checking_function:libsec_shared", "hilog:libhilog", @@ -48,16 +48,8 @@ ohos_source_set("pac_sign_feature") { } ohos_shared_library("libjit_code_sign") { - sources = [ "src/jit_code_signer_factory.cpp" ] - if (jit_code_sign_enable) { - defines = [ "JIT_CODE_SIGN_ENABLE" ] - sources += [ - "src/jit_code_signer_base.cpp", - "src/jit_code_signer_hybrid.cpp", - "src/jit_code_signer_single.cpp", - ] - deps = [ ":pac_sign_feature" ] - } + sources = [ "src/jit_code_signer.cpp" ] + deps = [ ":pac_sign_feature" ] cflags_cc = [ "-Os", "-fno-asynchronous-unwind-tables", diff --git a/interfaces/inner_api/jit_code_sign/include/jit_buffer_integrity.h b/interfaces/inner_api/jit_code_sign/include/jit_buffer_integrity.h index 5b61c48..0b88c1d 100644 --- a/interfaces/inner_api/jit_code_sign/include/jit_buffer_integrity.h +++ b/interfaces/inner_api/jit_code_sign/include/jit_buffer_integrity.h @@ -20,8 +20,7 @@ #include #include "errcode.h" -#include "jit_code_signer_base.h" -#include "jit_code_signer_factory.h" +#include "jit_code_signer.h" #include "jit_fort_helper.h" #include "securec.h" @@ -40,12 +39,11 @@ namespace CodeSign { /** * @brief Create Jit Code signer of specific level - * @param level see jit_code_signer_factory.h * @return error code, see errcode.h */ -static inline JitCodeSignerBase *CreateJitCodeSigner(JitBufferIntegrityLevel level) +static inline JitCodeSigner *CreateJitCodeSigner() { - return JitCodeSignerFactory::GetInstance().CreateJitCodeSigner(level); + return new JitCodeSigner(); } /** @@ -63,7 +61,7 @@ static bool IsSupportJitCodeSigner() * @param tmpBuffer tmp buffer storing jit code * @return error code, see errcode.h */ -static inline int32_t RegisterTmpBuffer(JitCodeSignerBase *signer, void *tmpBuffer) +static inline int32_t RegisterTmpBuffer(JitCodeSigner *signer, void *tmpBuffer) { CHECK_NULL_AND_RETURN_CODE(signer); signer->RegisterTmpBuffer(CAST_TO_BYTES(tmpBuffer)); @@ -76,7 +74,7 @@ static inline int32_t RegisterTmpBuffer(JitCodeSignerBase *signer, void *tmpBuff * @param instr an instruction to be signed * @return error code, see errcode.h */ -static inline int32_t AppendInstruction(JitCodeSignerBase *signer, Instr instr) +static inline int32_t AppendInstruction(JitCodeSigner *signer, Instr instr) { CHECK_NULL_AND_RETURN_CODE(signer); signer->SignInstruction(instr); @@ -90,7 +88,7 @@ static inline int32_t AppendInstruction(JitCodeSignerBase *signer, Instr instr) * @param size data size * @return error code, see errcode.h */ -static inline int32_t AppendData(JitCodeSignerBase *signer, const void *const data, uint32_t size) +static inline int32_t AppendData(JitCodeSigner *signer, const void *const data, uint32_t size) { CHECK_NULL_AND_RETURN_CODE(signer); return signer->SignData(CAST_TO_CONST_BYTES(data), size); @@ -102,7 +100,7 @@ static inline int32_t AppendData(JitCodeSignerBase *signer, const void *const da * @param n the amount of intsructions * @return error code, see errcode.h */ -static inline int32_t WillFixUp(JitCodeSignerBase *signer, uint32_t n = 1) +static inline int32_t WillFixUp(JitCodeSigner *signer, uint32_t n = 1) { CHECK_NULL_AND_RETURN_CODE(signer); signer->SkipNext(n); @@ -115,7 +113,7 @@ static inline int32_t WillFixUp(JitCodeSignerBase *signer, uint32_t n = 1) * @param instr target intruction * @return error code, see errcode.h */ -static inline int32_t PatchInstruction(JitCodeSignerBase *signer, int offset, Instr instr) +static inline int32_t PatchInstruction(JitCodeSigner *signer, int offset, Instr instr) { CHECK_NULL_AND_RETURN_CODE(signer); return signer->PatchInstruction(offset, instr); @@ -128,7 +126,7 @@ static inline int32_t PatchInstruction(JitCodeSignerBase *signer, int offset, In * @param instr target intruction * @return error code, see errcode.h */ -static inline int32_t PatchInstruction(JitCodeSignerBase *signer, +static inline int32_t PatchInstruction(JitCodeSigner *signer, void *address, Instr insn) { CHECK_NULL_AND_RETURN_CODE(signer); @@ -142,7 +140,7 @@ static inline int32_t PatchInstruction(JitCodeSignerBase *signer, * @param size data size * @return error code, see errcode.h */ -static inline int32_t PatchData(JitCodeSignerBase *signer, int offset, +static inline int32_t PatchData(JitCodeSigner *signer, int offset, const void *const data, uint32_t size) { CHECK_NULL_AND_RETURN_CODE(signer); @@ -157,7 +155,7 @@ static inline int32_t PatchData(JitCodeSignerBase *signer, int offset, * @param size data size * @return error code, see errcode.h */ -static inline int32_t PatchData(JitCodeSignerBase *signer, void *address, +static inline int32_t PatchData(JitCodeSigner *signer, void *address, const void *const data, uint32_t size) { CHECK_NULL_AND_RETURN_CODE(signer); @@ -171,8 +169,7 @@ static inline int32_t PatchData(JitCodeSignerBase *signer, void *address, * @param size memory size * @return error code, see errcode.h */ -__attribute__((no_sanitize("cfi"))) static inline int32_t ResetJitCode( - void *jitMemory, int size) +static inline int32_t ResetJitCode(void *jitMemory, int size) { if (jitMemory == nullptr) { return CS_ERR_JIT_MEMORY; @@ -201,8 +198,8 @@ __attribute__((no_sanitize("cfi"))) static inline int32_t ResetJitCode( * @param size memory size * @return error code, see errcode.h */ -__attribute__((no_sanitize("cfi"))) static inline int32_t CopyToJitCode( - JitCodeSignerBase *signer, void *jitMemory, void *tmpBuffer, int size) +static inline int32_t CopyToJitCode( + JitCodeSigner *signer, void *jitMemory, void *tmpBuffer, int size) { CHECK_NULL_AND_RETURN_CODE(signer); int32_t ret = CS_SUCCESS; diff --git a/interfaces/inner_api/jit_code_sign/include/jit_code_signer_base.h b/interfaces/inner_api/jit_code_sign/include/jit_code_signer.h similarity index 80% rename from interfaces/inner_api/jit_code_sign/include/jit_code_signer_base.h rename to interfaces/inner_api/jit_code_sign/include/jit_code_signer.h index bba02bc..b1d9902 100644 --- a/interfaces/inner_api/jit_code_sign/include/jit_code_signer_base.h +++ b/interfaces/inner_api/jit_code_sign/include/jit_code_signer.h @@ -34,15 +34,15 @@ static inline int GetIndexFromOffset(int offset) return static_cast(static_cast(offset) >> LOG_2_INSTRUCTION_SIZE); } -class JitCodeSignerBase { +class JitCodeSigner { public: - JitCodeSignerBase() : tmpBuffer_(nullptr), offset_(0) {}; - virtual ~JitCodeSignerBase() {} - virtual void Reset() = 0; - virtual void SignInstruction(Instr insn) = 0; - virtual void SkipNext(uint32_t n) = 0; - virtual int32_t PatchInstruction(int offset, Instr insn) = 0; - virtual int32_t ValidateCodeCopy(Instr *jitMemory, Byte *jitBuffer, int size) = 0; + JitCodeSigner(); + ~JitCodeSigner() {}; + void Reset(); + void SignInstruction(Instr insn); + void SkipNext(uint32_t n); + int32_t PatchInstruction(int offset, Instr insn); + int32_t ValidateCodeCopy(Instr *jitMemory, Byte *jitBuffer, int size); void RegisterTmpBuffer(Byte *tmpBuffer); int32_t SignData(const Byte *data, uint32_t size); diff --git a/interfaces/inner_api/jit_code_sign/include/jit_code_signer_factory.h b/interfaces/inner_api/jit_code_sign/include/jit_code_signer_factory.h deleted file mode 100644 index 1edff6b..0000000 --- a/interfaces/inner_api/jit_code_sign/include/jit_code_signer_factory.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CODE_SIGN_JIT_CODE_SIGNER_FACTORY_H -#define CODE_SIGN_JIT_CODE_SIGNER_FACTORY_H - -#include "jit_code_signer_base.h" - -namespace OHOS { -namespace Security { -namespace CodeSign { -// The higher the level, the richer the signing context information -// and the higher the overhead when updating instrucions. -enum class JitBufferIntegrityLevel { - Level0, - Level1, -}; - -class JitCodeSignerFactory { -public: - static JitCodeSignerFactory &GetInstance(); - JitCodeSignerBase *CreateJitCodeSigner( - JitBufferIntegrityLevel level = JitBufferIntegrityLevel::Level0); - -private: - JitCodeSignerFactory(); - ~JitCodeSignerFactory() = default; -}; -} -} -} -#endif \ No newline at end of file diff --git a/interfaces/inner_api/jit_code_sign/include/jit_code_signer_hybrid.h b/interfaces/inner_api/jit_code_sign/include/jit_code_signer_hybrid.h deleted file mode 100644 index 1db682e..0000000 --- a/interfaces/inner_api/jit_code_sign/include/jit_code_signer_hybrid.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CODE_SIGN_JIT_CODE_SIGNER_HYBRID_H -#define CODE_SIGN_JIT_CODE_SIGNER_HYBRID_H - -#include -#include -#include "jit_code_signer_base.h" - -namespace OHOS { -namespace Security { -namespace CodeSign { - -class JitCodeSignerHybrid : public JitCodeSignerBase { -public: - JitCodeSignerHybrid(); - ~JitCodeSignerHybrid() {} - void Reset(); - void SignInstruction(Instr insn); - void SkipNext(uint32_t n); - int32_t PatchInstruction(int offset, Instr insn); - int32_t ValidateCodeCopy(Instr *jitMemory, Byte *jitBuffer, int size); -private: - int32_t ValidateSubCode(Instr *jitMemory, PACSignCtx &verifyCtx, - Byte *jitBuffer, int pos, int size); - - std::vector skippedOffset_; - uint32_t skipSize_; - bool ctxInited_; -}; -} -} -} -#endif \ No newline at end of file diff --git a/interfaces/inner_api/jit_code_sign/include/jit_code_signer_single.h b/interfaces/inner_api/jit_code_sign/include/jit_code_signer_single.h deleted file mode 100644 index 3ee86b3..0000000 --- a/interfaces/inner_api/jit_code_sign/include/jit_code_signer_single.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CODE_SIGN_JIT_CODE_SIGNER_SINGLE_H -#define CODE_SIGN_JIT_CODE_SIGNER_SINGLE_H - -#include -#include -#include "jit_code_signer_base.h" - -namespace OHOS { -namespace Security { -namespace CodeSign { - -class JitCodeSignerSingle : public JitCodeSignerBase { -public: - JitCodeSignerSingle(); - ~JitCodeSignerSingle() {} - void Reset(); - void SignInstruction(Instr insn); - void SkipNext(uint32_t n); - int32_t PatchInstruction(int offset, Instr insn); - int32_t ValidateCodeCopy(Instr *jitMemory, Byte *jitBuffer, int size); -}; -} -} -} -#endif \ No newline at end of file diff --git a/interfaces/inner_api/jit_code_sign/src/jit_code_signer_base.cpp b/interfaces/inner_api/jit_code_sign/src/jit_code_signer.cpp similarity index 57% rename from interfaces/inner_api/jit_code_sign/src/jit_code_signer_base.cpp rename to interfaces/inner_api/jit_code_sign/src/jit_code_signer.cpp index 543dbf0..69f50a8 100644 --- a/interfaces/inner_api/jit_code_sign/src/jit_code_signer_base.cpp +++ b/interfaces/inner_api/jit_code_sign/src/jit_code_signer.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "jit_code_signer_base.h" +#include "jit_code_signer.h" #include #include "errcode.h" @@ -26,6 +26,20 @@ namespace CodeSign { constexpr int32_t BYTE_BIT_SIZE = 8; constexpr uint32_t UNALIGNMENT_MASK = 0x3; +JitCodeSigner::JitCodeSigner() +{ + Reset(); +} + +void JitCodeSigner::Reset() +{ + tmpBuffer_ = nullptr; + ctx_.InitSalt(); + ctx_.Init(0); + signTable_.clear(); + offset_ = 0; +} + inline static Instr GetOneInstrForQueue(std::queue &queue) { Instr insn = 0; @@ -38,12 +52,12 @@ inline static Instr GetOneInstrForQueue(std::queue &queue) return insn; } -void JitCodeSignerBase::RegisterTmpBuffer(Byte *tmpBuffer) +void JitCodeSigner::RegisterTmpBuffer(Byte *tmpBuffer) { tmpBuffer_ = tmpBuffer; } -int32_t JitCodeSignerBase::SignData(const Byte *const data, uint32_t size) +int32_t JitCodeSigner::SignData(const Byte *const data, uint32_t size) { if (data == nullptr) { return CS_ERR_INVALID_DATA; @@ -76,7 +90,7 @@ int32_t JitCodeSignerBase::SignData(const Byte *const data, uint32_t size) return CS_SUCCESS; } -int32_t JitCodeSignerBase::PatchInstruction(Byte *buffer, Instr insn) +int32_t JitCodeSigner::PatchInstruction(Byte *buffer, Instr insn) { if ((buffer == nullptr) || (tmpBuffer_ == nullptr)) { return CS_ERR_PATCH_INVALID; @@ -84,7 +98,7 @@ int32_t JitCodeSignerBase::PatchInstruction(Byte *buffer, Instr insn) return PatchInstruction(static_cast(buffer - tmpBuffer_), insn); } -int32_t JitCodeSignerBase::PatchData(int offset, const Byte *const data, uint32_t size) +int32_t JitCodeSigner::PatchData(int offset, const Byte *const data, uint32_t size) { if (size & UNALIGNMENT_MASK) { return CS_ERR_JIT_SIGN_SIZE; @@ -103,7 +117,7 @@ int32_t JitCodeSignerBase::PatchData(int offset, const Byte *const data, uint32_ return CS_SUCCESS; } -int32_t JitCodeSignerBase::PatchData(Byte *buffer, const Byte *const data, uint32_t size) +int32_t JitCodeSigner::PatchData(Byte *buffer, const Byte *const data, uint32_t size) { if ((buffer == nullptr) || (tmpBuffer_ == nullptr)) { return CS_ERR_PATCH_INVALID; @@ -111,7 +125,7 @@ int32_t JitCodeSignerBase::PatchData(Byte *buffer, const Byte *const data, uint3 return PatchData(static_cast(buffer - tmpBuffer_), data, size); } -bool JitCodeSignerBase::ConvertPatchOffsetToIndex(const int offset, int &curIndex) +bool JitCodeSigner::ConvertPatchOffsetToIndex(const int offset, int &curIndex) { if ((offset < 0) || ((static_cast(offset) & UNALIGNMENT_MASK) != 0)) { return false; @@ -125,7 +139,7 @@ bool JitCodeSignerBase::ConvertPatchOffsetToIndex(const int offset, int &curInde return true; } -int32_t JitCodeSignerBase::CheckDataCopy(Instr *jitMemory, Byte *tmpBuffer, int size) +int32_t JitCodeSigner::CheckDataCopy(Instr *jitMemory, Byte *tmpBuffer, int size) { if (jitMemory == nullptr) { return CS_ERR_JIT_MEMORY; @@ -147,6 +161,67 @@ int32_t JitCodeSignerBase::CheckDataCopy(Instr *jitMemory, Byte *tmpBuffer, int } return CS_SUCCESS; } + +void JitCodeSigner::SignInstruction(Instr insn) +{ + int index = GetIndexFromOffset(offset_); +#ifdef JIT_CODE_SIGN_DEBUGGABLE + LOG_INFO("Offset = %{public}x, insn = %{public}x", offset_, insn); + if (static_cast(index) != signTable_.size()) { + LOG_ERROR("Index = %{public}d not equal signtable size = %{public}zu.", + GetIndexFromOffset(offset_), signTable_.size()); + } +#endif + signTable_.push_back(ctx_.SignSingle(insn, index)); + offset_ += INSTRUCTION_SIZE; +} + +void JitCodeSigner::SkipNext(uint32_t n) {} + +int32_t JitCodeSigner::PatchInstruction(int offset, Instr insn) +{ +#ifdef JIT_CODE_SIGN_DEBUGGABLE + LOG_INFO("offset = %{public}x, insn = %{public}x", offset, insn); +#endif + int curIndex = 0; + if (!ConvertPatchOffsetToIndex(offset, curIndex)) { + LOG_ERROR("Offset invalid"); + return CS_ERR_PATCH_INVALID; + } + uint32_t signature = ctx_.SignSingle(insn, curIndex); + signTable_[curIndex] = signature; + return CS_SUCCESS; +} + +int32_t JitCodeSigner::ValidateCodeCopy(Instr *jitMemory, + Byte *tmpBuffer, int size) +{ + int32_t ret = CheckDataCopy(jitMemory, tmpBuffer, size); + if (ret != CS_SUCCESS) { + return ret; + } + + PACSignCtx verifyCtx(CTXPurpose::VERIFY, ctx_.GetSalt()); + int offset = 0; + while (offset < size) { + int index = GetIndexFromOffset(offset); + Instr insn = *reinterpret_cast(tmpBuffer_ + offset); + uint32_t signature = verifyCtx.SignSingle(insn, index); + if (signature != signTable_[index]) { +#ifdef JIT_FORT_DISABLE + LOG_ERROR("validate insn(%{public}x) without context failed at index = " \ + "%{public}x, signature(%{public}x) != wanted(%{public}x)", + insn, index * INSTRUCTION_SIZE, signature, signTable_[index]); +#endif +#ifndef JIT_CODE_SIGN_PERMISSIVE + return CS_ERR_VALIDATE_CODE; +#endif + } + *(jitMemory + index) = insn; + offset += INSTRUCTION_SIZE; + } + return CS_SUCCESS; +} } } } \ No newline at end of file diff --git a/interfaces/inner_api/jit_code_sign/src/jit_code_signer_factory.cpp b/interfaces/inner_api/jit_code_sign/src/jit_code_signer_factory.cpp deleted file mode 100644 index a0d952c..0000000 --- a/interfaces/inner_api/jit_code_sign/src/jit_code_signer_factory.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "jit_code_signer_factory.h" - -#include "jit_fort_helper.h" -#ifdef JIT_CODE_SIGN_ENABLE -#include "jit_code_signer_hybrid.h" -#include "jit_code_signer_single.h" -#include "log.h" -#endif - -namespace OHOS { -namespace Security { -namespace CodeSign { - -JitCodeSignerFactory::JitCodeSignerFactory() {} - -JitCodeSignerFactory &JitCodeSignerFactory::GetInstance() -{ - static JitCodeSignerFactory singleJitCodeSignerFactory; - return singleJitCodeSignerFactory; -} - -#ifdef JIT_CODE_SIGN_ENABLE -JitCodeSignerBase *JitCodeSignerFactory::CreateJitCodeSigner( - JitBufferIntegrityLevel level) -{ - if (!IsSupportPACFeature()) { - return nullptr; - } - switch (level) { - case JitBufferIntegrityLevel::Level0: - return new JitCodeSignerSingle(); - case JitBufferIntegrityLevel::Level1: - return new JitCodeSignerHybrid(); - default: - LOG_ERROR("Unsupport level of jit code signer."); - return nullptr; - } -} -#else // !JIT_CODE_SIGN_ENABLE -JitCodeSignerBase *JitCodeSignerFactory::CreateJitCodeSigner( - JitBufferIntegrityLevel level) -{ - return nullptr; -} -#endif -} -} -} \ No newline at end of file diff --git a/interfaces/inner_api/jit_code_sign/src/jit_code_signer_hybrid.cpp b/interfaces/inner_api/jit_code_sign/src/jit_code_signer_hybrid.cpp deleted file mode 100644 index bf74a40..0000000 --- a/interfaces/inner_api/jit_code_sign/src/jit_code_signer_hybrid.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "jit_code_signer_hybrid.h" - -#include -#include "errcode.h" -#include "log.h" - -namespace OHOS { -namespace Security { -namespace CodeSign { -JitCodeSignerHybrid::JitCodeSignerHybrid() -{ - Reset(); -} - -void JitCodeSignerHybrid::Reset() -{ - tmpBuffer_ = nullptr; - ctx_.InitSalt(); - ctx_.Init(0); - ctxInited_ = true; - skipSize_ = 0; - offset_ = 0; - signTable_.clear(); - skippedOffset_.clear(); - while (!willSign_.empty()) { - willSign_.pop(); - } -} - -void JitCodeSignerHybrid::SignInstruction(Instr insn) -{ -#ifdef JIT_CODE_SIGN_DEBUGGABLE - if (static_cast(GetIndexFromOffset(offset_)) != signTable_.size()) { - LOG_ERROR("Index = %{public}d not equal signtable size = %{public}zu.", - GetIndexFromOffset(offset_), signTable_.size()); - } - LOG_INFO("Offset = %{public}x, insn = %{public}x", offset_, insn); -#endif - if (skipSize_ > 0) { - skippedOffset_.push_back(offset_); - signTable_.push_back(ctx_.SignSingle(insn, GetIndexFromOffset(offset_))); - skipSize_ -= 1; - } else { - if (!ctxInited_) { - ctx_.Init(GetIndexFromOffset(offset_)); - ctxInited_ = true; - } - uint32_t signature = ctx_.Update(insn); - signTable_.push_back(signature); - } - offset_ += INSTRUCTION_SIZE; -} - -void JitCodeSignerHybrid::SkipNext(uint32_t n) -{ - skipSize_ = std::max(skipSize_, n); - ctxInited_ = false; -} - -int32_t JitCodeSignerHybrid::PatchInstruction(int offset, Instr insn) -{ -#ifdef JIT_CODE_SIGN_DEBUGGABLE - if (std::find(skippedOffset_.begin(), skippedOffset_.end(), offset) - == skippedOffset_.end()) { - LOG_ERROR("Update no skipped instruction failed at offset" \ - "= %{public}x", offset); - } - LOG_INFO("offset = %{public}x, insn = %{public}x", offset, insn); -#endif - int curIndex = 0; - if (!ConvertPatchOffsetToIndex(offset, curIndex)) { - LOG_ERROR("Offset invalid"); - return CS_ERR_PATCH_INVALID; - } - uint32_t signature = ctx_.SignSingle(insn, curIndex); - signTable_[curIndex] = signature; - return CS_SUCCESS; -} - -int32_t JitCodeSignerHybrid::ValidateSubCode(Instr *jitMemory, PACSignCtx &verifyCtx, - Byte *jitBuffer, int pos, int size) -{ - if (size == 0) { - return CS_SUCCESS; - } -#if defined(JIT_CODE_SIGN_DEBUGGABLE) && defined(JIT_FORT_DISABLE) - LOG_INFO("Validate start = %{public}p, offset = %{public}x, size = %{public}d", - jitBuffer, pos, size); -#endif - int32_t index = GetIndexFromOffset(pos); - verifyCtx.Init(index); - auto insnPtr = reinterpret_cast(jitBuffer + pos); - while (size > 0) { - uint32_t signature = verifyCtx.Update(*insnPtr); - if (signature != signTable_[index]) { -#ifdef JIT_FORT_DISABLE - LOG_ERROR("Validate insn (%{public}8x) failed at offset = %{public}x, " \ - "signature(%{public}x) != wanted(%{public}x)", - *(insnPtr), index * INSTRUCTION_SIZE, signature, signTable_[index]); -#endif -#ifndef JIT_CODE_SIGN_PERMISSIVE - return CS_ERR_VALIDATE_CODE; -#else - break; -#endif - } - *(jitMemory + index) = *insnPtr; - index++; - insnPtr++; - size -= INSTRUCTION_SIZE; - } - return CS_SUCCESS; -} - -__attribute__((no_sanitize("cfi"))) int32_t JitCodeSignerHybrid::ValidateCodeCopy( - Instr *jitMemory, Byte *tmpBuffer, int size) -{ - int32_t ret = CheckDataCopy(jitMemory, tmpBuffer, size); - if (ret != CS_SUCCESS) { - return ret; - } - - PACSignCtx verifyCtx(CTXPurpose::VERIFY, ctx_.GetSalt()); - int offset = 0; - for (uint32_t i = 0; i < skippedOffset_.size(); i++) { - if (ValidateSubCode(jitMemory, verifyCtx, tmpBuffer_, offset, - skippedOffset_[i] - offset) != CS_SUCCESS) { - return CS_ERR_VALIDATE_CODE; - } - - int32_t index = GetIndexFromOffset(skippedOffset_[i]); - Instr insn = *reinterpret_cast(tmpBuffer_ + skippedOffset_[i]); - uint32_t signature = verifyCtx.SignSingle(insn, index); - if (signature != signTable_[index]) { -#ifdef JIT_FORT_DISABLE - LOG_ERROR("Validate insn (%{public}x) without context failed at index = %{public}x," \ - "signature(%{public}x) != wanted(%{public}x).", - insn, index, signature, signTable_[index]); -#endif -#ifndef JIT_CODE_SIGN_PERMISSIVE - return CS_ERR_VALIDATE_CODE; -#endif - } - *(jitMemory + index) = insn; - offset = skippedOffset_[i] + INSTRUCTION_SIZE; - } - - if (ValidateSubCode(jitMemory, verifyCtx, tmpBuffer_, - offset, size - offset) != CS_SUCCESS) { - return CS_ERR_VALIDATE_CODE; - } - return CS_SUCCESS; -} -} -} -} diff --git a/interfaces/inner_api/jit_code_sign/src/jit_code_signer_single.cpp b/interfaces/inner_api/jit_code_sign/src/jit_code_signer_single.cpp deleted file mode 100644 index d4fae3d..0000000 --- a/interfaces/inner_api/jit_code_sign/src/jit_code_signer_single.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "jit_code_signer_single.h" - -#include -#include "errcode.h" -#include "log.h" - -namespace OHOS { -namespace Security { -namespace CodeSign { - -JitCodeSignerSingle::JitCodeSignerSingle() -{ - Reset(); -} - -void JitCodeSignerSingle::Reset() -{ - tmpBuffer_ = nullptr; - ctx_.InitSalt(); - ctx_.Init(0); - signTable_.clear(); - offset_ = 0; -} - -void JitCodeSignerSingle::SignInstruction(Instr insn) -{ - int index = GetIndexFromOffset(offset_); -#ifdef JIT_CODE_SIGN_DEBUGGABLE - LOG_INFO("Offset = %{public}x, insn = %{public}x", offset_, insn); - if (static_cast(index) != signTable_.size()) { - LOG_ERROR("Index = %{public}d not equal signtable size = %{public}zu.", - GetIndexFromOffset(offset_), signTable_.size()); - } -#endif - signTable_.push_back(ctx_.SignSingle(insn, index)); - offset_ += INSTRUCTION_SIZE; -} - -void JitCodeSignerSingle::SkipNext(uint32_t n) {} - -int32_t JitCodeSignerSingle::PatchInstruction(int offset, Instr insn) -{ -#ifdef JIT_CODE_SIGN_DEBUGGABLE - LOG_INFO("offset = %{public}x, insn = %{public}x", offset, insn); -#endif - int curIndex = 0; - if (!ConvertPatchOffsetToIndex(offset, curIndex)) { - LOG_ERROR("Offset invalid"); - return CS_ERR_PATCH_INVALID; - } - uint32_t signature = ctx_.SignSingle(insn, curIndex); - signTable_[curIndex] = signature; - return CS_SUCCESS; -} - -int32_t JitCodeSignerSingle::ValidateCodeCopy(Instr *jitMemory, - Byte *tmpBuffer, int size) -{ - int32_t ret = CheckDataCopy(jitMemory, tmpBuffer, size); - if (ret != CS_SUCCESS) { - return ret; - } - - PACSignCtx verifyCtx(CTXPurpose::VERIFY, ctx_.GetSalt()); - int offset = 0; - while (offset < size) { - int index = GetIndexFromOffset(offset); - Instr insn = *reinterpret_cast(tmpBuffer_ + offset); - uint32_t signature = verifyCtx.SignSingle(insn, index); - if (signature != signTable_[index]) { -#ifdef JIT_FORT_DISABLE - LOG_ERROR("validate insn(%{public}x) without context failed at index = " \ - "%{public}x, signature(%{public}x) != wanted(%{public}x)", - insn, index * INSTRUCTION_SIZE, signature, signTable_[index]); -#endif -#ifndef JIT_CODE_SIGN_PERMISSIVE - return CS_ERR_VALIDATE_CODE; -#endif - } - *(jitMemory + index) = insn; - offset += INSTRUCTION_SIZE; - } - return CS_SUCCESS; -} -} -} -} \ No newline at end of file diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index d71d822..02d2a12 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -425,8 +425,6 @@ group("unittest_group") { if (code_signature_support_oh_code_sign) { deps += [ ":key_enable_utils_unittest" ] } - if (jit_code_sign_enable) { - deps += [ ":jit_code_sign_unittest" ] - } + deps += [ ":jit_code_sign_unittest" ] } } diff --git a/test/unittest/jit_code_sign_test.cpp b/test/unittest/jit_code_sign_test.cpp index 6542fb6..98e4f59 100644 --- a/test/unittest/jit_code_sign_test.cpp +++ b/test/unittest/jit_code_sign_test.cpp @@ -25,7 +25,6 @@ #include #include "errcode.h" -#include "jit_code_signer_factory.h" #include "jit_buffer_integrity.h" #include "code_sign_attr_utils.h" #include "pac_sign_ctx.h" @@ -37,6 +36,11 @@ using namespace std; using namespace testing::ext; using namespace testing::mt; +enum class JitBufferIntegrityLevel { + Level0, + Level1, +}; + #define CAST_VOID_PTR(buffer) (reinterpret_cast(buffer)) static Instr g_testInstructionSet[] = { @@ -146,10 +150,10 @@ public: */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0001, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); int i = 0; while (i < INSTRUCTIONS_SET_SIZE) { AppendInstruction(signer, g_testInstructionSet[i]); @@ -174,10 +178,10 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0001, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0002, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); AppendData(signer, g_testInstructionBuf, INSTRUCTIONS_SET_SIZE_BYTES); EXPECT_EQ(CopyToJitCode(signer, g_jitMemory, g_testInstructionBuf, @@ -197,11 +201,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0002, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0003, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); int i = 0, offset = 0; while (i < TEST_PATCH_INDEX) { AppendInstruction(signer, g_testInstructionSet[i]); @@ -239,11 +243,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0003, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0004, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); int i = 0, offset = 0; while (i < TEST_PATCH_INDEX) { AppendInstruction(signer, g_testInstructionSet[i]); @@ -288,11 +292,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0004, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0005, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); AppendData(signer, g_testInstructionBuf, INSTRUCTIONS_SET_SIZE_BYTES); int sizeInByte = sizeof(g_testInstructionSet); EXPECT_EQ(CopyToJitCode(signer, g_jitMemory, g_afterPatchInstructionBuf, @@ -311,11 +315,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0005, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0006, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); RegisterTmpBuffer(signer, g_testInstructionBuf); AppendData(signer, g_testInstructionBuf, INSTRUCTIONS_SET_SIZE_BYTES); @@ -335,11 +339,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0006, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0007, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); RegisterTmpBuffer(signer, g_testInstructionBuf); AppendData(signer, g_testInstructionBuf, INSTRUCTIONS_SET_SIZE_BYTES - 1); @@ -359,11 +363,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0007, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0008, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); Byte *ptr = reinterpret_cast(g_testInstructionBuf) + 1; AppendData(signer, g_testInstructionBuf, 1); AppendData(signer, CAST_VOID_PTR(ptr), INSTRUCTIONS_SET_SIZE_BYTES - 1); @@ -384,11 +388,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0008, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0009, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); int i = 0, offset = 0; while (i < TEST_PATCH_INDEX) { AppendInstruction(signer, g_testInstructionSet[i]); @@ -424,11 +428,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0009, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0010, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); int i = 0, offset = 0; while (i < TEST_PATCH_INDEX) { AppendInstruction(signer, g_testInstructionSet[i]); @@ -468,11 +472,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0010, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0011, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); RegisterTmpBuffer(signer, g_afterPatchInstructionBuf); EXPECT_EQ(PatchInstruction(signer, nullptr, INSTRUCTION_SIZE), CS_ERR_PATCH_INVALID); @@ -507,11 +511,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_00012, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_00013, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); AppendData(signer, g_testInstructionBuf, INSTRUCTIONS_SET_SIZE_BYTES); EXPECT_EQ(CopyToJitCode(signer, g_jitMemory, g_testInstructionBuf, INSTRUCTIONS_SET_SIZE_BYTES - 1), CS_ERR_JIT_SIGN_SIZE); @@ -533,11 +537,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_00013, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_00014, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); Byte *data = reinterpret_cast(g_testInstructionSet); uint32_t dataSize[] = {1, 2, 1, 4, 2, 8, 2, 1, 3}; int pos = 0; @@ -563,11 +567,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_00014, TestSize.Level0) */ HWMTEST_F(JitCodeSignTest, JitCodeSignTest_00015, TestSize.Level1, MULTI_THREAD_NUM) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); int i = 0; while (i < INSTRUCTIONS_SET_SIZE) { AppendInstruction(signer, g_testInstructionSet[i]); @@ -611,11 +615,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_00016, TestSize.Level0) PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); #endif EXPECT_NE(tmpMemory, MAP_FAILED); - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); int i = 0; while (i < INSTRUCTIONS_SET_SIZE) { AppendInstruction(signer, g_testInstructionSet[i]); @@ -657,7 +661,7 @@ HWMTEST_F(JitCodeSignTest, JitCodeSignTest_0017, TestSize.Level1, MULTI_THREAD_N for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - JitCodeSignerBase *signer = CreateJitCodeSigner(level); + JitCodeSigner *signer = CreateJitCodeSigner(); int i = 0; while (i < instructionNum) { AppendInstruction(signer, tmpBuffer[i]); @@ -705,8 +709,7 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0018, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0019, TestSize.Level0) { - EXPECT_EQ(CreateJitCodeSigner( - static_cast(static_cast(MAX_LEVEL) + 1)), + EXPECT_NE(CreateJitCodeSigner(), nullptr); } @@ -718,10 +721,10 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0019, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0020, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast(static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); AppendData(signer, g_testInstructionBuf, INSTRUCTIONS_SET_SIZE_BYTES); // offset is greater than signed size @@ -749,11 +752,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0020, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0021, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast( static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); AppendData(signer, nullptr, INSTRUCTIONS_SET_SIZE_BYTES); AppendData(signer, g_testInstructionBuf, INSTRUCTIONS_SET_SIZE_BYTES); @@ -777,11 +780,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0021, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0022, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast( static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); EXPECT_EQ(ResetJitCode(nullptr, 0), CS_ERR_JIT_MEMORY); EXPECT_EQ(CopyToJitCode(signer, nullptr, g_testInstructionBuf, 0), CS_ERR_JIT_MEMORY); @@ -798,11 +801,11 @@ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0022, TestSize.Level0) */ HWTEST_F(JitCodeSignTest, JitCodeSignTest_0023, TestSize.Level0) { - JitCodeSignerBase *signer = nullptr; + JitCodeSigner *signer = nullptr; for (JitBufferIntegrityLevel level = MIN_LEVEL; level <= MAX_LEVEL; level = static_cast( static_cast(level) + 1)) { - signer = CreateJitCodeSigner(level); + signer = CreateJitCodeSigner(); for (int i = 0; i < INSTRUCTIONS_SET_SIZE_BYTES; i++) { uint32_t tmpBuffer[INSTRUCTIONS_SET_SIZE]; (void) memcpy_s(tmpBuffer, INSTRUCTIONS_SET_SIZE_BYTES, g_testInstructionBuf, INSTRUCTIONS_SET_SIZE_BYTES); -- Gitee