Change mount namespace 20/270520/2
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 4 Feb 2022 04:56:38 +0000 (13:56 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 4 Feb 2022 05:21:01 +0000 (14:21 +0900)
When executing the debug tool process, the child process has to change
the mount namespace to the mount namespace of the target process if the
option is 'attach'.

Change-Id: I9db343a70f614d18d291018ecab04a4db2b8fec0
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad-process-pool/inc/launchpad_debug.h
src/launchpad-process-pool/src/launchpad.c
src/launchpad-process-pool/src/launchpad_debug.c

index a866270f1d982507b261c679ddeb2acfc3e63fe4..169790054c6ea81e7afb37269c2ac3d59e6f978b 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdbool.h>
 #include <bundle.h>
 
+int _debug_change_mount_namespace(void);
 int _debug_create_extra_argv(int *arg, char ***argv);
 int _debug_create_argv(int *argc, char ***argv, bool *attach);
 void _debug_destroy_argv(int argc, char **argv);
index c2690061e2432d5fb544b84f7f97d8f4db662ecb..b4907f01902de7e5fd1b5417c65b16e79a08e902 100644 (file)
@@ -1263,6 +1263,9 @@ static int __prepare_exec(const char *appid, const char *app_path,
        if (ret < 0)
                return PAD_ERR_FAILED;
 
+       if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE)
+               _debug_change_mount_namespace();
+
        /* SET PRIVILEGES*/
        _W("security_manager_prepare_app ++");
        ret = security_manager_prepare_app(appid);
index 37934e0297c3327a2fd16296b8ae9ad6a2534bb1..8040f452ce2be3c2e246d555f3d6aa7cd83c7d72 100644 (file)
@@ -23,6 +23,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <bundle_internal.h>
+#include <ctype.h>
 
 #include "debugger_info.h"
 #include "key.h"
@@ -38,6 +39,32 @@ static debugger_info_h __debugger_info;
 static GList *__debug_argv_list;
 static GList *__extra_argv_list;
 
+int _debug_change_mount_namespace(void)
+{
+       const char *pid_str;
+       char buf[PATH_MAX];
+       int ret;
+       int fd;
+
+       pid_str = getenv("TARGET_PID");
+       if (pid_str == NULL)
+               return 0;
+
+       snprintf(buf, sizeof(buf), "/proc/%s/ns/mnt", pid_str);
+       fd = open(buf, O_RDONLY);
+       if (fd < 0) {
+               _E("open() is failed. path(%s), errno(%d)", buf, errno);
+               return -1;
+       }
+
+       ret = setns(fd, CLONE_NEWNS);
+       close(fd);
+       if (ret != 0)
+               _E("setns() is failed. errno(%d)", errno);
+
+       return ret;
+}
+
 int _debug_create_extra_argv(int *argc, char ***argv)
 {
        int new_argc;
@@ -296,6 +323,12 @@ static void __add_debug_argv(gpointer data, gpointer user_data)
 
                __debug_argv_list = g_list_append(__debug_argv_list,
                                strdup(str_arr[i]));
+               if (!strcmp(key, "__DLP_ATTACH_ARG__")) {
+                       if (isdigit(str_arr[i][0])) {
+                               _D("Target PID: %s", str_arr[i]);
+                               setenv("TARGET_PID", str_arr[i], 1);
+                       }
+               }
        }
 
        if (str_arr)