From nobody Fri Oct 2 13:03:57 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 D0DB53C6606 for ; Fri, 31 Jul 2026 08:15:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785485743; cv=none; b=G0Y+oikwuN3qhY1GIlyhSalIIxjvJeGTDjAfzGpfD4/c08p8pQ89vEMUx5qxQ8D0ZZhZp/4IObJoutA+X/rWx91wEiOLRRNpMWoqAOCiwTTU+injTjRzINPyF5geqdWzwaL9bgWt3yQfi2Z5CNWN+g+Tu0DN5kwe6pnxmXx6F8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785485743; c=relaxed/simple; bh=mTddoh9a0O1vK0v/uct4YxJDRHM+GF3kw/qWs0avgBk=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=oDntw3kIHoQjUyx1gSwCNSsCaq/APT1cVcZDXIaRywxCn6iob+CjeZjlF4D0znqMgB7eMtEbkCVRZ2ormx4dDgAyZvVEUXmeUOslzB17dfMQ6n8tM3u+G07gWGez/97Rl4UEHcGKGJEGHObsoW81qFk9t8D6vVltW/qz/EGG25A= 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=i17FdR9T; arc=none smtp.client-ip=209.85.214.182 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="i17FdR9T" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2cf452def93so12720235ad.1 for ; Fri, 31 Jul 2026 01:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785485733; x=1786090533; 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=L7qVGVE6k+yrpPk+UhHXnejs9qdoQvkOw+rsZvIfl6o=; b=i17FdR9TqHFqeztPvnO0Uu3z/Yowf84zMZZn+r1F8rY95IJepZAAhM2QBPCJz3Y4x3 WELxC/uhE1VGSqZcFyD0daanSMuDK0NJVRa5TMhsQZqNAQeUcOPEbp4nrPj+wY9Fo+DW IQ7dyeFJBjQ+JM8cpKWy+5JgqFGvVg1VQSWNw6koC7+U+bdkQEVmNdcsAH+PC5nq/hV3 jGtg5lEJPcWWEC8RrpFuPi+fSe2ENrNJ7kU6huHfp0Ea8d1wwW7YozHseZ0cKOneXZL3 9PRpY91o1OA5PZLpw6fYg3jPMdIz7wboj6jQyh3LbKDOPx4snwLP/8EDXaCoj+wrU/kO 6guw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785485733; x=1786090533; 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=L7qVGVE6k+yrpPk+UhHXnejs9qdoQvkOw+rsZvIfl6o=; b=fzHiItfnBT5IVjD8mVJJJTI2Q8GOxqR+3aXvYTdm0OzG2zeYnIjMQviQn/cn6x99Lb kcjfVWJbUGDBQUTCkIO61KdyrMRwx0LXq0LkkgzUPygM1FT7T7f6BNJv2zpwSQ+NC7ZC VmAFGtFhycfarjd7TvIP9pHvbh46n7yJUsojluTz5+yLf8gOteRKUPnK+oUBmX4ginUb J0L4fP/cc2HVgYCgHGanElUswLS7rn7PaEqYRIm/BnycWp4pLgYN7fKJcWgPUsa1NAVC t1qsxRM7kxMMRPhG+iebl7ul3LWROfMnOupp5r2ujClEvjzl9iZHoBLogCKvgbqqE5Ij QmZA== X-Forwarded-Encrypted: i=1; AHgh+RrvbG0tACoeY5ULZBA4qzy9nGRmVGau4rNK1rc/jCIgRZ9B5qbhoftlrXgLcPPFWbv3t4y9fkerxjdkypU=@vger.kernel.org X-Gm-Message-State: AOJu0YxbF/Bqylw4uJ486+W+c1obbvoSbNQPMYzHIb4kFUX2rAutWadt BAxCvb8KMz1eCY82LURZkBLeNyxMo9TomomF56rs7veQGAVbJ3yO6WsN X-Gm-Gg: AR+sD11V3boRDD2Ip7vF1BBgQpSdgQRBKvarfqoXsxnfflwNGkSFniIhGmT9Cu3K9ED OxEhlSNnulVJ6/hC30LOGMQv9Z9/3FsF90nniMx/DcBE3kVM3rZjKCNwQ96AQUavY5JU4WXawQl sPJ2Nc1YEj0QTSz/txsGvZkkoJdsyWL4gibnweHRD/YoLukKkbmBybFovRSIel/fjX3VwaojJcQ GfTZKvaO8W7WHvaCZTMDuytRV+B9X5uU1eq8b7G8ucmvS4kPWsf1XCCrOu7Eo/HBqdWtFecbvHW MiRXmOjkwvZRFFMgaCTpWvlnrgG8ucVl81iPiZuzlsu67/t1sjsbHZiHI4sjldxQaDipMGWiUIp x6KeO3qlaRqkyG+bRqNBZOoZL4qXJqFraD6cnKRmX8aVlQa0PqrY/FJoyzTspV27HM1MCy9ehur lEqLaS3gyIIHRggAfkpqTafNQ5BlAnHjWzf6J5n5/AeBZfYt5DluMuBkhtQzd8l2WcbKFrQSEFZ 6dc8WLje6Gy7L4WnIugWocgdcDvp1ONmhtZbIngDQ== X-Received: by 2002:a17:903:17c3:b0:2cf:bbdb:425d with SMTP id d9443c01a7336-2d047e38bc5mr8591215ad.18.1785485733348; Fri, 31 Jul 2026 01:15:33 -0700 (PDT) Received: from li-1a3e774c-28e4-11b2-a85c-acc9f2883e29.ibm.com.com ([106.51.160.163]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153e06fc98sm3088605eec.21.2026.07.31.01.15.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 01:15:32 -0700 (PDT) From: "Mukesh Kumar Chaurasiya (IBM)" To: maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, mkchauras@gmail.com, mchauras@linux.ibm.com, msuchanek@suse.de, sshegde@linux.ibm.com, david@kernel.org, thuth@redhat.com, agordeev@linux.ibm.com, mark.rutland@arm.com, ruanjinjie@huawei.com, ryan.roberts@arm.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH V6] powerpc/syscall: Fix syscall skip handling for seccomp and ptrace Date: Fri, 31 Jul 2026 13:45:21 +0530 Message-ID: <20260731081521.1852133-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 by introducing a thread flag that is set whenever syscall_set_return_value() explicitly updates the return value. In system_call_exception(), check and clear this flag before dispatching the syscall, and return the preset value directly when it is present. This ensures that an explicitly supplied return value always suppresses syscall execution, regardless of the syscall number. 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) --- v5 -> v6: - remove the pt_regs field and use preexisting thread_info flag. v5: https://lore.kernel.org/linuxppc-dev/20260714075935.1830145-1-mkchauras= @gmail.com/ v4 -> v5: - Fixed build failure where BITS macro is not available v4: https://lore.kernel.org/linuxppc-dev/20260707063729.387129-1-mkchauras@= gmail.com/ v3 -> v4: - Use syscall_get_error (Michal) v3:https://lore.kernel.org/linuxppc-dev/20260703081100.1681924-1-mkchauras@= gmail.com/=20 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/syscall.h | 6 ++++++ arch/powerpc/include/asm/thread_info.h | 1 + arch/powerpc/kernel/syscall.c | 3 +++ 3 files changed, 10 insertions(+) diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/= syscall.h index 834fcc4f7b54..19d1739af0b7 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_thread_flag(TIF_SYSCALL_RET); } =20 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/= asm/thread_info.h index ee3b9adb5b67..bf08b476fb3b 100644 --- a/arch/powerpc/include/asm/thread_info.h +++ b/arch/powerpc/include/asm/thread_info.h @@ -119,6 +119,7 @@ void arch_setup_new_exec(void); #endif #define TIF_POLLING_NRFLAG 19 /* true if poll_idle() is polling TIF_NEED_R= ESCHED */ #define TIF_32BIT 20 /* 32 bit binary */ +#define TIF_SYSCALL_RET 21 /* syscall error value set */ =20 /* as above, but as bit values */ #define _TIF_SYSCALL_TRACE (1<=3D NR_syscalls)) { if (unlikely(trap_is_unsupported_scv(regs))) { /* Unsupported scv vector */ --=20 2.55.0