blob: 5ab8225923af6c343594d29bba064c9e9398c1a2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * 32 bit compatibility code for System V IPC
4 *
5 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
7 * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
8 * Copyright (C) 2000 VA Linux Co
9 * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
10 * Copyright (C) 2000 Hewlett-Packard Co.
11 * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
12 * Copyright (C) 2000 Gerhard Tonn (ton@de.ibm.com)
13 * Copyright (C) 2000-2002 Andi Kleen, SuSE Labs (x86-64 port)
14 * Copyright (C) 2000 Silicon Graphics, Inc.
15 * Copyright (C) 2001 IBM
16 * Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation
17 * Copyright (C) 2004 Arnd Bergmann (arnd@arndb.de)
18 *
19 * This code is collected from the versions for sparc64, mips64, s390x, ia64,
20 * ppc64 and x86_64, all of which are based on the original sparc64 version
21 * by Jakub Jelinek.
22 *
23 */
24#include <linux/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/errno.h>
26#include <linux/highuid.h>
27#include <linux/init.h>
28#include <linux/msg.h>
29#include <linux/shm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/syscalls.h>
Chris Metcalf48b25c42012-03-15 13:13:38 -040031#include <linux/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Ingo Molnar5f921ae2006-03-26 01:37:17 -080033#include <linux/mutex.h>
Paul McQuade7153e402014-06-06 14:37:37 -070034#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#include "util.h"
37
Al Viroc0ebccb2017-07-09 10:03:23 -040038int get_compat_ipc64_perm(struct ipc64_perm *to,
39 struct compat_ipc64_perm __user *from)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
Al Viroc0ebccb2017-07-09 10:03:23 -040041 struct compat_ipc64_perm v;
42 if (copy_from_user(&v, from, sizeof(v)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 return -EFAULT;
Al Viroc0ebccb2017-07-09 10:03:23 -040044 to->uid = v.uid;
45 to->gid = v.gid;
46 to->mode = v.mode;
47 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
Al Viroc0ebccb2017-07-09 10:03:23 -040050int get_compat_ipc_perm(struct ipc64_perm *to,
51 struct compat_ipc_perm __user *from)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Al Viroc0ebccb2017-07-09 10:03:23 -040053 struct compat_ipc_perm v;
54 if (copy_from_user(&v, from, sizeof(v)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return -EFAULT;
Al Viroc0ebccb2017-07-09 10:03:23 -040056 to->uid = v.uid;
57 to->gid = v.gid;
58 to->mode = v.mode;
59 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Al Viroc0ebccb2017-07-09 10:03:23 -040062void to_compat_ipc64_perm(struct compat_ipc64_perm *to, struct ipc64_perm *from)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Al Viroc0ebccb2017-07-09 10:03:23 -040064 to->key = from->key;
65 to->uid = from->uid;
66 to->gid = from->gid;
67 to->cuid = from->cuid;
68 to->cgid = from->cgid;
69 to->mode = from->mode;
70 to->seq = from->seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Al Viroc0ebccb2017-07-09 10:03:23 -040073void to_compat_ipc_perm(struct compat_ipc_perm *to, struct ipc64_perm *from)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Al Viroc0ebccb2017-07-09 10:03:23 -040075 to->key = from->key;
76 SET_UID(to->uid, from->uid);
77 SET_GID(to->gid, from->gid);
78 SET_UID(to->cuid, from->cuid);
79 SET_GID(to->cgid, from->cgid);
80 to->mode = from->mode;
81 to->seq = from->seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}