[LTP] tst_kconfig: load and unload kernel modules for CONFIG_*=m

Li Wang li.wang@linux.dev
Thu Oct 8 07:09:58 CEST 2026


On Wed, Oct 07, 2026 at 02:17:58PM +0000, linuxtestproject.agent@gmail.com wrote:
> Hi Li,
> 
> On Wed, 7 Oct 2026, Li Wang wrote:
> > tst_kconfig: load and unload kernel modules for CONFIG_*=m
> 
> --- [PATCH 1/3] ---
> 
> > diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
> > +	if (loaded_module_count < MAX_LOADED_MODULES)
> > +		loaded_modules[loaded_module_count++] = mod;
> 
> High: This records config matches, not modules newly loaded by the test,
> so cleanup can remove an unused module that was already loaded beforehand.
> A read-only tst_kconfig_read() during a callback also adds unload targets
> without loading them. Separate config discovery from ownership tracking
> and unload only modules successfully added by this test.

Good point, will fix it in v2.

> 
> > diff --git a/lib/tst_test.c b/lib/tst_test.c
> > +	tst_kconfig_module_unload_all();
> 
> High: Loading happens once in the library parent, but this cleanup runs
> in each test child. Setup aborts and killed children leak modules, later
> variants can lose modules removed by the first child, and cve-2026-46331
> cannot unload after dropping initial-user-namespace privileges. Move
> unloading to parent do_cleanup(), after all variants and resource teardown.

Agreed.

> 
> > diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
> > +		tst_modprobe(loaded_modules[i], NULL);
> > +		const char *const argv[] = { "rmmod", loaded_modules[i - 1], NULL };
> 
> Medium: modprobe also inserts dependencies that this list never records;
> with both initially absent, loading can-raw inserts can, but cleanup only
> removes can-raw and leaves can loaded. Track newly inserted dependencies
> relative to the initial module state and remove owned modules in
> dependency order.
> 
> > diff --git a/include/tst_kconfig.h b/include/tst_kconfig.h
> > +/*
> > + * tst_kconfig_module_load() - Load kernel modules for CONFIG_*=m entries.
> 
> Low: Both new public API comments use /* rather than /** and are omitted
> from the generated kernel-doc reference. Use kernel-doc comment openers
> for both declarations.

+1

> 
> --- [PATCH 2/3] ---
> 
> > Map CONFIG_VSOCKETS and CONFIG_VSOCKETS_LOOPBACK to their kernel
> > modules (vsock, vsock_loopback).
> 
> Low: The body only restates the mappings and does not explain the new
> config and privilege gates in cve-2025-21756. Explain the missing-loopback
> bind failure and why the test now requires root.

Will add the note in v2.

> 
> > diff --git a/testcases/cve/cve-2025-21756.c b/testcases/cve/cve-2025-21756.c
> > +	.needs_root = 1,
> 
> Low: Document this new root requirement in the test's high-level
> description, identifying module loading as the privileged operation.

Sure.

> 
> --- [PATCH 3/3] ---
> 
> > diff --git a/testcases/kernel/syscalls/keyctl/keyctl29.c b/testcases/kernel/syscalls/keyctl/keyctl29.c
> > -	tst_modprobe("x509_key_parser", NULL);
> > diff --git a/testcases/kernel/syscalls/keyctl/keyctl30.c b/testcases/kernel/syscalls/keyctl/keyctl30.c
> > -	tst_modprobe("pkcs8_key_parser", NULL);
> 
> Medium: With KCONFIG_SKIP_CHECK=1, tst_kconfig_check() returns before
> recording modules, leaving these removed loads without a replacement.
> When parser modules are installed but unloaded, keyctl29/keyctl30 now
> skip with EBADMSG instead of executing their checks. Preserve module
> setup independently of config validation, or retain the explicit loads.

With KCONFIG_SKIP_CHECK=1 the config check returns early and the
automatic module loading is skipped as well. However, I consider
that the intended behaviour rather than a regression.

KCONFIG_SKIP_CHECK=1 is an explicit opt-out from the kernel config
check. Loading the modules depends on the result of that check: the
list of modules is built by kconfig_parse_line() while parsing the
config, and with the check skipped that parsing never happens. To
load the modules anyway we would have to either re-parse the config,
which contradicts the whole point of skipping it, or hardcode the
module list, which would duplicate config_module_maps[].

So skipping the automatic load together with the config check keeps
the semantics consistent: KCONFIG_SKIP_CHECK=1 skips everything that
depends on the config check, and users who set it are expected to
make sure the modules their tests need are already loaded.

The affected tests are still executed normally when the config check
runs, which is the default. I've added a note to the commit message
to make the KCONFIG_SKIP_CHECK=1 behaviour explicit.


-- 
Regards,
Li Wang


More information about the ltp mailing list