From 24d8697cef52cf7919f38061b4d06e4c1659c338 Mon Sep 17 00:00:00 2001 From: Balazs Gerofi Date: Thu, 3 Nov 2016 13:41:25 +0900 Subject: [PATCH] mcexec: workaround for overlayed /sys FS directory lseek() bug lseek() on directories under /sys filesystem that are part of an overlayed filesystem behave differently than in the original /sys. This causes segfault in libnuma when discovering topology information. The patch fakes return value as it is supposed to be, which also fixes the Intel MPI 2017 MPI_Init() crash. --- executer/user/mcexec.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 2fe80139..62a3f169 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -1686,6 +1686,40 @@ do_generic_syscall( ret = -errno; } + /* Overlayfs /sys/X directory lseek() problem work around */ + if (w->sr.number == __NR_lseek && ret == -EINVAL) { + char proc_path[512]; + char path[512]; + struct stat sb; + + sprintf(proc_path, "/proc/self/fd/%d", (int)w->sr.args[0]); + + /* Get filename */ + if (readlink(proc_path, path, sizeof(path)) < 0) { + fprintf(stderr, "%s: error: readlink() failed for %s\n", + __FUNCTION__, proc_path); + goto out; + } + + /* Not in /sys? */ + if (strncmp(path, "/sys/", 5)) + goto out; + + /* Stat */ + if (stat(path, &sb) < 0) { + fprintf(stderr, "%s: error stat() failed for %s\n", + __FUNCTION__, path); + goto out; + } + + /* Not dir? */ + if ((sb.st_mode & S_IFMT) != S_IFDIR) + goto out; + + ret = 0; + } + +out: __dprintf("do_generic_syscall(%ld):%ld (%#lx)\n", w->sr.number, ret, ret); return ret; }