Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1139163pxb; Thu, 28 Jan 2021 08:53:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxXZCq5E1q8TxViOZKRDu6NZptHojHmzqOM81P0Dp9Qf+/co6DQMJyJVYSTzE0FHg7cQaI X-Received: by 2002:a50:c8c3:: with SMTP id k3mr488740edh.302.1611852810483; Thu, 28 Jan 2021 08:53:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611852810; cv=none; d=google.com; s=arc-20160816; b=nQYk1w9BM9iGKqxCxtlM8o842bxhA2HZ7vigqo56h4go9BK/AnmNrz0sTPefveaS7z FmOUWTnvzw+wwTbt0P2C2YpebZQYbV9Lm65ElMlOHIvh3J+8ipUz2bELATZgFbPXzGZV PeUi5T5yDSD56u/x3ofl2EZA/SbcRGlOQV8QusmeAZCud09nbi3Cx7KHJbjrjyBxD87V 6ic06EQsAKNnbSm68JfKdKKypApA7K+Swulr0zLYx0y8BQ33x6CopoSe4vMe5167gkrq FkEubl8HFDU5Z2weQ49UaPG47r1lJd/KmzQfUf9e1vNIhHlOpg/Rcfi6wYnCqhhrIPpU aOFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=r33CpG98rw/mr6rLy4ACeQ8mouSsHQS8jL40ZLPrdjc=; b=MzuNley/fKK/PCeB/kp+QLNwysGm3pVUoYRJwjBYn5nwMtV3Rdms9xjjoA8zmbsMwn tzC7DAUyrfb3ww+b3RV/xn7nZqKoIEy4CzjCXPo+S2ic/9iSnUTAlivr6yjacd0kvYrU wedDPoQ9NpkyPlwTxyTJBhJnIxNxDlWlR0CoNnR79CcO2NBM4/msACRoIixN14Ha4JG4 FUx3jTQEYcfEqDjvPSImqQyoEzF6H+XE9DuVqXX9IWilZDy8C6YVz4GspEFUGaKzEuuu OBZ9a7K63dBcfQXIaQSpUrUAoBe8DUTAFvjZsye4m0TD/4Do4W1sm0lUMKDpMTJfGZds dH3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g27SPpKE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f22si3498641edj.405.2021.01.28.08.53.05; Thu, 28 Jan 2021 08:53:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g27SPpKE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232705AbhA1Qvu (ORCPT + 99 others); Thu, 28 Jan 2021 11:51:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52707 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232681AbhA1Qvs (ORCPT ); Thu, 28 Jan 2021 11:51:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611852622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r33CpG98rw/mr6rLy4ACeQ8mouSsHQS8jL40ZLPrdjc=; b=g27SPpKE/+wTW2rpESoILqL3bGSa+EsSI9pPHsM9PAEea7z/9/I9G595E6GLSYw76MBq2s EJJRCRaWS6fuIuTWW7Bv/E0BrVdn277T+DtLIOC0DGKjT1r+mFKluXO3WtPCaoPhTbVAR5 1MjtoTLUvf06NyU0x6cQAtkSwrbab1o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-H4bP6a7rNJaQIZhk8G-ODA-1; Thu, 28 Jan 2021 11:50:20 -0500 X-MC-Unique: H4bP6a7rNJaQIZhk8G-ODA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D4DF1081B38; Thu, 28 Jan 2021 16:50:18 +0000 (UTC) Received: from treble (ovpn-120-118.rdu2.redhat.com [10.10.120.118]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 967C95C1BB; Thu, 28 Jan 2021 16:50:16 +0000 (UTC) Date: Thu, 28 Jan 2021 10:50:14 -0600 From: Josh Poimboeuf To: Nikolay Borisov Cc: Masami Hiramatsu , Masami Hiramatsu , Peter Zijlstra , LKML , Alexei Starovoitov , bpf@vger.kernel.org, Steven Rostedt Subject: Re: kprobes broken since 0d00449c7a28 ("x86: Replace ist_enter() with nmi_enter()") Message-ID: <20210128165014.xc77qtun6fl2qfun@treble> References: <25cd2608-03c2-94b8-7760-9de9935fde64@suse.com> <20210128001353.66e7171b395473ef992d6991@kernel.org> <20210128002452.a79714c236b69ab9acfa986c@kernel.org> <20210128103415.d90be51ec607bb6123b2843c@kernel.org> <20210128123842.c9e33949e62f504b84bfadf5@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 28, 2021 at 06:45:56PM +0200, Nikolay Borisov wrote: > On 28.01.21 г. 18:12 ч., Nikolay Borisov wrote: > > On 28.01.21 г. 5:38 ч., Masami Hiramatsu wrote: > >> Hi, > > > > > >> > >> Alexei, could you tell me what is the concerning situation for bpf? > > > > Another data point masami is that this affects bpf kprobes which are > > entered via int3, alternatively if the kprobe is entered via > > kprobe_ftrace_handler it works as expected. I haven't been able to > > determine why a particular bpf probe won't use ftrace's infrastructure > > if it's put at the beginning of the function. An alternative call chain > > is : > > > > => __ftrace_trace_stack > > => trace_call_bpf > > => kprobe_perf_func > > => kprobe_ftrace_handler > > => 0xffffffffc095d0c8 > > => btrfs_validate_metadata_buffer > > => end_bio_extent_readpage > > => end_workqueue_fn > > => btrfs_work_helper > > => process_one_work > > => worker_thread > > => kthread > > => ret_from_fork > > > >> > > I have a working theory why I'm seeing this. My kernel (broken) was > compiled with retpolines off and with the gcc that comes with ubuntu > (both 9 and 10: > gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 > gcc-10 (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0 > ) > > this results in CFI being enabled so functions look like: > 0xffffffff81493890 <+0>: endbr64 > 0xffffffff81493894 <+4>: callq 0xffffffff8104d820 <__fentry__> > > i.e fentry's thunk is not the first instruction on the function hence > it's not going through the optimized ftrace handler. Instead it's using > int3 which is broken as ascertained. > > After testing with my testcase I confirm that with cfi off and > __fentry__ being the first entry bpf starts working. And indeed, even > with CFI turned on if I use a probe like : > > bpftrace -e 'kprobe:btrfs_sync_file+4 {printf("kprobe: %s\n", > kstack());}' &>bpf-output & > > > it would be placed on the __fentry__ (and not endbr64) hence it works. > So perhaps a workaround outside of bpf could essentially detect this > scenario and adjust the probe to be on the __fentry__ and not preceding > instruction if it's detected to be endbr64 ? For now (and the foreseeable future), CET isn't enabled in the kernel. So that endbr64 shouldn't be there in the first place. I can make a proper patch in a bit. diff --git a/Makefile b/Makefile index e0af7a4a5598..5ccc4cdf1fb5 100644 --- a/Makefile +++ b/Makefile @@ -948,11 +948,8 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) # change __FILE__ to the relative path from the srctree KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) -# ensure -fcf-protection is disabled when using retpoline as it is -# incompatible with -mindirect-branch=thunk-extern -ifdef CONFIG_RETPOLINE +# Intel CET isn't enabled in the kernel KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none) -endif # include additional Makefiles when needed include-y := scripts/Makefile.extrawarn