Commit 079a96ae authored by Will Deacon's avatar Will Deacon Committed by Linus Torvalds

ipc: add COMPAT_SHMLBA support

If the SHMLBA definition for a native task differs from the definition for
a compat task, the do_shmat() function would need to handle both.

This patch introduces COMPAT_SHMLBA, which is used by the compat shmat
syscall when calling the ipc code and allows architectures such as AArch64
(where the native SHMLBA is 64k but the compat (AArch32) definition is
16k) to provide the correct semantics for compat IPC system calls.

Cc: David S. Miller <davem@davemloft.net>
Cc: Chris Zankel <chris@zankel.net>
Cc: Arnd Bergmann <arnd@arndb.de>
Acked-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 63dca8d5
...@@ -470,7 +470,7 @@ SYSCALL_DEFINE6(sparc_ipc, unsigned int, call, int, first, unsigned long, second ...@@ -470,7 +470,7 @@ SYSCALL_DEFINE6(sparc_ipc, unsigned int, call, int, first, unsigned long, second
switch (call) { switch (call) {
case SHMAT: { case SHMAT: {
ulong raddr; ulong raddr;
err = do_shmat(first, ptr, (int)second, &raddr); err = do_shmat(first, ptr, (int)second, &raddr, SHMLBA);
if (!err) { if (!err) {
if (put_user(raddr, if (put_user(raddr,
(ulong __user *) third)) (ulong __user *) third))
......
...@@ -44,7 +44,7 @@ asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg) ...@@ -44,7 +44,7 @@ asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg)
unsigned long ret; unsigned long ret;
long err; long err;
err = do_shmat(shmid, shmaddr, shmflg, &ret); err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
if (err) if (err)
return err; return err;
return (long)ret; return (long)ret;
......
...@@ -107,12 +107,14 @@ struct shmid_kernel /* private to the kernel */ ...@@ -107,12 +107,14 @@ struct shmid_kernel /* private to the kernel */
#define SHM_NORESERVE 010000 /* don't check for reservations */ #define SHM_NORESERVE 010000 /* don't check for reservations */
#ifdef CONFIG_SYSVIPC #ifdef CONFIG_SYSVIPC
long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr); long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr,
unsigned long shmlba);
extern int is_file_shm_hugepages(struct file *file); extern int is_file_shm_hugepages(struct file *file);
extern void exit_shm(struct task_struct *task); extern void exit_shm(struct task_struct *task);
#else #else
static inline long do_shmat(int shmid, char __user *shmaddr, static inline long do_shmat(int shmid, char __user *shmaddr,
int shmflg, unsigned long *addr) int shmflg, unsigned long *addr,
unsigned long shmlba)
{ {
return -ENOSYS; return -ENOSYS;
} }
......
...@@ -514,6 +514,10 @@ long compat_sys_msgctl(int first, int second, void __user *uptr) ...@@ -514,6 +514,10 @@ long compat_sys_msgctl(int first, int second, void __user *uptr)
return err; return err;
} }
#ifndef COMPAT_SHMLBA
#define COMPAT_SHMLBA SHMLBA
#endif
#ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC #ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
long compat_sys_shmat(int first, int second, compat_uptr_t third, int version, long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
void __user *uptr) void __user *uptr)
...@@ -524,7 +528,7 @@ long compat_sys_shmat(int first, int second, compat_uptr_t third, int version, ...@@ -524,7 +528,7 @@ long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
if (version == 1) if (version == 1)
return -EINVAL; return -EINVAL;
err = do_shmat(first, uptr, second, &raddr); err = do_shmat(first, uptr, second, &raddr, COMPAT_SHMLBA);
if (err < 0) if (err < 0)
return err; return err;
uaddr = compat_ptr(third); uaddr = compat_ptr(third);
...@@ -536,7 +540,7 @@ long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) ...@@ -536,7 +540,7 @@ long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg)
unsigned long ret; unsigned long ret;
long err; long err;
err = do_shmat(shmid, compat_ptr(shmaddr), shmflg, &ret); err = do_shmat(shmid, compat_ptr(shmaddr), shmflg, &ret, COMPAT_SHMLBA);
if (err) if (err)
return err; return err;
force_successful_syscall_return(); force_successful_syscall_return();
......
...@@ -953,7 +953,8 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf) ...@@ -953,7 +953,8 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)
* "raddr" thing points to kernel space, and there has to be a wrapper around * "raddr" thing points to kernel space, and there has to be a wrapper around
* this. * this.
*/ */
long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr) long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
unsigned long shmlba)
{ {
struct shmid_kernel *shp; struct shmid_kernel *shp;
unsigned long addr; unsigned long addr;
...@@ -973,9 +974,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr) ...@@ -973,9 +974,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
if (shmid < 0) if (shmid < 0)
goto out; goto out;
else if ((addr = (ulong)shmaddr)) { else if ((addr = (ulong)shmaddr)) {
if (addr & (SHMLBA-1)) { if (addr & (shmlba - 1)) {
if (shmflg & SHM_RND) if (shmflg & SHM_RND)
addr &= ~(SHMLBA-1); /* round down */ addr &= ~(shmlba - 1); /* round down */
else else
#ifndef __ARCH_FORCE_SHMLBA #ifndef __ARCH_FORCE_SHMLBA
if (addr & ~PAGE_MASK) if (addr & ~PAGE_MASK)
...@@ -1107,7 +1108,7 @@ SYSCALL_DEFINE3(shmat, int, shmid, char __user *, shmaddr, int, shmflg) ...@@ -1107,7 +1108,7 @@ SYSCALL_DEFINE3(shmat, int, shmid, char __user *, shmaddr, int, shmflg)
unsigned long ret; unsigned long ret;
long err; long err;
err = do_shmat(shmid, shmaddr, shmflg, &ret); err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
if (err) if (err)
return err; return err;
force_successful_syscall_return(); force_successful_syscall_return();
......
...@@ -73,7 +73,7 @@ SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second, ...@@ -73,7 +73,7 @@ SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
default: { default: {
unsigned long raddr; unsigned long raddr;
ret = do_shmat(first, (char __user *)ptr, ret = do_shmat(first, (char __user *)ptr,
second, &raddr); second, &raddr, SHMLBA);
if (ret) if (ret)
return ret; return ret;
return put_user(raddr, (unsigned long __user *) third); return put_user(raddr, (unsigned long __user *) third);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment