Skip to content

Commit e237506

Browse files
npigginmpe
authored andcommitted
powerpc/32: fix syscall wrappers with 64-bit arguments of unaligned register-pairs
powerpc 32-bit system call (and function) calling convention for 64-bit arguments requires the next available odd-pair (two sequential registers with the first being odd-numbered) from the standard register argument allocation. The first argument register is r3, so a 64-bit argument that appears at an even position in the argument list must skip a register (unless there were preceding 64-bit arguments, which might throw things off). This requires non-standard compat definitions to deal with the holes in the argument register allocation. With pt_regs syscall wrappers which use a standard mapper to map pt_regs GPRs to function arguments, 32-bit kernels hit the same basic problem, the standard definitions don't cope with the unused argument registers. Fix this by having 32-bit kernels share those syscall definitions with compat. Thanks to Jason for spending a lot of time finding and bisecting this and developing a trivial reproducer. The perfect bug report. Reported-by: Jason A. Donenfeld <[email protected]> Signed-off-by: Nicholas Piggin <[email protected]> Fixes: 7e92e01 ("powerpc: Provide syscall wrapper") Reviewed-by: Arnd Bergmann <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ae5b677 commit e237506

File tree

4 files changed

+56
-15
lines changed

4 files changed

+56
-15
lines changed

arch/powerpc/include/asm/syscalls.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ long compat_sys_rt_sigreturn(void);
8989
* responsible for combining parameter pairs.
9090
*/
9191

