xpmem: Add xpmem_openat

In arm64, glibc-open of /dev/xpmem is hooked in sys_openat. This
commit adds xpmem_openat which is called by sys_openat.
This commit silently applies copy_from_user fix to sys_open as well.

Change-Id: I3b4f7bf0e152c359250bb2b56910db9192390cb1
Fujitsu: POSTK_DEBUG_ARCH_DEP_46, POSTK_DEBUG_ARCH_DEP_62
This commit is contained in:
Masamichi Takagi
2018-10-26 15:51:53 +09:00
committed by Dominique Martinet
parent e12d5ed341
commit 04c11f35e9
6 changed files with 83 additions and 110 deletions

View File

@@ -3486,66 +3486,67 @@ SYSCALL_DECLARE(ioctl)
SYSCALL_DECLARE(open)
{
const char *pathname = (const char *)ihk_mc_syscall_arg0(ctx);
const char *_pathname = (const char *)ihk_mc_syscall_arg0(ctx);
int flags = (int)ihk_mc_syscall_arg1(ctx);
int len;
char *xpmem_wk;
char *pathname;
long rc;
len = strlen_user(pathname);
len = strlen_user(_pathname);
if (len < 0)
return len;
if (!(xpmem_wk = kmalloc(len + 1, IHK_MC_AP_NOWAIT)))
return -ENOMEM;
if (copy_from_user(xpmem_wk, pathname, len + 1)) {
kfree(xpmem_wk);
return -EFAULT;
}
dkprintf("open(): pathname=%s\n", xpmem_wk);
rc = strcmp(xpmem_wk, XPMEM_DEV_PATH);
#ifdef POSTK_DEBUG_ARCH_DEP_62 /* Absorb the difference between open and openat args. */
if (!rc) {
rc = xpmem_open(__NR_open, xpmem_wk, (int)ihk_mc_syscall_arg1(ctx), ctx);
}
else {
rc = syscall_generic_forwarding(__NR_open, ctx);
}
kfree(xpmem_wk);
#else /* POSTK_DEBUG_ARCH_DEP_62 */
kfree(xpmem_wk);
if (!rc) {
rc = xpmem_open(ctx);
}
else {
rc = syscall_generic_forwarding(__NR_open, ctx);
}
#endif /* POSTK_DEBUG_ARCH_DEP_62 */
return rc;
}
#ifdef POSTK_DEBUG_ARCH_DEP_62 /* Absorb the difference between open and openat args. */
SYSCALL_DECLARE(openat)
{
const char *pathname_user = (const char *)ihk_mc_syscall_arg1(ctx);
int flags = (int)ihk_mc_syscall_arg2(ctx);
char *pathname;
int len = strlen_user(pathname_user) + 1;
long rc;
len++;
pathname = kmalloc(len, IHK_MC_AP_NOWAIT);
if (!pathname) {
dkprintf("%s: error allocating pathname\n", __FUNCTION__);
dkprintf("%s: error allocating pathname\n", __func__);
return -ENOMEM;
}
if (copy_from_user(pathname, pathname_user, len)) {
dkprintf("%s: error: copy_from_user pathname\n", __FUNCTION__);
if (copy_from_user(pathname, _pathname, len)) {
dkprintf("%s: error: copy_from_user pathname\n", __func__);
rc = -EFAULT;
goto out;
}
dkprintf("open(): pathname=%s\n", pathname);
if (!strncmp(pathname, XPMEM_DEV_PATH, len)) {
rc = xpmem_open(pathname, flags, ctx);
} else {
rc = syscall_generic_forwarding(__NR_open, ctx);
}
out:
kfree(pathname);
return rc;
}
SYSCALL_DECLARE(openat)
{
const char *_pathname = (const char *)ihk_mc_syscall_arg1(ctx);
int flags = (int)ihk_mc_syscall_arg2(ctx);
char *pathname;
int len;
long rc;
len = strlen_user(_pathname);
if (len < 0)
return len;
len++;
pathname = kmalloc(len, IHK_MC_AP_NOWAIT);
if (!pathname) {
dkprintf("%s: error allocating pathname\n", __func__);
return -ENOMEM;
}
if (copy_from_user(pathname, _pathname, len)) {
dkprintf("%s: error: copy_from_user pathname\n", __func__);
rc = -EFAULT;
goto out;
}
dkprintf("openat(): pathname=%s\n", pathname);
if (!strcmp(pathname, XPMEM_DEV_PATH)) {
rc = xpmem_open(__NR_openat, pathname, flags, ctx);
if (!strncmp(pathname, XPMEM_DEV_PATH, len)) {
rc = xpmem_openat(pathname, flags, ctx);
} else {
rc = syscall_generic_forwarding(__NR_openat, ctx);
}
@@ -3554,7 +3555,6 @@ out:
kfree(pathname);
return rc;
}
#endif /* POSTK_DEBUG_ARCH_DEP_62 */
SYSCALL_DECLARE(close)
{