]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: Fail if ELF cannot be stripped
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 11 Oct 2024 13:37:14 +0000 (15:37 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 18 Oct 2024 18:36:35 +0000 (13:36 -0500)
Do not fall back to regular module operations, but keep going if data
which must be stripped is not available.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/176
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-elf.c
libkmod/libkmod-module.c

index c62bd0d849034bf0ce7a39e4563b974350a5d498..63f5e88215ad98e547bee3fc3b9eb26e2a3d6154 100644 (file)
@@ -572,7 +572,7 @@ static int elf_strip_versions_section(const struct kmod_elf *elf, uint8_t *chang
        uint64_t val;
 
        if (idx < 0)
-               return idx;
+               return idx == -ENODATA ? 0 : idx;
 
        buf = elf_get_section_header(elf, idx);
        off = (const uint8_t *)buf - elf->memory;
@@ -600,7 +600,7 @@ static int elf_strip_vermagic(const struct kmod_elf *elf, uint8_t *changed)
 
        err = kmod_elf_get_section(elf, ".modinfo", &buf, &size);
        if (err < 0)
-               return err;
+               return err == -ENODATA ? 0 : err;
        strings = buf;
        if (strings == NULL || size == 0)
                return 0;
@@ -657,14 +657,18 @@ const void *kmod_elf_strip(const struct kmod_elf *elf, unsigned int flags)
 
        if (flags & KMOD_INSERT_FORCE_MODVERSION) {
                err = elf_strip_versions_section(elf, changed);
-               if (err < 0)
+               if (err < 0) {
+                       errno = -err;
                        goto fail;
+               }
        }
 
        if (flags & KMOD_INSERT_FORCE_VERMAGIC) {
                err = elf_strip_vermagic(elf, changed);
-               if (err < 0)
+               if (err < 0) {
+                       errno = -err;
                        goto fail;
+               }
        }
 
        return changed;
index 32e16605ecdb719e0fa1a36e8fc7da44e0bd3712..0415e828f41ebb11b4e5b3355a14025f7d48f907 100644 (file)
@@ -673,12 +673,11 @@ static int do_init_module(struct kmod_module *mod, unsigned int flags, const cha
 
                stripped = kmod_elf_strip(elf, flags);
                if (stripped == NULL) {
-                       INFO(mod->ctx, "Failed to strip version information: %s\n",
-                            strerror(errno));
-                       mem = kmod_elf_get_memory(elf);
-               } else {
-                       mem = stripped;
+                       ERR(mod->ctx, "Failed to strip version information: %s\n",
+                           strerror(errno));
+                       return -errno;
                }
+               mem = stripped;
        } else {
                err = kmod_file_load_contents(mod->file);
                if (err)