Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp739232ybk; Wed, 20 May 2020 10:43:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNPxXXLdoShp94kwyKrd3GUwcJ0L66Bpv1CvUYPoesEJ4G776jpOZ1TDbmYvew+ho/mNd8 X-Received: by 2002:a17:906:9a1:: with SMTP id q1mr180740eje.296.1589996620808; Wed, 20 May 2020 10:43:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589996620; cv=none; d=google.com; s=arc-20160816; b=rtcuNJ5yhUFE4zercu/l8mLqt4Ob7qotPr6Dyxow1PS0Bt0sHvHcveW27w3SdieSaT 889dk7VALfSLCt2H40HjgOgKuCXkVkI3exy6DLxSEvIXdJuSv+fbMOU6UPQvZbeCbREq MwlsxJa44IaWqvNDXVKN5V+unSHxtf67vsNZh2cBDotZ9A/9UVCW3uK9AblF12ExoDy6 PT3O+cVbMtl4o3wFMRc3ovNeduMPheJyLvLnKUb9CPVkE0rx9SGJEHYXBe8JylJsn6DN J3YLXl/0frG+PivWOwgb62R3ql/c80gE/EXTIbczF2Ko6Zh7/RXzUgfd88CXgSaz0SVw NCaA== 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=+WXF+Rq/iWC2vRa1UvPuuLEW4snNK50L8VWxGKktza0=; b=fLIMnDDLNa0Yzb6nLRHQTg0noamj0gD/NLhVYWSJejsnkRYCOmL6zapOvTAEngdmL+ 05j+oiL9W/yDuFJ+t3xa3ErLlJYw9ganDrnITojIbeDP3UVKlvEY7O1MPKqcgmyjs4mj xXcdp0NeGcy6KCpQmsv416SEWWHOYXrZMmrAtOus7wgB6sgS0Dklih7AGv6bMQmRPft0 5dAz/ltGeX8CtQecjiihi2LcTwLFv71v6DU/PTwGYKFnSeWat1UhjrNEg+EN+naTD5R1 My30r2DM9WFKuU34ed8Qy2u83kvlSWyLep5Seuth41CTyXcMPHSN8TYmgDzvnYYDHrn1 oIOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kNyKyCDz; 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 u6si1857480edx.460.2020.05.20.10.43.17; Wed, 20 May 2020 10:43:40 -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=kNyKyCDz; 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 S1726785AbgETRlz (ORCPT + 99 others); Wed, 20 May 2020 13:41:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:52254 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726439AbgETRly (ORCPT ); Wed, 20 May 2020 13:41:54 -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 35DF020709; Wed, 20 May 2020 17:41:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589996514; bh=vwO5w+JtVONHfb0euQ8pgchCgtobqFMlado05i6hxzE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kNyKyCDzEBiEp9U/hzypTeDYnsOS2t6Wh55G/pV23Pg0+rv8ymIZsfBsT6iYxVLMg YuSOHyJ2aM5+x5TC5MbYPPx1BZ5uQyaiujC8mclcVJCNusddgnmCGP3hPPKFvmeQ8l N/D88s10AuUVD503Mi/ctOIw0KF+NZINj+0+OFCo= Date: Wed, 20 May 2020 18:41:50 +0100 From: Will Deacon To: Keno Fischer Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Oleg Nesterov , Linux Kernel Mailing List , Kyle Huey Subject: Re: arm64: Register modification during syscall entry/exit stop Message-ID: <20200520174149.GB27629@willie-the-truck> References: <20200519081551.GA9980@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Hi Keno, On Tue, May 19, 2020 at 04:37:34AM -0400, Keno Fischer wrote: > > Yes, we inherited this from ARM and I think strace relies on it. In > > hindsight, it is a little odd, although x7 is a parameter register in the > > PCS and so it won't be live on entry to a system call. > > I'm not familiar with the PCS acronym, but I assume you mean the > calling convention? You have more faith in userspace than I do ;). For > example, cursory googling brought up this arm64 syscall definition in musl: > > https://github.com/bminor/musl/blob/593caa456309714402ca4cb77c3770f4c24da9da/arch/aarch64/syscall_arch.h Hmm, does that actually result in the SVC instruction getting inlined? I think that's quite dangerous, since we document that we can trash the SVE register state on a system call, for example. I'm also surprised that the register variables are honoured by compilers if that inlining can occur. > The constraints on those asm blocks allow the compiler to assume that > x7 is preserved across the syscall. If a ptracer accidentally modified it > (which is easy to do in the situations that I mentioned), it could > absolutely cause incorrect execution of the userspace program. > > > Although the examples you've > > listed above are interesting, I don't see why x7 is important in any of > > them (and we only support up to 6 system call arguments). > > It's not so much that x7 is important, it's that lying to the ptracer is > problematic, because it might remember that lie and act on it later. > I did run into exactly this problem, where my ptracer accidentally > changed the value of x7 and caused incorrect execution in the tracee > (now that incorrect execution happened to be an assertion, because > my application is paranoid about these kinds of issues, but it was > incorrect nevertheless) > > If it would be helpful, I can code up the syscall entry -> signal trap example > ptracer to have a concrete example. I guess I'm more interested in situations where the compiler thinks x7 is live, yet we clobber it. Will