Re: [PATCH] m68k: Define the m68k-specific syscalls with SYSCALL_DEFINE

From: Arnd Bergmann

Date: Tue Nov 24 2026 - 02:06:27 EST


On Tue, Nov 24, 2026, at 03:55, Daniel Palmer wrote:
> 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>

This looks all good to me, nice analysis and description!

With the follow-up fix you posted

Reviewed-by: Arnd Bergmann <arnd@xxxxxxxx>

It would be nice to also wrap the other four syscalls that don't
take an argument for consistency and also have them use
SYSCALL_DEFINE0(). Can you add a second patch for that?

Arnd