[PATCH] m68k: Define the m68k-specific syscalls with SYSCALL_DEFINE
From: Daniel Palmer
Date: Mon Nov 23 2026 - 21:56:22 EST
On m68k a syscall handler's stack arguments are the user's registers
saved in pt_regs, and RESTORE_ALL reloads them on the way out. The C
ABI lets a function reuse its incoming argument slots, so anything the
handler writes there ends up in user space. SYSCALL_DEFINEn() stops
the compiler doing that with asmlinkage_protect(), but sys_mmap2() and
the other m68k-specific syscalls are plain asmlinkage functions.
With GCC 16 and a kernel built with -O2, sys_mmap2() becomes a tail
call to ksys_mmap_pgoff(), which builds its call to vm_mmap_pgoff() by
shifting its arguments up one slot in place. User space gets d2-d5
back holding addr/len/prot/flags.
This issue was noticed in nolibc programs that are using mmap() and
I initially thought nolibc's m68k support was to blame.
Define sys_mmap2(), sys_cacheflush(), sys_atomic_cmpxchg_32() and
sys_set_thread_area() with SYSCALL_DEFINEn() so their arguments are
protected, and make their prototypes in asm/syscalls.h return long to
match.
Fixes: a90f590a1bee ("mm: add ksys_mmap_pgoff() helper; remove in-kernel calls to sys_mmap_pgoff()")
Signed-off-by: Daniel Palmer <daniel@xxxxxxxx>
---
I think this is right, I've tested it on real 030, 040 and 060 machines.
I found this issue making DRM/KMS programs with nolibc. Since I wrote the m68k
support for nolibc I suspected I had missed some ABI thing and messed it up and
I put a local workaround in there. Then the issue started showing up a normal libc.
I fixed the sys_mmap2() place by stepping through the kernel in QEMU and working
out who was messing up the registers. My fix worked but I wasn't sure why
there was an issue to start with so I asked my clanker and it disassembled the
kernel and explained the tail-call thing in the commit message.
arch/m68k/include/asm/syscalls.h | 10 +++++-----
arch/m68k/kernel/sys_m68k.c | 26 ++++++++++++--------------
2 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/arch/m68k/include/asm/syscalls.h b/arch/m68k/include/asm/syscalls.h
index fb3639acd07b..f317b35d6970 100644
--- a/arch/m68k/include/asm/syscalls.h
+++ b/arch/m68k/include/asm/syscalls.h
@@ -5,13 +5,13 @@
#include <linux/compiler_types.h>
#include <linux/linkage.h>
-asmlinkage int sys_cacheflush(unsigned long addr, int scope, int cache,
- unsigned long len);
-asmlinkage int sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3,
- int d4, int d5, unsigned long __user *mem);
+asmlinkage long sys_cacheflush(unsigned long addr, int scope, int cache,
+ unsigned long len);
+asmlinkage long sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3,
+ int d4, int d5, unsigned long __user *mem);
asmlinkage int sys_getpagesize(void);
asmlinkage unsigned long sys_get_thread_area(void);
-asmlinkage int sys_set_thread_area(unsigned long tp);
+asmlinkage long sys_set_thread_area(unsigned long tp);
asmlinkage int sys_atomic_barrier(void);
#include <asm-generic/syscalls.h>
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index 1af5e6082467..9e6d38e57495 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -37,9 +37,9 @@
#include "../mm/fault.h"
-asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
- unsigned long prot, unsigned long flags,
- unsigned long fd, unsigned long pgoff)
+SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
+ unsigned long, prot, unsigned long, flags,
+ unsigned long, fd, unsigned long, pgoff)
{
/*
* This is wrong for sun3 - there PAGE_SIZE is 8Kb,
@@ -374,8 +374,8 @@ cache_flush_060 (unsigned long addr, int scope, int cache, unsigned long len)
}
/* sys_cacheflush -- flush (part of) the processor cache. */
-asmlinkage int
-sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
+SYSCALL_DEFINE4(cacheflush, unsigned long, addr, int, scope, int, cache,
+ unsigned long, len)
{
int ret = -EINVAL;
@@ -459,9 +459,8 @@ sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
/* This syscall gets its arguments in A0 (mem), D2 (oldval) and
D1 (newval). */
-asmlinkage int
-sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
- unsigned long __user * mem)
+SYSCALL_DEFINE6(atomic_cmpxchg_32, unsigned long, newval, int, oldval,
+ int, d3, int, d4, int, d5, unsigned long __user *, mem)
{
/* This was borrowed from ARM's implementation. */
for (;;) {
@@ -533,8 +532,8 @@ sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
#else
/* sys_cacheflush -- flush (part of) the processor cache. */
-asmlinkage int
-sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
+SYSCALL_DEFINE4(cacheflush, unsigned long, addr, int, scope, int, cache,
+ unsigned long, len)
{
flush_cache_all();
return 0;
@@ -542,9 +541,8 @@ sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
/* This syscall gets its arguments in A0 (mem), D2 (oldval) and
D1 (newval). */
-asmlinkage int
-sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
- unsigned long __user * mem)
+SYSCALL_DEFINE6(atomic_cmpxchg_32, unsigned long, newval, int, oldval,
+ int, d3, int, d4, int, d5, unsigned long __user *, mem)
{
struct mm_struct *mm = current->mm;
unsigned long mem_value;
@@ -571,7 +569,7 @@ asmlinkage unsigned long sys_get_thread_area(void)
return current_thread_info()->tp_value;
}
-asmlinkage int sys_set_thread_area(unsigned long tp)
+SYSCALL_DEFINE1(set_thread_area, unsigned long, tp)
{
current_thread_info()->tp_value = tp;
return 0;
--
2.55.0