!1593 The fdsan error level of the child process from fork becomes disabled, but the child process from appspawn is an exception

Merge pull request !1593 from zzulilyw/master
This commit is contained in:
openharmony_ci 2024-10-28 01:39:32 +00:00 committed by Gitee
commit 23f9147b03
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 14 additions and 1 deletions

View File

@ -20,6 +20,7 @@
#include <sched.h>
#include <signal.h>
#include <time.h>
#include <stdio.h>
#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();

View File

@ -765,7 +765,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],
@ -796,6 +796,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);

View File

@ -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);