Check caller pid to reject invalid request 65/62665/2 accepted/tizen/common/20160321.150450 accepted/tizen/mobile/20160321.113402 accepted/tizen/tv/20160321.113423 accepted/tizen/wearable/20160321.113442 submit/tizen/20160321.014821
authorJunghoon Park <jh9216.park@samsung.com>
Thu, 17 Mar 2016 09:19:47 +0000 (18:19 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Fri, 18 Mar 2016 01:54:29 +0000 (10:54 +0900)
- 'User' and 'System' label are only allowed

Change-Id: Id372592ed76f8373c4eeba2818ae885ef0dcf246
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
inc/launchpad_common.h
src/launchpad.c
src/launchpad_common.c

index ca63615..0cbeca1 100644 (file)
@@ -101,5 +101,6 @@ char *_get_libdir(const char *path);
 appinfo_t* _appinfo_create(bundle *kb);
 void _appinfo_free(appinfo_t *menu_info);
 char *_appinfo_get_app_path(appinfo_t *menu_info);
+int _proc_get_attr_by_pid(int pid, char *buf, int size);
 
 #endif
index 3c53dab..b2959cb 100755 (executable)
@@ -871,6 +871,22 @@ static int __dispatch_cmd_remove_loader(bundle *kb)
        return -1;
 }
 
+static int __check_caller_by_pid(int pid)
+{
+       int ret;
+       char buf[PATH_MAX] = { 0, };
+
+       ret = _proc_get_attr_by_pid(pid, buf, sizeof(buf));
+
+       if (ret < 0)
+               return -1;
+
+       if (strcmp(buf, "User") == 0 || strcmp(buf, "System") == 0)
+               return 0;
+
+       return -1;
+}
+
 static gboolean __handle_launch_event(gpointer data)
 {
        loader_context_t *lc = (loader_context_t*) data;
@@ -895,6 +911,11 @@ static gboolean __handle_launch_event(gpointer data)
                goto end;
        }
 
+       if (__check_caller_by_pid(cr.pid) < 0) {
+               _E("Invalid caller pid");
+               goto end;
+       }
+
        kb = bundle_decode(pkt->data, pkt->len);
        if (!kb) {
                _E("bundle decode error");
index 97b868f..a6fba4e 100644 (file)
@@ -641,3 +641,17 @@ char *_get_libdir(const char *path)
 
        return strdup(buf);
 }
+
+int _proc_get_attr_by_pid(int pid, char *buf, int size)
+{
+       char path[PATH_MAX] = { 0, };
+       int ret;
+
+       snprintf(path, sizeof(path), "/proc/%d/attr/current", pid);
+       ret = __read_proc(path, buf, size);
+       if (ret <= 0)
+               return -1;
+
+       return 0;
+}
+