Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Unchecked NULL pointer dereference when allocating test symbol buffer. --
--- Patch [4]: [PATCH v7 4/4] kallsyms: add KUnit tests for lineinfo feature --- commit aa7a75a3dcd2a5f7456eb96f884496c36509f6d7 Author: Sasha Levin <[email protected]> kallsyms: add KUnit tests for lineinfo feature This commit adds a KUnit test module to verify that the kallsyms lineinfo feature produces correct annotations in stack traces. It also exports sprint_backtrace() and sprint_backtrace_build_id() so the test module can exercise the backtrace APIs. > diff --git a/lib/tests/lineinfo_kunit.c b/lib/tests/lineinfo_kunit.c > new file mode 100644 > index 0000000000000..dad1522a44f5a > --- /dev/null > +++ b/lib/tests/lineinfo_kunit.c [ ... ] > +static char *alloc_sym_buf(struct kunit *test) > +{ > + return kunit_kzalloc(test, KSYM_SYMBOL_LEN, GFP_KERNEL); > +} [ ... ] > +static void test_normal_function(struct kunit *test) > +{ > + char *buf = alloc_sym_buf(test); > + unsigned long addr = target_addr(lineinfo_target_normal); > + > + skip_without_module_lineinfo(test); > + > + sprint_with_lineinfo(buf, addr); [Severity: Medium] Will this crash the kernel if kunit_kzalloc() fails and returns NULL? If memory allocation fails under pressure, alloc_sym_buf() returns NULL. The callers like test_normal_function() pass this buffer unchecked into sprint_with_lineinfo(), which eventually passes it to kallsyms_lookup_buildid() as the namebuf parameter. Looking at kallsyms_lookup_buildid() in kernel/kallsyms.c, the buffer is dereferenced immediately: kernel/kallsyms.c:kallsyms_lookup_buildid() { ... namebuf[0] = 0; ... } Should alloc_sym_buf() use KUNIT_ASSERT_NOT_NULL(test, buf) to gracefully fail the test instead of causing a NULL pointer dereference? -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=4
