Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1180120imi; Fri, 1 Jul 2022 04:55:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v3e1+/2wgu7C0ASQ/bx6rLnpe4J6bnosCwLj1VvEtWpOD+ohI0w2RQ/Tu5awzoikTu02FK X-Received: by 2002:a63:4c57:0:b0:40d:d28e:bfb1 with SMTP id m23-20020a634c57000000b0040dd28ebfb1mr12636141pgl.77.1656676550151; Fri, 01 Jul 2022 04:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656676550; cv=none; d=google.com; s=arc-20160816; b=wqcDFGrVJYgpkFAXAf9ckExjX64nJ7lX6KOzeWxcvJ3Ukx5cLMjCIDnk/7o5vOVlkI gP886yTza2dyg4SZgcmDVSCIUMor4WCwiLkSZOmr+g49c9Ptig3zsI2vnirfQd38TxLm jTMLIq7dmV0tCBa8tvkXTir6q2n6vhGo7xDmLSw7poLCI0a5Gf3GLh0IpDXOjOVn1xpR 2ycLOQSvGnNg3GhbqWZM019eGUd7LvczN1GNGVq0VfPgxxhLCKQ8wDaFffX5XnsqQi9o 0m2aFca0WFY6CZ1h83EMbx8qui4XGHt84hqLBoUIVEJgHUAq0rkdJDktE25zabgZfnT/ n9yA== 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=K6Z9FCdWuk2MYdNd2UKjF0QN6thecXJY6sw8pEEV1Yo=; b=yFLsP2Awbi1rliAMjOXILSINanJTRFcj2LU7rlF4wzQZeEoJGrFwvy96v9248LMeRM Mob4kfFzL7r7d9alxCgqXmT+S1+YLFRMnOBeJ+2JRUPl/40EWKZQE41gBrv7iEY+ASf+ QgIA60+14POSKqutLcgNvKEkp3S5gApuHMpxXOswec49azXmH5COmMtkNCX6nqu5IbXX 6+Pcyo0ejecTT/hZu0UbVs8SxVFlXbOhbC0NaaHo2xZyA6BsrhLW1BVz70DLM1G0dH3V DbaSIVo9dRg5WkpGEFaXXKvDUheGI0i2hXpNx+CjXWT5Vv/fReJwPmnyCjSkOt+kex+Q 0nkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qyZWqqP3; 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 oe17-20020a17090b395100b001eca4dac6d2si2016008pjb.77.2022.07.01.04.55.37; Fri, 01 Jul 2022 04:55:50 -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=qyZWqqP3; 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 S230045AbiGALgo (ORCPT + 99 others); Fri, 1 Jul 2022 07:36:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234207AbiGALgl (ORCPT ); Fri, 1 Jul 2022 07:36:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD80D814AE; Fri, 1 Jul 2022 04:36: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 ams.source.kernel.org (Postfix) with ESMTPS id 8F7CDB80813; Fri, 1 Jul 2022 11:36:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8F63C3411E; Fri, 1 Jul 2022 11:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656675398; bh=ht0/icXtp2sEhQfzOe1RuBtF1QGRO0mLy1F9NHIwIJo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qyZWqqP3YjsMKExY+ED0ZanHiTPDFeMdcC/nLGmH+vSBWrYqBQh8SxDCTc5Q21gLf Lv5facBuIZ1jWgWiHzMjhxV4Occp1skkxdu6vo21XEI1H/F53M6Ye4LgopehyHWt49 htVQPCblbBFrPs9L7ob86ybN7B2z263YOm5+d3cq+yTRVCh0+rvTSDCHjwePEH5+wo XEndL5gBSwwkmwkIWxSXidRDERgwEVE4V96JMjZ6g0aIzNE1k2HqV4wEZsAVbitjak PC9dlRbm/nJ44eKV1THZwK+9YC2Sx7dSYUGjsd2DMCBAEuX9rSalrKbr+HGGdzg/1b A5IWpBj0QR6GA== Date: Fri, 1 Jul 2022 12:36:32 +0100 From: Will Deacon To: Francis Laniel Cc: linux-trace-devel@vger.kernel.org, James Morse , Daniel Kiss , Catalin Marinas , Mark Brown , Peter Collingbourne , Kees Cook , Mark Rutland , Christophe Leroy , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/1] arm64: Do not forget syscall when starting a new thread. Message-ID: <20220701113631.GC28070@willie-the-truck> References: <20220608162447.666494-1-flaniel@linux.microsoft.com> <20220628135834.GA24116@willie-the-truck> <3439466.iIbC2pHGDl@pwmachine> <4722000.GXAFRqVoOG@pwmachine> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4722000.GXAFRqVoOG@pwmachine> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Thu, Jun 30, 2022 at 07:16:44PM +0200, Francis Laniel wrote: > Hi. > > Le mardi 28 juin 2022, 21:26:32 CEST Francis Laniel a ?crit : > > Hi. > > > > Le mardi 28 juin 2022, 15:58:35 CEST Will Deacon a ?crit : > > > On Wed, Jun 08, 2022 at 05:24:46PM +0100, Francis Laniel wrote: > > > > This patch enables exeve*() to be traced with syscalls:sys_exit_execve > > > > tracepoint. > > > > Previous to it, by calling forget_syscall(), this tracepoint would not > > > > print its information as syscall is -1. > > > > So, this patch removes call to forget_syscall() and set regs->syscallno > > > > to its previous value. > > > > > > > > Signed-off-by: Francis Laniel > > > > --- > > > > > > > > arch/arm64/include/asm/processor.h | 3 ++- > > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/arch/arm64/include/asm/processor.h > > > > b/arch/arm64/include/asm/processor.h index 9e58749db21d..86eb0bfe3b38 > > > > 100644 > > > > --- a/arch/arm64/include/asm/processor.h > > > > +++ b/arch/arm64/include/asm/processor.h > > > > @@ -272,8 +272,9 @@ 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); > > > > + regs->syscallno = previous_syscall; > > > > > > I'm still unsure about this. Even if we preserve the syscall number here, > > > won't all the arguments be reported as 0? > > > > I am not really sure what you meant about arguments, can you please precise > > between command line arguments (ls -al) and syscall arguments (argp, envp, > > etc.)? > > Indeed, if my understanding is correct syscall arguments are showed by > > sys_enter_* while sys_exit_* only reports the syscall return code. > > > > Regarding the return code I think the value is correct as it is used in > > syscall_trace_exit() but set in invoke_syscall() after the syscall finishes > > [1, 2]. > > The comparison of arm64 and amd64 output also shows no difference: > > # amd64 > > ls 435739 [002] 24689.292479: syscalls:sys_exit_execve: 0x0 > > 7fc43732e100 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) > > # arm64 > > ls 266 [000] 34.708444: syscalls:sys_exit_execve: 0x0 > > 1140 [unknown] (/usr/lib/aarch64-linux-gnu/ld-2.31.so) > > > > > I also looked quickly at the 32-bit arch/arm/ code and it looks like the > > > same behaviour exists there (module CONFIG_BINFMT_ELF_FDPIC). > > > > I tested arm32 and it is not affected (even though I did not have > CONFIG_BINFMT_ELF_FDPIC set). > Here is ftrace output for arm64 without this patch: > bash-316 [000] ..... 72.167342: sys_execve(filename: > aaaaf9bbcd30, argv: aaaaf9bb54f0, envp: aaaaf9a7d9b0) > Here is the output for arm64 with this patch: > cat-313 [000] ..... 417.926073: sys_execve(filename: > aaaaee7ce9f0, argv: aaaaee7833a0, envp: aaaaee6a69b0) > cat-313 [000] ..... 417.939619: sys_execve -> 0x0 > And here is output for arm32: > cat-254 [000] ..... 127.804128: sys_execve(filename: 5bff18, > argv: 53bb00, envp: 5543a8) > cat-254 [000] ..... 127.809142: sys_execve -> 0x0 > From the above, the arm32 output seems correct even though: > # CONFIG_BINFMT_ELF_FDPIC is not set > > After some debugging, I realized that arm32 syscall_get_nr() uses abi_syscall > to get the syscall number and not a register (I guess abi_syscall was set to > value of R7 before) [1]. > So the fact that regs->uregs are memset'ed to 0 is not a problem. Thanks for confirming this, I'll go ahead and queue your patch and let's hope nothing breaks :) Will