From 06878b80befee9ee6e196daf7489255f1f10ebd3 Mon Sep 17 00:00:00 2001 From: zzulilyw Date: Mon, 21 Oct 2024 15:18:03 +0800 Subject: [PATCH] Bugfix: fix fdsan: The fdsan error level of the child process from becomes disabled, but the child process from appspawn is an exception issue: https://gitee.com/openharmony/third_party_musl/issues/IAVWEZ Test: Build & Boot devices & xts Signed-off-by: zzulilyw --- common/appspawn_server.c | 8 ++++++++ standard/appspawn_service.c | 4 +++- standard/nwebspawn_launcher.c | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/common/appspawn_server.c b/common/appspawn_server.c index b8c1c86d..1539142f 100644 --- a/common/appspawn_server.c +++ b/common/appspawn_server.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "appspawn_trace.h" #include "appspawn_utils.h" @@ -175,6 +176,9 @@ static void NwebSpawnCloneChildProcess(AppSpawnContent *content, AppSpawnClient static void AppSpawnForkChildProcess(AppSpawnContent *content, AppSpawnClient *client, pid_t *pid) { struct timespec forkStart = {0}; +#ifndef OHOS_LITE + enum fdsan_error_level errorLevel = fdsan_get_error_level(); +#endif clock_gettime(CLOCK_MONOTONIC, &forkStart); StartAppspawnTrace("AppspawnForkStart"); *pid = fork(); @@ -183,6 +187,10 @@ static void AppSpawnForkChildProcess(AppSpawnContent *content, AppSpawnClient *c clock_gettime(CLOCK_MONOTONIC, &forkEnd); uint64_t diff = DiffTime(&forkStart, &forkEnd); APPSPAWN_CHECK_ONLY_LOG(diff < MAX_FORK_TIME, "fork time %{public}" PRId64 " us", diff); +#ifndef OHOS_LITE + // Inherit the error level of the original process + (void)fdsan_set_error_level(errorLevel); +#endif ProcessExit(AppSpawnChild(content, client)); } else { FinishAppspawnTrace(); diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 79d783ae..3ee3aa24 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -694,7 +694,7 @@ static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) APPSPAWN_CHECK_ONLY_EXPER(content->parentToChildFd[1] <= 0, close(content->parentToChildFd[1]); content->parentToChildFd[1] = -1); APPSPAWN_CHECK(pipe(content->parentToChildFd) == 0, return, "prefork with prefork pipe failed %{public}d", errno); - + enum fdsan_error_level errorLevel = fdsan_get_error_level(); content->reservedPid = fork(); APPSPAWN_LOGV("prefork fork finish %{public}d,%{public}d,%{public}d,%{public}d,%{public}d", content->reservedPid, content->preforkFd[0], content->preforkFd[1], content->parentToChildFd[0], @@ -725,6 +725,8 @@ static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) return; } ClearMMAP(property->client.id); + // Inherit the error level of the original process + (void)fdsan_set_error_level(errorLevel); ProcessExit(AppSpawnChild(content, &property->client)); } else if (content->reservedPid < 0) { APPSPAWN_LOGE("prefork fork child process failed %{public}d", content->reservedPid); diff --git a/standard/nwebspawn_launcher.c b/standard/nwebspawn_launcher.c index 24113eb8..58c337c8 100644 --- a/standard/nwebspawn_launcher.c +++ b/standard/nwebspawn_launcher.c @@ -87,8 +87,11 @@ void NWebSpawnInit(void) pid_t NWebSpawnLaunch(void) { + enum fdsan_error_level errorLevel = fdsan_get_error_level(); pid_t ret = fork(); if (ret == 0) { + // Inherit the error level of the original process + (void)fdsan_set_error_level(errorLevel); NWebSpawnInit(); } APPSPAWN_LOGI("nwebspawn fork success pid: %{public}d", ret);