Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6243316iob; Tue, 10 May 2022 13:47:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmln/shlmiYwwGQErvZdPo/vyqOAvur9XHs+lABsW49SjmnUcxvMK02HedzwaoK5XSt7rB X-Received: by 2002:a17:907:160e:b0:6f4:54c0:657e with SMTP id hb14-20020a170907160e00b006f454c0657emr22039433ejc.253.1652215623058; Tue, 10 May 2022 13:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652215623; cv=none; d=google.com; s=arc-20160816; b=fOAoHMSzWC6VH4WfbliBAhVPT5e/NGVqCwcKH+pNe95SxHcLqQAjfextiVVGnveDio QfUJFseV0izuQ0nL9RTs1bHO1FZ5SyKnNYqxZs5cdvjcYqwtBOt0HE4m13DA48aowPQc oOP8ZYA2Y4QPXi6jU9uL1zj43BhoZLSOKWnIAWrSJXrQSZ97mBcLdynWeCYvPY95WTqV eSSArZcl9VpD/eNVxH+v53mPoOVW2dqNU/1ir7FgJPbZaewg/95kYT2IwIS0n8KCt66E stcj3rdDQ/9ZiPYuR2Y2XewTnulJqeIh8CB83EFSALM0pjM7xK4WaqRi5IQXN5l20+xt xaLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=GngUY6bplhMg0RrdQ0bPUIqORATO7gGxxWbcA4rSjSI=; b=I5k1BPBXQJNDSqdzBfPMZxCVkxp9Cag6FLAbaJ3co7l0029yaSBkfp+54ubCelFNf5 QJPJkR+nDXtXMRV+cUMZuJzkxjqD0hFV5mtc0QMtnTuLOwMjnlN8hPKKlRIRpkgoCAAY QhNKkYfGtKpFqLRZNlKBANwC7VRUde8fVv1KxWINQiBhzjheNCe2VHi0zlpMNXEKCmDm HqO1SWWp2RfFWBEAjPYcl9S4j9cVf+Jh5pAkjA8e5jQSvFhesXJ7KkGfki7747AOn0RY b5HyH7yBhvfcf/WF6j3GAgoEbLxcvOIOE0JtKQ1L4OC+CWPrM6gJCxht430YX7t2s+Sg szzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ftzgu9vN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt8-20020a170907728800b006f3a02976f6si421109ejc.484.2022.05.10.13.46.40; Tue, 10 May 2022 13:47:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ftzgu9vN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S244193AbiEJOpA (ORCPT + 99 others); Tue, 10 May 2022 10:45:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344748AbiEJOoi (ORCPT ); Tue, 10 May 2022 10:44:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CAE524641E; Tue, 10 May 2022 07:03:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1849B6062B; Tue, 10 May 2022 14:03:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B0D7C385C2; Tue, 10 May 2022 14:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652191419; bh=KjDXrMRIgjl9mqK+1lZepnUpO/sXpVuQ6BE0MJGcLl4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ftzgu9vNda3LniGP6pt1aUYcmfQNMsGRCzzkPe7Ju5jVv55Vo8Km6RS6REDd052BK ZPSzQRrNz/z5Du+mxpMlcqlPRTPsmXopKmmYWzaDphQboUeez0V7FKSP1JjN23tjlb YbJIEKiZUVtLttBvGAarW3b+yiJOB2QP7KW1vJBiLvnWPZAb6OYhQqogyC9ukkZgj4 JkP8meYhGRCkL0uFRsxf0b5UAMx61qj+hYK3iSmMDh4I6KugoCSWl0zalm+qzFmdLE f0pb8YOFwvDDTqVNFf219lp7UUQPvIwvUm5Y3ccEBaBLTXfjz6Lc80JiSmYd/GrMkM zVa5iw1mP7J7g== Date: Tue, 10 May 2022 15:03:33 +0100 From: Will Deacon To: Francis Laniel Cc: linux-arm-kernel@lists.infradead.org, linux-trace-devel@vger.kernel.org, Catalin Marinas , Mark Brown , Peter Collingbourne , Mark Rutland , Kees Cook , Daniel Kiss , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v1 1/1] arm64: Forget syscall if different from execve*() Message-ID: <20220510140333.GA28104@willie-the-truck> References: <20220509151958.441240-1-flaniel@linux.microsoft.com> <20220509151958.441240-2-flaniel@linux.microsoft.com> <20220510105948.GB27557@willie-the-truck> <2826417.e9J7NaK4W3@pwmachine> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2826417.e9J7NaK4W3@pwmachine> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,LOTS_OF_MONEY, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 10, 2022 at 03:00:11PM +0100, Francis Laniel wrote: > Le mardi 10 mai 2022, 11:59:48 BST Will Deacon a ?crit : > > On Mon, May 09, 2022 at 04:19:57PM +0100, Francis Laniel wrote: > > > diff --git a/arch/arm64/include/asm/processor.h > > > b/arch/arm64/include/asm/processor.h index 73e38d9a540c..e12ceb363d6a > > > 100644 > > > --- a/arch/arm64/include/asm/processor.h > > > +++ b/arch/arm64/include/asm/processor.h > > > @@ -34,6 +34,8 @@ > > > > > > #include > > > > > > +#include > > > + > > > > > > #include > > > #include > > > #include > > > > > > @@ -250,8 +252,12 @@ void tls_preserve_current_state(void); > > > > > > static inline void start_thread_common(struct pt_regs *regs, unsigned > > > long pc) { > > > > > > + s32 previous_syscall = regs->syscallno; > > > > > > memset(regs, 0, sizeof(*regs)); > > > > > > - forget_syscall(regs); > > > + if (previous_syscall == __NR_execve || previous_syscall == > > > __NR_execveat) > > > + regs->syscallno = previous_syscall; > > > + else > > > + forget_syscall(regs); > > > > Hmm, this really looks like a bodge and it doesn't handle the compat case > > either. > > > > How do other architectures handle this? > > My understanding of others architectures is quite limited, but here are my > findings and understanding of some of them: > * arm (32 bits) EABI: start_thread() sets r7 to previous r7 for ELF FDPIC and > to 0 for other binfmts [1]. > * arm (32 bits) OABI: syscall number is set to -1 if > ptrace_report_syscall_entry() failed [2]. > * mips: start_thread() does not modify current_thread_info->syscall which is > taken directly from v0 [3, 4]. > * riscv: start_thread() does not modify a7 [5]. > * x86_64: start_thread_common() does not touch orig_ax which seems to contain > the syscall number [6]. Hmm, so the million dollar question is why on Earth we have that forget_syscall() call to start with. Amusingly I've, err, forgotten; forget_forget_syscall() perhaps? Catalin? It's been there since day one afaict. Will