Verify pull path in do_stat itself to fix security issue in VD. accepted/tizen/unified/20191107.140654 submit/tizen/20191107.091911
authoradhavan.m <adhavan.m@samsung.com>
Wed, 6 Nov 2019 14:45:34 +0000 (20:15 +0530)
committeradhavan.m <adhavan.m@samsung.com>
Wed, 6 Nov 2019 14:45:34 +0000 (20:15 +0530)
Signed-off-by: adhavan.m <adhavan.m@samsung.com>
src/file_sync_service.c
src/services.c

index 6ebbd0b..8ec4268 100644 (file)
@@ -164,12 +164,21 @@ static int mkdirs(int noti_fd, char *name)
     return 0;
 }
 
-static int do_stat(int s, const char *path)
+static int do_stat(int s, const char *path, const char* cmd)
 {
     syncmsg msg;
     struct stat st;
 
     msg.stat.id = ID_STAT;
+    if (cmd && !strncmp(cmd, "pull", 4)) {
+        if (!request_validity_to_plugin(PLUGIN_SYNC_CMD_VERIFY_PULL, path)) {
+            D("cannot pull files from this path.\n");
+            msg.stat.mode = 1;
+            msg.stat.size = 0;
+            msg.stat.time = 0;
+            return writex(s, &msg.stat, sizeof(msg.stat));
+        }
+    }
 
     /* follow link */
     if(stat(path, &st)) {
@@ -583,6 +592,8 @@ void file_sync_service(int fd, void *cookie)
     struct timeval timeout;
     int rv;
     int s[2];
+    char* cmd = (char*)cookie;
+    D("file_sync_service cmd: %s\n", cmd);
 
     if(sdb_socketpair(s)) {
         E("cannot create service socket pair\n");
@@ -650,7 +661,7 @@ void file_sync_service(int fd, void *cookie)
 
             switch(msg.req.id) {
             case ID_STAT:
-                if(do_stat(fd, name)) goto fail;
+                if(do_stat(fd, name, cmd)) goto fail;
                 break;
             case ID_LIST:
                 if(do_list(fd, name)) goto fail;
index d3d83ff..1a7bebd 100644 (file)
@@ -893,11 +893,11 @@ static int create_sync_subprocess(void (*func)(int, void *), void* cookie) {
     return s[0];
 }
 
-static int create_syncproc_thread()
+static int create_syncproc_thread(const char *cmd)
 {
     int ret_fd;
 
-    ret_fd = create_sync_subprocess(file_sync_service, NULL);
+    ret_fd = create_sync_subprocess(file_sync_service, cmd);
     // FIXME: file missing bug when root on mode
     /*
     if (should_drop_privileges()) {
@@ -1540,7 +1540,7 @@ int service_to_fd(const char *name)
         }
     } else if(!strncmp(name, "sync:", 5)) {
         //ret = create_service_thread(file_sync_service, NULL);
-        ret = create_syncproc_thread();
+        ret = create_syncproc_thread(name + 5);
     }/*  else if(!strncmp(name, "remount:", 8)) {
         ret = create_service_thread(remount_service, NULL);
     } else if(!strncmp(name, "reboot:", 7)) {