From: Tobias Stoeckmann Date: Fri, 11 Oct 2024 13:37:14 +0000 (+0200) Subject: libkmod: Fail if ELF cannot be stripped X-Git-Tag: v34~209 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=386acb3fdc801262866717dd3f5063b8b25d614d;p=thirdparty%2Fkmod.git libkmod: Fail if ELF cannot be stripped 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 Link: https://github.com/kmod-project/kmod/pull/176 Signed-off-by: Lucas De Marchi --- diff --git a/libkmod/libkmod-elf.c b/libkmod/libkmod-elf.c index c62bd0d8..63f5e882 100644 --- a/libkmod/libkmod-elf.c +++ b/libkmod/libkmod-elf.c @@ -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; diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 32e16605..0415e828 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -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)