From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218]) (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 8E2EE30C372 for ; Sat, 25 Jul 2026 09:44:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.32.30.218 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784972697; cv=none; b=uSyGzcsgLV/P7K3Vvthm9IBDKvscoUMMsIf6PhcTDNq077uqvwNt435k8Ftcoboe1RcOxk7fWby4G8iIZ4sbW5FwFhi39rChJQdsjtArleeWY9Ec8gOF9R4c/0g2yzzQPlVCG7V7/ts7uoGGAHunpDinayOUKlomWM/9w2e6VQQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784972697; c=relaxed/simple; bh=KAFcm/kZJqkrKVXu2l24dQImgjc+rOzQGaLsOYFhH2g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RtXDVvZ/Wk9qZI3tnJlbrfnnzMEHOTNqQUJlwx7Z+vo8bkPEhxWfQTvCXZJDi0A5v780q5aexZfoEOPSIdXjcwhFyong6RIGB2BGUVfybtJCKhxw7dvcJcjoDmOa9l8y/JRNSj/OBQNgzWz5cFYwak6bhq/Ax+p672H2CSElews= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk; spf=none smtp.mailfrom=armlinux.org.uk; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b=cSvQdan3; arc=none smtp.client-ip=78.32.30.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="cSvQdan3" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=nse59uKSbhPUMpbFVq/RzvbJFREq8A6NSpxrD2lV2Eo=; b=cSvQdan3pvRVS4EwxQk562Dshw JukCR/vsQNXtCHZVrP6c3WX6BreP+S27k+mG2G/aFIplstqFLSUocJAt1UxuDvcBpN7rIRkFJT9iN HRf0rOQEA6ONjF9bIGEKTGQpexHi5LkAN2f8I5VUB848skla2PIw/LG4Bz/Ca3rCCEDUcztCtL/RH nIclT9+Vt0RnGFSea5LYJfU7EARAVVaPWwU9YFC7UdWqiPa58IOy1B07Co5a6Of16hUWTHOTbJFa2 S8wOeC+AnF/M52BiKHpmY+ipWCnQcDI68IeTVJNF7yGpEIrZNdqVJq8bwl7ODUa2n/+OUI6U1KgQO L6b2iwbw==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:38466) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wnYvo-000000002ZR-0d1t; Sat, 25 Jul 2026 10:44:32 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.98.2) (envelope-from ) id 1wnYvk-000000000Cy-2sNh; Sat, 25 Jul 2026 10:44:28 +0100 Date: Sat, 25 Jul 2026 10:44:28 +0100 From: Russell King To: Jinjie Ruan Cc: oleg@redhat.com, wade_farnsworth@mentor.com, will@kernel.org, stevenrwalter@gmail.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ARM: ptrace: keep ARM_ORIG_r0 consistent with ARM_r0 after ptrace writes Message-ID: References: <20260725091452.1875627-1-ruanjinjie@huawei.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20260725091452.1875627-1-ruanjinjie@huawei.com> Sender: "Russell King,,," On Sat, Jul 25, 2026 at 05:14:52PM +0800, Jinjie Ruan wrote: > When ptrace modifies r0 during a syscall-entry stop via PTRACE_SETREGS or > PTRACE_POKEUSR, ARM_ORIG_r0 is not updated. This causes seccomp filters > and tracepoints to read stale arguments, which disagree with the actual > value dispatched by the kernel. This is particularly critical for the > SECCOMP_RET_TRACE re-evaluation path. > > Fix it by synchronizing ARM_ORIG_r0 after every arch-level ptrace register > write. The update safely skips syscall-exit stops (where r0 holds the > return value) and NO_SYSCALL states to avoid corrupting non-syscall > contexts. And use ARM_ORIG_r0 in audit_syscall_entry to fix data > inconsistency with seccomp/tracepoints ARM_ORIG_r0 is intentionally not always the same as ARM_r0, just as orig_eax is not always the same as eax in x86. These exist to allow syscall restart as ARM_r0 / eax will be overwritten when a syscall returns. I don't see arch/x86/kernel/ptrace.c::putreg32() needing this kind of fixup, so why does ARM? ARM_ORIG_r0 is set to the value of ARM_r0 when a syscall is entered, otherwise it is set to ~0 as for other exception cases, the value is meaningless (there is no syscall restart in that path.) If one changes both ARM_ORIG_r0 and ARM_r0 during the syscall exit path to e.g. -ERESTARTSYS and then raises a signal against the user program, then is it not possible that do_signal() to then see that case, and as regs->ARM_ORIG_r0 would now also contain -ERESTARTSYS, call the syscall with the first argument set to -ERESTARTSYS rather than the user's actual value? Userspace has full access to both ARM_r0 and ARM_ORIG_r0, and can decide what it wants to do in the same way that userspace has access to eax and orig_eax on x86. Please check how this is handled on x86. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!