]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: Add build-id item to kmod_module_get_info()
authorLucas De Marchi <demarchi@kernel.org>
Wed, 25 Mar 2026 05:28:46 +0000 (00:28 -0500)
committerLucas De Marchi <demarchi@kernel.org>
Sat, 20 Jun 2026 16:09:52 +0000 (11:09 -0500)
If available, add the build-id to the info list returned by
kmod_module_get_info(). This allows us to compare the build-id of a
loaded module versus the build-id of the file. It's rather cumbersome
command, but it works:

$ ./build/modinfo -F build-id hid
AE:7A:2E:37:E0:2B:31:D5:72:7C:87:87:15:8C:05:FA:77:7A:4F:57
$ xxd -p -u -s16  /sys/module/hid/notes/.note.gnu.build-id  | sed 's/../&:/g;s/:$//'
AE:7A:2E:37:E0:2B:31:D5:72:7C:87:87:15:8C:05:FA:77:7A:4F:57

An option to modinfo to really to just dump the raw value can be added
in future.

Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/432
libkmod/libkmod-module.c

index e849dd9f1282bac3e0031dec0cbbfe54e25edfcd..29ae608b0c9c355abaff7bb55ea7c7888fa48a26 100644 (file)
@@ -1914,6 +1914,22 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod,
                        goto list_error;
        }
 
+       if (mod->elf) {
+               const void *build_id;
+               size_t build_id_len;
+
+               if (kmod_elf_get_build_id(mod->elf, &build_id, &build_id_len) == 0) {
+                       struct kmod_list *n;
+
+                       n = kmod_module_info_append_hex(list, "build-id",
+                                                       strlen("build-id"), build_id,
+                                                       build_id_len);
+                       if (n == NULL)
+                               goto list_error;
+                       count++;
+               }
+       }
+
        if (mod->file && kmod_module_signature_info(mod->file, &sig_info)) {
                struct kmod_list *n;