From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F4C4CD37B7 for ; Mon, 11 May 2026 09:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:To:From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LbfiKYp0BjJiBaKRav7eVm8nvSFoVg8FGD5F8goH9yE=; b=y89zRg+xyfuDM6KEEyojfscY+h J3Ya0gPdjbm5LhBmoVI+qiiecjH4YCJvoNb+DKfTUM0VAghdB4y28j+U/TdXkP0wZ95ykR2J/Nqbe 3B4JmetaBlWS+6Iud71t8p9BCskSxC+OqU3vk+7N6WndlNrekJLfGaRF4TFDCKAvGoEhOZOoie3jy Qy50R/S3ZPPyaHSKZSPk6eU7t8rslDkK4uPpJfgLyUOj7Qyqji3w9bu9y4v81g7wEQdhjR5Dz9jCK vFRvqR5Z0Nu4W4WCd1wyquQT0qv92h2B31cdrThKnxO6rxUe/C2cti2GM59dAoOo8ZTSClcbP2CKu hODOiUtw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMMq1-0000000CszN-0xBz; Mon, 11 May 2026 09:22:09 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMMpz-0000000CsxV-2LcX for linux-arm-kernel@bombadil.infradead.org; Mon, 11 May 2026 09:22:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description; bh=LbfiKYp0BjJiBaKRav7eVm8nvSFoVg8FGD5F8goH9yE=; b=CvQ0PY7vA2tN3gxCz8QhqOBJ3v CvgtOAAI6OiHoX6fdi6nFiOY2lQv9gLQAVaERap7xm41SyGGejQhLnLyz4ZBJjTo7WnBeaNMfmnE8 yQhVdNzLvHWirRJVUgK3uZUuTXkWUK6u9gE1j5j15+It9NdlkpFpNpb6aY8x+5fKsrql/2jjhl38W K4kZLrWEJuCts78O22thr9EbopQVFunKj5noEcPUNBhJ5PYI3w0dm+BvvegaBftQ0JC0tD8uRr3eU pxqXPW6juff4Gi6RCUU4W37zOj/fGRZ6MRuBdqLmTTerMS6qm0lhaLXuCj/xjtNpChhMbJ94bjJB9 DEDb7Zuw==; Received: from canpmsgout04.his.huawei.com ([113.46.200.219]) by desiato.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMMpu-0000000BA4T-3EEw for linux-arm-kernel@lists.infradead.org; Mon, 11 May 2026 09:22:06 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=LbfiKYp0BjJiBaKRav7eVm8nvSFoVg8FGD5F8goH9yE=; b=xydvXXV2eSRteu3BRkV0wMQzyQ7j/Z+cYvWbIz79iBXTpsLGFBzY51vAPBd5Fkkx0vVcAeAq9 Rw79nTj9ZIMM25QOkd0RKbHt4jlONxY77Zzjl/8veCzC6vs0KUJklq+To1FNbArIwhWBctILlvs PMqg3mm0nJqhdXxczlUtnus= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvK3JWvz1prKs; Mon, 11 May 2026 17:14:21 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id D5C1040572; Mon, 11 May 2026 17:21:59 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:21:58 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 06/11] arm64: ptrace: Move rseq_syscall() before audit_syscall_exit() Date: Mon, 11 May 2026 17:20:58 +0800 Message-ID: <20260511092103.1974980-7-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-1-ruanjinjie@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260511_102203_766523_71C98E4B X-CRM114-Status: GOOD ( 14.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Move the rseq_syscall() check earlier in the syscall exit path to ensure it operates on the original instruction pointer (regs->pc) before any potential modification by a tracer. [Background] When CONFIG_DEBUG_RSEQ is enabled, rseq_syscall() verifies that a system call was not executed within an rseq critical section by examining regs->pc. If a violation is detected, it triggers a SIGSEGV. [Problem] Currently, arm64 invokes rseq_syscall() after report_syscall_exit(). However, during report_syscall_exit(), a ptrace tracer can modify the task's instruction pointer via PTRACE_SETREGS. This leads to an inconsistency where rseq may analyze a post-trace PC instead of the actual PC at the time of syscall exit. [Why this matters] The rseq check is intended to validate the execution context of the syscall itself. Analyzing a tracer-modified PC can lead to incorrect detection or missed violations. Moving the check earlier ensures rseq sees the authentic state of the task. [Alignment] This change aligns arm64 with: - Generic entry, which calls rseq_syscall() first. - arm32 implementation, which also performs the check before audit. [Impact] There is no functional change to signal delivery; SIGSEGV will still be processed in arm64_exit_to_user_mode() at the end of the exit path. Cc: Mark Rutland Cc: Thomas Gleixner Cc: Will Deacon Cc: Catalin Marinas Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan --- arch/arm64/kernel/ptrace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 20441e0f6328..15a45eeb56da 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2456,6 +2456,8 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned long flags) void syscall_trace_exit(struct pt_regs *regs, unsigned long flags) { + rseq_syscall(regs); + audit_syscall_exit(regs); if (flags & _TIF_SYSCALL_TRACEPOINT) @@ -2463,8 +2465,6 @@ void syscall_trace_exit(struct pt_regs *regs, unsigned long flags) if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP)) report_syscall_exit(regs); - - rseq_syscall(regs); } /* -- 2.34.1