Blame ipc/compat.c

f2d475
// SPDX-License-Identifier: GPL-2.0
f2d475
/*
f2d475
 * 32 bit compatibility code for System V IPC
f2d475
 *
f2d475
 * Copyright (C) 1997,1998	Jakub Jelinek (jj@sunsite.mff.cuni.cz)
f2d475
 * Copyright (C) 1997		David S. Miller (davem@caip.rutgers.edu)
f2d475
 * Copyright (C) 1999		Arun Sharma <arun.sharma@intel.com>
f2d475
 * Copyright (C) 2000		VA Linux Co
f2d475
 * Copyright (C) 2000		Don Dugger <n0ano@valinux.com>
f2d475
 * Copyright (C) 2000           Hewlett-Packard Co.
f2d475
 * Copyright (C) 2000           David Mosberger-Tang <davidm@hpl.hp.com>
f2d475
 * Copyright (C) 2000           Gerhard Tonn (ton@de.ibm.com)
f2d475
 * Copyright (C) 2000-2002      Andi Kleen, SuSE Labs (x86-64 port)
f2d475
 * Copyright (C) 2000		Silicon Graphics, Inc.
f2d475
 * Copyright (C) 2001		IBM
f2d475
 * Copyright (C) 2004		IBM Deutschland Entwicklung GmbH, IBM Corporation
f2d475
 * Copyright (C) 2004		Arnd Bergmann (arnd@arndb.de)
f2d475
 *
f2d475
 * This code is collected from the versions for sparc64, mips64, s390x, ia64,
f2d475
 * ppc64 and x86_64, all of which are based on the original sparc64 version
f2d475
 * by Jakub Jelinek.
f2d475
 *
f2d475
 */
f2d475
#include <linux/compat.h>
f2d475
#include <linux/errno.h>
f2d475
#include <linux/highuid.h>
f2d475
#include <linux/init.h>
f2d475
#include <linux/msg.h>
f2d475
#include <linux/shm.h>
f2d475
#include <linux/syscalls.h>
f2d475
#include <linux/ptrace.h>
f2d475
f2d475
#include <linux/mutex.h>
f2d475
#include <linux/uaccess.h>
f2d475
f2d475
#include "util.h"
f2d475
f2d475
int get_compat_ipc64_perm(struct ipc64_perm *to,
f2d475
			  struct compat_ipc64_perm __user *from)
f2d475
{
f2d475
	struct compat_ipc64_perm v;
f2d475
	if (copy_from_user(&v, from, sizeof(v)))
f2d475
		return -EFAULT;
f2d475
	to->uid = v.uid;
f2d475
	to->gid = v.gid;
f2d475
	to->mode = v.mode;
f2d475
	return 0;
f2d475
}
f2d475
f2d475
int get_compat_ipc_perm(struct ipc64_perm *to,
f2d475
			struct compat_ipc_perm __user *from)
f2d475
{
f2d475
	struct compat_ipc_perm v;
f2d475
	if (copy_from_user(&v, from, sizeof(v)))
f2d475
		return -EFAULT;
f2d475
	to->uid = v.uid;
f2d475
	to->gid = v.gid;
f2d475
	to->mode = v.mode;
f2d475
	return 0;
f2d475
}
f2d475
f2d475
void to_compat_ipc64_perm(struct compat_ipc64_perm *to, struct ipc64_perm *from)
f2d475
{
f2d475
	to->key = from->key;
f2d475
	to->uid = from->uid;
f2d475
	to->gid = from->gid;
f2d475
	to->cuid = from->cuid;
f2d475
	to->cgid = from->cgid;
f2d475
	to->mode = from->mode;
f2d475
	to->seq = from->seq;
f2d475
}
f2d475
f2d475
void to_compat_ipc_perm(struct compat_ipc_perm *to, struct ipc64_perm *from)
f2d475
{
f2d475
	to->key = from->key;
f2d475
	SET_UID(to->uid, from->uid);
f2d475
	SET_GID(to->gid, from->gid);
f2d475
	SET_UID(to->cuid, from->cuid);
f2d475
	SET_GID(to->cgid, from->cgid);
f2d475
	to->mode = from->mode;
f2d475
	to->seq = from->seq;
f2d475
}