[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>
This commit is contained in:
Zhang Chen
2019-04-04 08:29:41 -04:00
committed by Don Porter
parent 5cd91c596c
commit 06b71fc1a0
4 changed files with 63 additions and 1 deletions
+3 -1
View File
@@ -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);
}
}
}
}
@@ -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
View File
@@ -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");
}
}
@@ -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