ASAN incorrectly reports this as unaligned access if compiler
optimizes code. Since ASAN support is valued higher than this
kind of optimization, just copy these few bytes into a stack
variable and avoid false positives in tests.
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/147 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
If an excessively large root directory is supplied, subsequent
operations might process unexpected parts in file system.
Inform user that supplied directory paths are too long and stop
program execution.
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/72 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Remove arbitrary limits due to file sizes (INTPR_MAX check). Reduce
amount of system calls by up to 90 % utilizing stream functions.
Also make sure that no TOCTOU could ever happen by not iterating
through the file twice: First to figure out amount of strings, then
parsing them. If the file changes in between, this can lead to
memory corruption.
Even though more memory allocations might occur due to strbuf usage,
performance generally increased by heavy reduction of system calls.
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/136 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The modinfo command can show information about builtin modules. Make
sure that it functions correctly.
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/136 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Thu, 19 Sep 2024 14:50:21 +0000 (15:50 +0100)]
testsuite: sort modnames only, if available
In some tests we expect zero modules to be loaded. In those cases, skip
the sorting - qsort is annotated as non-null(1,2) so we shouldn't
provide null as expected/loaded modules.
Emil Velikov [Sun, 22 Sep 2024 11:52:42 +0000 (12:52 +0100)]
ci: add SPDX copyright/license identifiers
To make it clear and explicit on the topic. Inspired by me reusing some
of those for usbutils and reuse-tool [1] flagging the lack of proper
attribution.
Emil Velikov [Wed, 18 Sep 2024 16:32:31 +0000 (17:32 +0100)]
libkmod: remove __secure_getenv handling
The build-time checking for __secure_getenv was dropped earlier, yet I
forgot to remove the actual users :facepalm:
Fixes: 9dc54a3 ("build: stop checking for __secure_getenv") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/139 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Wed, 18 Sep 2024 15:49:08 +0000 (16:49 +0100)]
tools/insmod: add --force longopt and document it
As of the initial import to git, the option was silently ignored.
Shortly afterwards, functionality was reinstated lacking a longopt and
any documentation.
As per insmod(8) for most use-cases you'd want to use modprobe(8).
Although since the option is available and we have an equivalent in
rmmod(8) having it documented and consistent triumphs.
Emil Velikov [Wed, 18 Sep 2024 15:49:08 +0000 (16:49 +0100)]
tools/insmod: remove unused -p -s shortopts
These have been around since the import to git, doing nothing. There are
no users that I can see, the manual page does not list them and the
shell completions (fish and bash lack any for insmod, zsh has one) don't
suggest it either.
Emil Velikov [Wed, 18 Sep 2024 15:49:08 +0000 (16:49 +0100)]
tools/rmmod: tweak --force help message
Drop the kernel configuration details - the CONFIG toggle name is more
useful (since you can see it in /proc/config.*) and generally the part
is better suited for the manual page.
Move DANGEROUS at the front, so it's obvious from the start
Emil Velikov [Wed, 18 Sep 2024 15:49:08 +0000 (16:49 +0100)]
tools/rmmod: remove unused -w shortopt
The (long)option and handling was removed some 10 years ago, yet the
shortopt remained... oops
Fixes: a4bd144 ("Remove "rmmod -w" documentation and getopt entry") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/138 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Wed, 18 Sep 2024 15:49:08 +0000 (16:49 +0100)]
tools: add kmod_version() helper
Add a trivial helper that prints the version + features combo. I will be
adding another instance of those, so I'm aiming to keep the boilerplate
code to a minimum.
Apply same logic as in delete_module.c, i.e. pass a reference to a
pointer instead of the pointer value, otherwise we cannot update
the linked list and added entries are lost.
Spotted with ASAN while running testsuite.
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/141 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
If an index file with INDEX_NODE_CHILDS flag contains illegal first
and last markers for children, it is possible to trigger an out of
boundary write.
Make sure that first value is not larger than last value while reading
index files.
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/126 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Tue, 17 Sep 2024 09:49:38 +0000 (10:49 +0100)]
shared: remove no longer used NOFAIL() macro
Closes: https://github.com/kmod-project/kmod/issues/60 Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/135 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Since off_t can (and most likely will) be 64 bit on 32 bit systems,
check its actual value before casting it to 32 bit size_t.
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/96 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
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/123 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Forward errors to callers instead of relying on unimplemented macro.
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/123 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
If read_char fails, stop operations and return an error instead.
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/123 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The fatal macro was never implemented. Its only user, libkmod-index,
should propagate error condition through errno as good as possible.
Other logging mechanisms are not available without adjusting API
because context is missing.
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/123 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
If read_long fails, forward error up to caller. Also perform proper
fread return value check.
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/123 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The return value is currently not needed. In prepration for subsequent
commits, use the return value to report if errors occurred or not.
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/123 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Sun, 15 Sep 2024 00:40:37 +0000 (01:40 +0100)]
build: stop checking for __secure_getenv
Currently we check for both __secure_getenv and secure_getenv. The
former was introduced with glibc 2.2.5 as internal(?) API, while the
has been part of glibc 2.17, circa 2012.
Drop the former check. It may have been required over 10 years ago, but
not any more.
Emil Velikov [Sun, 15 Sep 2024 00:40:14 +0000 (01:40 +0100)]
build: check for __xstat declarations
Currently we check the function is resolved at link time. Although what
we really care is if the headers are silently transposing any of our stat
calls to __xstat{,64}. If so, we'd want to wrap the latter functions.
As the now-removed comment says, glibc 2.33 was the first release to no
longer have static inline wrappers that do the transposition. See the
glibc commit 8ed005daf0ab ("Remove stat wrapper functions, move them to
exported symbols") for more details.
So change the checking to check_decl/has_header_symbol and keep them for
distributions with older glibc.
NOTE: to summarise/contrast this wrt the previous open64, etc
- here: we had inline wrappers and declarations (as below)
- others: no inline wrappers and optionally declarations
Emil Velikov [Sun, 15 Sep 2024 18:04:19 +0000 (19:04 +0100)]
meson: use has_header_symbol for checking declarations
Currently we use has_function, which will construct local declaration
and see if the program links successfully. What we're really interested
is if the referenced header has a declaration of the respective symbol.
Emil Velikov [Sun, 15 Sep 2024 10:03:00 +0000 (11:03 +0100)]
build: check properly for __stat64_time64
Having learned from prior LFS64 experience the glibc developers have
implemented stat in (albeit varying but) neater way:
- declaration with asm linkage to __stat64_time64
- or, `#define stat __stat64_time64`
- or, `#define stat stat64; #define stat64 __stat64_time64`
In all cases __stat64_time64 lacks an explicit declaration, unlike
open64, stat64, fopen64 mentioned earlier.
Since we lack declaration, we have no other option but to check if a
program with reference to __stat64_time64 can link, so we use the
check/has function.
For more details glibc commit aa03f722f3 ("linux: Add {f}stat{at} y2038
support") added internal.
Emil Velikov [Sun, 15 Sep 2024 10:03:00 +0000 (11:03 +0100)]
testsuite/path: s/__stat64_t64/void/
The exact struct varies across the build-options, but in practise is
never __stat64_t64 - this is the internal name used within glibc.
When the fstat declaration with __fstat64_time64 asm linkage is used, we
have "struct stat". Whenever the `#define stat __stat64_time64` kicks
in, both function and struct get redefined/renamed.
Since we don't care about it (apart from the pointer part) just use void.
For more details glibc commit aa03f722f3 ("linux: Add {f}stat{at} y2038
support") added internal.
Emil Velikov [Sun, 15 Sep 2024 09:11:49 +0000 (10:11 +0100)]
build: check for open64, stat64 and fopen64
... and use behind the respective ifdef HAVE_FOO guards instead of the
HAVE_DECL___GLIBC__ currently.
Since day one, glibc has declarations for the functions, which was
forwarding the normal functions to them, via asm linkage, et al.
Aka `extern int open(....) asm_linkage("open64").
In addition, a lot of libraries have grown to depend on the declarations
being available and functions being statically exposed via libc.so.
Whereas musl pre 1.2.4 (circa 2023) have exposed the symbols
statically, without a declaration for well over a decade. Newer musl,
no longer expose the symbol in their runtime but have retained the
define trick, stating it will be removed in the future.
Looking at the bionic front things are somewhat similar. Newer bionic
(circa 2019) have a declaration and an inline wrapper open64 function
forwarding to open. Throughout 2019, open64 did forward to misc other
internal functions thought.
Older pre 2019 bionic had a declaration alongside plug exposing the
symbol statically in their C runtime.... since 2014. Not sure what they
did prior to 2014, it's a target out of scope for us.
Considering the above, the most robust approach is to do a check/has
function checking.
With that, we no longer need the __GLIBC__ guard for the respective
functions.
Emil Velikov [Sat, 14 Sep 2024 14:08:59 +0000 (15:08 +0100)]
testsuite: remove access() sub-test
Our test does access + stat, where stat is sufficient. In addition, the
kmod codebase never used access (afaict), so we're safe to remove the
access() part.
Emil Velikov [Sat, 14 Sep 2024 13:57:44 +0000 (14:57 +0100)]
testsuite: remove *lstat* wrappers
The majority of these were initially introduced with commit 123e827
("testsuite preload: Factorize into macros, add more stat and open
variants").
The commit itself was meant to refactor existing wrappers and add new
_xstat (aka stat) variants. The lstat variants were never used in kmod
directly nor indirectly via header macros.
The rest were added to mimic the original, without much testing it
seems.
They are all dead code - remove them.
In theory one could have a macro/helper that calls `lstat` for `stat`
itself, although that isn't a practical solution for a few reasons.
The functionality across the two varies, where if the path provided is
a symlink `stat` follows it, while `lstat` gets the details for the link
itself. To fix this, the wrapper would need second syscall to resolve
the symlink, which will cause notable performance regression wrt using
using the `stat`/`stat64` syscall alone.
Emil Velikov [Mon, 16 Sep 2024 22:39:23 +0000 (23:39 +0100)]
CONTRIBUTING.md: mention license and SPDX
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/134
[ Mention LGPL is preferred, even for tools/ ] Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
While CODING-STYLE states that using Signed-off-by is an error, a large
number of contributors have been using it. Most, if not all, of those
are people who have contributed to the kernel, and by extension know
about the DCO.
So let's add an in-tree copy of the file, explicitly document what is
meant with the tag (other projects use if for different purposes) and
drop the note from CODING-STYLE.
I have not went full bananas to require it, since based on the numbers
below, majority of commits lack it. We could reconsider that at later
point, if needed.
Numbers, as of commit 11ccabd ("libkmod: document the symbols file")
- total number of commits - 1640
- number of commits with at least one s-o-b - 357
- this can be s-o-b by the author, maintainer and/or both
- total number of contributors (bots including) - 109
- number of individuals with at least one s-o-b - 42
Closes: https://github.com/kmod-project/kmod/issues/98 Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/128 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Fri, 13 Sep 2024 12:02:54 +0000 (13:02 +0100)]
man: remove slash before @MODULE_DIRECTORY@
... otherwise we get a double-slash in the manual.
Fixes: e2536ab ("man: Provide examples for paths") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/129 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Document some of the practises and expectations that we've been using
in the project.
Large chunks of the document are inspired by wlroots - thank you o/
Going further, I think we'd want to document the use of SoB/DCO and
mention about our CI pipelines, so that people try them before opening
PRs/sending patches.
Although I think that can follow-up at another day.
Lucas De Marchi [Wed, 11 Sep 2024 13:51:23 +0000 (08:51 -0500)]
build: Fix KDIR again
KDIR is not related to the what we configure in kmod's build. It's only
used in kmod to locate where the distro's kernel source/headers is,
which may be different from what we are configuring the (under
development) kmod with.
Remove the setting from meson/autotools and figure it out inside the
module-playground Makefile what should be used. For advanced use cases,
KDIR= can be passed to override the location.
For our own tests, which includes testing with a different module_directory,
scripts/setup-rootfs.sh will copy the module to the desired location
according to the map defined in the script.
Fixes: 27ff72732666 ("testsuite: correct the default KDIR") 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/125
Lucas De Marchi [Mon, 9 Sep 2024 06:13:55 +0000 (01:13 -0500)]
man: Reword depmod's paths
Main goal is to give the reader the complete picture of each component
of the path being used, divided in <BASEDIR>, <MODULEDIR>, version.
Then reword the options accordingly to refer to what they are
overriding.
Michal Suchanek [Wed, 4 Sep 2024 06:54:06 +0000 (08:54 +0200)]
depmod: Add option to override MODULE_DIRECTORY
This a compile time option. When building modules for a different system
that uses a different value of this option it is useful to be able to
override it without rebuilding kmod.
Closes: https://github.com/kmod-project/kmod/issues/85 Signed-off-by: Michal Suchanek <msuchanek@suse.de> Link: https://github.com/kmod-project/kmod/pull/100 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Mon, 9 Sep 2024 13:33:35 +0000 (08:33 -0500)]
meson: Stop rebuilding modules over and over
Instead of removing the sources every time and rebuilding, just use
rsync to preserve the timestamps and allow Make to do its job of
rebuilding if it changed.
There's a bug in meson that keeps building the testsuite even outside of
`ninja test`, but if the build result is cached, we can greatly minimize
the impact for developers.
Closes: https://github.com/kmod-project/kmod/issues/119 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/121
Lucas De Marchi [Mon, 9 Sep 2024 07:08:54 +0000 (02:08 -0500)]
meson: Move symlinks up
Currently it's only possible to test the tools by using the symlink.
However, differently from autotools, the symlink is created inside the
testsuite dir, and only if build-tests=true. Move it to the same
directory that kmod is so it's possible to test without the testsuite.
Emil Velikov [Sat, 7 Sep 2024 00:28:19 +0000 (01:28 +0100)]
testsuite: use size_t with strbuf
We recently updated the API, but forgot to update the tests.
Fixes: 38943b2 ("shared: use size_t for strbuf") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/115 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Sun, 8 Sep 2024 10:38:12 +0000 (11:38 +0100)]
.editorconfig: max_line_length=90 like clang-format
Ideally the config (and editors) will have hard and soft limit for the
line length. Until then, update the config so that clang-format does not
excessively reformat.
Lucas De Marchi [Sun, 8 Sep 2024 10:38:12 +0000 (11:38 +0100)]
clang-format: Override settings
- Define our own foreach macros
- Add defines for attributes. This also needs the minimum clang-format
version to be raised so it has the AttributeMacros setting.
- Redefine a few settings related to max number of columns and
penalties for breaking lines
Emil Velikov [Sun, 8 Sep 2024 10:38:12 +0000 (11:38 +0100)]
libkmod: guard some functions with clang-format off
Running this through clang-format results in a massacre. In some cases
we get function names starting at column 1, in others, every argument is
on separate line.
Just block the lot, so things are somewhat sane and consistent.