From 9f2fa82713d82b40d32224f77ca1c8467329b60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E7=A5=A5?= Date: Sat, 21 Jun 2025 03:02:50 +0000 Subject: [PATCH] fix vab dm verity target creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 高祥 --- .../innerkits/fs_manager/libfs_hvb/fs_hvb.c | 82 +++++++++++-------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c b/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c index a77ba8193..0bf79cf38 100755 --- a/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c +++ b/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c @@ -53,6 +53,7 @@ extern "C" { #define FS_HVB_CMDLINE_PATH "/proc/cmdline" #define FS_HVB_PARTITION_PREFIX "/dev/block/by-name/" #define HVB_CMDLINE_EXT_CERT_DIGEST "ohos.boot.hvb.ext_rvt" +#define FS_HVB_SNAPSHOT_PREFIX "/dev/block/" #define HASH_ALGO_SHA256 0 #define HASH_ALGO_SHA256_STR "sha256" @@ -318,6 +319,34 @@ int FsHvbInit(InitHvbType hvbType) return 0; } +static int FsHvbFindVabPartition(const char *devName, HvbDeviceParam *devPara) +{ + int rc; + HOOK_EXEC_OPTIONS options; + if (devPara == NULL) { + BEGET_LOGE("error, get devPara"); + return -1; + } + if (memcpy_s(devPara->partName, sizeof(devPara->partName), devName, strlen(devName)) != 0) { + BEGET_LOGE("error, fail to copy shapshot name"); + return -1; + } + (void)memset_s(devPara->value, sizeof(devPara->value), 0, sizeof(devPara->value)); + devPara->reverse = 1; + devPara->len = (int)sizeof(devPara->value); + options.flags = TRAVERSE_STOP_WHEN_ERROR; + options.preHook = NULL; + options.postHook = NULL; + + rc = HookMgrExecute(GetBootStageHookMgr(), INIT_VAB_HVBCHECK, (void*)devPara, &options); + BEGET_LOGW("try find partition from snapshot path %s, ret = %d", devName, rc); + if (rc == 0) { + BEGET_LOGW("found partition %s, len=%d", devPara->value, devPara->len); + } + + return rc; +} + static int FsHvbGetCert(struct hvb_cert *cert, const char *devName, struct hvb_verified_data *vd) { enum hvb_errno hr; @@ -325,6 +354,13 @@ static int FsHvbGetCert(struct hvb_cert *cert, const char *devName, struct hvb_v struct hvb_cert_data *p = vd->certs; struct hvb_cert_data *end = p + vd->num_loaded_certs; + // for virtual ab boot, find partition name with snapshot name + HvbDeviceParam devPara = {}; + if (FsHvbFindVabPartition(devName, &devPara) == 0) { + devName = devPara.value; + devNameLen = strlen(devName); + } + int bootSlots = GetBootSlots(); if (bootSlots > 1) { if (devNameLen <= FS_HVB_AB_SUFFIX_LEN) { @@ -519,6 +555,15 @@ static int FsHvbVerityTargetAddFecArgs(struct hvb_cert *cert, char *devPath, cha return 0; } +static const char *FsHvbGetFsPrefix(const char *devName) +{ + HvbDeviceParam devPara = {}; + if (FsHvbFindVabPartition(devName, &devPara) == 0) { + return FS_HVB_SNAPSHOT_PREFIX; + } + return FS_HVB_PARTITION_PREFIX; +} + /* * target->paras is verity table target, format as below; * @@ -549,7 +594,7 @@ int FsHvbConstructVerityTarget(DmVerityTarget *target, const char *devName, stru } if (snprintf_s(&devPath[0], sizeof(devPath), sizeof(devPath) - 1, "%s%s", - ((strchr(devName, '/') == NULL) ? FS_HVB_PARTITION_PREFIX : ""), devName) == -1) { + ((strchr(devName, '/') == NULL) ? FsHvbGetFsPrefix(devName) : ""), devName) == -1) { BEGET_LOGE("error, snprintf_s devPath"); return -1; } @@ -652,34 +697,6 @@ void FsHvbDestoryVerityTarget(DmVerityTarget *target) } } -static int FsHvbFindPartitionName(const char *devName, HvbDeviceParam *devPara) -{ - int rc; - HOOK_EXEC_OPTIONS options; - if (devPara == NULL) { - BEGET_LOGE("error, get devPara"); - return -1; - } - if (memcpy_s(devPara->partName, sizeof(devPara->partName), devName, strlen(devName)) != 0) { - BEGET_LOGE("error, fail to copy shapshot name"); - return -1; - } - (void)memset_s(devPara->value, sizeof(devPara->value), 0, sizeof(devPara->value)); - devPara->reverse = 1; - devPara->len = (int)sizeof(devPara->value); - options.flags = TRAVERSE_STOP_WHEN_ERROR; - options.preHook = NULL; - options.postHook = NULL; - - rc = HookMgrExecute(GetBootStageHookMgr(), INIT_VAB_HVBCHECK, (void*)devPara, &options); - BEGET_LOGW("try find partition from snapshot path %s, ret = %d", devName, rc); - if (rc == 0) { - BEGET_LOGW("found partition %s, len=%d", devPara->value, devPara->len); - } - - return rc; -} - int FsHvbSetupHashtree(FstabItem *fsItem) { int rc; @@ -699,13 +716,6 @@ int FsHvbSetupHashtree(FstabItem *fsItem) return -1; } - // for virtual ab boot, find partition name with snapshot name - HvbDeviceParam devPara = {}; - rc = FsHvbFindPartitionName(devName, &devPara); - if (rc == 0) { - devName = devPara.value; - } - rc = FsHvbCreateVerityTarget(&target, devName, g_vd); if (rc != 0) { BEGET_LOGE("error 0x%x, create verity-table", rc); -- Gitee