From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3A9DC433ED for ; Mon, 5 Apr 2021 13:46:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CEC5E613B1 for ; Mon, 5 Apr 2021 13:46:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237445AbhDENqj (ORCPT ); Mon, 5 Apr 2021 09:46:39 -0400 Received: from linux.microsoft.com ([13.77.154.182]:38312 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234370AbhDENqi (ORCPT ); Mon, 5 Apr 2021 09:46:38 -0400 Received: from [192.168.254.32] (unknown [47.187.194.202]) by linux.microsoft.com (Postfix) with ESMTPSA id BF21F20B5680; Mon, 5 Apr 2021 06:46:31 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BF21F20B5680 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1617630392; bh=mfFXVOtba3ncfAFXQnaH/4f2gUVkhGmFdDMee2De2aI=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=aA0jBlh89QQf6RrYXD8Azqv+RnNSLgNxm2+2chKzT8G7hB1Nc33YXx8pYyp3g4zRL yOtkKIPyIvJnqAoAznVQt83KEiS6OHqIET49ogrIjpphXTCNkx6VBGqgdpKEe4i0dS vEcumkZdnVdhSo/aMxU0fh99bhz7gYDUwgPOuPEg= Subject: Re: [RFC PATCH v1 0/4] arm64: Implement stack trace reliability checks To: Masami Hiramatsu Cc: Josh Poimboeuf , mark.rutland@arm.com, broonie@kernel.org, jthierry@redhat.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org References: <77bd5edeea72d44533c769b1e8c0fea7a9d7eb3a> <20210330190955.13707-1-madvenka@linux.microsoft.com> <20210403170159.gegqjrsrg7jshlne@treble> <20210405222436.4fda9a930676d95e862744af@kernel.org> From: "Madhavan T. Venkataraman" Message-ID: <7db94d60-3cb5-625a-a90b-d843e88f4533@linux.microsoft.com> Date: Mon, 5 Apr 2021 08:46:30 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210405222436.4fda9a930676d95e862744af@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: live-patching@vger.kernel.org On 4/5/21 8:24 AM, Masami Hiramatsu wrote: > Hi Madhaven, > > On Sat, 3 Apr 2021 22:29:12 -0500 > "Madhavan T. Venkataraman" wrote: > > >>>> Check for kretprobe >>>> =================== >>>> >>>> For functions with a kretprobe set up, probe code executes on entry >>>> to the function and replaces the return address in the stack frame with a >>>> kretprobe trampoline. Whenever the function returns, control is >>>> transferred to the trampoline. The trampoline eventually returns to the >>>> original return address. >>>> >>>> A stack trace taken while executing in the function (or in functions that >>>> get called from the function) will not show the original return address. >>>> Similarly, a stack trace taken while executing in the trampoline itself >>>> (and functions that get called from the trampoline) will not show the >>>> original return address. This means that the caller of the probed function >>>> will not show. This makes the stack trace unreliable. >>>> >>>> Add the kretprobe trampoline to special_functions[]. >>>> >>>> FYI, each task contains a task->kretprobe_instances list that can >>>> theoretically be consulted to find the orginal return address. But I am >>>> not entirely sure how to safely traverse that list for stack traces >>>> not on the current process. So, I have taken the easy way out. >>> >>> For kretprobes, unwinding from the trampoline or kretprobe handler >>> shouldn't be a reliability concern for live patching, for similar >>> reasons as above. >>> >> >> Please see previous answer. >> >>> Otherwise, when unwinding from a blocked task which has >>> 'kretprobe_trampoline' on the stack, the unwinder needs a way to get the >>> original return address. Masami has been working on an interface to >>> make that possible for x86. I assume something similar could be done >>> for arm64. >>> >> >> OK. Until that is available, this case needs to be addressed. > > Actually, I've done that on arm64 :) See below patch. > (and I also have a similar code for arm32, what I'm considering is how > to unify x86/arm/arm64 kretprobe_find_ret_addr(), since those are very > similar.) > > This is applicable on my x86 series v5 > > https://lore.kernel.org/bpf/161676170650.330141.6214727134265514123.stgit@devnote2/ > > Thank you, > > OK. I will take a look. Thanks. Madhavan