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

@ -7,11 +7,7 @@ SYSCALL_DELEGATED(25, fcntl)
SYSCALL_HANDLED(29, ioctl)
SYSCALL_DELEGATED(43, statfs)
SYSCALL_DELEGATED(44, fstatfs)
#ifdef POSTK_DEBUG_ARCH_DEP_62 /* Absorb the difference between open and openat args. */
SYSCALL_HANDLED(56, openat)
#else /* POSTK_DEBUG_ARCH_DEP_62 */
SYSCALL_DELEGATED(56, openat)
#endif /* POSTK_DEBUG_ARCH_DEP_62 */
SYSCALL_HANDLED(57, close)
SYSCALL_DELEGATED(61, getdents64)
SYSCALL_DELEGATED(62, lseek)

View File

@ -133,9 +133,7 @@ SYSCALL_HANDLED(238, set_mempolicy)
SYSCALL_HANDLED(239, get_mempolicy)
SYSCALL_HANDLED(247, waitid)
SYSCALL_HANDLED(256, migrate_pages)
#ifdef POSTK_DEBUG_ARCH_DEP_62 /* Absorb the difference between open and openat args. */
SYSCALL_HANDLED(257, openat)
#endif /* POSTK_DEBUG_ARCH_DEP_62 */
SYSCALL_DELEGATED(270, pselect6)
SYSCALL_DELEGATED(271, ppoll)
SYSCALL_HANDLED(273, set_robust_list)

View File

