X-Received: by 2002:a17:90b:1b07:b0:1b8:af50:5c0f with SMTP id nu7-20020a17090b1b0700b001b8af505c0fmr15296101pjb.184.1645719884266; Thu, 24 Feb 2022 08:24:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645719884; cv=none; d=google.com; s=arc-20160816; b=miZ4c9qhYuNCyyA+lTcwUAv2RWGE3YcKbq0PHo6naUL8R7BwSMolZ6+gtWNMAu8mdr 8SJJe/4Uwl1ftqbT2FrFF3+4mDe5VdOpUnCdy3hIvu8+CldIk4VDNY7nG0E8aEZucwpT zXrU4WtxwXib9MJs3jopkmylCmritNRRZfXxl7SXsTafgWW7LoflBtLrutgeeibvfeJG v1FoWLkpx5w2bZvTvNJdkrQC8kCrWdwi9xvIdsrG0nwnzeJ9BZTaLqs2xfp8cVXN9oEj wgdKP5dccNk/Vlb7xRGm2p3bldHiUuDvJbDNpIQlcKNQeeySBMBSBLzC2Ezf2hpfuPta wvxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=gyQOZ/OewxIV9rsoR2cpSRnntRDVjwTBBtcxSpgojPk=; b=T/1QdmiUymnFrIGJu/5YS4l5UiaFGJBIK7h5RXSLrRKF9EI4CzyDtKjsPVidYOedLM 7Cq3hbfotqHG9lsBV+Jtt95dScmy6ETwTrpTXFdtgRP6WXkMgQ71MhxfCPJZFvA+6BZS qssMaid7DqVQkB7N1rIlYSsUGIMZRvaQceIZ3gmbpTI/zhxEwfOq8sxxD6gjphIESwoa ixIMrnlw0RotX6eJ8GPsPNrgKv69MthT1vP9plWLQt89GzCO3PhoW9eT4JXBYA9As4SS hI+B3VCtgS946PxmX24EcDkAP9rbkAx9S7eIdOi5RIcK9eR0kK3Q9oV4mX0/KR8p2A7T kNJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=G8mxPQm3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k4si2675062plt.331.2022.02.24.08.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 08:24:44 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=G8mxPQm3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 489C3279459; Thu, 24 Feb 2022 08:14:42 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236087AbiBXPUJ (ORCPT + 99 others); Thu, 24 Feb 2022 10:20:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235987AbiBXPSc (ORCPT ); Thu, 24 Feb 2022 10:18:32 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 462E9159280 for ; Thu, 24 Feb 2022 07:17:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=gyQOZ/OewxIV9rsoR2cpSRnntRDVjwTBBtcxSpgojPk=; b=G8mxPQm3NU7ZV/zLjmPmTh333F ltP75Fc9ZTdxk0Ikc5JZd86lcWO8ZFrnZFSiHXyUwBH7v95v794zZiqTjtHlYMRXYobsTu0JClaao HMjQV4MWpw8i7eRG464mRlWHYxRIxfspn/F2CQI46Evm47hJw69zjug3h2IT9fXkmGRCikzCDqpg2 N/OdKOQq63tzHJ6Xsr7VYxD+5ecckOPM5EJtRa5mm+wiFJEtAlOyDCVgCCZVeaxjuJ7bHLgUJR86d T2YpACOUwA+7V9EnNjxJUsDrIKq1tzDRZWxpd58btziLmHhoqkEEmI2QGEmKEso0Ke5AAwXyZamGD iaM/rNKg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNFs3-00CeLh-Nl; Thu, 24 Feb 2022 15:17:31 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 38BAA301A96; Thu, 24 Feb 2022 16:17:29 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 59AA02B354785; Thu, 24 Feb 2022 16:17:28 +0100 (CET) Message-ID: <20220224151322.892372059@infradead.org> User-Agent: quilt/0.66 Date: Thu, 24 Feb 2022 15:51:53 +0100 From: Peter Zijlstra To: x86@kernel.org, joao@overdrivepizza.com, hjl.tools@gmail.com, jpoimboe@redhat.com, andrew.cooper3@citrix.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, ndesaulniers@google.com, keescook@chromium.org, samitolvanen@google.com, mark.rutland@arm.com, alyssa.milburn@intel.com, mbenes@suse.cz, rostedt@goodmis.org, mhiramat@kernel.org, alexei.starovoitov@gmail.com Subject: [PATCH v2 15/39] x86/ibt,kprobes: Fix more +0 assumptions References: <20220224145138.952963315@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 With IBT on, sym+0 is no longer the __fentry__ site. NOTE: the architecture has a special case and *does* allow placing an INT3 breakpoint over ENDBR in which case #BP has precedence over #CP and as such we don't need to disallow probing these instructions. NOTE: irrespective of the above; there is a complication in that direct branches to functions are rewritten to not execute ENDBR, so any breakpoint thereon might miss lots of actual function executions. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/kernel/kprobes/core.c | 11 +++++++++++ kernel/kprobes.c | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -1156,3 +1162,8 @@ int arch_trampoline_kprobe(struct kprobe { return 0; } + +bool arch_kprobe_on_func_entry(unsigned long offset) +{ + return offset <= 4*HAS_KERNEL_IBT; +} --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -67,10 +67,19 @@ static bool kprobes_all_disarmed; static DEFINE_MUTEX(kprobe_mutex); static DEFINE_PER_CPU(struct kprobe *, kprobe_instance); -kprobe_opcode_t * __weak kprobe_lookup_name(const char *name, - unsigned int __unused) +kprobe_opcode_t * __weak kprobe_lookup_name(const char *name, unsigned int offset) { - return ((kprobe_opcode_t *)(kallsyms_lookup_name(name))); + kprobe_opcode_t *addr = NULL; + + addr = ((kprobe_opcode_t *)(kallsyms_lookup_name(name))); +#ifdef CONFIG_KPROBES_ON_FTRACE + if (addr && !offset) { + unsigned long faddr = ftrace_location((unsigned long)addr); + if (faddr) + addr = (kprobe_opcode_t *)faddr; + } +#endif + return addr; } /*