From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796471149; b=U2hDouJ2OT/92kI9xPzUza2afbrLCraJtNVKKGgyld9s6FcGMvr/lZbOzJlz+2t7sv2T Jm1pmZccam0uGOJAIKUjfeJWRq39Xp9uREBfLt1Bk37OsXBXRMB+JG4wRJ7aA5NKmngaA 3G/yOzp2L2RyLmQ3gMEn79aZIlB+TkATc8jWuYG6TQ8VHG6BFVmcbB2vOgYLrbAEDoj4g HM5W6nVFL2p8mPC1I8KinMGaskC66ahP/6HUQQD2k3ob23Z0yvHsKXJ/AymFbsJVjkGot v/F3eI+fus8kgHbu9tcrvT+8z6MOegDwQsf/+tk/TlXVKAgletB9DOKChe4fdPJtJEg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796471149; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:X-Google-Original-From:Date:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=XOKEjuAOUw9rqcEzFQpQcZuLQMOM8k0pD+Zw9zxhWis=; b=vIHUa3iAcx+eKFPX8Qa62CG1NDSc/yzDS/tOENPOB3r63/1rDoBCYuVzjmyls23PBypZ mSM3tp6nHLfnVkIyREWW2F1tgmp/4p2gnsZA7v2g7OV70hBZ8hyeR81sGDJ00hliscmNI JHTduuNix+wRkCZOmZU3KHpHXukO//RLNI61xtes5i4zijchYTbJNJTS72wQEK94cr9MV mqCM7yTx7JVWLwJiyjVyFroh88s/hjAl2wvkrdk2ygr34ky+rYuAXxB0Gg9u0E2n1oFKG p3DwrrfYPV2jorVGQHkI01f1McZiqRYJIH1+NdzHCIYZUkM1ee2WznRt8CIGDI3GG+A== 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=e3GSLo35; arc=none smtp.remote-ip=209.85.221.50 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 B7A5D606A322 for ; Sat, 5 Dec 2026 11:45:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B7A5D606A322 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=e3GSLo35 Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-4a357b1c649so1018428f8f.3 for ; Sat, 05 Dec 2026 03:45:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796471147; x=1797075947; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=XOKEjuAOUw9rqcEzFQpQcZuLQMOM8k0pD+Zw9zxhWis=; b=e3GSLo35LL/MyrG6Vp1G/mKHg0VYYS8htwZMxzsoGL9GyPy4qRru9g20ZztnE4hLEa ksz8DXSI53H2LsBN2xcGiXTdgS+OUUSFuPhddygiEPFBo3B0YHJK0tNTyAc/YwZ5Nk3L V/jKAZ1atnImh6r2CvC+JsIx7kmURWZqwIdpLTn9RL3XcD5HFSKcGU8jQHfvTvtwnaiX YiCpHYVINjDPyxElc5+z9cNYo3XI6WnUzjy2nOY3DmEAyGnFhalA5QKoBvLLZt7AK8RT Liz0mxbzfOwHZFTQI/GLd15pk0NYn+WgLMnSIt5YctSwjLv3o/mZFRaXLfAkZyjfiktj 2HJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796471147; x=1797075947; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=XOKEjuAOUw9rqcEzFQpQcZuLQMOM8k0pD+Zw9zxhWis=; b=rNZUU905pr0AgwGelPTu4Cr30wCu/Eqj7YLKnN8EZ7lwmh3LzMkJs/mDfMGf5Zsba/ o75jZwQHguDMXyl1KxN92jY1tIVxcmU2KukD75FtbW+oHZM/gGGdiYmghoRQtn4A0tT5 UZhYG45zzlmeKROqZgavAZkrNuzO/686y/fxyOJhP8ejfNadh8nePKOC/msplURYyaIY mBoEPIp17k0WeEUsW8AHjur/uBMutLRM2NX9wC2FVl78Ri6w1wU539dg7GqVcOYETmVk h8N2q+5p1Pb7mE7Jz4EFlCti96GZNPT8heGsW4HR5HbFqOjP8Bu4YR6srl/AwoPORYkY VGTA== X-Forwarded-Encrypted: i=1; AL+hErFyGtdhoFcAJotwW8SLVc5flsUOMQlS5esBYBtpZ0THshtmqGgRR5R/zvNGFlZpK3lLmSc=@vger.kernel.org X-Gm-Message-State: AB4q+uGC7MaTerZHpMjcTIFIYBnGw/3nGPQzqQvnQ2o9OclmtxOz4N8P tuk5OQvioV9wswJ7htL7LYzOKMXnphO16bg4Hz5cYqQZeQdPd99URs/b X-Gm-Gg: AZFdTZfDXEcmvCXbwaJ6sLhqoPMx98mHMUcRsGG3A9UEcyWruliXT6sVM5aIQJ7wao6 hezS5eLWaox9Z20j9BoHSuFNt1olnuEQhCt6kyGMJgfSpRK6FngNRVTFKxG254/EIG+489PEWp+ SoodZ+PrQQObr2HOWLVkNQwiKt0DDgpVvomsrciYl4droehRX92fZjX4a5MnyhoLxG5gOE+cNVu f/43nNZMRKQ5iDdK+923ks+nWzZnQfXFz/6KxLsdUHrV5CJUHWlYQrATy8fRcHmSMj94KyLCBvH U3MkDdISaVnwGE2B1Ow9iFuALA+OSD/20B+rzqxfmyfv9/uPhlees+GnilstbWVxGCVI6s36ODS gwlyEhFdRouG811prRvc2j/WOpuOCM1R5BM3Em+uftvncqdAtqnraWp164pnDxeqZ5mQZnGj8G+ VxPqvXKmwQcIIkte1NLE13NSFbwaFyJObZVHRYLZNC5bysG/dmDUXXcjzcetyccQNm5U9Ah+wja GVu06WLKfpsxVG7yyCBdOC4xXq/VSrqTgIHkrzYlQT9jfp6yJd/WXEyvIXC0ePGGrpbO+2XmVno X-Received: by 2002:a05:6000:60e:b0:4bc:d311:c64a with SMTP id ffacd0b85a97d-4d1eb7d718bmr8813910f8f.53.1796471146881; Sat, 05 Dec 2026 03:45:46 -0800 (PST) Received: from krava ([2a02:8308:a00c:e200::25dc]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d1723b8ab8sm10748369f8f.20.2026.12.05.03.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 03:45:46 -0800 (PST) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Sat, 5 Dec 2026 12:45:44 +0100 To: Alexei Starovoitov Cc: Anton Protopopov , bpf@vger.kernel.org, Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , 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 Message-ID: References: <20261204154705.1411391-1-a.s.protopopov@gmail.com> 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Sat, Dec 05, 2026 at 03:47:28AM +0000, Alexei Starovoitov wrote: > 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]); I like the fix one nit: the btf_own_func_id name seems a bit misleading to me when the module does not have that function we keep the vmlinux id, so the result is not always module's own id. Would something like btf_remap_func_id fit better? thanks, jirka