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 <Jason@zx2c4.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Fixes: 7e92e01b72
("powerpc: Provide syscall wrapper")
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20221012035335.866440-1-npiggin@gmail.com
154 lines
4.8 KiB
C
154 lines
4.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __ASM_POWERPC_SYSCALLS_H
|
|
#define __ASM_POWERPC_SYSCALLS_H
|
|
#ifdef __KERNEL__
|
|
|
|
#include <linux/compiler.h>
|
|
#include <linux/linkage.h>
|
|
#include <linux/types.h>
|
|
#include <linux/compat.h>
|
|
|
|
#include <asm/syscall.h>
|
|
#ifdef CONFIG_PPC64
|
|
#include <asm/syscalls_32.h>
|
|
#endif
|
|
#include <asm/unistd.h>
|
|
#include <asm/ucontext.h>
|
|
|
|
#ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
|
|
long sys_ni_syscall(void);
|
|
#else
|
|
long sys_ni_syscall(const struct pt_regs *regs);
|
|
#endif
|
|
|
|
struct rtas_args;
|
|
|
|
/*
|
|
* long long munging:
|
|
* The 32 bit ABI passes long longs in an odd even register pair.
|
|
* High and low parts are swapped depending on endian mode,
|
|
* so define a macro (similar to mips linux32) to handle that.
|
|
*/
|
|
#ifdef __LITTLE_ENDIAN__
|
|
#define merge_64(low, high) (((u64)high << 32) | low)
|
|
#else
|
|
#define merge_64(high, low) (((u64)high << 32) | low)
|
|
#endif
|
|
|
|
/*
|
|
* PowerPC architecture-specific syscalls
|
|
*/
|
|
|
|
#ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
|
|
|
|
long sys_rtas(struct rtas_args __user *uargs);
|
|
|
|
#ifdef CONFIG_PPC64
|
|
long sys_ppc64_personality(unsigned long personality);
|
|
#ifdef CONFIG_COMPAT
|
|
long compat_sys_ppc64_personality(unsigned long personality);
|
|
#endif /* CONFIG_COMPAT */
|
|
#endif /* CONFIG_PPC64 */
|
|
|
|
long sys_swapcontext(struct ucontext __user *old_ctx,
|
|
struct ucontext __user *new_ctx, long ctx_size);
|
|
long sys_mmap(unsigned long addr, size_t len,
|
|
unsigned long prot, unsigned long flags,
|
|
unsigned long fd, off_t offset);
|
|
long sys_mmap2(unsigned long addr, size_t len,
|
|
unsigned long prot, unsigned long flags,
|
|
unsigned long fd, unsigned long pgoff);
|
|
long sys_switch_endian(void);
|
|
|
|
#ifdef CONFIG_PPC32
|
|
long sys_sigreturn(void);
|
|
long sys_debug_setcontext(struct ucontext __user *ctx, int ndbg,
|
|
struct sig_dbg_op __user *dbg);
|
|
#endif
|
|
|
|
long sys_rt_sigreturn(void);
|
|
|
|
long sys_subpage_prot(unsigned long addr,
|
|
unsigned long len, u32 __user *map);
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
long compat_sys_swapcontext(struct ucontext32 __user *old_ctx,
|
|
struct ucontext32 __user *new_ctx,
|
|
int ctx_size);
|
|
long compat_sys_old_getrlimit(unsigned int resource,
|
|
struct compat_rlimit __user *rlim);
|
|
long compat_sys_sigreturn(void);
|
|
long compat_sys_rt_sigreturn(void);
|
|
#endif /* CONFIG_COMPAT */
|
|
|
|
/*
|
|
* Architecture specific signatures required by long long munging:
|
|
* The 32 bit ABI passes long longs in an odd even register pair.
|
|
* The following signatures provide a machine long parameter for
|
|
* each register that will be supplied. The implementation is
|
|
* responsible for combining parameter pairs.
|
|
*/
|
|
|
|
#ifdef CONFIG_PPC32
|
|
long sys_ppc_pread64(unsigned int fd,
|
|
char __user *ubuf, compat_size_t count,
|
|
u32 reg6, u32 pos1, u32 pos2);
|
|
long sys_ppc_pwrite64(unsigned int fd,
|
|
const char __user *ubuf, compat_size_t count,
|
|
u32 reg6, u32 pos1, u32 pos2);
|
|
long sys_ppc_readahead(int fd, u32 r4,
|
|
u32 offset1, u32 offset2, u32 count);
|
|
long sys_ppc_truncate64(const char __user *path, u32 reg4,
|
|
unsigned long len1, unsigned long len2);
|
|
long sys_ppc_ftruncate64(unsigned int fd, u32 reg4,
|
|
unsigned long len1, unsigned long len2);
|
|
long sys_ppc32_fadvise64(int fd, u32 unused, u32 offset1, u32 offset2,
|
|
size_t len, int advice);
|
|
#endif
|
|
#ifdef CONFIG_COMPAT
|
|
long compat_sys_mmap2(unsigned long addr, size_t len,
|
|
unsigned long prot, unsigned long flags,
|
|
unsigned long fd, unsigned long pgoff);
|
|
long compat_sys_ppc_pread64(unsigned int fd,
|
|
char __user *ubuf, compat_size_t count,
|
|
u32 reg6, u32 pos1, u32 pos2);
|
|
long compat_sys_ppc_pwrite64(unsigned int fd,
|
|
const char __user *ubuf, compat_size_t count,
|
|
u32 reg6, u32 pos1, u32 pos2);
|
|
long compat_sys_ppc_readahead(int fd, u32 r4,
|
|
u32 offset1, u32 offset2, u32 count);
|
|
long compat_sys_ppc_truncate64(const char __user *path, u32 reg4,
|
|
unsigned long len1, unsigned long len2);
|
|
long compat_sys_ppc_ftruncate64(unsigned int fd, u32 reg4,
|
|
unsigned long len1, unsigned long len2);
|
|
long compat_sys_ppc32_fadvise64(int fd, u32 unused, u32 offset1, u32 offset2,
|
|
size_t len, int advice);
|
|
long compat_sys_ppc_sync_file_range2(int fd, unsigned int flags,
|
|
unsigned int offset1,
|
|
unsigned int offset2,
|
|
unsigned int nbytes1,
|
|
unsigned int nbytes2);
|
|
#endif /* CONFIG_COMPAT */
|
|
|
|
#if defined(CONFIG_PPC32) || defined(CONFIG_COMPAT)
|
|
long sys_ppc_fadvise64_64(int fd, int advice,
|
|
u32 offset_high, u32 offset_low,
|
|
u32 len_high, u32 len_low);
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, native)
|
|
#define __SYSCALL(nr, entry) \
|
|
long entry(const struct pt_regs *regs);
|
|
|
|
#ifdef CONFIG_PPC64
|
|
#include <asm/syscall_table_64.h>
|
|
#else
|
|
#include <asm/syscall_table_32.h>
|
|
#endif /* CONFIG_PPC64 */
|
|
|
|
#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
|
|
|
|
#endif /* __KERNEL__ */
|
|
#endif /* __ASM_POWERPC_SYSCALLS_H */
|