The offsets of node children can be stored on stack.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/188
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Index files in pre-order have a significant performance improvement
for libkmod users.
On Arch Linux system, dumping configuration takes 296 read calls
in pre-order, compared to 4080 in post-order. Tests on a Raspberry
Pi 2 test system have shown an improvement by 9 %.
Even writing is faster now. This happens because we must know in
advance how many bytes index nodes will consume in the resulting file.
Although this code calculates it on the fly and caches the results,
saving lseek system calls has a significant positive effect which
compensates this extra overhead.
On Arch Linux system, writing index takes 6143 lseek calls now, compared
to previous 83701, leading to a performance gain of 13 %.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/188
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
When using -D b_ndebug=true or inheriting CFLAGS="-DNDEBUG" from the
environment, the asserts will be no-op thus the checks in the
LD_PRELOADED libraries will be omitted.
Explicitly undefine the macro, so we don't accidentally shoot ourselves
in the foot.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/238
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
If an overly long signature is found in a module file, it is possible to
trigger an out of boundary write in kmod_module_hex_to_str due to
integer and subsequent heap buffer overflow.
This approach replaces malloc + sprintf with a simple hex-lookup and a
strbuf approach, being slightly faster in real life scenarios while
adding around 100 bytes to library size. A much faster approach could be
done without strbuf and using our overflow check functions, but
readability should win here.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/236
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Specially crafted files could overflow internal counters, allowing out of
boundary writes. Make sure that neither counters nor resulting calculations
overflow.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/234
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Add the clang::suppress attribute to places where allocation is done and
that rely on the cleanup attribute. Clang analyzer doesn't handle those
(yet), so keep it from giving us false positive.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/233
When using the cleanup attribute we know we are not leaking that
allocation. Most of the time the assignment is together with the
declaration, so we can simplify additional clang annotations by making
the cleanup attribute imply clang::suppress.
In cases declaration and assignment are not together, provide
_clang_suppress_alloc_ to annotate the code. That is only defined for
clang analyzer.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/233
That attribute allows us to instruct the Clang Static Analyzer to stop
giving some false positives. However when building the code (with gcc
and clang) they warn that the attribute is ignored. Just ignore as we
know what the attribute is for.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/233
Move to macro.h where other attributes are located. The inline helper
function can also move along as we don't need to keep it separate.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/233
Seemingly Fedora and friends have been carrying this one for years. Just
add it to kmod itself so that people using multiple distros have
consistent experience.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/231
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Install the /{etc,usr/lib}/{depmod,modprobe}.d/ configuration
directories as part of out install action.
Currently a handful of distros (Debian, Gentoo, Fedora, Arch) do that
manually, where we can have it in the upstream project instead.
As a pie in the sky idea, in the future we may choose to enforce
particular permissions, ownership, etc and this should make it a little
less fragile across the ecosystem.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/231
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
With earlier commit we added support for kmod itself to install the
symlinks to kmod. While it works across the board, some distributions
still support (to varying degree) split /usr/bin and /usr/sbin.
This commit changes the location where those are created and bears no
functional change for merged bin-sbin users. While for split ones, it
follows what distributions are doing to a varying extend:
- Fedora, Alpine - this commit matches exactly what they do
- Debian, Yocto - they have an extra /bin/lsmod -> ../sbin/kmod symlink
- Gentoo - as Debian plus an extra /bin/modinfo -> ../sbin/kmod symlink
Loosely based on a Debian patch by Marco d'Itri.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/231
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The buxybox version of ln supports only the short options and does not
support -r/--relative.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/231
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Add a simple code coverage pipeline based on the CodeQL one.
Should give us pretty reports in the PRs and web UI with the results. We
can consider having HTML reports on our website (once it's up that is)
in addition or instead of at a future point.
Closes: https://github.com/kmod-project/kmod/issues/61
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/229
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This reverts commit ae0c0c4c89.
The commit reasoning was correct, but did not consider the case where
other third-party files are created. Namely: when generating the code
coverage files.
Thus the gcna files were created in $test_rootdir/$abs_top_builddir
which meant they won't get picked when the coverage info/xml/html files
were created and the statistics reported were quite wrong.
Revert the commit and add an inline comment, so we don't feel tempted to
change it in the future.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/229
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
While in here drop the docs and manpages flags - both of those combined
take ~1s of CI time - and disable the sanitizers and tests instead.
This means we no longer get pre-existing code problems in the tests,
which is fine considering the number of pre-existing issues in there.
Another nice side effect is that the pipeline time is reduced by ~50%.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/229
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
For almost 13 years, since commit 769becb5db ("tools: kmod: Add
handling of compat modinfo") we have a non-spoken joke in the build
system showing "-DANOTHER_BRICK_IN_THE -Wall" in honour of the famous
Pink Floyd song.
With configure flags now being sorted, I'm looking at the logs and
seeing: "-DANOTHER_BRICK_IN_THE -fdata-sections". That makes no sense.
Also the new meson build system did not join the joke. Not fun. Let's
drop it and let this commit serve as recognition of what it was.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/226
Pipe the lot through sort so one can reasonably search, add, edit
without going crazy.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/226
Nearly all the -Wno flags are not applicable any more - remove them.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/226
Make sure we are running in non-interactive mode and that we don't get
blocked on tzdata update.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/235
If fstatat fails, do not access the uninitialized variable st.
Instead, filter the file out.
Basically synchronization with libkmod's conf_files_filter_out.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/230
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Do not access memory out of bounds if the first character read by fgets
is NUL. Treat such a character as EOL instead. This is a purely
defensive measure since /proc/modules should normaly not contain such
characters.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/227
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The index_mm_{search,read,dump}* API does not mutate the index_mm
struct. So let's annotate it as constant.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The callers are interested if the file is within the list of builtins or
not. So change the return type and push the free() down the stack.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Create a simple helper and reuse it instead of duplicating code.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The compiler already creates an empty string as applicable, drop the
extra variable.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
As seen with previous commit, the way we pass an empty string to
index_{,mm_}dump() is very error prone.
Swap that with a bool, which makes things a lot more obvious.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
For non-alias indexes prefix is an empty string, where
strbuf_pushchars() returns the number of characters added to the strbuf.
Since those are zero, we end up completely skipping the dump process.
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Fixes: 889d02b1 ("libkmod: check strbuf return values")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Make sure that symbol names in ELF files are actually NUL terminated.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/222
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Whenever sizeof(mv->crc) is used, it's called crclen, not offcrc.
Move retrieval of field sizes into its own function.
Prepare this as a cleanup for easier auditing.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/222
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This may be useful for anyone trying a non-debug build and serve as
baseline for distros. Even for developers, when benchmarking kmod, it's
better to run a release-oriented kmod rather than the slow one due to
all debug/sanitizers.
By keeping the -D in the command line rather than in a ini file,
we also guarantee meson shows it in the summary, regardless of
https://github.com/mesonbuild/meson/issues/13865.
Closes: https://github.com/kmod-project/kmod/issues/220
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/221
For meson it's configure & build & install in the same snippet.
Do the same for autotools.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/221
We had the sanitizers disabled on Fedora 40, since the shared library
sanitizers comings with clang were not packaged. With Fedora 41 that has
changed, so let's try re-enabling them.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/219
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Seemingly with version 19, the CPU arch was dropped from the DSO name.
Try that and fallback to the old one, as applicable.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/219
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
As seen with the upcoming clang 19 change, the library name has changed.
Enhance the current test to check if the compiler provided string is a
file and produce a warning with some handy tips when that's not the
case.
v2:
- convert to heredoc
- output to stderr
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/219
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Should make it more distinguishable, depending on shell and/or CI setup,
from the informational message.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/219
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Convert to heredoc and add leading/trailing blank lines so it stands out
from the rest. It makes for cleaner reading experience both of the
script itself and its output.
As suggested by Lucas.
v2:
- don't escape ", drop spurious instance
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/219
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Fix the typo in the option description.
Reported-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/225
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
With last commit we've default-enabled a few options. So the optional
dependencies become required now.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/225
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The default for the compressions and openssl is based on the autotools
build ones. With the initial goal to make migration as easy as possible
- identical option names, help messages, defaults...
Although a bunch of these have changed already, plus we want builders to
get support for compressed/signed modules out of the box.
So let's flip the defaults - everyone is welcome to adjust those when
calling `meson setup -D foo=bar`.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/225
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The kmod.pc file, contains module_signatures and module_compressions
space-separated lists, indicating how kmod is built. For the meson
generated file, any spaces are escaped where the autotools one does not
do that.
Update the meson build to be consistent with the original autotools one
and omit the escaping that we don't want.
Aside: seems like autotools does not escape the directory variables
either, so if the path(s) have any spaces in them pkg-config (pkgconf at
least) produces rubbish, quite rightfully IMHO.
Eg.
$ cat .../autotools-file.pc
prefix=/usr
includedir=${prefix}/include bar
Cflags: -I${includedir}
...
$ pkg-config --cflags autotools-file.pc
bar
$ cat .../meson-file.pc
prefix=/usr
includedir=${prefix}/include\ bar
Cflags: -I${includedir}
...
$ pkg-config --cflags meson-file.pc
-I/usr/include\ bar
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/217
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Autotools uses $prefix/lib as the default for distconfdir, while meson
$libdir - which is not guaranteed to be the same.
In particular: Debian and derivatives use /usr/lib/$target-triplet as a
$libdir, while still keep the configuration directory as /usr/lib.
Fixes: 370141c1 ("meson: introduce meson, covering libkmod.so")
Reported-by: Marco d'Itri <md@linux.it>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/216
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This fixes a regression introduced while converting pointer to
offset arithmetics.
The for-loop itself starts at 1 already, so reflect this with the
manually performed offset + length calculation right at the start.
Closes: https://github.com/kmod-project/kmod/issues/214
Fixes: 25ab561b ("libkmod: Use ELF offsets more often")
Reported-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/215
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Return result of kmod_module_new directly in kmod_module_new_from_alias
so this function handles return values like the others.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/211
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
If kmod_module_parse_depline runs out of memory, it is possible
that not all dependency modules are unlinked.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/211
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The module_get_dependencies_noref function may modify content of
given kmod_module struct, so clarify this fact.
Actually we would have to adjust kmod API for total clarification,
but let's start with internally used functions first.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/211
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>