Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796318079; b=nrQWmXM/CmtbfnyvPYgcJe2/w2hmeZwOyoQIdlgl5pMr5HSWePLmYou1KPPR4yD3o+bO XIvUhbVWKOFzbW7197wvNqGKLpZuzEftDDo+Mnf+0jiGNVBCXCGKfjUhugkRgnBrPS+Dy mVooFEc2W7F6Q9ePpU1K05L3JHPKgZRu+D489XQNKRDVuBUAll36NXjdTZl7K9hfnEEhq oRdbuy0qQxXaHmFNRhpKBInIPNOgthqEu0VMRmTa/OA8BHXGHR+I7mqB4nGAOWSEPP/3L Duz4GNeFSuHrLtWMgbu4jrhf/r4X3lUsJaltYpRJGWNIGazp+kYBvSqpmURvcGUtILQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796318079; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=jMZnkbEwXJbTBz3z5UQugDW/zlmSxMZGGFnTsvcMRXU=; b=IMhNHAb/XpGv2laubZzQknkuldEWeJ9MsAk8EqnNdiVhfv+DhSEmh1bXcagBxdm2CiCo V6ytOhHM1mJaMneZ9dE4f+0Id/BANuQ4GAtv5XFaruhbiA3udPaIlRJ5v1pLPwUTkw5/a WGB+1QHx+sRULFag1sJLtnCCe6uB1+2Gp7d/hy3ikaVfOSZ8Sl3kzbHvm4KE0gUDQzzLL k2upXxxv9Ztcfic/5E59YpcTx08gBW3Utd52MbAVwhQZu/7dzFX18LVhKQiYYjvoDm5xF 5CJdZvBsMf7+YwU5YpbCM4hIKDVlW3PNHWrrYvuBnVWzYwAUC39/1J9l0bfKfU8LiJA== 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=Jra35D91; arc=none smtp.remote-ip=209.85.221.49 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 2B27B606A322 for ; Thu, 3 Dec 2026 17:14:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2B27B606A322 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=Jra35D91 Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-498f5fa5103so59129f8f.2 for ; Thu, 03 Dec 2026 09:14:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796318077; x=1796922877; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=jMZnkbEwXJbTBz3z5UQugDW/zlmSxMZGGFnTsvcMRXU=; b=Jra35D91FDPAqr8A7d16EpNAWuH2oFaAkenSZFvBStjnbAAfmtQXM6K0x5wXLzIQuZ UVEU+7zBBWUBZwHUClg7MYkM+XN8Woqrxt4FJTaT08A6nf9wNFHzq9lH7rU2CCVGWRP9 tIbViMk9jXTT8xwaCgvtfDBLkiKWdc+EESL/ggiI1/1cHtGq70+VUH392V3L2CJtexW5 sfwiRlUCwl+Fh80g9MS/Bp2lUsv4j+sVw6yVr2QFry6QTrfKNT+VW5FycZy9J2QNyAKv /s4gVwz+GfFVslxfq7PbeH1Scat2dO0LRJTMvlnCHz29jDioZkezinaqTGXWCXks22bX 7nGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796318077; x=1796922877; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jMZnkbEwXJbTBz3z5UQugDW/zlmSxMZGGFnTsvcMRXU=; b=gqFNpLIfCiJMDoADW52OVZqyfEGByGRbHpsagiHtA7TPhWOseF5NNOJwkq24VTylnl IX9DzapmzRI+3+RsS32jsm1LqoGXKGXEdGXhCFuA1gdFdLKqsxDJbfuWucuiK0JvroPR D2imOkhaAMyreADsutFhw59BmCw6wfCd73QQ1o4jhukCEI47glqrImKWw7KsdjRHDLv5 BtxahA43IeQEn5h2LsLG3Rk22aWm8wqyEjIQgXAXKTYc3VYk2/Wotwh1WNRLskVZFd3g 2cGcPA8v3iXH8to3JVzLgIOPRHUBTD/EEkjUn8zakxCrkAtfQLTzlcNC0QNaNi54X7nP WXqw== X-Gm-Message-State: APuU4Z9uIjBFgZOt8VAXHb3S0FOvAg8JTYOeVBb46xi6akGkTR0N2PTN w3VS5ZaNfa/UP7CvnztC4zMUMkmL5yJj6oKWcpmvkQAc2olMr7aSo1/ykW3T9Bed X-Gm-Gg: AZFdTZff0FdU6bHaFTel1Phr7KhlFJsS4ugPUHblWS6BTbSAoKhteN1zyvEZ8X+ytNO 0pRrnwXcxzm/5nAaa5fMJRrhrPXadF7es6xl6UZ5A1QilfzWjIcuKsCX9P4ZN101nSfYsolt8qS 7c8w/PycGOJ99TT0GiqOmpYoLRSy85TpAe+WTKm1U8+jNu/FTUv9azB2TIHF9wyP++Otnv+sMul IihnmVKwBeT0b8J48737uW4AvDeBTlc7jZPvn+pQwFBqU5sHFJPpCLVxISHrLNBoXAueG1FM+4h ez+ZGM4HS31G56u06zpOHWFLewm5VNWNu/iQoQjpWtKnXqx9tSacLn6De3eZNVx4x1yfZyMVolT w/FxMZ1o7U78YCMfV0plIaqT004sZZHsm7x6Mk2/8pEh/yHick7Qh4gDPkj5GCocJkpEN1PZN3p s3gLn1csMUQKuCYdWGFJ8dEUSrPkpPXXRKpstMSC5AzDk8d9wwkZwEDZQaBkBdIQiEhPWxXdpeb AFewfH7RCPUVsb+xM1ii9eVEKriPmUuwhaJGXgt5zgGdmPpqFlT83tvDPi0SuezUKG9eOlhSkn7 NENWJaAE+iVNoYaacJMWNvmD15apbqWm97HULukGMskmsVw= X-Received: by 2002:a05:600c:a117:b0:4bb:a5e1:7497 with SMTP id 5b1f17b1804b1-4bba5e18d83mr431893165e9.32.1796318077340; Thu, 03 Dec 2026 09:14:37 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb9067846esm906409615e9.4.2026.12.03.09.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 09:14:36 -0800 (PST) From: Anton Protopopov To: bpf@vger.kernel.org, Alexei Starovoitov , 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 Cc: Anton Protopopov Subject: [PATCH v1 bpf-next 0/4] bpf: Refuse the vmlinux prototype for a module function Date: Thu, 3 Dec 2026 17:26:11 +0000 Message-ID: <20261203172617.1137735-1-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.43.0 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-Transfer-Encoding: 8bit A tracing program can be loaded with the BTF of a module and the ID of a vmlinux function. The kernel then attaches it to the module function but with the vmlinux prototype. If the two prototypes differ the program reads the arguments as wrong types. Even worse, if the module function takes more arguments the trampoline doesn't save them. A tracing multi link has the same problem with its IDs. And libbpf makes such pairs itself for "fentry/mod:func" and for module globs, since it searches the types of vmlinux first. Patches 1 and 2 refuse the ID of a vmlinux function with the BTF of a module if the module has its own function of that name. This is checked at load and at the creation of a tracing multi link. Patch 3 makes libbpf look up the functions of a module first. Patch 4 tests the kernel and libbpf. A simpler check "with the BTF of a module the ID must be a module type" doesn't work, because pahole and resolve_btfids dedup the BTF of a module against vmlinux and a module function with the name and the prototype of a vmlinux function is merged into the vmlinux FUNC. The vmlinux ID is then the only way to attach to it. Some selftests rely on this. One case stays open: a module function which pahole leaves out of BTF and which has the name of a vmlinux function of another prototype. pahole drops a function whose prototype doesn't match how it is compiled or whose name has several prototypes in the module. Its symbol is still in kallsyms and the module has no FUNC to tell it by, so the kernel takes the vmlinux ID and uses the wrong prototype. 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 stock Ubuntu 7.0 arm64 kernel six module functions have their own FUNC with the name of a vmlinux function. Four of them have another prototype and are the bug which patches 1 and 2 fix. Only two, ghash_setkey() and ghash_update() of ghash_ce, differ just in parameter names. 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. Patches 1-3 have Fixes tags, however the bug is old and needs CAP_BPF and CAP_PERFMON, so I am sending this to bpf-next. Anton Protopopov (4): bpf: Refuse the vmlinux prototype for a module function bpf: Refuse the vmlinux prototype for a module function in multi links libbpf: Look up the functions of a module first selftests/bpf: Test a vmlinux function ID with the BTF of a module include/linux/btf.h | 2 + kernel/bpf/btf.c | 40 ++++++-- kernel/bpf/syscall.c | 14 +++ kernel/bpf/verifier.c | 6 ++ tools/lib/bpf/libbpf.c | 73 +++++++++----- .../selftests/bpf/prog_tests/module_attach.c | 11 +++ .../bpf/prog_tests/module_fentry_shadow.c | 96 +++++++++++++++++-- .../selftests/bpf/progs/test_module_attach.c | 16 ++++ .../selftests/bpf/test_kmods/bpf_testmod.c | 10 ++ 9 files changed, 230 insertions(+), 38 deletions(-) -- 2.43.0