Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1104192lqe; Sun, 7 Apr 2024 20:17:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFkB9Szs+8Wu4cDDLnFOAUrjlPtC85e862dhKbkPE+MPSN8JUenyltA30FFKbbUTUSga+hwDcNXs0fu4jpLt2s0m5nuGbErf3snJIEuw== X-Google-Smtp-Source: AGHT+IEWaAiHQtaGIgH5BA13x2pKltbrDlMpi9POqw6GLRdHWAArFWNKtTX8G1k/WGc6KpiserJP X-Received: by 2002:a17:906:f107:b0:a4e:3fad:b973 with SMTP id gv7-20020a170906f10700b00a4e3fadb973mr4285798ejb.65.1712546237589; Sun, 07 Apr 2024 20:17:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712546237; cv=pass; d=google.com; s=arc-20160816; b=mwGy1f350b/pvrqT7ur8/mg7wacetfAlfilFz54YbG6Z1OFEQUan/45kJx54U+J5nS HvBdWrJBsRKPtSS9CP2CwrU39IyTR+LeUz63eUSkW/fc78JTJJjsUiTykDt2DSoHbbm6 hbFptAwne5uj6iTHHjZedIPWAxwSlSzN1mvdIf0iF82gsfp8OQCwNtoMbioMGrDSia2D L2eS3c8QS5w4vDRb5gMQRbt/4zXspcz4r9KTE1AZFUFZkP3T2wOS864poRK0Fa4M+Pxj 7exETsXFxjGLXSWAukvCiPK+/vuJKF/mrInZNybhGBpTlcNOO+1wh5NC4ZiU0IaAnXYd ag0A== 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=AEntxq16ZUJwDrSTgQxugFF03y5dJUcRG04II7RlkEQ=; fh=rwS+VOcxaKwuwzHo0C+ihi3Sbuej762uMsxdw/6Rl/Q=; b=iM+NPQAXZkalXpggB6Qp6RsD+Slpo1Ms2tUB8t4kf0U+r7Ejc5i5jeTWk491OYvL2p vgUJrYu9Kui7TNfHTdjLIfBPrAjn1bX+9cxo0erTMLqi9Ap155wRBJZPhf0JEWMltMUF lgsq2zBgh6Iv8N447Z6zwi3YwUS78gzbySBKHj6C22ipTWHASyIIVDjkGQsybN08dmD9 X2uCxNcdjQaOp3Wgrgg0ubGXZgjRt7SJ80am8KutcvqHPvoQuClZjQyszu8Wzdprj6+q vOp0D8AYm1If1TKzkfLwPhhfTYhNutuEGkRtwdNb1ur0Le/DEmcIjCutH3le3LGq3qWu 56XQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZyUYHtHT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-134748-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134748-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dr12-20020a170907720c00b00a4df4a5f583si3221065ejc.417.2024.04.07.20.17.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 20:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134748-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZyUYHtHT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-134748-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134748-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 54ABC1F222C4 for ; Mon, 8 Apr 2024 03:17:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4620E469D; Mon, 8 Apr 2024 03:17:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZyUYHtHT" 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 5D9BB6FA8; Mon, 8 Apr 2024 03:17:04 +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=1712546224; cv=none; b=tYVArEFvIjb9BxOJeej0SG4DkBmoury+EqI3cpEGWh4M9JEkLAF1xIAMZoI19zR3xffVPq8hqtFYLptwaaN9U8VKIGud+KQAQZiYRofxSbf/jouhVgR+6vs8oCnx3W0k/VethtUL62oazUNiS5ZZewk7l8o1NrII12vAOsDmiq4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712546224; c=relaxed/simple; bh=88xy5ncDJIYZXTN7bl3r8g56wJn0PxbweOPTs/roHCw=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=UcZuCi6fTHrFAo9WkRiC1h+Rbp9s98vYQ9VszgNMdaCLnUvBKGnppPo6MwIrjTGcc8fQHh7OM/UQWaj79YLVWrrykYjFpNjHFzjSJkIVxqDSA4uvCYBRNUkJR6j44AQTwPAreTSEv18TnR+Y/+IwJug3H+b2CIaN4FLuBcBi+70= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZyUYHtHT; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F18CFC433C7; Mon, 8 Apr 2024 03:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712546224; bh=88xy5ncDJIYZXTN7bl3r8g56wJn0PxbweOPTs/roHCw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ZyUYHtHTQhKODKjnshXcOh/ThkToFRTSnqBmTTyiXmfdqVvUGvDpFgtFv6y0CX0i2 N+uf4vuOTZqzxAAvYglXPWOiWX7Tm+xP7RdhHcU8+vfaxRLIWBBJGR72blU3qHKrmZ UR6eb37f4kkGT8pkfjWoiQPXUVYobVQWTY32f171Dbtql4XC3LvYqLkfNefKr3TWdn GZin3RVDKASvgMnXdND7GADgx0SxhLAR8If7Q89aua45ku3iFhqkAHBYrQYiCjNK8c jH8BkDVU1shiWB+keBsxv3JFuZS3F6Gc9bGhE02ZZrjaA5gAli5PCr5cDBRCqTzsvk LD3bvQZJCP3UA== Date: Mon, 8 Apr 2024 12:16:57 +0900 From: Masami Hiramatsu (Google) To: Jiri Olsa Cc: Oleg Nesterov , Andrii Nakryiko , 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: <20240408121657.5603eb93a55ba22a29b0c24b@kernel.org> In-Reply-To: References: <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> <20240405102203.825c4a2e9d1c2be5b2bffe96@kernel.org> 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 Fri, 5 Apr 2024 10:56:15 +0200 Jiri Olsa wrote: > > > > Can we avoid this with below strict check? > > > > if (ri->stack != regs->sp + expected_offset) > > goto sigill; > > hm the current uprobe 'alive' check makes sure the return_instance is above > or at the same stack address, not sure we can match it exactly, need to think > about that more > > > > > expected_offset should be 16 (push * 3 - ret) on x64 if we ri->stack is the > > regs->sp right after call. > > the syscall trampoline already updates the regs->sp before calling > handle_trampoline > > regs->sp += sizeof(r11_cx_ax); Yes, that is "push * 3" part. And "- ret" is that the stack entry is consumed by the "ret", which is stored by call. 1: |--------| <- sp at function entry == ri->stack 0: |ret-addr| <- call pushed it 0: |ret-addr| <- sp at return trampoline 3: |r11 | <- regs->sp at syscall 2: |rcx | 1: |rax | <- ri->stack 0: |ret-addr| (Note: The lower the line, the larger the address.) Thus, we can check the stack address by (regs->sp + 16 == ri->stack). Thank you, -- Masami Hiramatsu (Google)