Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1914446ybm; Sun, 31 May 2020 02:37:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMRB1rkQFmM6LarxJh8YbJB5MZf7EZ/Is95BLZrKSNvxJ6ZkQj01llRKw0suKb+Ed44Rpb X-Received: by 2002:aa7:c682:: with SMTP id n2mr3937261edq.18.1590917868900; Sun, 31 May 2020 02:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590917868; cv=none; d=google.com; s=arc-20160816; b=n4eUwWF/IGUm1zn/fmtI+Z8aXT2nSjNHqcEes2JFusYWh4Q2k/EaciFVHpmwacdJZv gpJZuPGBC2rNF1mgfKkrUyVP85nfWKKkbhSjmCS09rc3qs3yZSMD3aCWnDyiKQdUKPzm Tk4HTqy5lZL2aAZ6bJ5MZrTLnhPvpr/tSFObBLRsNfOruXf+mVL8Zj1LezZ7WEd+L8jw dlyqQnRUdBihOcmAg37Iv1gYZJyPKMqvzSgNuOKbTrNnON7Gy5wK5051aMtEeGOG0ik/ y4cm5E8iMSNyc59FiWQPbNUM1jkj4Ib8+IrtX8tMhR8ei+ukoKgfZfibRV3zDwnzefXo 0JNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YuR4/IjqJjaFW1VPXwimshqKoCeqLeX1PjALR2ktjL4=; b=RrfIdg6ksvYs4UoKLfGsEwuaDmID0odmlhBrmocteJRAh1Hh9jg5Xl1trqBw3yj8mF 2igkdwVhPjnkdg5AbntNLqdSTHQEzJoGifji6lVNXY7PHKir/GK444qEJbv2MnvIELVw PDlBM9rjiFFWO1W4E01yf2CsNv//fIH2mFmZv29xCpr2Hc3nX9O6r7fM7SsdLvZ+Fi/W tGc/Qbnriw1/bEl/EEWS08BwqSWl02YUrZxjNtcqO3F4OmlBuGKGlXQm0r5Ud/ZImVH3 TDcBpu/EAATiasRIqg5hjg9VobsPdk+lfth71em3lwqERZKEqhM3e9lcyBBLLBylCiI9 lCgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QVgLaPjK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x20si10112849edi.323.2020.05.31.02.37.25; Sun, 31 May 2020 02:37:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QVgLaPjK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727942AbgEaJd1 (ORCPT + 99 others); Sun, 31 May 2020 05:33:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:36334 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbgEaJd0 (ORCPT ); Sun, 31 May 2020 05:33:26 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C00F620707; Sun, 31 May 2020 09:33:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590917606; bh=kbhIhCTvdYW4T4mcknrnXd2owAVuTRk+XLhdT0D6n/g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QVgLaPjKeNPKoDEZ3JzbTnF18GnJA5ji6Z7/k7XbKT9vyhxZX0am6CiqSmG5G8xZI 7zfxuddxUHbu/04/SOXjg60iwuTMZ7iRTiNMsfUUDqhvDbx+undYop7J56Az0Pg51r VZkcNB7+Mx+HVp74Zo3tw7nyo3RS3y9l7eaESOFY= Date: Sun, 31 May 2020 10:33:21 +0100 From: Will Deacon To: Dave Martin Cc: Keno Fischer , Catalin Marinas , Kyle Huey , Oleg Nesterov , linux-arm-kernel@lists.infradead.org, Linux Kernel Mailing List Subject: Re: arm64: Register modification during syscall entry/exit stop Message-ID: <20200531093320.GA30204@willie-the-truck> References: <20200519081551.GA9980@willie-the-truck> <20200520174149.GB27629@willie-the-truck> <20200527095528.GC11111@willie-the-truck> <20200527101929.GT5031@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200527101929.GT5031@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 27, 2020 at 11:19:29AM +0100, Dave Martin wrote: > On Wed, May 27, 2020 at 10:55:29AM +0100, Will Deacon wrote: > > On Sun, May 24, 2020 at 02:56:35AM -0400, Keno Fischer wrote: > > > Just ran into this issue again, with what I think may be most compelling > > > example yet why this is problematic: > > > > > > The tracee incurred a signal, we PTRACE_SYSEMU'd to the rt_sigreturn, > > > which the tracer tried to emulate by applying the state from the signal frame. > > > However, the PTRACE_SYSEMU stop is a syscall-stop, so the tracer's write > > > to x7 was ignored and x7 retained the value it had in the signal handler, > > > which broke the tracee. > > > > Yeah, that sounds like a good justification to add a way to stop this. Could > > you send a patch, please? > > > > Interestingly, I *thought* the current behaviour was needed by strace, but I > > can't find anything there that seems to require it. Oh well, we're stuck > > with it anyway. > > The fact that PTRACE_SYSEMU is only implemented for a few arches makes > we wonder whether it was a misguided addition that should not be ported > to new arches... i.e., why does hardly anyone need it? But I haven't > attempted to understand the history. > > Can't PTRACE_SYSEMU be emulated by using PTRACE_SYSCALL, cancelling the > syscall at the syscall enter stop, then modifying the regs at the > syscall exit stop? > > > If SYSEMU was obviously always broken, perhaps we can withdraw support > for it. Assuming nobody is crazy enough to try to emulate execve() I > can't see anything other than sigreturn that would be affected by this > issue though. So maybe SYSEMU isn't broken enough to justify > withdrawal. Indeed, my preference on another thread [1] was to remove it, but it would need agreement from Arm, since it was added by them (Sudeep). But setting that aside, Keno has convinced me that the clobbering of x7 on syscall enter/exit can cause some problems for userspace, so I think that having a way to disable that seems like a good idea. We can't change the current default behaviour, but having an explicit opt-in seems worthwhile. Keno -- are you planning to send out a patch? You previously spoke about implementing this using PTRACE_SETOPTIONS. Will [1] https://lore.kernel.org/r/20200515121346.GA22919@willie-the-truck