[M120 Migration][VD] Add waiting for RW image mount 98/311498/3
authorjiangyuwei <yuwei.jiang@samsung.com>
Wed, 22 May 2024 03:20:56 +0000 (11:20 +0800)
committerBot Blink <blinkbot@samsung.com>
Thu, 23 May 2024 11:01:11 +0000 (11:01 +0000)
When UWE is used but RW image was not mounted yet,
Engine could wrongly dlopen RO package.

This patch adds additional waiting for RW mount
to prevent from opening RO package by mistake.

Max waiting time for RW mount: 10s

Reference:
  - https://review.tizen.org/gerrit/301389/
  - https://review.tizen.org/gerrit/301791/

Change-Id: I9178bcb4316030645c0a141ee01aecf53eb7ef6f
Signed-off-by: jiangyuwei <yuwei.jiang@samsung.com>
tizen_src/downloadable/chromium_efl_install.cc
tizen_src/downloadable/ewk_interface_main.cc

index a1694fc5aaeb6bf2f3a13da4d9754a701f992a09..a382e4fbb15a4470c8c7390dbe5cd4b3a62c8bd4 100644 (file)
@@ -73,7 +73,10 @@ __attribute__((destructor)) void close_log_file() {
 #define SUCCESS 0
 #define FAIL -1
 
-const char* kChromiumMountReady = "/tmp/.chromium_mount.ready";
+const char* kChromiumUpdateOrPreloadMountReady =
+    "/tmp/.chromium_update_or_preload_mount.ready";
+const char* kChromiumUpgradeMountReady = "/tmp/.chromium_upgrade_mount.ready";
+const char* kChromiumUpgradeTPKExists = "/tmp/.chromium_upgrade_tpk.exists";
 const char* kColdBootRequester = "chromium-efl";
 const char* kLaunchFail = "rtc/memory/WebApp/LaunchFail";
 const char* kPSAgentReady = "/run/ps_agent.pid";
@@ -153,12 +156,6 @@ static int mount(bool mount, const char* args, bool use_system = false) {
     return FAIL;
   }
 
-  if (LwipcEventDone(kChromiumMountReady) < 0) {
-    // The Lwipc api simply calls the ioctl() inside the function.
-    // Failure of this API means that there are some kernel issues.
-    LOG(ERROR) << kChromiumMountReady << " Event Failed.";
-  }
-
   return SUCCESS;
 }
 
