From nobody Sun Feb 8 09:10:24 2026 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 789F7264A90 for ; Wed, 30 Apr 2025 16:47:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746031635; cv=none; b=dop/I4zhZ2hljVoenA0WMPsoCpY+JE0jRvTCRuR1wNjwZ8PpWY7q7DZsW4/AII8tFL8oldZtOznxUibKOelyULX3T3R6M6VBrAX+HKQIeA5rHgsQiIzHtBd9DUFVryETah64IfkXRIvJgWN7AfEPx6hQdaHZcQFKE8qCMbuc57k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746031635; c=relaxed/simple; bh=q9ytZ2bqnS4AW5iOsrYAArh8ag5ZF0zJhleYllk09Tw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P4FFQ1BZie3zDrxDZ1R8LO/bjN5OwkTECDgDnUGTaPnplVdRK9xL9l9NkCd0fEdn4Br3uBIDppLomcdLHQjGdNue2NiIuhkgy/fNyB/mNTzbOIMCbWw+GVam4uZX08r0NAatuLH3TrbksGMRxio5V4H06ERDAtjDtluCFkSPceA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=otrJNo1A; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="otrJNo1A" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1746031631; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DZoAG17QbBV/4PAv7+P9YXWHmX6KfllOZqrH5JYkMPo=; b=otrJNo1AcYDrI0/AhSwcB4K20up9Ma9jsPFVr8QgJDLYZPBHJMsocjpyJu5pYC7+5iAh2l MowTfTwI3XJeWRSC5LtPu6KtW/kU2TffsYPra/INRbRQ7eplhEc6R82A9VqF02uWb1u0Bq KKgT4Yctyk6VaYze8jIb1R8QjDhsSco= From: Tao Chen To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, alan.maguire@oracle.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Tao Chen Subject: [RFC PATCH bpf-next 2/2] bpf: Get fentry func addr from user when BTF info invalid Date: Thu, 1 May 2025 00:46:08 +0800 Message-Id: <20250430164608.3790552-3-chen.dylane@linux.dev> In-Reply-To: <20250430164608.3790552-1-chen.dylane@linux.dev> References: <20250430164608.3790552-1-chen.dylane@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" If kernel function optimized by the compiler, the function name in kallsyms will have suffix like ".isra.0" or others. And fentry uses function name from BTF to find the function address in kallsyms, in this situation, it will fail due to the inconsistency of function names. If so, try to use the function address passed from the user. Signed-off-by: Tao Chen --- include/linux/bpf.h | 1 + include/uapi/linux/bpf.h | 1 + kernel/bpf/syscall.c | 1 + kernel/bpf/verifier.c | 9 +++++++++ 4 files changed, 12 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 3f0cc89c06..fd53d1817f 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1626,6 +1626,7 @@ struct bpf_prog_aux { struct work_struct work; struct rcu_head rcu; }; + u64 fentry_func; }; =20 struct bpf_prog { diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 07ee73cdf9..7016e47a70 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1577,6 +1577,7 @@ union bpf_attr { * If provided, prog_flags should have BPF_F_TOKEN_FD flag set. */ __s32 prog_token_fd; + __aligned_u64 fentry_func; /* The fd_array_cnt can be used to pass the length of the * fd_array array. In this case all the [map] file descriptors * passed in this array will be bound to the program, even if diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 9794446bc8..6c1e3572cc 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2892,6 +2892,7 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr= _t uattr, u32 uattr_size) prog->sleepable =3D !!(attr->prog_flags & BPF_F_SLEEPABLE); prog->aux->attach_btf =3D attach_btf; prog->aux->attach_btf_id =3D attr->attach_btf_id; + prog->aux->fentry_func =3D attr->fentry_func; prog->aux->dst_prog =3D dst_prog; prog->aux->dev_bound =3D !!attr->prog_ifindex; prog->aux->xdp_has_frags =3D attr->prog_flags & BPF_F_XDP_HAS_FRAGS; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 54c6953a8b..507c281ddc 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -23304,6 +23304,15 @@ int bpf_check_attach_target(struct bpf_verifier_lo= g *log, } else { addr =3D kallsyms_lookup_name(tname); } + + if (!addr && (prog->expected_attach_type =3D=3D BPF_TRACE_FENTRY || + prog->expected_attach_type =3D=3D BPF_TRACE_FEXIT)) { + fname =3D kallsyms_lookup((unsigned long)prog->aux->fentry_func, + NULL, NULL, NULL, trace_symbol); + if (fname) + addr =3D (long)prog->aux->fentry_func; + } + if (!addr) { module_put(mod); bpf_log(log, --=20 2.43.0