2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* 32 bit compatibility code for System V IPC
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
|
|
|
|
* Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
|
|
|
|
* Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
|
|
|
|
* Copyright (C) 2000 VA Linux Co
|
|
|
|
* Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
|
|
|
|
* Copyright (C) 2000 Hewlett-Packard Co.
|
|
|
|
* Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
|
|
|
|
* Copyright (C) 2000 Gerhard Tonn (ton@de.ibm.com)
|
|
|
|
* Copyright (C) 2000-2002 Andi Kleen, SuSE Labs (x86-64 port)
|
|
|
|
* Copyright (C) 2000 Silicon Graphics, Inc.
|
|
|
|
* Copyright (C) 2001 IBM
|
|
|
|
* Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation
|
|
|
|
* Copyright (C) 2004 Arnd Bergmann (arnd@arndb.de)
|
|
|
|
*
|
|
|
|
* This code is collected from the versions for sparc64, mips64, s390x, ia64,
|
|
|
|
* ppc64 and x86_64, all of which are based on the original sparc64 version
|
|
|
|
* by Jakub Jelinek.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/compat.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/highuid.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/msg.h>
|
|
|
|
#include <linux/shm.h>
|
|
|
|
#include <linux/syscalls.h>
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
#include <linux/ptrace.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-03-26 13:37:17 +04:00
|
|
|
#include <linux/mutex.h>
|
2014-06-07 01:37:37 +04:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
struct compat_msgbuf {
|
|
|
|
compat_long_t mtype;
|
|
|
|
char mtext[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_semid_ds {
|
|
|
|
struct compat_ipc_perm sem_perm;
|
|
|
|
compat_time_t sem_otime;
|
|
|
|
compat_time_t sem_ctime;
|
|
|
|
compat_uptr_t sem_base;
|
|
|
|
compat_uptr_t sem_pending;
|
|
|
|
compat_uptr_t sem_pending_last;
|
|
|
|
compat_uptr_t undo;
|
|
|
|
unsigned short sem_nsems;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_ipc_kludge {
|
|
|
|
compat_uptr_t msgp;
|
|
|
|
compat_long_t msgtyp;
|
|
|
|
};
|
|
|
|
|
2017-07-09 05:52:47 +03:00
|
|
|
static inline int __compat_ipc_parse_version(int *cmd)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2012-07-31 01:42:46 +04:00
|
|
|
#ifdef CONFIG_ARCH_WANT_COMPAT_IPC_PARSE_VERSION
|
2005-04-17 02:20:36 +04:00
|
|
|
int version = *cmd & IPC_64;
|
|
|
|
|
|
|
|
/* this is tricky: architectures that have support for the old
|
|
|
|
* ipc structures in 64 bit binaries need to have IPC_64 set
|
|
|
|
* in cmd, the others need to have it cleared */
|
|
|
|
#ifndef ipc_parse_version
|
|
|
|
*cmd |= IPC_64;
|
|
|
|
#else
|
|
|
|
*cmd &= ~IPC_64;
|
|
|
|
#endif
|
|
|
|
return version;
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
#else
|
|
|
|
/* With the asm-generic APIs, we always use the 64-bit versions. */
|
|
|
|
return IPC_64;
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __get_compat_ipc64_perm(struct ipc64_perm *p64,
|
|
|
|
struct compat_ipc64_perm __user *up64)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = __get_user(p64->uid, &up64->uid);
|
|
|
|
err |= __get_user(p64->gid, &up64->gid);
|
|
|
|
err |= __get_user(p64->mode, &up64->mode);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __get_compat_ipc_perm(struct ipc64_perm *p,
|
|
|
|
struct compat_ipc_perm __user *up)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = __get_user(p->uid, &up->uid);
|
|
|
|
err |= __get_user(p->gid, &up->gid);
|
|
|
|
err |= __get_user(p->mode, &up->mode);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __put_compat_ipc64_perm(struct ipc64_perm *p64,
|
|
|
|
struct compat_ipc64_perm __user *up64)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = __put_user(p64->key, &up64->key);
|
|
|
|
err |= __put_user(p64->uid, &up64->uid);
|
|
|
|
err |= __put_user(p64->gid, &up64->gid);
|
|
|
|
err |= __put_user(p64->cuid, &up64->cuid);
|
|
|
|
err |= __put_user(p64->cgid, &up64->cgid);
|
|
|
|
err |= __put_user(p64->mode, &up64->mode);
|
|
|
|
err |= __put_user(p64->seq, &up64->seq);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __put_compat_ipc_perm(struct ipc64_perm *p,
|
2014-10-14 02:54:16 +04:00
|
|
|
struct compat_ipc_perm __user *uip)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int err;
|
2005-09-07 02:16:40 +04:00
|
|
|
__compat_uid_t u;
|
|
|
|
__compat_gid_t g;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-10-14 02:54:16 +04:00
|
|
|
err = __put_user(p->key, &uip->key);
|
2005-04-17 02:20:36 +04:00
|
|
|
SET_UID(u, p->uid);
|
2014-10-14 02:54:16 +04:00
|
|
|
err |= __put_user(u, &uip->uid);
|
2005-04-17 02:20:36 +04:00
|
|
|
SET_GID(g, p->gid);
|
2014-10-14 02:54:16 +04:00
|
|
|
err |= __put_user(g, &uip->gid);
|
2005-04-17 02:20:36 +04:00
|
|
|
SET_UID(u, p->cuid);
|
2014-10-14 02:54:16 +04:00
|
|
|
err |= __put_user(u, &uip->cuid);
|
2005-04-17 02:20:36 +04:00
|
|
|
SET_GID(g, p->cgid);
|
2014-10-14 02:54:16 +04:00
|
|
|
err |= __put_user(g, &uip->cgid);
|
|
|
|
err |= __put_user(p->mode, &uip->mode);
|
|
|
|
err |= __put_user(p->seq, &uip->seq);
|
2005-04-17 02:20:36 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-10-14 02:54:16 +04:00
|
|
|
static inline int get_compat_semid64_ds(struct semid64_ds *sem64,
|
2005-04-17 02:20:36 +04:00
|
|
|
struct compat_semid64_ds __user *up64)
|
|
|
|
{
|
2014-01-28 05:07:04 +04:00
|
|
|
if (!access_ok(VERIFY_READ, up64, sizeof(*up64)))
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EFAULT;
|
2014-10-14 02:54:16 +04:00
|
|
|
return __get_compat_ipc64_perm(&sem64->sem_perm, &up64->sem_perm);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int get_compat_semid_ds(struct semid64_ds *s,
|
|
|
|
struct compat_semid_ds __user *up)
|
|
|
|
{
|
2014-01-28 05:07:04 +04:00
|
|
|
if (!access_ok(VERIFY_READ, up, sizeof(*up)))
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EFAULT;
|
|
|
|
return __get_compat_ipc_perm(&s->sem_perm, &up->sem_perm);
|
|
|
|
}
|
|
|
|
|
2014-10-14 02:54:16 +04:00
|
|
|
static inline int put_compat_semid64_ds(struct semid64_ds *sem64,
|
2005-04-17 02:20:36 +04:00
|
|
|
struct compat_semid64_ds __user *up64)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2014-01-28 05:07:04 +04:00
|
|
|
if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64)))
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EFAULT;
|
2014-10-14 02:54:16 +04:00
|
|
|
err = __put_compat_ipc64_perm(&sem64->sem_perm, &up64->sem_perm);
|
|
|
|
err |= __put_user(sem64->sem_otime, &up64->sem_otime);
|
|
|
|
err |= __put_user(sem64->sem_ctime, &up64->sem_ctime);
|
|
|
|
err |= __put_user(sem64->sem_nsems, &up64->sem_nsems);
|
2005-04-17 02:20:36 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int put_compat_semid_ds(struct semid64_ds *s,
|
|
|
|
struct compat_semid_ds __user *up)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2014-01-28 05:07:04 +04:00
|
|
|
if (!access_ok(VERIFY_WRITE, up, sizeof(*up)))
|
2007-07-06 13:39:53 +04:00
|
|
|
return -EFAULT;
|
2005-04-17 02:20:36 +04:00
|
|
|
err = __put_compat_ipc_perm(&s->sem_perm, &up->sem_perm);
|
|
|
|
err |= __put_user(s->sem_otime, &up->sem_otime);
|
|
|
|
err |= __put_user(s->sem_ctime, &up->sem_ctime);
|
|
|
|
err |= __put_user(s->sem_nsems, &up->sem_nsems);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
static long do_compat_semctl(int first, int second, int third, u32 pad)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2013-03-06 00:04:55 +04:00
|
|
|
unsigned long fourth;
|
2005-04-17 02:20:36 +04:00
|
|
|
int err, err2;
|
2014-10-14 02:54:16 +04:00
|
|
|
struct semid64_ds sem64;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct semid64_ds __user *up64;
|
2017-07-09 05:52:47 +03:00
|
|
|
int version = __compat_ipc_parse_version(&third);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-10-14 02:54:16 +04:00
|
|
|
memset(&sem64, 0, sizeof(sem64));
|
2010-10-28 02:34:17 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if ((third & (~IPC_64)) == SETVAL)
|
2013-03-06 00:04:55 +04:00
|
|
|
#ifdef __BIG_ENDIAN
|
|
|
|
fourth = (unsigned long)pad << 32;
|
|
|
|
#else
|
|
|
|
fourth = pad;
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
else
|
2013-03-06 00:04:55 +04:00
|
|
|
fourth = (unsigned long)compat_ptr(pad);
|
2005-04-17 02:20:36 +04:00
|
|
|
switch (third & (~IPC_64)) {
|
|
|
|
case IPC_INFO:
|
|
|
|
case IPC_RMID:
|
|
|
|
case SEM_INFO:
|
|
|
|
case GETVAL:
|
|
|
|
case GETPID:
|
|
|
|
case GETNCNT:
|
|
|
|
case GETZCNT:
|
|
|
|
case GETALL:
|
|
|
|
case SETVAL:
|
|
|
|
case SETALL:
|
|
|
|
err = sys_semctl(first, second, third, fourth);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IPC_STAT:
|
|
|
|
case SEM_STAT:
|
2014-10-14 02:54:16 +04:00
|
|
|
up64 = compat_alloc_user_space(sizeof(sem64));
|
2013-03-06 00:04:55 +04:00
|
|
|
fourth = (unsigned long)up64;
|
2005-04-17 02:20:36 +04:00
|
|
|
err = sys_semctl(first, second, third, fourth);
|
|
|
|
if (err < 0)
|
|
|
|
break;
|
2014-10-14 02:54:16 +04:00
|
|
|
if (copy_from_user(&sem64, up64, sizeof(sem64)))
|
2005-04-17 02:20:36 +04:00
|
|
|
err2 = -EFAULT;
|
|
|
|
else if (version == IPC_64)
|
2014-10-14 02:54:16 +04:00
|
|
|
err2 = put_compat_semid64_ds(&sem64, compat_ptr(pad));
|
2005-04-17 02:20:36 +04:00
|
|
|
else
|
2014-10-14 02:54:16 +04:00
|
|
|
err2 = put_compat_semid_ds(&sem64, compat_ptr(pad));
|
2005-04-17 02:20:36 +04:00
|
|
|
if (err2)
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IPC_SET:
|
2014-01-28 05:07:06 +04:00
|
|
|
if (version == IPC_64)
|
2014-10-14 02:54:16 +04:00
|
|
|
err = get_compat_semid64_ds(&sem64, compat_ptr(pad));
|
2014-01-28 05:07:06 +04:00
|
|
|
else
|
2014-10-14 02:54:16 +04:00
|
|
|
err = get_compat_semid_ds(&sem64, compat_ptr(pad));
|
2014-01-28 05:07:06 +04:00
|
|
|
|
2014-10-14 02:54:16 +04:00
|
|
|
up64 = compat_alloc_user_space(sizeof(sem64));
|
|
|
|
if (copy_to_user(up64, &sem64, sizeof(sem64)))
|
2005-04-17 02:20:36 +04:00
|
|
|
err = -EFAULT;
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
|
2013-03-06 00:04:55 +04:00
|
|
|
fourth = (unsigned long)up64;
|
2005-04-17 02:20:36 +04:00
|
|
|
err = sys_semctl(first, second, third, fourth);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-02-03 23:36:44 +04:00
|
|
|
static long compat_do_msg_fill(void __user *dest, struct msg_msg *msg, size_t bufsz)
|
2013-01-05 03:34:52 +04:00
|
|
|
{
|
|
|
|
struct compat_msgbuf __user *msgp = dest;
|
|
|
|
size_t msgsz;
|
|
|
|
|
|
|
|
if (put_user(msg->m_type, &msgp->mtype))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
msgsz = (bufsz > msg->m_ts) ? msg->m_ts : bufsz;
|
|
|
|
if (store_msg(msgp->mtext, msg, msgsz))
|
|
|
|
return -EFAULT;
|
|
|
|
return msgsz;
|
|
|
|
}
|
|
|
|
|
2013-02-03 23:36:44 +04:00
|
|
|
#ifndef COMPAT_SHMLBA
|
|
|
|
#define COMPAT_SHMLBA SHMLBA
|
|
|
|
#endif
|
2013-01-22 08:15:25 +04:00
|
|
|
|
2013-02-03 23:36:44 +04:00
|
|
|
#ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
|
2013-01-22 08:15:25 +04:00
|
|
|
COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
|
|
|
|
u32, third, compat_uptr_t, ptr, u32, fifth)
|
|
|
|
{
|
|
|
|
int version;
|
2013-02-03 23:36:44 +04:00
|
|
|
u32 pad;
|
2013-01-22 08:15:25 +04:00
|
|
|
|
|
|
|
version = call >> 16; /* hack for backward compatibility */
|
|
|
|
call &= 0xffff;
|
|
|
|
|
|
|
|
switch (call) {
|
|
|
|
case SEMOP:
|
|
|
|
/* struct sembuf is the same on 32 and 64bit :)) */
|
|
|
|
return sys_semtimedop(first, compat_ptr(ptr), second, NULL);
|
|
|
|
case SEMTIMEDOP:
|
|
|
|
return compat_sys_semtimedop(first, compat_ptr(ptr), second,
|
|
|
|
compat_ptr(fifth));
|
|
|
|
case SEMGET:
|
|
|
|
return sys_semget(first, second, third);
|
|
|
|
case SEMCTL:
|
2013-02-03 23:36:44 +04:00
|
|
|
if (!ptr)
|
|
|
|
return -EINVAL;
|
|
|
|
if (get_user(pad, (u32 __user *) compat_ptr(ptr)))
|
|
|
|
return -EFAULT;
|
|
|
|
return do_compat_semctl(first, second, third, pad);
|
|
|
|
|
|
|
|
case MSGSND: {
|
|
|
|
struct compat_msgbuf __user *up = compat_ptr(ptr);
|
|
|
|
compat_long_t type;
|
|
|
|
|
|
|
|
if (first < 0 || second < 0)
|
|
|
|
return -EINVAL;
|
2013-01-22 08:15:25 +04:00
|
|
|
|
2013-02-03 23:36:44 +04:00
|
|
|
if (get_user(type, &up->mtype))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return do_msgsnd(first, type, up->mtext, second, third);
|
|
|
|
}
|
|
|
|
case MSGRCV: {
|
|
|
|
void __user *uptr = compat_ptr(ptr);
|
|
|
|
|
|
|
|
if (first < 0 || second < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!version) {
|
|
|
|
struct compat_ipc_kludge ipck;
|
|
|
|
if (!uptr)
|
|
|
|
return -EINVAL;
|
2014-01-28 05:07:04 +04:00
|
|
|
if (copy_from_user(&ipck, uptr, sizeof(ipck)))
|
2013-02-03 23:36:44 +04:00
|
|
|
return -EFAULT;
|
|
|
|
uptr = compat_ptr(ipck.msgp);
|
|
|
|
fifth = ipck.msgtyp;
|
|
|
|
}
|
2014-01-28 05:07:11 +04:00
|
|
|
return do_msgrcv(first, uptr, second, (s32)fifth, third,
|
2013-02-03 23:36:44 +04:00
|
|
|
compat_do_msg_fill);
|
|
|
|
}
|
2013-01-22 08:15:25 +04:00
|
|
|
case MSGGET:
|
|
|
|
return sys_msgget(first, second);
|
|
|
|
case MSGCTL:
|
|
|
|
return compat_sys_msgctl(first, second, compat_ptr(ptr));
|
|
|
|
|
2013-02-03 23:36:44 +04:00
|
|
|
case SHMAT: {
|
|
|
|
int err;
|
|
|
|
unsigned long raddr;
|
|
|
|
|
|
|
|
if (version == 1)
|
|
|
|
return -EINVAL;
|
|
|
|
err = do_shmat(first, compat_ptr(ptr), second, &raddr,
|
|
|
|
COMPAT_SHMLBA);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
|
|
|
|
}
|
2013-01-22 08:15:25 +04:00
|
|
|
case SHMDT:
|
|
|
|
return sys_shmdt(compat_ptr(ptr));
|
|
|
|
case SHMGET:
|
|
|
|
return sys_shmget(first, (unsigned)second, third);
|
|
|
|
case SHMCTL:
|
|
|
|
return compat_sys_shmctl(first, second, compat_ptr(ptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2013-02-03 23:36:44 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
COMPAT_SYSCALL_DEFINE4(semctl, int, semid, int, semnum, int, cmd, int, arg)
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
{
|
|
|
|
return do_compat_semctl(semid, semnum, cmd, arg);
|
|
|
|
}
|
|
|
|
|
2013-02-03 23:36:44 +04:00
|
|
|
COMPAT_SYSCALL_DEFINE4(msgsnd, int, msqid, compat_uptr_t, msgp,
|
|
|
|
compat_ssize_t, msgsz, int, msgflg)
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
{
|
2013-02-03 23:36:44 +04:00
|
|
|
struct compat_msgbuf __user *up = compat_ptr(msgp);
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
compat_long_t mtype;
|
|
|
|
|
2013-02-03 23:36:44 +04:00
|
|
|
if (get_user(mtype, &up->mtype))
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
return -EFAULT;
|
2013-02-03 23:36:44 +04:00
|
|
|
return do_msgsnd(msqid, mtype, up->mtext, (ssize_t)msgsz, msgflg);
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
}
|
|
|
|
|
2013-02-03 23:36:44 +04:00
|
|
|
COMPAT_SYSCALL_DEFINE5(msgrcv, int, msqid, compat_uptr_t, msgp,
|
2014-03-04 15:39:03 +04:00
|
|
|
compat_ssize_t, msgsz, compat_long_t, msgtyp, int, msgflg)
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
{
|
2014-03-04 15:39:03 +04:00
|
|
|
return do_msgrcv(msqid, compat_ptr(msgp), (ssize_t)msgsz, (long)msgtyp,
|
2013-02-03 23:36:44 +04:00
|
|
|
msgflg, compat_do_msg_fill);
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-02-03 23:36:44 +04:00
|
|
|
COMPAT_SYSCALL_DEFINE3(shmat, int, shmid, compat_uptr_t, shmaddr, int, shmflg)
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
{
|
|
|
|
unsigned long ret;
|
|
|
|
long err;
|
|
|
|
|
2012-07-31 01:42:38 +04:00
|
|
|
err = do_shmat(shmid, compat_ptr(shmaddr), shmflg, &ret, COMPAT_SHMLBA);
|
[PATCH v3] ipc: provide generic compat versions of IPC syscalls
When using the "compat" APIs, architectures will generally want to
be able to make direct syscalls to msgsnd(), shmctl(), etc., and
in the kernel we would want them to be handled directly by
compat_sys_xxx() functions, as is true for other compat syscalls.
However, for historical reasons, several of the existing compat IPC
syscalls do not do this. semctl() expects a pointer to the fourth
argument, instead of the fourth argument itself. msgsnd(), msgrcv()
and shmat() expect arguments in different order.
This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
set to preserve this behavior for ports that use it (x86, sparc, powerpc,
s390, and mips). No actual semantics are changed for those architectures,
and there is only a minimal amount of code refactoring in ipc/compat.c.
Newer architectures like tile (and perhaps future architectures such
as arm64 and unicore64) should not select this option, and thus can
avoid having any IPC-specific code at all in their architecture-specific
compat layer. In the same vein, if this option is not selected, IPC_64
mode is assumed, since that's what the <asm-generic> headers expect.
The workaround code in "tile" for msgsnd() and msgrcv() is removed
with this change; it also fixes the bug that shmat() and semctl() were
not being properly handled.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
2012-03-15 21:13:38 +04:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
force_successful_syscall_return();
|
|
|
|
return (long)ret;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-03-04 14:17:50 +04:00
|
|
|
COMPAT_SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsems,
|
|
|
|
unsigned, nsops,
|
|
|
|
const struct compat_timespec __user *, timeout)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2014-02-02 06:54:11 +04:00
|
|
|
struct timespec __user *ts64;
|
|
|
|
if (compat_convert_timespec(&ts64, timeout))
|
|
|
|
return -EFAULT;
|
2005-04-17 02:20:36 +04:00
|
|
|
return sys_semtimedop(semid, tsems, nsops, ts64);
|
|
|
|
}
|