Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp413522lqp; Thu, 4 Apr 2024 18:22:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUUO+bSjm7irf7kkL/ZsyUfTPZvLjaubPiGuvRvsOXEpwUaVVTILtnxAeW9GCy0p+1Gtech86sysE0CO6FpnZhRTg5xafQCU/nGjAmrHQ== X-Google-Smtp-Source: AGHT+IFPmp7efMz3UvEhvBE0R7B5Sp8bnQo044a3KXU+YwZQJzWu/mziEgkQzXiIMuL58o/jCk2s X-Received: by 2002:a17:907:7751:b0:a4e:7f12:37c5 with SMTP id kx17-20020a170907775100b00a4e7f1237c5mr857476ejc.7.1712280142608; Thu, 04 Apr 2024 18:22:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712280142; cv=pass; d=google.com; s=arc-20160816; b=RmYGSil+YWDOa9MEUMmQo4ukQUO6iVQLTCzZuCVy0F4E/xZynCGoaw2dQ9l6S8ZYmz YbG8bLY28vR85lUgLW7MPQMjLaNnNNk0knD5YdpS8RXZOFMgtVcRHmHu3iJm8dqhchzj 78cS8aJNxB5iZ+QIhVAaXx/3prfNNwFr2sGQZHwIo+FXK6Xv/c/UVYju4MukAdQsbDw/ 9QZrAXLmXEHMzVtu9zW07asGEbeUc/dSLvPEFiVc9EOp/6fcju+L1TMR1L3t222flUlp CsdGblvVALtrDrPgmrFL4TqpOCrGUENUIb7oybT14k4DuFKu1+Grn9fcB4qcIU9uhAx+ Eq4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=zPe2YuTcsS2eytmVpSLp2Wg7rkOb3LBaZkutCxMUbgQ=; fh=vXBA0wvYIfdrOIKh9OS6IksddpsZcqqO+C1qtPFgVDc=; b=oVRy7zLUjyF1C93S3K/nnMofHo28+YOwQbVY94zAReJkyCf/ezmsCHOiE+cSQSUhJt Nq4zi+AeuFChEU96jruMnJ0lNC0ih2JlEJ6Pc6OAn+2k3We6u9RtD/dz/uxq1uNipKec 1+8vZAGtwUxwlcMFNnV5LoHsdVeAGQ2x5fMlSbfjdp58DU2gx34bNWjkJmbINyg2QGEh p8F5fcQEqEOiEULJd7LXKueEyJ1Pw7hp2zv/NZr8bCkwMRFdlwDQ6uKYYVrigQbtGLMX N39g8jlKVn2mGt8Uj+FGwXUtOl0gHGcL164ATdjvSGFMdGv13KhjecOfyRpBillnspQ6 Mo7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pWghTJZU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-132303-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132303-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ov10-20020a170906fc0a00b00a46b46a4319si181916ejb.717.2024.04.04.18.22.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 18:22:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132303-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pWghTJZU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-132303-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132303-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2EDE11F224BF for ; Fri, 5 Apr 2024 01:22:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71C7AD2FA; Fri, 5 Apr 2024 01:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pWghTJZU" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7FC1A7484; Fri, 5 Apr 2024 01:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712280130; cv=none; b=NJ2M24clVjY+4eUKka5WY13RNfTlbTwvb91PSVIi1l3w/A+PKBl3q10ERMdyUCPBLTDyhEJi2JWakQyU7UDLqHordWsAQm1udXTNLduGEXMPArk/IgqGHnrhcbzzG7/+1npm3er0gaU4YuciK1VJwhJXwhB82c7GxdqRtC06ZQ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712280130; c=relaxed/simple; bh=szljdTDB94eQ+EkiXsSkkkx9Poh6qFx1veGM9Mfl0+w=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=oeiiWVwGy2IVqb4hOhaoM9NCq9tf7EUauDslv1ouxgfLP4vcCRVFvhf+QrjBS8yikSuEG4/KcS92meUpETLiVulYio4P8EuJM/BqVnE/nxf3v8tf9/fNau51jPfblzk+9Er95KMXzWE3ks+rfaJ72xwdW8ETE3EJXV+mgS1nTOo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pWghTJZU; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A8CEC433C7; Fri, 5 Apr 2024 01:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712280129; bh=szljdTDB94eQ+EkiXsSkkkx9Poh6qFx1veGM9Mfl0+w=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=pWghTJZUHmUJad0KDGhWYm1a9qB9arTjFvpqXMQ7nVDgKzHACTber46um0xQNJNQO 4KQDZEG0lw6FGodDUdKkwzX1El///teqLI1cWXh4SNJtGdzWAHThtnSKKdiFlbZ+Rp /3ZpiKOD0MENLm5kf70YSRuzRE34dHbCCzKfJs58yocLrCdbHZ2x5XibvfvpLkl/sf XcssPS5/y0T6Q/xeWmBwbbYLaN4Gb6G94Pc6uglyGHejEF1yxWnthCIg0XYbkyZuYD 1jVuQhiowsnC+EbIT9qMm133Af2MTnerT5G4ZMKfIBFufXYBiqUgilNrWE2W0kFlxW ANrVfPjxgeWYQ== Date: Fri, 5 Apr 2024 10:22:03 +0900 From: Masami Hiramatsu (Google) To: Oleg Nesterov Cc: Andrii Nakryiko , Jiri Olsa , Steven Rostedt , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, Song Liu , Yonghong Song , John Fastabend , Peter Zijlstra , Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org, linux-api@vger.kernel.org Subject: Re: [PATCHv2 1/3] uprobe: Add uretprobe syscall to speed up return probe Message-Id: <20240405102203.825c4a2e9d1c2be5b2bffe96@kernel.org> In-Reply-To: <20240404161108.GG7153@redhat.com> References: <20240402093302.2416467-1-jolsa@kernel.org> <20240402093302.2416467-2-jolsa@kernel.org> <20240403100708.233575a8ac2a5bac2192d180@kernel.org> <20240403230937.c3bd47ee47c102cd89713ee8@kernel.org> <20240404095829.ec5db177f29cd29e849169fa@kernel.org> <20240405005405.9bcbe5072d2f32967501edb3@kernel.org> <20240404161108.GG7153@redhat.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Thu, 4 Apr 2024 18:11:09 +0200 Oleg Nesterov wrote: > On 04/05, Masami Hiramatsu wrote: > > > > Can we make this syscall and uprobe behavior clearer? As you said, if > > the application use sigreturn or longjump, it may skip returns and > > shadow stack entries are left in the kernel. In such cases, can uretprobe > > detect it properly, or just crash the process (or process runs wrongly)? > > Please see the comment in handle_trampoline(), it tries to detect this case. > This patch should not make any difference. I think you mean this loop will skip and discard the stacked return_instance to find the valid one. ---- do { /* * We should throw out the frames invalidated by longjmp(). * If this chain is valid, then the next one should be alive * or NULL; the latter case means that nobody but ri->func * could hit this trampoline on return. TODO: sigaltstack(). */ next = find_next_ret_chain(ri); valid = !next || arch_uretprobe_is_alive(next, RP_CHECK_RET, regs); instruction_pointer_set(regs, ri->orig_ret_vaddr); do { if (valid) handle_uretprobe_chain(ri, regs); ri = free_ret_instance(ri); utask->depth--; } while (ri != next); } while (!valid); ---- I think this expects setjmp/longjmp as below foo() { <- retprobe1 setjmp() bar() { <- retprobe2 longjmp() } } <- return to trampoline In this case, we need to skip retprobe2's instance. My concern is, if we can not find appropriate return instance, what happen? e.g. foo() { <-- retprobe1 bar() { # sp is decremented sys_uretprobe() <-- ?? } } It seems sys_uretprobe() will handle retprobe1 at that point instead of SIGILL. Can we avoid this with below strict check? if (ri->stack != regs->sp + expected_offset) goto sigill; expected_offset should be 16 (push * 3 - ret) on x64 if we ri->stack is the regs->sp right after call. Thank you, -- Masami Hiramatsu (Google)