Modify AppControl Checker 04/313104/2
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 19 Jun 2024 05:36:10 +0000 (14:36 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Thu, 27 Jun 2024 06:03:42 +0000 (06:03 +0000)
If the target application is a robot app, amd checks whether the caller
is the srp-app-launcher or not. If it's not, the launch request will be
rejected.

Change-Id: I8848f88ec46269da7d99ffd0cf501a79173531cd
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_launch.cc

index 591a67242cb7f87504850ca4d228effc3e6a8236..ae6cea7ee68270d8020bdcf9ac1b3702c8c51f00 100644 (file)
@@ -20,6 +20,7 @@
 #include <aul_cmd.h>
 #include <aul_svc.h>
 #include <aul_sock.h>
+#include <aul_proc.h>
 #include <aul_svc_priv_key.h>
 #include <bundle_internal.h>
 #include <pkgmgr-info.h>
@@ -54,6 +55,7 @@ constexpr const char APPID_WIDGET_VIEWER_SDK[] = "org.tizen.widget_viewer_sdk";
 constexpr const char PRIVILEGE_APPDEBUGGING[] =
     "http://tizen.org/privilege/internal/appdebugging";
 constexpr const unsigned int PENDING_REQUEST_TIMEOUT = 30000;  // msec
+constexpr const char kPathSrpAppLauncher[] = "/usr/bin/srp-app-launcher";
 
 class CheckerInfo {
  public:
@@ -1126,6 +1128,37 @@ static request_cmd_dispatch dispatch_table[] = {
   },
 };
 
+static bool IsSrpAppLauncher(pid_t pid, uid_t uid) {
+  if (uid >= REGULAR_UID_MIN) return false;
+
+  char buf[PATH_MAX];
+  int ret = aul_proc_get_cmdline(pid, buf, sizeof(buf));
+  if (ret != AUL_R_OK) {
+    _E("aul_proc_get_cmdline() is failed. pid=%d", pid);
+    return false;
+  }
+
+  _D("cmdline=%s", buf);
+  return std::string(buf) == kPathSrpAppLauncher;
+}
+
+static bool IsRobotApp(const std::shared_ptr<tizen_base::Bundle>& b,
+                       uid_t uid) {
+  auto appid = b->GetString(AUL_K_APPID);
+  if (appid.empty()) return false;
+
+  auto app_info = amd::AppInfoManager::GetInst().FindAppInfo(uid, appid);
+  if (app_info == nullptr) return false;
+
+  if (app_info->GetComponentType() == APP_TYPE_ROBOT) {
+    _W("The target application is a robot app");
+    return true;
+  }
+
+  _W("component_type: %s", app_info->GetComponentType().c_str());
+  return false;
+}
+
 static int CynaraAppControlChecker(caller_info_h info, request_h request,
     void* user_data) {
   auto* req = static_cast<amd::Request*>(request);
@@ -1133,6 +1166,13 @@ static int CynaraAppControlChecker(caller_info_h info, request_h request,
   if (b == nullptr)
     return AMD_CYNARA_ALLOWED;
 
+  if (IsRobotApp(b, req->GetTargetUID())) {
+    if (!IsSrpAppLauncher(req->GetPID(), req->GetUID())) {
+      _E("Caller must be srp-app-launcher");
+      return AMD_CYNARA_DENIED;
+    }
+  }
+
   int ret = CheckAppDebuggingPrivilege(request);
   if (ret != AMD_CYNARA_CONTINUE)
     return ret;