From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796442450; b=u3nfp3s2/J1nUHoss3Gy6YTd2aiw9g+ViVafd+ERYOcN97+fBd4DrurA8i+Jine1loTd OqJdj4cwg/7rvra3Oc2RDTEK2hV+zzs5NRNCRRTlFi5lz81yel+72wCiqej6S02FEEXKC 5HRzhdSW/LHxJ0eld6A41Bn4Fy4MUv18xr0rotqnQxSmUhzognG/j5JcDV5kXemR8v9Hk oCkE1k+NJ94auyfB+pbp9JdsZHHUmEI4a6to4QpduK12e08GF97dApQt0JJMKEXHd2JVg 7p8YxFdtJArxFl5XULYldX5WZbQExfMZBPrKH314QpqBkbLrDUzLsVUrbnQx1nNaySA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796442450; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Content-Type:Date:Message-Id:From:To:Subject:In-Reply-To:References: Content-Transfer-Encoding:MIME-Version; bh=8+uUSpVkfrbImy7s9lOdHaNd+xNIjMwHNcvtlVVrXjA=; b=fxE1TgeayxziKZjgIYepNZ0Z+AaUAKKaNumBYzDdpUWpphau4a2wMJHT8SCbCdZk5ONH aLr2vrfyDe3fGW7aSHMFwObUZFmAShMDXevR5Yi+SgRM6BvIY5tTpcWzx3Bpx/4Y0Swlc BR1YS7zVI+5euF/SBgjFXCSWYgzKrVB9omBJh5TDWpzCqhQIQylW7SjwwJQCTBqQnZH6H CaXBIF7Q72A1ZSFPJT+QszAXCWXhr2Nh90oBPKhbnCxqDAjB8buxC6vOk49xZC2Z4twhV hJOKeQCSoywJNfAH/ndhoyOy+Sd+/GnC330T/LiGSdJjSP/Ebyjtz8syAHKWIA5kX5A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Levp7vzT; arc=none smtp.remote-ip=209.85.214.178 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7791A606A322 for ; Sat, 5 Dec 2026 03:47:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7791A606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Levp7vzT Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2f06ff94acfso11320415ad.0 for ; Fri, 04 Dec 2026 19:47:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796442450; x=1797047250; darn=vger.kernel.org; h=mime-version:content-transfer-encoding:references:in-reply-to :subject:to:from:message-id:date:content-type:from:to:cc:subject :date:message-id:reply-to:content-type; bh=8+uUSpVkfrbImy7s9lOdHaNd+xNIjMwHNcvtlVVrXjA=; b=Levp7vzT/R6JjAXAa7SRwOOFxmhwXBDxqVRfCY4kdxW0lv0t3qoUEnyfD8tTIJ6h5I UYKvN+XZsEmhAlmvEjfGpMO00V8fau4d7LYqCMLCFevBEf78Kfjge0THDIXILJLk6wRQ miDISBh9w3IgmKxNkNKBxNvsUai0HPvOlkUrRcfhMhyjYs0FlKMzZasXctMVsaVwWEYi jdjxcJSQ0fdfjzetRORKABrWN7zwXxC7HTO3K3YQs9MPAm1v98EGu5VfW9ne79SXcIiE C5eHn2nnDtn2vUofEvA6xKQaVEcTuBj6KeLh7wwWMu78ClhzsXkV1zOx4njN0BsrltBM ANdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796442450; x=1797047250; h=mime-version:content-transfer-encoding:references:in-reply-to :subject:to:from:message-id:date:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8+uUSpVkfrbImy7s9lOdHaNd+xNIjMwHNcvtlVVrXjA=; b=C+om5PcCo+facfa1FE5O6Alj6iszakXS+mPCfjNqPh1JbuiTaITHj27fAx2wLstpM0 nxOcvXbCoH4zPPVFRbagDK91Nxpbw0NbAWYCNZltQHgZMjO7k0TBdn7CsNpnrlHi9FG3 INKhw/EwYjFkUwJ1cEDfVJQDKdCYzifU8Sg+CrZQGM1yKVT+s0oa0y2BtPYEvtEa66Ld WaqrbCNQZH7rgIzWaG7rV9xlocODK0sRMVebDYr0ySnpU1fEACcfylBepc/WLxNGHRuF hTJUDigCfZk9nyaSsmYzAaDqud/OeU75OaewSOFmKzWTJ97qrhiCWGq7I0ysqP3RUPk1 OVwQ== X-Forwarded-Encrypted: i=1; AL+hErHqCDhj4891boqye+egEXEDBXxoDmhoBSeQKKpGcrV49TBqMA+JfaFPsLIHQ6J/oI93z+w=@vger.kernel.org X-Gm-Message-State: APuU4Z9+Iyu0+Yr6WPxg/hgc3je9ZDAXnmGp5esCDHktYfL87zxB24ii 9fILxScJQvWL8jAbc1SPNdFPbX2OodyMqrG8PmWV2VO5Q0fL7WepcTB4 X-Gm-Gg: AZFdTZdEQp6NUSDgXQ56QOs7avU8OaYk7WuqJplP3mWpXvS9QYFipAXB18Q2AVZFGAw 5WibRU6dMoqfPEOTlthejh1Gai21dqIpv95i/WDQnGOTvKduxcsgdw/kCkFv1NMRyTFmUvO5i4Y TEoc8sFNgXjJIp+EDthTLJE7DsoBRTymEYArFvYQZLHSAOeXxB+tnLs18NKH8MjCyGZC9m16ScH 5yKDAYpypjAw7ugi719fsnDATLlgSYdV2d97SMFME/6Romgt8Us6kpUP94gaJvJDMRHTKPyILW1 eJdStK2u/tDuHAqFIqtALmI/ccuEU3/WGXVBQh/2oW5TASIAkcPLb2W61K2155F0aY7bebuiKGW 5Ww3eLcArSjMBnFiUgL6l2Ry/yIeZBGzgLmnJ7jNLHCNJQe8CuDNv+Fn4BOgUQRq2H+UdYj/X3X jdBVSpJ5VIVZP6S/cX8kVr+1hlxxqxVeyVLJ/IEXf0cxDWI2Ii7dxFARfb9jNq9mBaVNKOa0yCb uJrDOgIaX216Stkrsl30FzQM7udLMjRTDoJ8OpyKcv6IGKFrhvXCgM8/eq/EuUWT0gZWBlYFy9r ml4KVUENz8Qmejeb61PVK4lOPfQM5wvEMb2wTCFM6jTLSzfa1AtS8fMrEzDRxlfRFfqkh7rAAt3 o32R4xamhDj15rMDsR7s7Qi/lOO0DB9q5Ow== X-Received: by 2002:a17:902:d582:b0:2df:90d4:7758 with SMTP id d9443c01a7336-2f1ba16a6f8mr33277215ad.23.1796442449479; Fri, 04 Dec 2026 19:47:29 -0800 (PST) Received: from localhost ([153.61.198.248]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b7961aa5sm20924705ad.61.2026.12.04.19.47.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 19:47:29 -0800 (PST) Content-Type: text/plain; charset=UTF-8 Date: Sat, 05 Dec 2026 03:47:28 +0000 Message-Id: From: "Alexei Starovoitov" To: "Anton Protopopov" , , "Daniel Borkmann" , "Andrii Nakryiko" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Martin KaFai Lau" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Emil Tsalapatis" , "Ihor Solodrai" , "John Fastabend" , "Viktor Malik" Subject: Re: [PATCH v2 bpf-next 0/4] bpf: Refuse the vmlinux prototype for a module function In-Reply-To: <20261204154705.1411391-1-a.s.protopopov@gmail.com> References: <20261204154705.1411391-1-a.s.protopopov@gmail.com> Content-Transfer-Encoding: 8bit X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Fri, Dec 04, 2026 at 07:46 AM Anton Protopopov wrote: > And one case which worked before is now refused: a caller which > passes the vmlinux ID while the module has its own FUNC of a > compatible prototype, e.g. one with other parameter names, which > dedup doesn't merge. libbpf with patch 3 picks the module's own ID. > Other loaders have to do the same. Such functions are rare. In a It's more than one case, I think. vmlinux has foo(a, b), the module has foo(a), the prog doesn't read 'b'. x86 trampoline does: nr_regs = bpf_jit_place_args(&x86_arg_abi, m, pos_of_slot); It saves 2 regs, the module needs 1. Such prog works today. libbpf passes the vmlinux ID for "mod:foo" since commit 8f8a024272f3. These progs get -EINVAL until their libbpf is updated. What a prog gets with module BTF and the vmlinux ID: FUNC of the module today series diff below ---------------------------- ----------- ------- ---------- other names of params works -EINVAL works fewer args, 'b' is not read works -EINVAL works other type of an arg wrong type -EINVAL right type more args not saved -EINVAL saved > A proper longer-term (to deploy) fix: both cases go away if > btf__dedup() stops merging the FUNCs of a module into the FUNCs of > vmlinux. A FUNC stands for a symbol of one object, so the two aren't > the same type even when they look equal. Then the kernel can refuse > any vmlinux function ID with the BTF of a module. This needs a change > in btf__dedup() for split BTF and a pahole which picks it up. I'm > looking for comments on whether this follow-up is ok. The 2nd case doesn't go away. It grows to every name that is in both. test_shadow() has: btf_id[1] = btf__find_by_name_kind(mod_btf, symbol_name, BTF_KIND_FUNC); That's the vmlinux ID. With such pahole bpf_testmod has its own FUNC for bpf_fentry_shadow_test() and patch 1 refuses the load. The series finds the FUNC of the module already. Lets use it instead of failing. Old loaders get the right prototype, before and after the follow up. A FUNC that pahole dropped is still not covered. A glob that passes both IDs still gets -EINVAL. That needs patch 3. btf_own_func_id() replaces patches 1 and 2. diff --git a/include/linux/btf.h b/include/linux/btf.h index 6014282..510f587 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -254,6 +254,7 @@ int btf_check_and_fixup_fields(const struct btf *btf, struct btf_record *rec); bool btf_type_is_void(const struct btf_type *t); bool btf_type_is_arena_ptr(const struct btf *btf, const struct btf_type *t); s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind); +u32 btf_own_func_id(const struct btf *btf, u32 id); s32 bpf_find_btf_id(const char *name, u32 kind, struct btf **btf_p); struct btf *btf_get_module_btf(const struct module *module); __u32 btf_relocate_id(const struct btf *btf, __u32 id); diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 3597ba1..6312b7c 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -664,19 +664,13 @@ static s32 btf_find_by_name_kind_bsearch(const struct btf *btf, const char *name return btf_nr_types(btf); } -s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind) +/* Look up only the types of btf, not of its base */ +static s32 btf_find_by_name_kind_own(const struct btf *btf, const char *name, u8 kind) { - const struct btf *base_btf = btf_base_btf(btf); const struct btf_type *t; const char *tname; s32 id, total; - if (base_btf) { - id = btf_find_by_name_kind(base_btf, name, kind); - if (id > 0) - return id; - } - total = btf_nr_types(btf); if (btf->named_start_id > 0 && name[0]) { id = btf_find_by_name_kind_bsearch(btf, name); @@ -707,6 +701,42 @@ s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind) return -ENOENT; } +s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind) +{ + const struct btf *base_btf = btf_base_btf(btf); + s32 id; + + if (base_btf) { + id = btf_find_by_name_kind(base_btf, name, kind); + if (id > 0) + return id; + } + + return btf_find_by_name_kind_own(btf, name, kind); +} + +/* + * The address of an attach target is looked up by name in the module. Take + * the FUNC of the module when it has one of that name. Otherwise the dedup + * merged it into the FUNC of vmlinux. + */ +u32 btf_own_func_id(const struct btf *btf, u32 id) +{ + const struct btf_type *t; + s32 own_id; + + if (id >= btf->start_id) + return id; + + t = btf_type_by_id(btf, id); + if (!btf_type_is_func(t)) + return id; + + own_id = btf_find_by_name_kind_own(btf, btf_name_by_offset(btf, t->name_off), + BTF_KIND_FUNC); + return own_id > 0 ? own_id : id; +} + s32 bpf_find_btf_id(const char *name, u32 kind, struct btf **btf_p) { struct btf *btf; diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index b9cd3d5..2258861 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3069,6 +3069,7 @@ static struct bpf_prog *bpf_prog_alloc_attr(union bpf_attr *attr, bpfptr_t uattr goto put_token; } } + attach_btf_id = btf_own_func_id(attach_btf, attach_btf_id); } else if (dst_prog->aux->is_entry && dst_prog->aux->func_info[0].type_id != attr->attach_btf_id) { /* what an entry calls is a function of its owner */ diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 2031c37..42963a1 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -3918,6 +3918,11 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr, } } + for (int i = 0; i < cnt; i++) { + ids[i] = btf_own_func_id(prog->aux->attach_btf, ids[i]); + cond_resched(); + } + err = check_dup_ids(ids, cookies, cnt, log); if (err) goto error; pw-bot: cr