From 06b71fc1a0cfea1baa7a331c7850d09f5cd572dc Mon Sep 17 00:00:00 2001 From: Zhang Chen Date: Mon, 18 Feb 2019 00:24:38 +0800 Subject: [PATCH] [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 --- LibOS/shim/src/fs/shim_namei.c | 4 ++- LibOS/shim/test/regression/40_proc_path.py | 15 +++++++++++ LibOS/shim/test/regression/proc-path.c | 26 +++++++++++++++++++ .../regression/proc-path.manifest.template | 19 ++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 LibOS/shim/test/regression/40_proc_path.py create mode 100644 LibOS/shim/test/regression/proc-path.c create mode 100644 LibOS/shim/test/regression/proc-path.manifest.template diff --git a/LibOS/shim/src/fs/shim_namei.c b/LibOS/shim/src/fs/shim_namei.c index 8c4aac13..de9be8e0 100644 --- a/LibOS/shim/src/fs/shim_namei.c +++ b/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); + } } } } diff --git a/LibOS/shim/test/regression/40_proc_path.py b/LibOS/shim/test/regression/40_proc_path.py new file mode 100644 index 00000000..aad3bfd0 --- /dev/null +++ b/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) diff --git a/LibOS/shim/test/regression/proc-path.c b/LibOS/shim/test/regression/proc-path.c new file mode 100644 index 00000000..c0daeea8 --- /dev/null +++ b/LibOS/shim/test/regression/proc-path.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +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"); + } +} diff --git a/LibOS/shim/test/regression/proc-path.manifest.template b/LibOS/shim/test/regression/proc-path.manifest.template new file mode 100644 index 00000000..a7ff69a1 --- /dev/null +++ b/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