From nobody Sat Jul 25 20:00:06 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E9033F4107 for ; Tue, 14 Jul 2026 07:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784015987; cv=none; b=DpIL53cq2LrPYmJIfefM9E542LvzQ7c9PMBlk2RW7HpUy/8vLkiDWZlHXfU5IbhILfDXgpDhtNL6oSYWJ5BL8IcdwCrCVWd1OVdgUB1j/1sSFCXHGxWNYWTifaqymeTcOLTts67E9W3Y/DipUUu0I0PiznOSXkVHPPByGsPbZuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784015987; c=relaxed/simple; bh=C0T8KihYAtwQ5hedIz/3q4MsmG/t+REus8cXOq4uEDw=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=MgSx2tgtkiLQeKe3GeWdx9B0Iiz1Jzuk0tWIk9eTrS9UO7ZH4mijbLiWoipd+8Q4mxr/gXeLzsOVWwdLQgO2WZy3bJ3ZDZnNvbDai0wBW3WKIbXDE/5GKVMtytvyZmpXIE9rMGR4cPUBmMtzdYUJMuhXvrMjlsbqCc8R7Y07uBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CGmU3Wfk; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CGmU3Wfk" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2ce9e39fccbso5722765ad.1 for ; Tue, 14 Jul 2026 00:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784015986; x=1784620786; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=yj5ApoHt9xXhC677bK+ujyDHWz19Ntuz1e97qTuHnZM=; b=CGmU3Wfkkkm8DigIU7PJ5rhbLmZKGqSogNRWz8azKs4AaWGPjPT6CtTou1yWcLR6gs 80rUPpiTCpQcsHwKb9zJhYBd/wifCaWv9QToF9X48ST1iqPsPrxdbHWcwX+ik0g8AaCt e9aOGqksdBrzR+nq3VV0cxs7zfhmPgJNKqDgrdcfH8FmpWhI1zS+CuAvAUqe92uAlGWP WyBoH6a5oLH6FeoU9yXPEW32s+0aEh9XeDNw0Yx4E/BMtH6LUsSKN4oO+X5DZfvh3KRp 4x9oLBmtVPDvARoANeqRGCHIieF8Ub7SbaUexyj3gFrWOL/b3IbUneA8Ip08ILjfF63o /Jng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784015986; x=1784620786; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yj5ApoHt9xXhC677bK+ujyDHWz19Ntuz1e97qTuHnZM=; b=IzTBYasXbQ/5GJ/HDUHcEJeAhMBzuBJSXx+VfYIDaVwCqn40IZUWEOIDtitW/3G2/+ 07qY6MvjLpmyP4KFhCDlyEe9WkLEodB9dD19qNlBOSAe+ZeG4ZmXYaVVTHnCmUZajk+n RNcqDs1TjnBOKIz+ZxlwzLzAB4Vu1ejpbgi5J31A+DhwzleiTffXnD46KnRxlyDzTB4Z gKP4avpya8AClQAuH6wk73KwUQFjEdvOx5gV95I4KFTRZWXanEpiiVcp3BxeCdihhWJV UouV80Nrlq9Trf8cTHInYzsRMH9rHnlIhfLmMpuhYQv5I+mXM/AnvSHf+jMw1U4ykjN7 OWAQ== X-Forwarded-Encrypted: i=1; AHgh+RozTDBCGoMXK0sGnyochTxgfbbkwVmxwCqO/3dpYWEiMpU3nsN0clKb4n23vYOqwKkUlvNMf3m4GTI60K4=@vger.kernel.org X-Gm-Message-State: AOJu0Yxqx1pq1lcOpKrMTXw0ACAIQ++HmsLwuHAJSyfT57uoGUUGxcS6 YuCwM9NU15/EhH+xT0D9oWbnTuVNp9GVxSOrlzLCvUywiUKzBjCNFB64 X-Gm-Gg: AfdE7cnSeRPrGG+iPTogirw0nDyqtZSaQdW/gO9j/S5cBK9N6DTkeMeFiyodOGmiY0H P9/NlDfPCq8SKIoPcAOBwyhKpN4fb3GLRNc1lJlwwg5HYtjfTEbtFZEj8+F4sAEQBrbnTEKfE+q QmMpURTAdRNhotJPQLzAP6UBIx6ZIdm+H1b5GNLMdhHCFe7fnljp/A1UuaQkUfQNGcfCUHl9eRg 7CnFxU8eEhCljFK+MKN8ENOLZAEaF6BeUBJ929Mj+r/rJim7Y8/ECTnLZRC4oGDITogSANpa4sG OTgXBjwtTWqepUMmlJtbkskrs4yblW7p9Ld33cN9hSPTMZRnVT95evQGCKk8oyykQf6SVFxk8u7 K+m8e92krmKkgiQVPXWI1fpMdrKU3Xp2VxzXXQ2exzJUpri2U2O7ASsa4nH5r0ummh1iVh6MAyS Z8D5ASiIYP+MukRDZcgxb14BbnF/nNOPXb4doWOV5o/xtBAKMi5E0UmFF7LsXQ8CJX0/9kk3ZKm 5tL X-Received: by 2002:a05:6a20:748e:b0:3c0:2808:4732 with SMTP id adf61e73a8af0-3c112c5fec5mr10483937637.16.1784015985376; Tue, 14 Jul 2026 00:59:45 -0700 (PDT) Received: from li-1a3e774c-28e4-11b2-a85c-acc9f2883e29.ibm.com.com ([106.51.164.116]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31174accb0esm80362644eec.30.2026.07.14.00.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 00:59:45 -0700 (PDT) From: "Mukesh Kumar Chaurasiya (IBM)" To: oleg@redhat.com, maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, msuchanek@suse.de, mchauras@linux.ibm.com, mkchauras@gmail.com, sshegde@linux.ibm.com, segher@kernel.crashing.org, thuth@redhat.com, kees@kernel.org, ryan.roberts@arm.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH V5] powerpc/syscall: Fix syscall skip handling for seccomp and ptrace Date: Tue, 14 Jul 2026 13:29:35 +0530 Message-ID: <20260714075935.1830145-1-mkchauras@gmail.com> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable After enabling GENERIC_ENTRY on PowerPC, syscall_enter_from_user_mode() returns -1 as a sentinel to signal that seccomp or ptrace has intercepted the syscall and already set a return value via syscall_set_return_value(). system_call_exception() was not handling this sentinel, and since -1UL is >=3D NR_syscalls, the code fell into the out-of-range path and returned -ENOSYS, overwriting the errno already placed in regs->gpr[3]. The naive fix of checking r0 =3D=3D -1L before the NR_syscalls bounds check is ambiguous: a user legitimately calling syscall(-1) also produces r0 =3D= =3D -1L, and a tracer intercepting such a call would have its injected return value silently discarded. Fix this properly by introducing regs->entry_flags, a kernel-internal field in struct pt_regs (consuming one slot of the existing __pt_regs_pad so the ABI is preserved), with SYSCALL_ENTRY_RET_SET as an out-of-band flag. syscall_set_return_value() sets this flag whenever seccomp or ptrace injects a return value. system_call_exception() zeros entry_flags before calling syscall_enter_from_user_mode(), then checks and clears the flag afterwards: if set, it returns regs->gpr[3] directly regardless of what syscall number the user originally requested. This handles all seccomp actions correctly: - SECCOMP_RET_ERRNO, SECCOMP_RET_TRACE (no tracer), SECCOMP_RET_USER_NOTI= F: all call syscall_set_return_value(), flag is set, injected value return= ed. - SECCOMP_RET_TRAP, SECCOMP_RET_KILL: call syscall_rollback() and deliver a signal; flag is not set, but the process is dying so the return value is irrelevant. The fix covers both ppc32 and ppc64 with no #ifdefs. Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature") Reported-by: Michal Such=C3=A1nek Closes: https://lore.kernel.org/all/ajpp-_XnbF3UTM_E@kunlun.suse.cz/ Tested-by: Michal Such=C3=A1nek Reviewed-by: Michal Such=C3=A1nek Signed-off-by: Mukesh Kumar Chaurasiya (IBM) --- v4 -> v5: - Fixed build failure where BITS macro is not available v3 -> v4: - Use syscall_get_error (Michal) v2 -> v3: - Last fix is not working for -1 syscall. Fixed that with this. v2: https://lore.kernel.org/all/20260629182946.419552-1-mkchauras@gmail.com v1 -> v2: - Fix issues in the previous fix (Michal) v1: https://lore.kernel.org/all/20260624171520.772408-1-mkchauras@gmail.com arch/powerpc/include/asm/ptrace.h | 23 ++++++++++++++++++++++- arch/powerpc/include/asm/syscall.h | 6 ++++++ arch/powerpc/include/uapi/asm/ptrace.h | 6 ++++-- arch/powerpc/kernel/ptrace/ptrace.c | 2 ++ arch/powerpc/kernel/syscall.c | 18 ++++++++++++++++++ 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/p= trace.h index fdeb97421785..363a89787f1c 100644 --- a/arch/powerpc/include/asm/ptrace.h +++ b/arch/powerpc/include/asm/ptrace.h @@ -19,6 +19,7 @@ #ifndef _ASM_POWERPC_PTRACE_H #define _ASM_POWERPC_PTRACE_H =20 +#include #include #include #include @@ -54,8 +55,9 @@ struct pt_regs }; unsigned long result; unsigned long exit_flags; + unsigned long entry_flags; /* Maintain 16 byte interrupt stack alignment */ - unsigned long __pt_regs_pad[3]; + unsigned long __pt_regs_pad[2]; }; }; #if defined(CONFIG_PPC64) || defined(CONFIG_PPC_KUAP) @@ -233,6 +235,25 @@ static inline unsigned long frame_pointer(struct pt_re= gs *regs) #define current_pt_regs() \ ((struct pt_regs *)((unsigned long)task_stack_page(current) + THREAD_SIZE= ) - 1) =20 +/* + * SYSCALL_ENTRY_RET_SET: seccomp or ptrace called syscall_set_return_valu= e() + * and wants the syscall skipped; regs->gpr[3] already holds the return va= lue. + */ +#define SYSCALL_ENTRY_RET_SET BIT(0) + +static inline void set_syscall_entry_ret(struct pt_regs *regs) +{ + regs->entry_flags |=3D SYSCALL_ENTRY_RET_SET; +} + +static inline bool test_and_clear_syscall_entry_ret(struct pt_regs *regs) +{ + bool set =3D !!(regs->entry_flags & SYSCALL_ENTRY_RET_SET); + + regs->entry_flags &=3D ~SYSCALL_ENTRY_RET_SET; + return set; +} + /* * The 4 low bits (0xf) are available as flags to overload the trap word, * because interrupt vectors have minimum alignment of 0x10. TRAP_FLAGS_MA= SK diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/= syscall.h index 834fcc4f7b54..9ae79326abe3 100644 --- a/arch/powerpc/include/asm/syscall.h +++ b/arch/powerpc/include/asm/syscall.h @@ -98,6 +98,12 @@ static inline void syscall_set_return_value(struct task_= struct *task, regs->gpr[3] =3D val; } } + /* + * Mark that a return value has been explicitly set by seccomp or + * ptrace so that system_call_exception() can skip the syscall + * unconditionally, even when the user requested syscall(-1). + */ + set_syscall_entry_ret(regs); } =20 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/powerpc/include/uapi/asm/ptrace.h b/arch/powerpc/include/= uapi/asm/ptrace.h index a393b7f2760a..2f2a43414fe6 100644 --- a/arch/powerpc/include/uapi/asm/ptrace.h +++ b/arch/powerpc/include/uapi/asm/ptrace.h @@ -56,7 +56,8 @@ struct pt_regs unsigned long dsisr; /* on 4xx/Book-E used for ESR */ unsigned long result; /* Result of a system call */ unsigned long exit_flags; /* System call exit flags */ - unsigned long __pt_regs_pad[3]; /* Maintain 16 byte interrupt stack align= ment */ + unsigned long entry_flags; /* System call entry flags */ + unsigned long __pt_regs_pad[2]; /* Maintain 16 byte interrupt stack align= ment */ }; =20 #endif /* __ASSEMBLER__ */ @@ -117,7 +118,8 @@ struct pt_regs #define PT_DSISR 42 #define PT_RESULT 43 #define PT_EXIT_FLAGS 44 -#define PT_PAD 47 /* 3 times */ +#define PT_ENTRY_FLAGS 45 +#define PT_PAD 46 /* 2 times */ #define PT_DSCR 48 #define PT_REGS_COUNT 48 =20 diff --git a/arch/powerpc/kernel/ptrace/ptrace.c b/arch/powerpc/kernel/ptra= ce/ptrace.c index 316d4f5ead8e..440d00690cf2 100644 --- a/arch/powerpc/kernel/ptrace/ptrace.c +++ b/arch/powerpc/kernel/ptrace/ptrace.c @@ -235,6 +235,8 @@ void __init pt_regs_check(void) offsetof(struct user_pt_regs, dsisr)); BUILD_BUG_ON(offsetof(struct pt_regs, result) !=3D offsetof(struct user_pt_regs, result)); + BUILD_BUG_ON(offsetof(struct pt_regs, entry_flags) !=3D + offsetof(struct user_pt_regs, entry_flags)); =20 BUILD_BUG_ON(sizeof(struct user_pt_regs) > sizeof(struct pt_regs)); =20 diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c index a9da2af6efa8..a43d3a9428cc 100644 --- a/arch/powerpc/kernel/syscall.c +++ b/arch/powerpc/kernel/syscall.c @@ -19,9 +19,27 @@ notrace long system_call_exception(struct pt_regs *regs,= unsigned long r0) long ret; syscall_fn f; =20 + /* + * Zero entry_flags before syscall_enter_from_user_mode() so that + * syscall_set_return_value() can set SYSCALL_ENTRY_RET_SET as an + * unambiguous out-of-band signal. The field is not initialised by + * the entry assembly. + */ + regs->entry_flags =3D 0; add_random_kstack_offset(); r0 =3D syscall_enter_from_user_mode(regs, r0); =20 + /* + * Seccomp or ptrace may have set a return value and requested that + * the syscall be skipped. syscall_set_return_value() sets + * SYSCALL_ENTRY_RET_SET in regs->entry_flags as an + * unambiguous out-of-band signal. This avoids the ambiguity of + * using r0 =3D=3D -1 as the skip sentinel when the user themselves + * called syscall(-1). + */ + if (unlikely(test_and_clear_syscall_entry_ret(regs))) + return syscall_get_error(current, regs); + if (unlikely(r0 >=3D NR_syscalls)) { if (unlikely(trap_is_unsupported_scv(regs))) { /* Unsupported scv vector */ --=20 2.55.0