1b2441318SGreg Kroah-Hartman// SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds/*
31da177e4SLinus Torvalds * 32 bit compatibility code for System V IPC
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Copyright (C) 1997,1998	Jakub Jelinek (jj@sunsite.mff.cuni.cz)
61da177e4SLinus Torvalds * Copyright (C) 1997		David S. Miller (davem@caip.rutgers.edu)
71da177e4SLinus Torvalds * Copyright (C) 1999		Arun Sharma <arun.sharma@intel.com>
81da177e4SLinus Torvalds * Copyright (C) 2000		VA Linux Co
91da177e4SLinus Torvalds * Copyright (C) 2000		Don Dugger <n0ano@valinux.com>
101da177e4SLinus Torvalds * Copyright (C) 2000           Hewlett-Packard Co.
111da177e4SLinus Torvalds * Copyright (C) 2000           David Mosberger-Tang <davidm@hpl.hp.com>
121da177e4SLinus Torvalds * Copyright (C) 2000           Gerhard Tonn (ton@de.ibm.com)
131da177e4SLinus Torvalds * Copyright (C) 2000-2002      Andi Kleen, SuSE Labs (x86-64 port)
141da177e4SLinus Torvalds * Copyright (C) 2000		Silicon Graphics, Inc.
151da177e4SLinus Torvalds * Copyright (C) 2001		IBM
161da177e4SLinus Torvalds * Copyright (C) 2004		IBM Deutschland Entwicklung GmbH, IBM Corporation
171da177e4SLinus Torvalds * Copyright (C) 2004		Arnd Bergmann (arnd@arndb.de)
181da177e4SLinus Torvalds *
191da177e4SLinus Torvalds * This code is collected from the versions for sparc64, mips64, s390x, ia64,
201da177e4SLinus Torvalds * ppc64 and x86_64, all of which are based on the original sparc64 version
211da177e4SLinus Torvalds * by Jakub Jelinek.
221da177e4SLinus Torvalds *
231da177e4SLinus Torvalds */
241da177e4SLinus Torvalds#include <linux/compat.h>
251da177e4SLinus Torvalds#include <linux/errno.h>
261da177e4SLinus Torvalds#include <linux/highuid.h>
271da177e4SLinus Torvalds#include <linux/init.h>
281da177e4SLinus Torvalds#include <linux/msg.h>
291da177e4SLinus Torvalds#include <linux/shm.h>
301da177e4SLinus Torvalds#include <linux/syscalls.h>
3148b25c43SChris Metcalf#include <linux/ptrace.h>
321da177e4SLinus Torvalds
335f921ae9SIngo Molnar#include <linux/mutex.h>
347153e402SPaul McQuade#include <linux/uaccess.h>
351da177e4SLinus Torvalds
361da177e4SLinus Torvalds#include "util.h"
371da177e4SLinus Torvalds
38c0ebccb6SAl Viroint get_compat_ipc64_perm(struct ipc64_perm *to,
39c0ebccb6SAl Viro			  struct compat_ipc64_perm __user *from)
401da177e4SLinus Torvalds{
41c0ebccb6SAl Viro	struct compat_ipc64_perm v;
42c0ebccb6SAl Viro	if (copy_from_user(&v, from, sizeof(v)))
431da177e4SLinus Torvalds		return -EFAULT;
44c0ebccb6SAl Viro	to->uid = v.uid;
45c0ebccb6SAl Viro	to->gid = v.gid;
46c0ebccb6SAl Viro	to->mode = v.mode;
47c0ebccb6SAl Viro	return 0;
481da177e4SLinus Torvalds}
491da177e4SLinus Torvalds
50c0ebccb6SAl Viroint get_compat_ipc_perm(struct ipc64_perm *to,
51c0ebccb6SAl Viro			struct compat_ipc_perm __user *from)
521da177e4SLinus Torvalds{
53c0ebccb6SAl Viro	struct compat_ipc_perm v;
54c0ebccb6SAl Viro	if (copy_from_user(&v, from, sizeof(v)))
551da177e4SLinus Torvalds		return -EFAULT;
56c0ebccb6SAl Viro	to->uid = v.uid;
57c0ebccb6SAl Viro	to->gid = v.gid;
58c0ebccb6SAl Viro	to->mode = v.mode;
59c0ebccb6SAl Viro	return 0;
601da177e4SLinus Torvalds}
611da177e4SLinus Torvalds
62c0ebccb6SAl Virovoid to_compat_ipc64_perm(struct compat_ipc64_perm *to, struct ipc64_perm *from)
631da177e4SLinus Torvalds{
64c0ebccb6SAl Viro	to->key = from->key;
65c0ebccb6SAl Viro	to->uid = from->uid;
66c0ebccb6SAl Viro	to->gid = from->gid;
67c0ebccb6SAl Viro	to->cuid = from->cuid;
68c0ebccb6SAl Viro	to->cgid = from->cgid;
69c0ebccb6SAl Viro	to->mode = from->mode;
70c0ebccb6SAl Viro	to->seq = from->seq;
711da177e4SLinus Torvalds}
721da177e4SLinus Torvalds
73c0ebccb6SAl Virovoid to_compat_ipc_perm(struct compat_ipc_perm *to, struct ipc64_perm *from)
741da177e4SLinus Torvalds{
75c0ebccb6SAl Viro	to->key = from->key;
76c0ebccb6SAl Viro	SET_UID(to->uid, from->uid);
77c0ebccb6SAl Viro	SET_GID(to->gid, from->gid);
78c0ebccb6SAl Viro	SET_UID(to->cuid, from->cuid);
79c0ebccb6SAl Viro	SET_GID(to->cgid, from->cgid);
80c0ebccb6SAl Viro	to->mode = from->mode;
81c0ebccb6SAl Viro	to->seq = from->seq;
821da177e4SLinus Torvalds}
83