Re: [PATCH] modutils: prevent "Invalid ELF header magic" warning
Yao Zi via busybox <[email protected]> Sat, 25 Jul 2026 17:54:20 +0000
| Newsgroups | gmane.linux.busybox |
|---|---|
| Message-ID | <amT4TCNVGerWtg9V@pie> |
On Sat, Jul 25, 2026 at 12:24:12PM +0200, S=F6ren Tempel via busybox wrote: > This patch has the minor caveat that it causes modprobe to no longer > load uncomprossed modules, which do not have a .ko filename suffix via > finit_module, iff. CONFIG_DECOMPRESS is not set (it would still load > them via init_module). > = > The best, but more invasive change, would be to improve the check > determining if the given module is compressed. Currently, this is > achieved by looking at the file extension. Instead, we should check > if the file has a valid ELF header. This would allow us to eliminate > logic that invokes finit_module(2) twice (once with and once without > MODULE_INIT_COMPRESSED_FILE). > = > If there is an interest in improving handling of compressed modules > on kernels without CONFIG_DECOMPRESS, then I would be willing to revise > the patch accordingly. Back to Jul 6, 2024, I sent a patch to check whether a module is compressed by poking the ELF magic number[1]. Regards, Yao Zi [1]: https://lists.busybox.net/pipermail/busybox/2024-July/090802.html > Cheers > S=F6ren > = > S=F6ren Tempel <[email protected]> wrote: > > On Alpine Linux, I noticed a lot of "Invalid ELF header magic" warnings > > in the kernel log. These are caused by the fact that BusyBox calls > > finit_module(2) twice. Once with, and once w/o MODULE_INIT_COMPRESSED_F= ILE. > > On Alpine, the first call fails because the kernel is configured without > > kernel-space module decompression (i.e., CONFIG_MODULE_DECOMPRESS is > > not set). The second call then causes the aforementioned error message > > to be emitted as all of Alpine's Kernel modules are actually compressed. > > = > > This is fixed in this patch by not re-trying finit_module(2) when the > > error return value indicates that CONFIG_MODULE_DECOMPRESS is not set > > in the kernel configuration (i.e., EOPNOTSUPP is set in errno). The > > module is then decompressed in userspace and loaded using init_module(2= ). > > = > > Downstream issues: > > = > > * https://gitlab.alpinelinux.org/alpine/aports/-/work_items/13427 > > * https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/105839 > > = > > See also: af5277f883e8fc2e0236aa9ecc5115ecaffd0ccb > > = > > Signed-off-by: S=F6ren Tempel <[email protected]> > > --- > > modutils/modprobe-small.c | 2 ++ > > modutils/modutils.c | 2 ++ > > 2 files changed, 4 insertions(+) > > = > > diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c > > index 7f584102d..4fa1c462c 100644 > > --- a/modutils/modprobe-small.c > > +++ b/modutils/modprobe-small.c > > @@ -271,6 +271,8 @@ static int load_module(const char *fname, const cha= r *options) > > r =3D finit_module(fd, options, flags); > > if (r =3D=3D 0 || flags =3D=3D 0) > > break; > > + else if (errno =3D=3D EOPNOTSUPP) /* kernel compression disabled -= > don't retry */ > > + break; > > /* Loading non-.ko named uncompressed module? Not likely, but let'= s try it */ > > flags =3D 0; > > } > > diff --git a/modutils/modutils.c b/modutils/modutils.c > > index 862f71f57..cf619fc46 100644 > > --- a/modutils/modutils.c > > +++ b/modutils/modutils.c > > @@ -216,6 +216,8 @@ int FAST_FUNC bb_init_module(const char *filename, = const char *options) > > rc =3D finit_module(fd, options, flags); > > if (rc =3D=3D 0 || flags =3D=3D 0) > > break; > > + else if (errno =3D=3D EOPNOTSUPP) /* kernel compression disabled -= > don't retry */ > > + break; > > /* Loading non-.ko named uncompressed module? Not likely, but let'= s try it */ > > flags =3D 0; > > } > > _______________________________________________ > > busybox mailing list > > [email protected] > > https://lists.busybox.net/mailman/listinfo/busybox > _______________________________________________ > busybox mailing list > [email protected] > https://lists.busybox.net/mailman/listinfo/busybox