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=1796398531; b=JqucTSiCPHfpW2D8nHBF6USglI3+G5/nl472TsG0vu9HRP5MLQ7VU7e5cK3Urycza7nQ 0DFBPCsDg0z9Ovl344EhSAe+j4H0AJyqJ7kbQFo/WGoMIXUBXW6M9vBeZKYAM981XBwnj D1E/vRBlflf1Z2mXaGV/CAhOrSFMhEKWWS8Bi8QvEPPtsV6+s45eicF6YcmRNISSlsh3a 82Ct8mP5rbZXKgRm7v64Ll3hv0pLqhmeyJYsiHYWjHqwKvv6x6w1GwxpV7t/Lctd6u7Dy k/R3IwfzbR5/mnFtD89nIPerWP166bXjEWZbhouiglOQxJDalWKlmfo1o7HAWJjxF2A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796398531; 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=XHxHDCQ5w9JD1IgF+usfxdm90qHymHvJRBSZ7pRH7Ug=; b=GdBM6pwAc6cqXjGexAAvx2hYS8lkrNBGwT0ZX4eS+pG/sEzUoE/+azpL6l0MarkbtO/C ASkDmqaZkiQDWLNacN76vCtSUST29QWQAOeLbDdxT2pZpjfVcoIXjRVOiFq2BggpOlcfd pPCGkdAGysJMmoSFca19v4qJmq8XTWTY6dA5huhMvlaomW6J9MrXxw4eOzbxVMT5QU+uR oG5d/M5TqoAPSlDKQfVkmYkAD+UNemQNyBsD9k4a+3twtYbsnfx2CBXeA1Tv2O/yKsQ8j 4TNWJDhpAIoI2upPyUJ/txsodyntwHU0pS5XNodL3/bE2rKgvilKuJnyrtO2LzIPSMg== 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=j3vZlYwx; 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 D426B606A322 for ; Fri, 4 Dec 2026 15:35:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D426B606A322 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=j3vZlYwx Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-48e3b22e971so582226f8f.0 for ; Fri, 04 Dec 2026 07:35:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796398529; x=1797003329; 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=XHxHDCQ5w9JD1IgF+usfxdm90qHymHvJRBSZ7pRH7Ug=; b=j3vZlYwx0g9ypfNaYkORPxjI7n8aKAUJKsAl7KmH6lj7zTReXihih72G1iO6b7KAL6 H4mvqmPdaIlhZvrR3vYPYGG+AE/kqEb/QZmriXP3xvgQIpoZ4UejWOE+J5/0O2fEMj4Q fBSSBfehFvEDUrtSIC7hQLxsQCIABCyUvJ57M4R6c+eaCR4ZmFQsNHxz1keYQdNjxnTq AZreoHfqZLzRPnZG8aWB+Ab8DbjzYyhljeBDQM/qnpYl90EcRdP5aWq5N3CnedOEbsRm UsD7wxBOfsZ0KJBv247OrtdxK2zEAcVuUE+ZWmdnEYdY2SgXKA+ZEby2/ZbmCXoMR1lp c+VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796398529; x=1797003329; 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=XHxHDCQ5w9JD1IgF+usfxdm90qHymHvJRBSZ7pRH7Ug=; b=R0rmxSfT/OHcnnJ7Lv8TLKiqsb2Ebl0IxUTgnVcKgDtna7NH9zeK+JNHS3eE1+oURb RMvQueDHVWRnlngv2chjdGT6qj6fdVHW/yk9NySK/1iyBKzwTb0ZiYhv4FuTR5na5Rp0 gdiwOp8NSF6efwMXGTY2v4eaOLRBbDPVm6mvOK4ulWDKJSvATzWWNPEG8B8xjcvLqaSd dbZijon8dy2m7T3g6eJE6464vYEsCTcKUhWlPXD94B9lesaDAOsYYFBjsmrimkRztSHL qFUkPi1p072HBHjZwiBBDaPBcPDt5qv8m3aWzk9WURtTPpfR0xWejtkbRCtrcohx87lQ aDtw== X-Gm-Message-State: AB4q+uHNA9pErzQ3xHQqCIElmIV1fbNPaWDaiHVdoRlMN6QwKtIQeZr7 N/vDeP2AftAmDgHEFAEE7/SQZgZKbderGO/0FvYivwluu5yIyK0HhKfYCPx80ocs X-Gm-Gg: AZFdTZeJuUcW+FprHEa6WO5NYkFXPaq4TSgfHYPUr9u6vVyvuR0CN4Mro0k2rt4qbT7 ru4S7c1obU6vYxDimWlk31yEXaMbEUb/lvY4BJ+CXo2cZS1f/fWcVqKE+vssk2ZwMxzZx5w+c29 jwtTIkOIhHGkMNLifj+7K0ilyAQrbJLRpfw2HAh7OF/G2pv+/O05sxh71S0fmB0Q6odYjJyS3oP FQGQch1kyE6iMC/UqpHchbEpCUPOnZgJfY8IQ/VHqok6FmU9WPDUA2g1+OmhEC1SRkgFdcDbQ2B qJXQBtbea31K3GQBHpuQgdIC6uGkf3oqT5Ju3Cpz9GfBMn1DlRZd2VFSlLaNI3nMtCEIZWhKBel APU/IyczRC8dGdtqjOmbzDgaMKnlv0ZmuXXgnSjqsChD1BEdWPp5ylJx7RsSji+Y0HRqUPv+Pju InrDoLcIcgUskdvZZ6DQzdf6Wfe6KfbbHktaBdC5RMBthDSc588stFJ95qmo2DpMgoFxf4dfIAO 5bg865JQHwaEuurR9946XwruuvmXFDEHu5XIDJegaCI/7t8gvjPDFnqBr1oZ6WuQXiW9jxD+c8d uvxARpUWtZ0xwwQkEd1WgBJLpRYHQ5hMIiJBkw6QYvfMnas= X-Received: by 2002:a05:6000:60e:b0:4bc:d311:c64a with SMTP id ffacd0b85a97d-4d1eb7d718bmr4405857f8f.53.1796398529115; Fri, 04 Dec 2026 07:35:29 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d174fe6fbcsm5922841f8f.58.2026.12.04.07.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 07:35:28 -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 v2 bpf-next 0/4] bpf: Refuse the vmlinux prototype for a module function Date: Fri, 4 Dec 2026 15:46:59 +0000 Message-ID: <20261204154705.1411391-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. 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. 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. v1 -> v2: * Refuse the ID in bpf_check_attach_target(), which logs why, and fix the Fixes tag (patch 1) * Don't search the module twice when it has no function of that name (patch 3) v1: https://lore.kernel.org/bpf/20261203172617.1137735-1-a.s.protopopov@gmail.com 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/verifier.c | 17 ++++ tools/lib/bpf/libbpf.c | 75 ++++++++++----- .../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 ++ 8 files changed, 228 insertions(+), 39 deletions(-) -- 2.43.0