Modinfo rework - #451
Conversation
Codecov Report❌ Patch coverage is
... and 17 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
The latest revision has all the yaks shaved on my end ;-) v2:
Edit: this time for real - aka rebase + clang-format nitpick |
|
NOTE: this effectively prints the "parm" entries in inverse order... AFAICT that should not be an issue, since the output order was never meant to be deterministic. |
| { | ||
| const enum kmod_module_initstate state = kmod_module_get_initstate(mod); | ||
| const bool is_builtin = state == KMOD_MODULE_BUILTIN; | ||
| const char *filename = is_builtin ? "(builtin)" : kmod_module_get_path(mod); |
There was a problem hiding this comment.
I think we need to be careful here... we may be running modinfo() into a module that is builtin for the current kernel, but we are actually doing modinfo for something else.
Example: ext4 builtin on my distro, but I'm doing modinfo ./ext4.ko for a kernel I'm developing for another system. Previously it would notice that mod got constructed from a module and use that as filename. Here you'd wrongly report that it is builtin.
There was a problem hiding this comment.
Valid point - dropped for now.
As a whole, a few functions rely on parsing /sys/modules and friends even when a different kernel version is explicitly provided to kmod_ctx_new. The current behaviour seems suboptimal/buggy.
IMHO we should probably error out, although I could be missing something?
There was a problem hiding this comment.
Somewhat related:
It looks like we have different filename (path really) in database vs filesystem... without ever flagging it as an issue. Observed this while copying/adding more modinfo tests. To make it more interesting, setup-rootfs.sh manually changes the path in .dep files but not in .dep.bin and co.
One possible (perhaps overly comprehensive) solution is:
- have the proper depmod artefacts checked-in
- on test prep, re-generate ^^ into a throwaway location and error on miss-match
- ensure correct path is used across .dep/.dep.bin/etc - might need a patch to libkmod/depmod/
- on test closure, flag files with unchanged atime - ignoring the depmod regen/check
What do you think?
3978b74 to
a20e6ab
Compare
|
v3:
|
| uaddsz_overflow(strbuf_used(buf), vec_size, &total_size)) | ||
| return NULL; | ||
|
|
||
| /* XXX: Do not handle bytes behind the object's back */ |
There was a problem hiding this comment.
and we had strbuf_steal() for this kind of situation that got removed. IMO let's not drop these helpers if they may be used in future?
There was a problem hiding this comment.
Looking at the PR that removed it:
- there is one overflow bug (fixed in this PR)
- the function comment/description didn't get updated
- the above workaround was pre-existing
Can reintroduce and fix ^^ as a follow up PR.
Would you be OK with dropping "strbuf_init` or prefer to keep it - I don't mind either way.
There was a problem hiding this comment.
Can reintroduce and fix ^^ as a follow up PR.
sounds good
Would you be OK with dropping "strbuf_init` or prefer to keep it - I don't mind either way.
we can drop the callers from the codebase, but let's keep it in the more-or-less-self-contained strbuf implementation. I'll push an update here before merging.
As a followup I think it's also reasonable to move strbuf_to_vector() to be in strbuf.c so the re-init happens inside the strbuf implementation. Then we document that sbuf becomes invalid afte the call.
|
Also getting this: Since it's now using DECLARE_STRBUF_WITH_STACK(), we need to remove the strbuf_release() at the end. Added 2 fixup commits to handle the comments. |
The two extra fixups look good to me. Thanks o/ |
|
double checking this commit:
it actually isn't. Passing NULL here is undefined behavior regardless of the precision specifier. In the end this code was converted to strbuf so we don't need it. I will simply drop the commit and solve the conflicts. |
May I ask where did you spot that? The man page suggests that up-to precision specifier characters of the string are accessed/printed. Plus the undefined sanitizer included in gcc (16.1.1 20260725) doesn't complain either. Either way, thanks o/ |
|
There's some discussion here about that part of the standard: https://stackoverflow.com/questions/70499706/is-it-guaranteed-by-the-c-standard-to-be-safe-to-do-printf-s-0-null |
20881c8 to
67c2ae8
Compare
The generic (full) expression is: - "$name:$parm ($type)" Although currently, if no $parm is available and --field isn't used we instead print: - "$name:$type" Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: #451 Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
Currently we assume that the module is built-in if
kmod_module_get_path() returns NULL... Which isn't quite true, since it
can fail for a range of reasons.
Use kmod_module_get_initstate() instead, which will incur in an extra
open("/sys/module/.../initstate") + read() for non built-in modules.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: #451
Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
Specially crafted/corrupt modules may have a parm/parmtype entry which lacks the "name:" prefix. Throw a warning and skip such entries. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: #451 Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: #451 Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
The respective strings are guaranteed to be nil terminated, so drop the strlen() and respective len(th) fields. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: #451 Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
Currently, we if we fail to find a name, description or type in the
value token we emit an error and continue.
At the same time, if the name is longer than INT_MAX we error out.
Move the validation (overall strlen(value), which includes namelen)
further up the call stack and make it a non-fatal.
This allows us to garbage collect the no longer reachable error paths
around {add,process}_param().
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: #451
Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
This gets Valgrind on my Arch box to be 100% "leak-free" ;-) Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: #451 Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
|
Applied, thanks |
|
It seems like v2 got merged, including the UB I'm assuming that's by mistake - will send an update PR tomorrow/day after, with all of your comments addressed. |
|
ugh... sorry. That's what I get for working in 2 different computers :-/. |
|
I removed the commits from the master branch and will re-add once I get my other computer back. Sorry about that. |
The generic (full) expression is: - "$name:$parm ($type)" Although currently, if no $parm is available and --field isn't used we instead print: - "$name:$type" Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Specially crafted/corrupt modules may have a parm/parmtype entry which lacks the "name:" prefix. Throw a warning and skip such entries. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
The field provides end-user description what the parameter is used for. Rename it accordingly. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Store the `parm` vs `parmtype` instance as an enum, saving another streq() shortly afterwards. There's no practical benefit apart from making the code a tiny bit clearer IMHO. v2: Change enum names Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Thus using the correct format when `--null` is specified. In particular, the both name + filename use the correct format, when --null (mode) is requested. v2: - call kmod_module_get_name() as needed Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
No point in continuing if only a certain field is requested. While in here, use a consistent code-pattern for the process. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Add a couple of booleans to arguably make the code a wee-bit cleaner to follow. A follow-up commit will further reuse the latter (print_parm) to avoid repeatedly calling streq(). Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Earlier commit reworked so we always allocate space for the \0 byte. Although it did not (fully) consider that it can be the reason for an overflow. Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Fixes: 2b47598 ("shared: let strbuf_str never fail") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
The only caller of buf_realloc() already ensues that the size is 1 or more so let's drop the if statement. Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Fixes: 2b47598 ("shared: let strbuf_str never fail") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Introduce the simple macro and use it to (better) illustrate the strbuf size calculation. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
We'll need the function shortly, so make it public (within kmod). In the process, re-introduce the test with some changes: - cosmetics - test function signature, new test macros, DECLARE_* - do not request an extra byte for \0 - check both ::size and ::bytes Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
_cleanup_strbuf_ + strbuf_init() can be replaced by DECLARE_STRBUF. Make all call-sites to use the respective macro. The one place still calling strbuf_init() in strbuf_to_vector() is "documenting" that strbuf is invalidated after its data is stolen, so keep it as is for now. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
Currently, we grow a list of parm entries and print each entry upon being added. In addition, we have two separate code-paths for printing depending if "--field parm" was provided on not. Swap that for sufficiently sized, pre-allocated, buffers and unify the print paths. Effectively fixing the broken `modinfo -0 modulename` output. v2: - find matching or empty entry in a single loop (add_param) - match up-to UINT_MAX parm/parmtype entries - drop unneeded INT_MAX checks for strlen(value) - don't return success if we fail to [cm]alloc v3: - scope variable declaration - code dedup in parm/parmtype paths - use correct counter - avoid allocations on 0 parm(s) - (re)use strbuf Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
The respective strings are guaranteed to be nil terminated, so drop the strlen() and respective len(th) fields. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Currently, we if we fail to find a name, description or type in the
value token we emit an error and continue.
At the same time, if the name is longer than INT_MAX we error out.
Move the validation (overall strlen(value), which includes namelen)
further up the call stack and make it a non-fatal.
This allows us to garbage collect the no longer reachable error paths
around {add,process}_param().
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
This gets Valgrind on my Arch box to be 100% "leak-free" ;-) Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
The `caf` originates from the manual tar caf invocation, as part of the (now defunct) autotools build. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
67c2ae8 to
1587ef4
Compare
|
Ok, now it's hopefully the right branch pushed here. @evelikov can you double check? |
No problem - sh*t happens. Would prefer if we don't rewrite the branch history but revert/fixup instead. The former erodes the distro maintainers' trust, et al. The updated branch looks great. Thanks |
Here's a series addressing most of the formatting issues raised in #434. In particular the formatting code is unified and beaten into shape to use consistent formatting. With the outstanding bits being:
\t,\net alsignaturevalue is still has multi-line/wrapped/tabbed formattingIn all fairness, I'm inclined to leave those as-is and let other handle them in a future PR.
The first 3 commits are something we'd probably want for the stable 34.x branch assuming there will be another release. Although, in that case we should probably check the other PRs for similar non-invasive fixes.
For the PR itself - it mostly small prep and fixup patches with the most sizable change being
modinfo: rework parm handling.Resolves: #434