[WRTjs] Block new thread creation while prepare app 17/290117/5 submit/tizen/20230323.160013
authorDongHyun Song <dh81.song@samsung.com>
Mon, 20 Mar 2023 07:52:21 +0000 (16:52 +0900)
committerBot Blink <blinkbot@samsung.com>
Thu, 23 Mar 2023 08:49:09 +0000 (08:49 +0000)
While handles security_manager_prepare_app(), if new thread is
spawned by ThreadPoolService. Then smack error is happened from
security_manager_prepare_app(), which validates smack labeling of
threads because the spawned new thread has still System::Privileged.

PlatformThread::BlockThreading() will block CreateThread() until
security_manager_prepare_app() done.

This is alternative solution of self smack labeling, which is deleted
from m108.

Change-Id: Idfefe542904c7fbed89ee6ae0b98b6dede28a052
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
base/threading/platform_thread.h
base/threading/platform_thread_posix.cc
wrt/src/app/tv/wrt_main_delegate_tv.cc
wrt/src/app/wrt_content_main.cc

index e5699c0..1d49588 100644 (file)
@@ -253,6 +253,11 @@ class BASE_EXPORT PlatformThread {
   // Returns a realtime period provided by `delegate`.
   static TimeDelta GetRealtimePeriod(Delegate* delegate);
 
+#if defined(ENABLE_WRT_JS)
+  static void BlockThreading();
+  static void UnblockThreading();
+#endif
+
 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
   // Toggles a specific thread's type at runtime. This can be used to
   // change the priority of a thread in a different process and will fail
index 9a17c29..7b9361c 100644 (file)
@@ -115,12 +115,19 @@ void* ThreadFunc(void* params) {
   return nullptr;
 }
 
+#if defined(ENABLE_WRT_JS)
+base::Lock threading_lock;
+#endif
+
 bool CreateThread(size_t stack_size,
                   bool joinable,
                   PlatformThread::Delegate* delegate,
                   PlatformThreadHandle* thread_handle,
                   ThreadType thread_type,
                   MessagePumpType message_pump_type) {
+#if defined(ENABLE_WRT_JS)
+  base::AutoLock lock(threading_lock);
+#endif
   DCHECK(thread_handle);
   base::InitThreading();
 
@@ -353,6 +360,23 @@ void PlatformThread::Detach(PlatformThreadHandle thread_handle) {
   CHECK_EQ(0, pthread_detach(thread_handle.platform_handle()));
 }
 
+#if defined(ENABLE_WRT_JS)
+static bool is_acquired = false;
+
+// static
+void PlatformThread::BlockThreading() {
+  threading_lock.Acquire();
+  is_acquired = true;
+}
+
+// static
+void PlatformThread::UnblockThreading() {
+  if (is_acquired)
+    threading_lock.Release();
+  is_acquired = false;
+}
+#endif
+
 // Mac and Fuchsia have their own SetCurrentThreadType() and
 // GetCurrentThreadPriorityForTest() implementations.
 #if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_FUCHSIA)
index 34dddf9..5afd748 100644 (file)
@@ -12,7 +12,6 @@
 #include <tzplatform_config.h>
 
 #include "base/logging.h"
-#include "base/threading/thread_id_name_manager.h"
 #include "content/common/zygote/zygote_communication_linux.h"
 #include "content/public/common/zygote/zygote_handle.h"
 #include "tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.h"
index cf7f7ad..16923ce 100644 (file)
@@ -9,6 +9,7 @@
 #include "base/command_line.h"
 #include "base/files/file_util.h"
 #include "base/logging.h"
+#include "base/threading/platform_thread.h"
 #include "content/public/app/content_main.h"
 #include "content/public/app/content_main_runner.h"
 #include "content/public/common/content_switches.h"
@@ -69,6 +70,7 @@ class WRTContentMain::Loader {
                             const char* appid, const char* pkgid,
                             const char* pkg_type, void* user_data) {
       LOG(INFO) << "loader prelaunch";
+      base::PlatformThread::BlockThreading();
       auto* content_main = static_cast<Loader*>(user_data)->content_main_;
       content_main->PrelaunchOnLoader(app_path, pkgid);
       return 0;
@@ -78,6 +80,7 @@ class WRTContentMain::Loader {
                          const char* appid, const char* pkgid,
                          const char* pkg_type, void* user_data) {
       LOG(INFO) << "loader launch";
+      base::PlatformThread::UnblockThreading();
       return 0;
     };
     callback.terminate = [](int argc, char** argv, void* user_data) {