@ -19,14 +19,13 @@
#define XPMEM_DEV_PATH "/dev/xpmem"
#if defined(POSTK_DEBUG_ARCH_DEP_46) || defined(POSTK_DEBUG_ARCH_DEP_62)
extern int xpmem_open(int, const char*, int, ihk_mc_user_context_t *ctx);
#else /* POSTK_DEBUG_ARCH_DEP_46 || POSTK_DEBUG_ARCH_DEP_62 */
extern int xpmem_open(ihk_mc_user_context_t *ctx);
#endif /* POSTK_DEBUG_ARCH_DEP_46 || POSTK_DEBUG_ARCH_DEP_62 */
extern int xpmem_remove_process_memory_range(struct process_vm *vm,
int xpmem_open(const char *pathname,
int flags, ihk_mc_user_context_t *ctx);
int xpmem_openat(const char *pathname,
int flags, ihk_mc_user_context_t *ctx);
int xpmem_remove_process_memory_range(struct process_vm *vm,
struct vm_range *vmr);
extern int xpmem_fault_process_memory_range(struct process_vm *vm,
int xpmem_fault_process_memory_range(struct process_vm *vm,
struct vm_range *vmr, unsigned long vaddr, uint64_t reason);
#endif /* _XPMEM_H */

View File

@ -306,7 +306,7 @@ static void xpmem_unpin_pages(struct xpmem_segment *, struct process_vm *,
unsigned long, size_t);
static struct xpmem_thread_group *__xpmem_tg_ref_by_tgid_nolock_internal(
pid_t, int, int);
pid_t tgid, int index, int return_destroying);
static inline struct xpmem_thread_group *__xpmem_tg_ref_by_tgid(
pid_t tgid,
@ -357,14 +357,14 @@ static inline struct xpmem_thread_group *__xpmem_tg_ref_by_tgid_nolock(
static struct xpmem_thread_group *xpmem_tg_ref_by_segid(xpmem_segid_t);
static struct xpmem_thread_group *xpmem_tg_ref_by_apid(xpmem_apid_t);
static void xpmem_tg_deref(struct xpmem_thread_group *);
static void xpmem_tg_deref(struct xpmem_thread_group *tg);
static struct xpmem_segment *xpmem_seg_ref_by_segid(struct xpmem_thread_group *,
xpmem_segid_t);
static void xpmem_seg_deref(struct xpmem_segment *);
static void xpmem_seg_deref(struct xpmem_segment *seg);
static struct xpmem_access_permit * xpmem_ap_ref_by_apid(
struct xpmem_thread_group *, xpmem_apid_t);
static void xpmem_ap_deref(struct xpmem_access_permit *);
static void xpmem_att_deref(struct xpmem_attachment *);
struct xpmem_thread_group *ap_tg, xpmem_apid_t apid);
static void xpmem_ap_deref(struct xpmem_access_permit *ap);
static void xpmem_att_deref(struct xpmem_attachment *att);
static int xpmem_validate_access(struct xpmem_access_permit *, off_t, size_t,
int, unsigned long *);

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)
{

View File

@ -36,9 +36,7 @@
struct xpmem_partition *xpmem_my_part = NULL; /* pointer to this partition */
#if defined(POSTK_DEBUG_ARCH_DEP_46) || defined(POSTK_DEBUG_ARCH_DEP_62)
int xpmem_open(int num, const char *pathname,
static int do_xpmem_open(int syscall_num, const char *pathname,
int flags, ihk_mc_user_context_t *ctx)
{
int ret;
@ -48,23 +46,8 @@ int xpmem_open(int num, const char *pathname,
struct mckfd *mckfd;
long irqstate;
XPMEM_DEBUG("call: syscall_num=%d, pathname=%s, flags=%d", num, pathname, flags);
#else /* POSTK_DEBUG_ARCH_DEP_46 || POSTK_DEBUG_ARCH_DEP_62 */
int xpmem_open(
ihk_mc_user_context_t *ctx)
{
const char *pathname = (const char *)ihk_mc_syscall_arg0(ctx);
int flags = (int)ihk_mc_syscall_arg1(ctx);
int ret;
struct thread *thread = cpu_local_var(current);
struct process *proc = thread->proc;
struct syscall_request request IHK_DMA_ALIGN;
int fd;
struct mckfd *mckfd;
long irqstate;
XPMEM_DEBUG("call: pathname=%s, flags=%d", pathname, flags);
#endif /* POSTK_DEBUG_ARCH_DEP_46 || POSTK_DEBUG_ARCH_DEP_62 */
XPMEM_DEBUG("call: syscall_num=%d, pathname=%s, flags=%d",
syscall_num, pathname, flags);
if (!xpmem_my_part) {
ret = xpmem_init();
@ -73,22 +56,11 @@ int xpmem_open(
}
}
#ifdef POSTK_DEBUG_ARCH_DEP_62 /* Absorb the difference between open and openat args. */
fd = syscall_generic_forwarding(num, ctx);
fd = syscall_generic_forwarding(syscall_num, ctx);
if(fd < 0){
XPMEM_DEBUG("syscall_num=%d error: fd=%d", num, fd);
XPMEM_DEBUG("syscall_num=%d error: fd=%d", syscall_num, fd);
return fd;
}
#else /* POSTK_DEBUG_ARCH_DEP_62 */
request.number = __NR_open;
request.args[0] = (unsigned long)pathname;
request.args[1] = flags;
fd = do_syscall(&request, ihk_mc_get_processor_id());
if (fd < 0) {
XPMEM_DEBUG("__NR_open error: fd=%d", fd);
return fd;
}
#endif /* POSTK_DEBUG_ARCH_DEP_62 */
ret = __xpmem_open();
if (ret) {
@ -129,6 +101,17 @@ int xpmem_open(
return mckfd->fd;
}
int xpmem_open(const char *pathname,
int flags, ihk_mc_user_context_t *ctx)
{
return do_xpmem_open(__NR_open, pathname, flags, ctx);
}
int xpmem_openat(const char *pathname,
int flags, ihk_mc_user_context_t *ctx)
{
return do_xpmem_open(__NR_openat, pathname, flags, ctx);
}
static int xpmem_ioctl(
struct mckfd *mckfd,
@ -2215,8 +2198,7 @@ static struct xpmem_segment * xpmem_seg_ref_by_segid(
}
static void xpmem_seg_deref(
struct xpmem_segment *seg)
static void xpmem_seg_deref(struct xpmem_segment *seg)
{
DBUG_ON(ihk_atomic_read(&seg->refcnt) <= 0);
if (ihk_atomic_dec_return(&seg->refcnt) != 0) {
@ -2262,8 +2244,7 @@ static struct xpmem_access_permit * xpmem_ap_ref_by_apid(
}
static void xpmem_ap_deref(
struct xpmem_access_permit *ap)
static void xpmem_ap_deref(struct xpmem_access_permit *ap)
{
DBUG_ON(ihk_atomic_read(&ap->refcnt) <= 0);
if (ihk_atomic_dec_return(&ap->refcnt) != 0) {
@ -2278,8 +2259,7 @@ static void xpmem_ap_deref(
}
static void xpmem_att_deref(
struct xpmem_attachment *att)
static void xpmem_att_deref(struct xpmem_attachment *att)
{
DBUG_ON(ihk_atomic_read(&att->refcnt) <= 0);
if (ihk_atomic_dec_return(&att->refcnt) != 0) {