Skip to content

libkmod: fix NULL deref in module_options_concat(); merge multiple softdep/weakdep stanzas - #459

Open
prabhakarpujeri wants to merge 4 commits into
kmod-project:masterfrom
prabhakarpujeri:fixes
Open

prabhakarpujeri wants to merge 4 commits into
kmod-project:masterfrom
prabhakarpujeri:fixes

Conversation

@prabhakarpujeri

Copy link
Copy Markdown

Four small fixes:

1. libkmod: fix NULL dereference in module_options_concat()

The malloc() return value is dereferenced unguarded; on OOM this NULL-derefs
in the kmod_module_probe_insert_module() (modprobe) path. The function's
contract treats NULL as "no options" (the sole caller passes the result on to
kmod_module_insert_module() / module_do_install_commands() which both
accept NULL), so the fix returns NULL on OOM and documents this contract in a
comment rather than inventing a new error path.

2. libkmod: merge all matching softdep and weakdep config stanzas (fixes #33)

kmod_module_get_softdeps() / kmod_module_get_weakdeps() broke out of the
config iteration after the first matching stanza, silently dropping deps from
additional softdep / weakdep lines for the same module. Now every matching
stanza is accumulated, mirroring lookup_dep() itself. The multi_softdep
testsuite case was marked expected_fail with a FIXME referencing #33; with
this fix it becomes a normal passing test, verified with meson test
(TESTSUITE: PASSED: multi_softdep, full suite 7/7, plus an ASan+UBSan build).

3. depmod: add missing --dry-run to --help output

-n is accepted as both --show and --dry-run (and documented as such in
depmod(8)) but the help text only listed --show.

4. modprobe: merge duplicated -i lines in --help output

The help output printed -i twice (for --ignore-install and
--ignore-remove); merged into one line matching modprobe(8)'s joint wording.

All commits build warning-free (-Dwerror=true) and the full testsuite passes
(7/7 in both the regular and sanitizer builds; patches also round-trip cleanly
via git am on pristine master).

Prabhakar Pujeri added 4 commits August 31, 2026 15:35
module_options_concat() dereferences the result of malloc() without
checking it, so modprobe can crash when the allocation fails.

NULL already means that neither source supplied any options.  Return a
status separately from the allocated string so an allocation failure can
be reported as -ENOMEM.  This avoids both the crash and loading a module
without options that the caller requested.

Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
kmod_module_get_softdeps() and kmod_module_get_weakdeps() stop at the
first matching configuration stanza.  Additional dependency lines for
the same module are therefore ignored.  A generated modules.softdep entry
can also prevent a matching entry in modprobe.d from taking effect.

Append dependencies from every matching stanza, as lookup_dep() already
does for its per-module lists.  Enable the existing multi-softdep test and
extend the weakdep fixture to cover two matching stanzas.

Link: kmod-project#33
Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
The long option table accepts both --show and --dry-run as aliases of
-n and the man page documents "-n, --show, --dry-run", but the help
text only mentions --show. Add the --dry-run alias to match, wrapping
the description onto the next line as done for the other options that
don't fit the description column.

Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
The help text lists -i twice, once for --ignore-install and once for
--ignore-remove, while both long options map to the same flag and the
man page documents them jointly as "-i, --ignore-install,
--ignore-remove". Merge into a single entry, following the man page
wording.

Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using multiple softdep for a module, only one of them have effects

1 participant