Thread (58 messages) flat view 58 messages, 7 authors, 8d ago

Re: [PATCH v2 bpf-next 17/18] selftests/bpf: Test BTF sysfs inline representations

From: sashiko-bot@kernel.org
Date: 2026-09-01 17:22:20
Also in: bpf

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Memory leak of `module_btf` when a module does not have a corresponding `.inline` sysfs file.
--

commit ae17979b11eeb1a7bef7bec7a8817be3cb2cd64a
Author: Alan Maguire [off-list ref]

selftests/bpf: Test BTF sysfs inline representations

This commit adds a selftest to validate BTF sysfs inline representations for
the kernel and modules. It parses the base BTF, module BTF, and inline BTF 
files to ensure proper loading and relocation across different scenarios.
quoted hunk ↗ jump to hunk
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
index 3923e64c4c1d0..97eccfd7c1344 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
[ ... ]
+static void test_btf_inline_sysfs_all(void)
+{
[ ... ]
+	while ((dentry = readdir(dir)) != NULL) {
[ ... ]
+		if (!base_btf) {
+			module_btf = btf__parse_split(btf_path, vmlinux_btf);
+			err = libbpf_get_error(module_btf);
+			if (err) {
+				/* A module can be unloaded while its sysfs entry is iterated. */
+				if (err == -ENOENT)
+					continue;
+				ASSERT_OK(err, "parse_module_btf");
+				continue;
+			}
+			base_btf = module_btf;
+		}
+		if (stat(inline_path, &st)) {
+			err = errno;
+			if (err == ENOENT)
+				continue;
[Severity: Medium]
Does this code leak module_btf?

In test_btf_inline_sysfs_all(), when a module is parsed successfully but
lacks a corresponding .inline sysfs file, stat() fails with ENOENT and this
path calls continue. Since this ends the loop iteration early, the
btf__free(module_btf) at the bottom of the loop is bypassed.
+			ASSERT_OK(err, "stat_inline_btf");
+		}
+		inline_btf = btf__parse_split(inline_path, base_btf);
+		err = libbpf_get_error(inline_btf);
+		if (!err)
+			btf__free(inline_btf);
+		ASSERT_OK(err, "parse_inline_btf");
+		btf__free(module_btf);
+	}
+	closedir(dir);
-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260901165757.801449-1-alan.maguire@oracle.com?part=17
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help