From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37D96435EFD for ; Thu, 30 Jul 2026 13:27:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785418021; cv=none; b=fgAy4cOL/bj+MKDrgweKdsGQlwdeb+93wGEyDTiYgYbFPVuAF/BH8e91m7ZHIRJlnF6UwFKSldFdVUK83Zy5nLrI9i+aG12C0f+Kgn0nayAU7Sy7uGs4IRGa6RzRcHWjV7kHf+JY9Birgx6Q6KdayLsp4rafWMIT4r1KVDfhdE0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785418021; c=relaxed/simple; bh=kFQmtfd2iJpT6I7IMyHF8TIl2CFY1Zz4C/fGvPQaQEo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r/TrzaxEcBINFvO1x37F4Koj4q4ioLOgWn9iAwZsB53KBg1jO0aM+6dYtPXnXNeP/j++0y8vrdH+S6QCE2qhEotbkfW6mLCtRhPDRXQS+RuQFPk+YUcP94AZVGgcY+PoGE4vrb790VBYZIyRMymJo4jcfpvvuz744GUwvcM/LFw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XaMQFSAg; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XaMQFSAg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B4831F00A3A; Thu, 30 Jul 2026 13:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785418020; bh=C1ce9Ymnjm2nvkI/rfJMKPQme2TzcwLsmyRKNNh3nXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XaMQFSAg2lP3SZP3BaGZA7T/nQ97aZZVkldAI4noIpromQOZbtuIevxGS9qSg0waC DMWY/k6wXqF+g2lW345EAvNe0XxuO36ivlUE4YCy+wUqWRtDfoTHaYhDbnLx+oid6f 6pHDdIF/SdgsGbF1JcOMBasGNpzg/PM8f+i4yfndhbsayoq9eOnqZx7dI1fud7UIf/ cKQRNe4oxn29e3J45KEVHWbynavi+MHdMFcvMzY9VqvI7hU43P5CAng6jOiin7p5/i vDj+x0BO6h6xf+9irhJoJWSbHcLP+w7i/iDHHI9ur7v0Kc9h6W1iXfuw4Tp8ujuRu3 VPql/QSDtYD4A== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Kees Cook , Jinjie Ruan , Mark Rutland , Yiqi Sun Subject: [PATCH v4 1/2] arm64: ptrace: Keep 'orig_x0' in-sync with x0 on syscall entry Date: Thu, 30 Jul 2026 14:26:50 +0100 Message-ID: <20260730132651.25993-2-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260730132651.25993-1-will@kernel.org> References: <20260730132651.25993-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit e057b9477232 ("arm64: syscall: Ensure saved x0 is kept in-sync with tracer updates") attempted to resolve a long-standing issue with syscall entry tracing, where a tracer is able to manipulate the first syscall argument without being subjected to seccomp or audit checking. Unfortunately, that fix was incomplete [1], as it failed to update 'orig_x0' between a tracer updating x0 during a seccomp ptrace exit (SECCOMP_RET_TRACE) and the seccomp filter being re-evaluated. Rather than add hooks to the core seccomp code, instead move the synchronisation code into the ptrace GPR and syscall setting code so that 'orig_x0' is kept up to date with x0 whenever we're stopped on the syscall entry path. Cc: Kees Cook Cc: Jinjie Ruan Cc: Mark Rutland Link: https://sashiko.dev/#/patchset/20260716120640.6590-1-will@kernel.org [1] Reported-by: Yiqi Sun Link: https://lore.kernel.org/all/20260529065444.1336608-1-sunyiqixm@gmail.com/ Fixes: e057b9477232 ("arm64: syscall: Ensure saved x0 is kept in-sync with tracer updates") Fixes: a5cd110cb836 ("arm64/ptrace: run seccomp after ptrace") Tested-by: Jinjie Ruan Signed-off-by: Will Deacon --- arch/arm64/kernel/ptrace.c | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 4d08598e2891..7a97865acb79 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -560,6 +560,42 @@ static int gpr_get(struct task_struct *target, return membuf_write(&to, uregs, sizeof(*uregs)); } +static void update_syscall_orig_x0_after_ptrace(struct task_struct *target) +{ + struct pt_regs *regs = task_pt_regs(target); + struct kernel_siginfo *info = target->last_siginfo; + + /* + * Skip the update for NO_SYSCALL (set either by the user or the + * tracer), as regs[0] holds the return value (see the comment in + * el0_svc_common()) and can be unwound using syscall_rollback(). + */ + if (regs->syscallno == NO_SYSCALL) + return; + + /* We should only be called when target is in a ptrace stop */ + if (WARN_ON_ONCE(!info)) + return; + + /* + * For compat tasks, orig_r0 is provided directly through GPR index + * 17. + */ + if (is_compat_thread(task_thread_info(target))) + return; + + /* + * Don't update orig_x0 for a syscall-exit-stop, as x0 now contains the + * return value of the system call. + */ + if ((info->si_code & ~0x80) == SIGTRAP && + target->ptrace_message == PTRACE_EVENTMSG_SYSCALL_EXIT) { + return; + } + + regs->orig_x0 = regs->regs[0]; +} + static int gpr_set(struct task_struct *target, const struct user_regset *regset, unsigned int pos, unsigned int count, const void *kbuf, const void __user *ubuf) @@ -575,6 +611,14 @@ static int gpr_set(struct task_struct *target, const struct user_regset *regset, return -EINVAL; task_pt_regs(target)->user_regs = newregs; + + /* + * Keep orig_x0 authoritative so that seccomp (via + * syscall_get_arguments()), audit and the restart path all see the same + * first argument the syscall is dispatched with, even if it has been + * updated by a tracer. + */ + update_syscall_orig_x0_after_ptrace(target); return 0; } @@ -753,6 +797,12 @@ static int system_call_set(struct task_struct *target, return ret; task_pt_regs(target)->syscallno = syscallno; + + /* + * Re-sync orig_x0 in case the syscall number has been changed + * from NO_SYSCALL. + */ + update_syscall_orig_x0_after_ptrace(target); return ret; } -- 2.55.0.508.g3f0d502094-goog