Message ID | 20221121085113.611504-1-hu1.chen@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1463494wrr; Mon, 21 Nov 2022 00:56:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf7T3lkYGvM7LpV21puftpaaTlZDWfxyYOyIlYv1t+5aM4SU1V68fHaM+fgyUKg1mFKRls58 X-Received: by 2002:a17:906:c449:b0:7ae:cbae:af1 with SMTP id ck9-20020a170906c44900b007aecbae0af1mr14646060ejb.31.1669021015743; Mon, 21 Nov 2022 00:56:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669021015; cv=none; d=google.com; s=arc-20160816; b=qzf/hi/9APiugZA+JKpOW2P9qwZ3UoiXsXTr8JxHjGVOcHIrTjcqL4e+zXuTm40HKZ h9I+Z5UNdI+Y5nVZroxjxeIi14BVmlqqwnfvrApHSJVuFssvH9rzDnAXVw9cqVNMQJkk n9JM2Do5SLzKO+pPQ0SGEr0GoeS36wP9T2wpqI8K8s45Qte31Y5MxotIb6uOanmfZMPN tEhvmgVvzZMC2x/4uZszd2Bas21QT5wcw3ClNBERRya02glGcXT+Xzz28Ewjte1Pfl6H 9pfkDehmym63IHouywx3azetXsbIAEnLXWxXaH1WuIl52AoO0la7PKycGlTmZPLakxQy pcVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=bDNONSpFicQtZlQjRDlbOF258saoC4HchKSodlXg7yE=; b=BgXEEyKOLHBOTpcULXZdOeqkvddb88vttlCKmT39z9ohfGvtll+LC5gJBrwCj+EqO/ iqHM3vYumhr7FF7d+mYHvNNGTtU8g+UTAyDhL5IrBbWfFWqaco7+JwxwbODzrADpTE9E Mu1ZCihZrqfFP8XlXe9D4nlI0Jyio+coljUrz70o2xMf/S4ftKjGGVqvZDjDi6vII4aj /PlPxSFZZc2bqcaZSCAPeMXAXYN9q1aFCCvmOVIoZ02UgmMvi7eggPETU+NwETIZyGPZ tfPS1F6KLBTtVi7bWd2YIOWHh4f73nMTW+pSPYIqfRAMtUXgqyOhIOt0a+8hQ2E8UkzU TYgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@intel.com header.s=Intel header.b=h2xPBvv6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf15-20020a1709077f0f00b007b790c183d4si246564ejc.556.2022.11.21.00.56.30; Mon, 21 Nov 2022 00:56:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@intel.com header.s=Intel header.b=h2xPBvv6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229885AbiKUIwt (ORCPT <rfc822;peter110.wang@gmail.com> + 99 others); Mon, 21 Nov 2022 03:52:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbiKUIwE (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 21 Nov 2022 03:52:04 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 755F782217; Mon, 21 Nov 2022 00:52:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669020721; x=1700556721; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=PRZcPQKEh9lZYS6k17IpBGFrKOu26GUNvPvApWrz/lc=; b=h2xPBvv6bNCoJlna2SRRXh4LmTgnNuMLJpOaf4C5CFsEB0R3LlCjLEuc mvmP20HCxKj8XCDEXAOA6Bf2/DSMBcc5q8e1RDsjaC1GKKKbqiNYJgxem ZJpNX5HVpxWB1VNYzrjjViQatWXIpn6CjoXqRPcdTtmGznZvQF3cf2+tP d2F+hsOsPPsER7e0QmYBluGc13V57JEbkyMAaJWruJGiVXzIz3NbPQUbT OoMN2BAiuSqKv1PgyCCUKKwkp9c6vlPI3uYCL/KEvr+NFaRlhkAJtvUAj HcmSPApBanNPWXwz8h0sKqqqNadrVrTQ34Z+KbDZIznFn7Gma4BGfdTLx Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10537"; a="313536858" X-IronPort-AV: E=Sophos;i="5.96,180,1665471600"; d="scan'208";a="313536858" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2022 00:52:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10537"; a="709730243" X-IronPort-AV: E=Sophos;i="5.96,180,1665471600"; d="scan'208";a="709730243" Received: from a0cec8d9c8fc.jf.intel.com ([10.45.77.137]) by fmsmga004.fm.intel.com with ESMTP; 21 Nov 2022 00:51:46 -0800 From: Chen Hu <hu1.chen@intel.com> Cc: hu1.chen@intel.com, jpoimboe@kernel.org, memxor@gmail.com, bpf@vger.kernel.org, Pengfei Xu <pengfei.xu@intel.com>, Martin KaFai Lau <martin.lau@linux.dev>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org>, Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>, John Fastabend <john.fastabend@gmail.com>, KP Singh <kpsingh@kernel.org>, Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH bpf] selftests/bpf: Fix "missing ENDBR" BUG for destructor kfunc Date: Mon, 21 Nov 2022 00:51:13 -0800 Message-Id: <20221121085113.611504-1-hu1.chen@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750095380682334965?= X-GMAIL-MSGID: =?utf-8?q?1750095380682334965?= |
Series |
[bpf] selftests/bpf: Fix "missing ENDBR" BUG for destructor kfunc
|
|
Commit Message
Chen Hu
Nov. 21, 2022, 8:51 a.m. UTC
With CONFIG_X86_KERNEL_IBT enabled, the test_verifier triggers the following BUG: traps: Missing ENDBR: bpf_kfunc_call_test_release+0x0/0x30 ------------[ cut here ]------------ kernel BUG at arch/x86/kernel/traps.c:254! invalid opcode: 0000 [#1] PREEMPT SMP <TASK> asm_exc_control_protection+0x26/0x50 RIP: 0010:bpf_kfunc_call_test_release+0x0/0x30 Code: 00 48 c7 c7 18 f2 e1 b4 e8 0d ca 8c ff 48 c7 c0 00 f2 e1 b4 c3 0f 1f 44 00 00 66 0f 1f 00 0f 1f 44 00 00 0f 0b 31 c0 c3 66 90 <66> 0f 1f 00 0f 1f 44 00 00 48 85 ff 74 13 4c 8d 47 18 b8 ff ff ff bpf_map_free_kptrs+0x2e/0x70 array_map_free+0x57/0x140 process_one_work+0x194/0x3a0 worker_thread+0x54/0x3a0 ? rescuer_thread+0x390/0x390 kthread+0xe9/0x110 ? kthread_complete_and_exit+0x20/0x20 This is because there are no compile-time references to the destructor kfuncs, bpf_kfunc_call_test_release() for example. So objtool marked them sealable and ENDBR in the functions were sealed (converted to NOP) by apply_ibt_endbr(). This fix creates dummy compile-time references to destructor kfuncs so ENDBR stay there. Signed-off-by: Chen Hu <hu1.chen@intel.com> Tested-by: Pengfei Xu <pengfei.xu@intel.com> --- include/linux/btf_ids.h | 7 +++++++ net/bpf/test_run.c | 2 ++ 2 files changed, 9 insertions(+)
Comments
On Mon, Nov 21, 2022 at 12:51:13AM -0800, Chen Hu wrote: > With CONFIG_X86_KERNEL_IBT enabled, the test_verifier triggers the > following BUG: > > traps: Missing ENDBR: bpf_kfunc_call_test_release+0x0/0x30 > ------------[ cut here ]------------ > kernel BUG at arch/x86/kernel/traps.c:254! > invalid opcode: 0000 [#1] PREEMPT SMP > <TASK> > asm_exc_control_protection+0x26/0x50 > RIP: 0010:bpf_kfunc_call_test_release+0x0/0x30 > Code: 00 48 c7 c7 18 f2 e1 b4 e8 0d ca 8c ff 48 c7 c0 00 f2 e1 b4 c3 > 0f 1f 44 00 00 66 0f 1f 00 0f 1f 44 00 00 0f 0b 31 c0 c3 66 90 > <66> 0f 1f 00 0f 1f 44 00 00 48 85 ff 74 13 4c 8d 47 18 b8 ff ff ff > bpf_map_free_kptrs+0x2e/0x70 > array_map_free+0x57/0x140 > process_one_work+0x194/0x3a0 > worker_thread+0x54/0x3a0 > ? rescuer_thread+0x390/0x390 > kthread+0xe9/0x110 > ? kthread_complete_and_exit+0x20/0x20 > > This is because there are no compile-time references to the destructor > kfuncs, bpf_kfunc_call_test_release() for example. So objtool marked > them sealable and ENDBR in the functions were sealed (converted to NOP) > by apply_ibt_endbr(). nice :) thanks for the fix, some suggestions below > > This fix creates dummy compile-time references to destructor kfuncs so > ENDBR stay there. > > Signed-off-by: Chen Hu <hu1.chen@intel.com> > Tested-by: Pengfei Xu <pengfei.xu@intel.com> > --- > include/linux/btf_ids.h | 7 +++++++ > net/bpf/test_run.c | 2 ++ > 2 files changed, 9 insertions(+) > > diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h > index 2aea877d644f..6c6b520ea58f 100644 > --- a/include/linux/btf_ids.h > +++ b/include/linux/btf_ids.h > @@ -266,4 +266,11 @@ MAX_BTF_TRACING_TYPE, > > extern u32 btf_tracing_ids[]; > > +#if defined(CONFIG_X86_KERNEL_IBT) && !defined(__DISABLE_EXPORTS) > +#define BTF_IBT_NOSEAL(name) \ > + asm(IBT_NOSEAL(#name)); > +#else > +#define BTF_IBT_NOSEAL(name) > +#endif /* CONFIG_X86_KERNEL_IBT */ this is not BTF or BTF ID specific, instead should we add some generic macro like: FUNC_IBT_NOSEAL(...) > + > #endif > diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c > index 13d578ce2a09..465952e5de11 100644 > --- a/net/bpf/test_run.c > +++ b/net/bpf/test_run.c > @@ -1653,6 +1653,8 @@ BTF_ID(struct, prog_test_ref_kfunc) > BTF_ID(func, bpf_kfunc_call_test_release) > BTF_ID(struct, prog_test_member) > BTF_ID(func, bpf_kfunc_call_memb_release) > +BTF_IBT_NOSEAL(bpf_kfunc_call_test_release) > +BTF_IBT_NOSEAL(bpf_kfunc_call_memb_release) same here, it looks like it's part of the list above, I think this would be better after function body like: noinline void bpf_kfunc_call_memb_release(struct prog_test_member *p) { } FUNC_IBT_NOSEAL(bpf_kfunc_call_memb_release) thanks, jirka
diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h index 2aea877d644f..6c6b520ea58f 100644 --- a/include/linux/btf_ids.h +++ b/include/linux/btf_ids.h @@ -266,4 +266,11 @@ MAX_BTF_TRACING_TYPE, extern u32 btf_tracing_ids[]; +#if defined(CONFIG_X86_KERNEL_IBT) && !defined(__DISABLE_EXPORTS) +#define BTF_IBT_NOSEAL(name) \ + asm(IBT_NOSEAL(#name)); +#else +#define BTF_IBT_NOSEAL(name) +#endif /* CONFIG_X86_KERNEL_IBT */ + #endif diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 13d578ce2a09..465952e5de11 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -1653,6 +1653,8 @@ BTF_ID(struct, prog_test_ref_kfunc) BTF_ID(func, bpf_kfunc_call_test_release) BTF_ID(struct, prog_test_member) BTF_ID(func, bpf_kfunc_call_memb_release) +BTF_IBT_NOSEAL(bpf_kfunc_call_test_release) +BTF_IBT_NOSEAL(bpf_kfunc_call_memb_release) static int __init bpf_prog_test_run_init(void) {