Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * 32 bit compatibility code for System V IPC |
| 3 | * |
| 4 | * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
| 5 | * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) |
| 6 | * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com> |
| 7 | * Copyright (C) 2000 VA Linux Co |
| 8 | * Copyright (C) 2000 Don Dugger <n0ano@valinux.com> |
| 9 | * Copyright (C) 2000 Hewlett-Packard Co. |
| 10 | * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com> |
| 11 | * Copyright (C) 2000 Gerhard Tonn (ton@de.ibm.com) |
| 12 | * Copyright (C) 2000-2002 Andi Kleen, SuSE Labs (x86-64 port) |
| 13 | * Copyright (C) 2000 Silicon Graphics, Inc. |
| 14 | * Copyright (C) 2001 IBM |
| 15 | * Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 16 | * Copyright (C) 2004 Arnd Bergmann (arnd@arndb.de) |
| 17 | * |
| 18 | * This code is collected from the versions for sparc64, mips64, s390x, ia64, |
| 19 | * ppc64 and x86_64, all of which are based on the original sparc64 version |
| 20 | * by Jakub Jelinek. |
| 21 | * |
| 22 | */ |
| 23 | #include <linux/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/errno.h> |
| 25 | #include <linux/highuid.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/msg.h> |
| 28 | #include <linux/shm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/syscalls.h> |
Chris Metcalf | 48b25c4 | 2012-03-15 13:13:38 -0400 | [diff] [blame] | 30 | #include <linux/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Ingo Molnar | 5f921ae | 2006-03-26 01:37:17 -0800 | [diff] [blame] | 32 | #include <linux/mutex.h> |
Paul McQuade | 7153e40 | 2014-06-06 14:37:37 -0700 | [diff] [blame] | 33 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #include "util.h" |
| 36 | |
Al Viro | c0ebccb | 2017-07-09 10:03:23 -0400 | [diff] [blame] | 37 | int get_compat_ipc64_perm(struct ipc64_perm *to, |
| 38 | struct compat_ipc64_perm __user *from) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
Al Viro | c0ebccb | 2017-07-09 10:03:23 -0400 | [diff] [blame] | 40 | struct compat_ipc64_perm v; |
| 41 | if (copy_from_user(&v, from, sizeof(v))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | return -EFAULT; |
Al Viro | c0ebccb | 2017-07-09 10:03:23 -0400 | [diff] [blame] | 43 | to->uid = v.uid; |
| 44 | to->gid = v.gid; |
| 45 | to->mode = v.mode; |
| 46 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Al Viro | c0ebccb | 2017-07-09 10:03:23 -0400 | [diff] [blame] | 49 | int get_compat_ipc_perm(struct ipc64_perm *to, |
| 50 | struct compat_ipc_perm __user *from) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Al Viro | c0ebccb | 2017-07-09 10:03:23 -0400 | [diff] [blame] | 52 | struct compat_ipc_perm v; |
| 53 | if (copy_from_user(&v, from, sizeof(v))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | return -EFAULT; |
Al Viro | c0ebccb | 2017-07-09 10:03:23 -0400 | [diff] [blame] | 55 | to->uid = v.uid; |
| 56 | to->gid = v.gid; |
| 57 | to->mode = v.mode; |
| 58 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Al Viro | c0ebccb | 2017-07-09 10:03:23 -0400 | [diff] [blame] | 61 | void to_compat_ipc64_perm(struct compat_ipc64_perm *to, struct ipc64_perm *from) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Al Viro | c0ebccb | 2017-07-09 10:03:23 -0400 | [diff] [blame] | 63 | to->key = from->key; |
| 64 | to->uid = from->uid; |
| 65 | to->gid = from->gid; |
| 66 | to->cuid = from->cuid; |
| 67 | to->cgid = from->cgid; |
| 68 | to->mode = from->mode; |
| 69 | to->seq = from->seq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Al Viro | c0ebccb | 2017-07-09 10:03:23 -0400 | [diff] [blame] | 72 | void to_compat_ipc_perm(struct compat_ipc_perm *to, struct ipc64_perm *from) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Al Viro | c0ebccb | 2017-07-09 10:03:23 -0400 | [diff] [blame] | 74 | to->key = from->key; |
| 75 | SET_UID(to->uid, from->uid); |
| 76 | SET_GID(to->gid, from->gid); |
| 77 | SET_UID(to->cuid, from->cuid); |
| 78 | SET_GID(to->cgid, from->cgid); |
| 79 | to->mode = from->mode; |
| 80 | to->seq = from->seq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |