Procházet zdrojové kódy

[LibOS] shim_namei.c: Fix input absolute path error and add test case

This bug just occurs when reading a symlink on procfs.
If input is an absolute path, it will get wrong my_dent.
So we use stat syscall to check whether the "/proc/1/root"
and "/" is same path in graphene.

Signed-off-by: Zhang Chen <chen.zhang@intel.com>
Zhang Chen před 5 roky
rodič
revize
06b71fc1a0

+ 3 - 1
LibOS/shim/src/fs/shim_namei.c

@@ -385,10 +385,12 @@ int __path_lookupat (struct shim_dentry * start, const char * path, int flags,
                         put_dentry(my_dent);
                         my_dent = root;
                         get_dentry(my_dent);
-                    } else // Relative path, stay in this dir
+                    } else {
+                        // Relative path, stay in this dir
                         put_dentry(my_dent);
                         my_dent = start;
                         get_dentry(my_dent);
+                    }
                 }
             }
         }

+ 15 - 0
LibOS/shim/test/regression/40_proc_path.py

@@ -0,0 +1,15 @@
+#!/usr/bin/env python2
+
+import os, sys
+from regression import Regression
+
+loader = sys.argv[1]
+
+# Running Bootstrap
+regression = Regression(loader, "proc-path")
+
+regression.add_check(name="Base /proc path present",
+    check=lambda res: "proc path test success" in res[0].out)
+
+rv = regression.run_checks()
+if rv: sys.exit(rv)

+ 26 - 0
LibOS/shim/test/regression/proc-path.c

@@ -0,0 +1,26 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char ** argv)
+{
+    struct stat root, proc_root;
+
+    if (stat("/", &root) == -1) {
+        perror("stat");
+        exit(1);
+    }
+
+    if (stat("/proc/1/root", &proc_root) == -1) {
+        perror("stat");
+        exit(1);
+    }
+
+    if (root.st_dev == proc_root.st_dev &&
+        root.st_ino == proc_root.st_ino) {
+        printf("proc path test success\n");
+    } else {
+        printf("proc path test failure\n");
+    }
+}

+ 19 - 0
LibOS/shim/test/regression/proc-path.manifest.template

@@ -0,0 +1,19 @@
+loader.preload = file:../../src/libsysdb.so
+loader.env.LD_LIBRARY_PATH = /lib
+loader.debug_type = none
+loader.syscall_symbol = syscalldb
+
+fs.mount.lib.type = chroot
+fs.mount.lib.path = /lib
+fs.mount.lib.uri = file:../../../../Runtime
+
+fs.mount.bin.type = chroot
+fs.mount.bin.path = /bin
+fs.mount.bin.uri = file:/bin
+
+sys.brk.size = 32M
+sys.stack.size = 4M
+
+# sgx-related
+sgx.trusted_files.ld = file:../../../../Runtime/ld-linux-x86-64.so.2
+sgx.trusted_files.libc = file:../../../../Runtime/libc.so.6