@@ -166,10 +163,10 @@ static int MountPatchedTPK() {
   int result = FAIL;
   if (!access(LIB_RO_ROOT_DIR "/version", F_OK)) {
     LOG(INFO) << LIB_RO_ROOT_DIR "/version file already exists.";
-    if (LwipcEventDone(kChromiumMountReady) < 0) {
+    if (LwipcEventDone(kChromiumUpdateOrPreloadMountReady) < 0) {
       // The Lwipc api simply calls the ioctl() inside the function.
       // Failure of this API means that there are some kernel issues.
-      LOG(ERROR) << kChromiumMountReady << " Event Failed.";
+      LOG(ERROR) << kChromiumUpdateOrPreloadMountReady << " Event Failed.";
     }
     return SUCCESS;
   }
@@ -178,17 +175,43 @@ static int MountPatchedTPK() {
     LOG(INFO) << PATH_UPDATED_CHROMIUM_EFL_IMG << " exists.";
     kTargetTPK = "WebEngine Updated TPK ";
     result = mount(true, MOUNT_ARGS_UPDATED_CHROMIUM);
+
+    if (LwipcEventDone(kChromiumUpdateOrPreloadMountReady) < 0) {
+      // The Lwipc api simply calls the ioctl() inside the function.
+      // Failure of this API means that there are some kernel issues.
+      LOG(ERROR) << kChromiumUpdateOrPreloadMountReady << " Event Failed.";
+    }
   }
 
   if (result != SUCCESS && !access(PATH_PRELOAD_CHROMIUM_EFL_IMG, F_OK)) {
     LOG(INFO) << PATH_PRELOAD_CHROMIUM_EFL_IMG << " exists.";
     kTargetTPK = "WebEngine Preload TPK ";
     result = mount(true, MOUNT_ARGS_PRELOAD_CHROMIUM);
+
+    if (LwipcEventDone(kChromiumUpdateOrPreloadMountReady) < 0) {
+      // The Lwipc api simply calls the ioctl() inside the function.
+      // Failure of this API means that there are some kernel issues.
+      LOG(ERROR) << kChromiumUpdateOrPreloadMountReady << " Event Failed.";
+    }
   }
 
   return result;
 }
 
+static void AlertUpgradeTPK() {
+  if (!access(PATH_UPGRADE_CHROMIUM_EFL_IMG, F_OK)) {
+    LOG(INFO) << PATH_UPGRADE_CHROMIUM_EFL_IMG << " exists.";
+
+    if (LwipcEventDone(kChromiumUpgradeTPKExists) < 0) {
+      // The Lwipc api simply calls the ioctl() inside the function.
+      // Failure of this API means that there are some kernel issues.
+      LOG(ERROR) << kChromiumUpgradeTPKExists << " Event Failed.";
+    }
+  } else {
+    LOG(INFO) << "No WebEngine Upgrade TPK found";
+  }
+}
+
 static void MountUpgradeTPK() {
   if (!access(LIB_UPGRADE_ROOT_DIR "/version", F_OK)) {
     RequestColdBoot();
@@ -199,6 +222,11 @@ static void MountUpgradeTPK() {
     LOG(INFO) << PATH_UPGRADE_CHROMIUM_EFL_IMG << " exists.";
     kTargetTPK = "WebEngine Upgrade TPK ";
     mount(true, MOUNT_ARGS_UPGRADE_CHROMIUM);
+    if (LwipcEventDone(kChromiumUpgradeMountReady) < 0) {
+      // The Lwipc api simply calls the ioctl() inside the function.
+      // Failure of this API means that there are some kernel issues.
+      LOG(ERROR) << kChromiumUpgradeMountReady << " Event Failed.";
+    }
   } else {
     LOG(INFO) << "No WebEngine Upgrade TPK found";
   }
@@ -241,6 +269,7 @@ int main(int argc, char* argv[]) {
   }
 
   if (option == InstallTpk) {  // InstallTpk
+    AlertUpgradeTPK();
     // TV does not install tpk. Built-in installer installs.
     // To avoid concurrency problem, a lock must be shared with installer.
     //
index 628a68c1ae7eb7442a383004133b46afd355b7d6..945fd81025df917232f629ce71180525599986fe 100644 (file)
@@ -68,7 +68,11 @@ inline unsigned long long ConvertMilliseconds(timespec ts) {
 #if BUILDFLAG(IS_TIZEN_TV)
 bool g_upgrade_lib = false;  // conservative policy
 const char* kChromiumMountReady = "/tmp/.chromium_mount.ready";
-
+const char* kChromiumUpdateOrPreloadMountReady =
+    "/tmp/.chromium_update_or_preload_mount.ready";
+const char* kChromiumUpgradeMountReady = "/tmp/.chromium_upgrade_mount.ready";
+const char* kChromiumUpgradeTPKExists = "/tmp/.chromium_upgrade_tpk.exists";
+const unsigned int kUpgradeMountTimeout = 10000;
 #if defined(ENABLE_WRT_JS)
 #define SQUASHFS_MAGIC 0x73717368
 
@@ -114,6 +118,26 @@ void DisposeLoaderIfNecessary() {
 #endif  // TIZEN_VERSION_AT_LEAST(8, 0, 0) && defined(TIZEN_VD_ENTERPRISE_FEATURE)
 }
 
+inline bool upgradeTPKExists() {
+  if (LwipcIsDone(kChromiumUpgradeTPKExists) > 0) {
+    LOG(INFO) << "Upgrade TPK exists";
+    return true;
+  }
+
+  LOG(INFO) << "Upgrade TPK does not exist";
+  return false;
+}
+
+inline bool upgradeTPKMounted() {
+  bool result = !access(CHROMIUM_UPGRADE_LIB_PATH, F_OK);
+  LOG(INFO) << "path: " << CHROMIUM_UPGRADE_LIB_PATH << ", result: " << result;
+
+  if (!result)
+    LOG(INFO) << "error reason: " << strerror(errno);
+
+  return result;
+}
+
 void SetPriority(int absolute) {
   setpriority(PRIO_PROCESS, 0, absolute);
   LOG(INFO) << "Set process priority : " << absolute;
@@ -333,9 +357,29 @@ void* open_library() {
     return g_impl_lib_handle;
 
 #if BUILDFLAG(IS_TIZEN_TV)
-  g_upgrade_lib = (g_upgrade_lib && !access(CHROMIUM_UPGRADE_LIB_PATH, F_OK));
+  bool apply_upgrade = false;
+  if (g_upgrade_lib && upgradeTPKExists()) {
+    LOG(INFO) << "policy: " << g_upgrade_lib
+              << ", RW TPK found, attempt to mount RW TPK";
+    if (upgradeTPKMounted()) {
+      LOG(INFO) << "RW TPK mount already done. Load RW package.";
+      apply_upgrade = true;
+    } else {
+      LOG(INFO) << "Waiting for RW TPK mount done. Max wait: "
+                << kUpgradeMountTimeout << "ms";
+      int ret =
+          LwipcWaitEvent(kChromiumUpgradeMountReady, kUpgradeMountTimeout);
+      if (ret != 0) {
+        LOG(INFO) << "RW TPK exists, but mount failed. Load RO package.";
+        apply_upgrade = false;
+      } else {
+        LOG(INFO) << "RW TPK mount done. Load RW package.";
+        apply_upgrade = true;
+      }
+    }
+  }
   const char* path =
-      g_upgrade_lib ? CHROMIUM_UPGRADE_LIB_PATH : CHROMIUM_PRELOAD_LIB_PATH;
+      apply_upgrade ? CHROMIUM_UPGRADE_LIB_PATH : CHROMIUM_PRELOAD_LIB_PATH;
 #else
   const char* path = CHROMIUM_PRELOAD_LIB_PATH;
 #endif
@@ -403,11 +447,12 @@ Eina_Bool ewk_wait_chromium_ready(unsigned int timeout_msec) {
 #if BUILDFLAG(IS_TIZEN_TV)
   LOG(INFO) << "ewk_wait_chromium_ready called. timeout : " << timeout_msec;
 
-  int ret = LwipcWaitEvent(kChromiumMountReady, timeout_msec);
+  int ret = LwipcWaitEvent(kChromiumUpdateOrPreloadMountReady, timeout_msec);
   if (ret == 0) {
-    LOG(INFO) << "chromium mount is done.";
+    LOG(INFO) << "update or preload chromium mount is done.";
     return true;
   }
+
   LOG(ERROR) << "chromium mount is not ready yet: "
              << (ret > 0 ? "timeout" : "fail");
 #else
@@ -420,8 +465,8 @@ Eina_Bool ewk_check_chromium_ready() {
 #if BUILDFLAG(IS_TIZEN_TV)
   LOG(INFO) << "ewk_check_chromium_ready called.";
 
-  if (LwipcIsDone(kChromiumMountReady) > 0) {
-    LOG(INFO) << "chromium mount is done.";
+  if (LwipcIsDone(kChromiumUpdateOrPreloadMountReady) > 0) {
+    LOG(INFO) << "update or preload chromium mount is done.";
     return true;
   }
   LOG(ERROR) << "chromium mount is not ready yet.";