compat.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  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>
  25. #include <linux/errno.h>
  26. #include <linux/highuid.h>
  27. #include <linux/init.h>
  28. #include <linux/msg.h>
  29. #include <linux/shm.h>
  30. #include <linux/syscalls.h>
  31. #include <linux/ptrace.h>
  32. #include <linux/mutex.h>
  33. #include <linux/uaccess.h>
  34. #include "util.h"
  35. int get_compat_ipc64_perm(struct ipc64_perm *to,
  36. struct compat_ipc64_perm __user *from)
  37. {
  38. struct compat_ipc64_perm v;
  39. if (copy_from_user(&v, from, sizeof(v)))
  40. return -EFAULT;
  41. to->uid = v.uid;
  42. to->gid = v.gid;
  43. to->mode = v.mode;
  44. return 0;
  45. }
  46. int get_compat_ipc_perm(struct ipc64_perm *to,
  47. struct compat_ipc_perm __user *from)
  48. {
  49. struct compat_ipc_perm v;
  50. if (copy_from_user(&v, from, sizeof(v)))
  51. return -EFAULT;
  52. to->uid = v.uid;
  53. to->gid = v.gid;
  54. to->mode = v.mode;
  55. return 0;
  56. }
  57. void to_compat_ipc64_perm(struct compat_ipc64_perm *to, struct ipc64_perm *from)
  58. {
  59. to->key = from->key;
  60. to->uid = from->uid;
  61. to->gid = from->gid;
  62. to->cuid = from->cuid;
  63. to->cgid = from->cgid;
  64. to->mode = from->mode;
  65. to->seq = from->seq;
  66. }
  67. void to_compat_ipc_perm(struct compat_ipc_perm *to, struct ipc64_perm *from)
  68. {
  69. to->key = from->key;
  70. SET_UID(to->uid, from->uid);
  71. SET_GID(to->gid, from->gid);
  72. SET_UID(to->cuid, from->cuid);
  73. SET_GID(to->cgid, from->cgid);
  74. to->mode = from->mode;
  75. to->seq = from->seq;
  76. }