92+
#ifdef CONFIG_PPC32
93+
long sys_ppc_pread64(unsigned int fd,
94+
char __user *ubuf, compat_size_t count,
95+
u32 reg6, u32 pos1, u32 pos2);
96+
long sys_ppc_pwrite64(unsigned int fd,
97+
const char __user *ubuf, compat_size_t count,
98+
u32 reg6, u32 pos1, u32 pos2);
99+
long sys_ppc_readahead(int fd, u32 r4,
100+
u32 offset1, u32 offset2, u32 count);
101+
long sys_ppc_truncate64(const char __user *path, u32 reg4,
102+
unsigned long len1, unsigned long len2);
103+
long sys_ppc_ftruncate64(unsigned int fd, u32 reg4,
104+
unsigned long len1, unsigned long len2);
105+
long sys_ppc32_fadvise64(int fd, u32 unused, u32 offset1, u32 offset2,
106+
size_t len, int advice);
107+
#endif
92108
#ifdef CONFIG_COMPAT
93109
long compat_sys_mmap2(unsigned long addr, size_t len,
94110
unsigned long prot, unsigned long flags,

arch/powerpc/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ obj-y := cputable.o syscalls.o \
7373
obj-y += ptrace/
7474
obj-$(CONFIG_PPC64) += setup_64.o irq_64.o\
7575
paca.o nvram_64.o note.o
76+
obj-$(CONFIG_PPC32) += sys_ppc32.o
7677
obj-$(CONFIG_COMPAT) += sys_ppc32.o signal_32.o
7778
obj-$(CONFIG_VDSO32) += vdso32_wrapper.o
7879
obj-$(CONFIG_PPC_WATCHDOG) += watchdog.o

arch/powerpc/kernel/sys_ppc32.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
/*
3-
* sys_ppc32.c: Conversion between 32bit and 64bit native syscalls.
3+
* sys_ppc32.c: 32-bit system calls with complex calling conventions.
44
*
55
* Copyright (C) 2001 IBM
66
* Copyright (C) 1997,1998 Jakub Jelinek ([email protected])
77
* Copyright (C) 1997 David S. Miller ([email protected])
88
*
9-
* These routines maintain argument size conversion between 32bit and 64bit
10-
* environment.
9+
* 32-bit system calls with 64-bit arguments pass those in register pairs.
10+
* This must be specially dealt with on 64-bit kernels. The compat_arg_u64_dual
11+
* in generic compat syscalls is not always usable because the register
12+
* pairing is constrained depending on preceding arguments.
13+
*
14+
* An analogous problem exists on 32-bit kernels with ARCH_HAS_SYSCALL_WRAPPER,
15+
* the defined system call functions take the pt_regs as an argument, and there
16+
* is a mapping macro which maps registers to arguments
17+
* (SC_POWERPC_REGS_TO_ARGS) which also does not deal with these 64-bit
18+
* arguments.
19+
*
20+
* This file contains these system calls.
1121
*/
1222

1323
#include <linux/kernel.h>
@@ -47,44 +57,54 @@
4757
#include <asm/syscalls.h>
4858
#include <asm/switch_to.h>
4959

50-
COMPAT_SYSCALL_DEFINE6(ppc_pread64,
60+
#ifdef CONFIG_PPC32
61+
#define PPC32_SYSCALL_DEFINE4 SYSCALL_DEFINE4
62+
#define PPC32_SYSCALL_DEFINE5 SYSCALL_DEFINE5
63+
#define PPC32_SYSCALL_DEFINE6 SYSCALL_DEFINE6
64+
#else
65+
#define PPC32_SYSCALL_DEFINE4 COMPAT_SYSCALL_DEFINE4
66+
#define PPC32_SYSCALL_DEFINE5 COMPAT_SYSCALL_DEFINE5
67+
#define PPC32_SYSCALL_DEFINE6 COMPAT_SYSCALL_DEFINE6
68+
#endif
69+
70+
PPC32_SYSCALL_DEFINE6(ppc_pread64,
5171
unsigned int, fd,
5272
char __user *, ubuf, compat_size_t, count,
5373
u32, reg6, u32, pos1, u32, pos2)
5474
{
5575
return ksys_pread64(fd, ubuf, count, merge_64(pos1, pos2));
5676
}
5777

58-
COMPAT_SYSCALL_DEFINE6(ppc_pwrite64,
78+
PPC32_SYSCALL_DEFINE6(ppc_pwrite64,
5979
unsigned int, fd,
6080
const char __user *, ubuf, compat_size_t, count,
6181
u32, reg6, u32, pos1, u32, pos2)
6282
{
6383
return ksys_pwrite64(fd, ubuf, count, merge_64(pos1, pos2));
6484
}
6585

66-
COMPAT_SYSCALL_DEFINE5(ppc_readahead,
86+
PPC32_SYSCALL_DEFINE5(ppc_readahead,
6787
int, fd, u32, r4,
6888
u32, offset1, u32, offset2, u32, count)
6989
{
7090
return ksys_readahead(fd, merge_64(offset1, offset2), count);
7191
}
7292

73-
COMPAT_SYSCALL_DEFINE4(ppc_truncate64,
93+
PPC32_SYSCALL_DEFINE4(ppc_truncate64,
7494
const char __user *, path, u32, reg4,
7595
unsigned long, len1, unsigned long, len2)
7696
{
7797
return ksys_truncate(path, merge_64(len1, len2));
7898
}
7999

80-
COMPAT_SYSCALL_DEFINE4(ppc_ftruncate64,
100+
PPC32_SYSCALL_DEFINE4(ppc_ftruncate64,
81101
unsigned int, fd, u32, reg4,
82102
unsigned long, len1, unsigned long, len2)
83103
{
84104
return ksys_ftruncate(fd, merge_64(len1, len2));
85105
}
86106

87-
COMPAT_SYSCALL_DEFINE6(ppc32_fadvise64,
107+
PPC32_SYSCALL_DEFINE6(ppc32_fadvise64,
88108
int, fd, u32, unused, u32, offset1, u32, offset2,
89109
size_t, len, int, advice)
90110
{

arch/powerpc/kernel/syscalls/syscall.tbl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@
228228
176 64 rt_sigtimedwait sys_rt_sigtimedwait
229229
177 nospu rt_sigqueueinfo sys_rt_sigqueueinfo compat_sys_rt_sigqueueinfo
230230
178 nospu rt_sigsuspend sys_rt_sigsuspend compat_sys_rt_sigsuspend
231-
179 common pread64 sys_pread64 compat_sys_ppc_pread64
232-
180 common pwrite64 sys_pwrite64 compat_sys_ppc_pwrite64
231+
179 32 pread64 sys_ppc_pread64 compat_sys_ppc_pread64
232+
179 64 pread64 sys_pread64
233+
180 32 pwrite64 sys_ppc_pwrite64 compat_sys_ppc_pwrite64
234+
180 64 pwrite64 sys_pwrite64
233235
181 common chown sys_chown
234236
182 common getcwd sys_getcwd
235237
183 common capget sys_capget
@@ -242,10 +244,11 @@
242244
188 common putpmsg sys_ni_syscall
243245
189 nospu vfork sys_vfork
244246
190 common ugetrlimit sys_getrlimit compat_sys_getrlimit
245-
191 common readahead sys_readahead compat_sys_ppc_readahead
247+
191 32 readahead sys_ppc_readahead compat_sys_ppc_readahead
248+
191 64 readahead sys_readahead
246249
192 32 mmap2 sys_mmap2 compat_sys_mmap2
247-
193 32 truncate64 sys_truncate64 compat_sys_ppc_truncate64
248-
194 32 ftruncate64 sys_ftruncate64 compat_sys_ppc_ftruncate64
250+
193 32 truncate64 sys_ppc_truncate64 compat_sys_ppc_truncate64
251+
194 32 ftruncate64 sys_ppc_ftruncate64 compat_sys_ppc_ftruncate64
249252
195 32 stat64 sys_stat64
250253
196 32 lstat64 sys_lstat64
251254
197 32 fstat64 sys_fstat64
@@ -288,7 +291,8 @@
288291
230 common io_submit sys_io_submit compat_sys_io_submit
289292
231 common io_cancel sys_io_cancel
290293
232 nospu set_tid_address sys_set_tid_address
291-
233 common fadvise64 sys_fadvise64 compat_sys_ppc32_fadvise64
294+
233 32 fadvise64 sys_ppc32_fadvise64 compat_sys_ppc32_fadvise64
295+
233 64 fadvise64 sys_fadvise64
292296
234 nospu exit_group sys_exit_group
293297
235 nospu lookup_dcookie sys_lookup_dcookie compat_sys_lookup_dcookie
294298
236 common epoll_create sys_epoll_create

0 commit comments

Comments
 (0)