]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - arch/s390/kernel/compat_linux.c
Merge tag 'kbuild-fixes-v5.3-3' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-eoan-kernel.git] / arch / s390 / kernel / compat_linux.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4 2/*
1da177e4 3 * S390 version
a53c8fab 4 * Copyright IBM Corp. 2000
1da177e4
LT
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
6 * Gerhard Tonn (ton@de.ibm.com)
7 * Thomas Spatzier (tspat@de.ibm.com)
8 *
9 * Conversion between 31bit and 64bit native syscalls.
10 *
11 * Heavily inspired by the 32-bit Sparc compat code which is
12 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
13 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
14 *
15 */
16
17
1da177e4
LT
18#include <linux/kernel.h>
19#include <linux/sched.h>
20#include <linux/fs.h>
21#include <linux/mm.h>
22#include <linux/file.h>
23#include <linux/signal.h>
24#include <linux/resource.h>
25#include <linux/times.h>
1da177e4 26#include <linux/smp.h>
1da177e4
LT
27#include <linux/sem.h>
28#include <linux/msg.h>
29#include <linux/shm.h>
1da177e4 30#include <linux/uio.h>
1da177e4 31#include <linux/quota.h>
1da177e4
LT
32#include <linux/poll.h>
33#include <linux/personality.h>
34#include <linux/stat.h>
35#include <linux/filter.h>
36#include <linux/highmem.h>
1da177e4
LT
37#include <linux/mman.h>
38#include <linux/ipv6.h>
39#include <linux/in.h>
40#include <linux/icmpv6.h>
41#include <linux/syscalls.h>
42#include <linux/sysctl.h>
43#include <linux/binfmts.h>
a9415644 44#include <linux/capability.h>
1da177e4
LT
45#include <linux/compat.h>
46#include <linux/vfs.h>
47#include <linux/ptrace.h>
068e1b94 48#include <linux/fadvise.h>
cba4fbbf 49#include <linux/ipc.h>
5a0e3ad6 50#include <linux/slab.h>
1da177e4
LT
51
52#include <asm/types.h>
7c0f6ba6 53#include <linux/uaccess.h>
1da177e4
LT
54
55#include <net/scm.h>
56#include <net/sock.h>
57
58#include "compat_linux.h"
59
1df23957 60#ifdef CONFIG_SYSVIPC
49382d93
HC
61COMPAT_SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, compat_ulong_t, second,
62 compat_ulong_t, third, compat_uptr_t, ptr)
1da177e4
LT
63{
64 if (call >> 16) /* hack for backward compatibility */
65 return -EINVAL;
58fa4a41 66 return compat_ksys_ipc(call, first, second, third, ptr, third);
1da177e4 67}
1df23957 68#endif
1da177e4 69
e723e0cc 70COMPAT_SYSCALL_DEFINE3(s390_truncate64, const char __user *, path, u32, high, u32, low)
1da177e4 71{
df260e21 72 return ksys_truncate(path, (unsigned long)high << 32 | low);
1da177e4
LT
73}
74
52a0b536 75COMPAT_SYSCALL_DEFINE3(s390_ftruncate64, unsigned int, fd, u32, high, u32, low)
1da177e4 76{
411d9475 77 return ksys_ftruncate(fd, (unsigned long)high << 32 | low);
1da177e4
LT
78}
79
52a0b536
HC
80COMPAT_SYSCALL_DEFINE5(s390_pread64, unsigned int, fd, char __user *, ubuf,
81 compat_size_t, count, u32, high, u32, low)
1da177e4
LT
82{
83 if ((compat_ssize_t) count < 0)
84 return -EINVAL;
36028d5d 85 return ksys_pread64(fd, ubuf, count, (unsigned long)high << 32 | low);
1da177e4
LT
86}
87
52a0b536
HC
88COMPAT_SYSCALL_DEFINE5(s390_pwrite64, unsigned int, fd, const char __user *, ubuf,
89 compat_size_t, count, u32, high, u32, low)
1da177e4
LT
90{
91 if ((compat_ssize_t) count < 0)
92 return -EINVAL;
36028d5d 93 return ksys_pwrite64(fd, ubuf, count, (unsigned long)high << 32 | low);
1da177e4
LT
94}
95
52a0b536 96COMPAT_SYSCALL_DEFINE4(s390_readahead, int, fd, u32, high, u32, low, s32, count)
1da177e4 97{
c7b95d51 98 return ksys_readahead(fd, (unsigned long)high << 32 | low, count);
1da177e4
LT
99}
100
1da177e4
LT
101struct stat64_emu31 {
102 unsigned long long st_dev;
103 unsigned int __pad1;
104#define STAT64_HAS_BROKEN_ST_INO 1
105 u32 __st_ino;
106 unsigned int st_mode;
107 unsigned int st_nlink;
108 u32 st_uid;
109 u32 st_gid;
110 unsigned long long st_rdev;
111 unsigned int __pad3;
112 long st_size;
113 u32 st_blksize;
114 unsigned char __pad4[4];
115 u32 __pad5; /* future possible st_blocks high bits */
116 u32 st_blocks; /* Number 512-byte blocks allocated. */
117 u32 st_atime;
118 u32 __pad6;
119 u32 st_mtime;
120 u32 __pad7;
121 u32 st_ctime;
122 u32 __pad8; /* will be high 32 bits of ctime someday */
123 unsigned long st_ino;
124};
125
24954a14 126static int cp_stat64(struct stat64_emu31 __user *ubuf, struct kstat *stat)
1da177e4
LT
127{
128 struct stat64_emu31 tmp;
129
130 memset(&tmp, 0, sizeof(tmp));
131
132 tmp.st_dev = huge_encode_dev(stat->dev);
133 tmp.st_ino = stat->ino;
134 tmp.__st_ino = (u32)stat->ino;
135 tmp.st_mode = stat->mode;
136 tmp.st_nlink = (unsigned int)stat->nlink;
a7c1938e
EB
137 tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
138 tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
1da177e4
LT
139 tmp.st_rdev = huge_encode_dev(stat->rdev);
140 tmp.st_size = stat->size;
141 tmp.st_blksize = (u32)stat->blksize;
142 tmp.st_blocks = (u32)stat->blocks;
143 tmp.st_atime = (u32)stat->atime.tv_sec;
144 tmp.st_mtime = (u32)stat->mtime.tv_sec;
145 tmp.st_ctime = (u32)stat->ctime.tv_sec;
146
147 return copy_to_user(ubuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
148}
149
52a0b536 150COMPAT_SYSCALL_DEFINE2(s390_stat64, const char __user *, filename, struct stat64_emu31 __user *, statbuf)
1da177e4
LT
151{
152 struct kstat stat;
153 int ret = vfs_stat(filename, &stat);
154 if (!ret)
155 ret = cp_stat64(statbuf, &stat);
156 return ret;
157}
158
a0f8c6da 159COMPAT_SYSCALL_DEFINE2(s390_lstat64, const char __user *, filename, struct stat64_emu31 __user *, statbuf)
1da177e4
LT
160{
161 struct kstat stat;
162 int ret = vfs_lstat(filename, &stat);
163 if (!ret)
164 ret = cp_stat64(statbuf, &stat);
165 return ret;
166}
167
a0f8c6da 168COMPAT_SYSCALL_DEFINE2(s390_fstat64, unsigned int, fd, struct stat64_emu31 __user *, statbuf)
1da177e4
LT
169{
170 struct kstat stat;
171 int ret = vfs_fstat(fd, &stat);
172 if (!ret)
173 ret = cp_stat64(statbuf, &stat);
174 return ret;
175}
176
a0f8c6da
HC
177COMPAT_SYSCALL_DEFINE4(s390_fstatat64, unsigned int, dfd, const char __user *, filename,
178 struct stat64_emu31 __user *, statbuf, int, flag)
19bf9cbf
HC
179{
180 struct kstat stat;
0112fc22 181 int error;
19bf9cbf 182
0112fc22
OD
183 error = vfs_fstatat(dfd, filename, &stat, flag);
184 if (error)
185 return error;
186 return cp_stat64(statbuf, &stat);
19bf9cbf
HC
187}
188
1da177e4
LT
189/*
190 * Linux/i386 didn't use to be able to handle more than
191 * 4 system call parameters, so these system calls used a memory
192 * block for parameter passing..
193 */
194
195struct mmap_arg_struct_emu31 {
d3815898
HC
196 compat_ulong_t addr;
197 compat_ulong_t len;
198 compat_ulong_t prot;
199 compat_ulong_t flags;
200 compat_ulong_t fd;
201 compat_ulong_t offset;
1da177e4
LT
202};
203
a0f8c6da 204COMPAT_SYSCALL_DEFINE1(s390_old_mmap, struct mmap_arg_struct_emu31 __user *, arg)
1da177e4
LT
205{
206 struct mmap_arg_struct_emu31 a;
1da177e4
LT
207
208 if (copy_from_user(&a, arg, sizeof(a)))
d3815898 209 return -EFAULT;
1da177e4 210 if (a.offset & ~PAGE_MASK)
d3815898 211 return -EINVAL;
a90f590a
DB
212 return ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
213 a.offset >> PAGE_SHIFT);
1da177e4
LT
214}
215
a0f8c6da 216COMPAT_SYSCALL_DEFINE1(s390_mmap2, struct mmap_arg_struct_emu31 __user *, arg)
1da177e4
LT
217{
218 struct mmap_arg_struct_emu31 a;
1da177e4
LT
219
220 if (copy_from_user(&a, arg, sizeof(a)))
d3815898 221 return -EFAULT;
a90f590a 222 return ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
1da177e4
LT
223}
224
5383d2c8 225COMPAT_SYSCALL_DEFINE3(s390_read, unsigned int, fd, char __user *, buf, compat_size_t, count)
1da177e4
LT
226{
227 if ((compat_ssize_t) count < 0)
228 return -EINVAL;
229
3ce4a7bf 230 return ksys_read(fd, buf, count);
1da177e4
LT
231}
232
5383d2c8 233COMPAT_SYSCALL_DEFINE3(s390_write, unsigned int, fd, const char __user *, buf, compat_size_t, count)
1da177e4
LT
234{
235 if ((compat_ssize_t) count < 0)
236 return -EINVAL;
237
e7a3e8b2 238 return ksys_write(fd, buf, count);
1da177e4
LT
239}
240
068e1b94
MS
241/*
242 * 31 bit emulation wrapper functions for sys_fadvise64/fadvise64_64.
243 * These need to rewrite the advise values for POSIX_FADV_{DONTNEED,NOREUSE}
244 * because the 31 bit values differ from the 64 bit values.
245 */
246
5383d2c8 247COMPAT_SYSCALL_DEFINE5(s390_fadvise64, int, fd, u32, high, u32, low, compat_size_t, len, int, advise)
068e1b94
MS
248{
249 if (advise == 4)
250 advise = POSIX_FADV_DONTNEED;
251 else if (advise == 5)
252 advise = POSIX_FADV_NOREUSE;
9d5b7c95
DB
253 return ksys_fadvise64_64(fd, (unsigned long)high << 32 | low, len,
254 advise);
068e1b94
MS
255}
256
257struct fadvise64_64_args {
258 int fd;
259 long long offset;
260 long long len;
261 int advice;
262};
263
5383d2c8 264COMPAT_SYSCALL_DEFINE1(s390_fadvise64_64, struct fadvise64_64_args __user *, args)
068e1b94
MS
265{
266 struct fadvise64_64_args a;
267
268 if ( copy_from_user(&a, args, sizeof(a)) )
269 return -EFAULT;
270 if (a.advice == 4)
271 a.advice = POSIX_FADV_DONTNEED;
272 else if (a.advice == 5)
273 a.advice = POSIX_FADV_NOREUSE;
9d5b7c95 274 return ksys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
068e1b94 275}
2c81fc4f
HC
276
277COMPAT_SYSCALL_DEFINE6(s390_sync_file_range, int, fd, u32, offhigh, u32, offlow,
278 u32, nhigh, u32, nlow, unsigned int, flags)
279{
806cbae1 280 return ksys_sync_file_range(fd, ((loff_t)offhigh << 32) + offlow,
2c81fc4f
HC
281 ((u64)nhigh << 32) + nlow, flags);
282}
283
284COMPAT_SYSCALL_DEFINE6(s390_fallocate, int, fd, int, mode, u32, offhigh, u32, offlow,
285 u32, lenhigh, u32, lenlow)
286{
edf292c7
DB
287 return ksys_fallocate(fd, mode, ((loff_t)offhigh << 32) + offlow,
288 ((u64)lenhigh << 32) + lenlow);
2c81fc4f 289}