[LTP] lib: add module is loaded check
linuxtestproject.agent@gmail.com
linuxtestproject.agent@gmail.com
Mon Nov 2 09:26:57 CET 2026
Hi Li,
On Mon Nov 2 10:43:25 2026 +0800, Li Wang (Hieco) <li.wang@linux.dev> wrote:
> lib: add module is loaded check
--- [PATCH 1/4] ---
> --- a/include/tst_module.h
> +++ b/include/tst_module.h
> @@ -49,5 +49,6 @@ static inline void tst_requires_module_signature_disabled(void)
>
> void tst_modprobe(const char *mod_name, char *const argv[]);
> void tst_module_reload(const char *mod_name, char *const argv[]);
> +bool tst_module_is_loaded(const char *mod_name);
Add a kernel-doc comment (/** ... */) for tst_module_is_loaded() documenting
@mod_name and Return:.
--- [PATCH 2/4] ---
> +static void kconfig_module_record(struct tst_kconfig_var *var)
> +{
> + unsigned int i;
> + const char *mod = NULL;
> +
> + if (var->choice != 'm')
> + return;
> +
> + for (i = 0; config_module_maps[i].config; i++) {
> + if (!strcmp(config_module_maps[i].config, var->id)) {
> + mod = config_module_maps[i].module_name;
> + break;
> + }
> + }
> +
> + if (!mod)
> + return;
> +
> + if (tst_module_is_loaded(mod))
> + return;
> +
> + for (i = 0; i < loaded_module_count; i++) {
> + if (!strcmp(loaded_modules[i], mod))
> + return;
> + }
> +
> + if (loaded_module_count < MAX_LOADED_MODULES)
> + loaded_modules[loaded_module_count++] = mod;
> +}
Recording modules into loaded_modules[] inside kconfig_parse_line() happens
even when geteuid() != 0, when tst_kconfig_check() fails with TCONF (e.g.
CONFIG_X509_CERTIFICATE_PARSER=y on a =m kernel), or when tst_kconfig_read()
is called later during the test. Consequently, tst_kconfig_module_unload() in
do_cleanup() attempts to unload modules that were never loaded by
tst_kconfig_module_load(), and fails with EPERM (emitting a spurious TWARN)
when running unprivileged (such as vsock01). Only record modules in the
unload list when tst_kconfig_module_load() actually loads them.
> + default:
> + tst_res(TWARN, "Failed to unload module '%s'", name);
> + }
Use TWARN | TERRNO so the failure reason from delete_module() is printed.
--- [PATCH 3/4] ---
> static struct tst_test test = {
> + .needs_root = 1,
> + .setup = setup,
> .test_all = run,
Document why root is required (loading the vsock/vsock_loopback modules) in
the top-level /*\ ... */ test description block.
--- [PATCH 4/4] ---
> /*\
> * Test ``KEYCTL_RESTRICT_KEYRING`` builtin_trusted of :manpage:`keyctl(2)`.
> *
> - * Requires root (CAP_SYS_MODULE) to load the ``x509_key_parser`` module.
> + * * Requires root (CAP_SYS_MODULE) so that the test library can load the
> + * ``x509_key_parser`` module.
Remove the extra asterisk in "* * Requires root", which creates a malformed
reST bullet item. Also update .needs_kconfigs in keyctl23.c from
"CONFIG_X509_CERTIFICATE_PARSER=y" to "CONFIG_X509_CERTIFICATE_PARSER",
otherwise tst_kconfig_check() aborts with TCONF on =m kernels instead of
loading x509_key_parser.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
More information about the ltp
mailing list