Bug 274936 - Unsupported file type while loading kernel modules that are already compiled into kernel
Summary: Unsupported file type while loading kernel modules that are already compiled ...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: Zhenlei Huang
URL: https://reviews.freebsd.org/D42474
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-06 09:07 UTC by Zhenlei Huang
Modified: 2024-01-15 10:36 UTC (History)
0 users

See Also:
zlei: mfc-stable14+
zlei: mfc-stable13+
zlei: mfc-stable12+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhenlei Huang freebsd_committer freebsd_triage 2023-11-06 09:07:55 UTC
Noticed this while repeating https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=274375 .


Steps to repeat:

```
# kldload virtio.ko
kldload: an error occurred while loading module virtio.ko. Please check dmesg(8) for more details.
# dmesg | tail -n 2 
interface virtio.1 already present in the KLD 'kernel'!
linker_load_file: /boot/kernel/virtio.ko - unsupported file type
```

The error code should be EEXIST (the same with `kldload virtio`).
Comment 1 Zhenlei Huang freebsd_committer freebsd_triage 2023-11-06 09:56:51 UTC
Proposed fix https://reviews.freebsd.org/D42474 .
Comment 2 Zhenlei Huang freebsd_committer freebsd_triage 2023-11-06 10:01:14 UTC
To get the error code:

```
# truss kldload virtio.ko
...
kldload("virtio.ko")    ERR#8 'Exec format error'
...
```
Comment 3 commit-hook freebsd_committer freebsd_triage 2023-11-07 04:49:07 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ecf710f0e04e3314a492747124166ccb7cf4019e

commit ecf710f0e04e3314a492747124166ccb7cf4019e
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-11-07 04:45:25 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-11-07 04:45:25 +0000

    kern linker: Do not retry loading modules on EEXIST

    LINKER_LOAD_FILE() calls linker_load_dependencies() which will return
    EEXIST in case the module to be loaded has already been compiled into
    the kernel. Since the format of the module is now recognized then there
    is no need to retry loading with a different linker, otherwise the
    userland will get misleading error number ENOEXEC.

    PR:             274936
    Reviewed by:    dfr
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D42474

 sys/kern/kern_linker.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Comment 4 Zhenlei Huang freebsd_committer freebsd_triage 2023-11-09 02:50:55 UTC
This affects amd64 hardware only. Other architectures do not have 'sys/kern/link_elf_obj.c' compiled into kernel.
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2024-01-02 20:04:58 UTC
^Triage: FreeBSD 12 is now out of support.
Comment 6 commit-hook freebsd_committer freebsd_triage 2024-01-15 10:29:44 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e7fd435d3d4e888d9894d8c212c29ae6e2768f74

commit e7fd435d3d4e888d9894d8c212c29ae6e2768f74
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-11-07 04:45:25 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-01-15 10:28:25 +0000

    kern linker: Do not retry loading modules on EEXIST

    LINKER_LOAD_FILE() calls linker_load_dependencies() which will return
    EEXIST in case the module to be loaded has already been compiled into
    the kernel. Since the format of the module is now recognized then there
    is no need to retry loading with a different linker, otherwise the
    userland will get misleading error number ENOEXEC.

    PR:             274936
    Reviewed by:    dfr
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D42474

    (cherry picked from commit ecf710f0e04e3314a492747124166ccb7cf4019e)

 sys/kern/kern_linker.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2024-01-15 10:30:46 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=d18326a7cf14804086550c7463be9721e8d28b64

commit d18326a7cf14804086550c7463be9721e8d28b64
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-11-07 04:45:25 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-01-15 10:30:02 +0000

    kern linker: Do not retry loading modules on EEXIST

    LINKER_LOAD_FILE() calls linker_load_dependencies() which will return
    EEXIST in case the module to be loaded has already been compiled into
    the kernel. Since the format of the module is now recognized then there
    is no need to retry loading with a different linker, otherwise the
    userland will get misleading error number ENOEXEC.

    PR:             274936
    Reviewed by:    dfr
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D42474

    (cherry picked from commit ecf710f0e04e3314a492747124166ccb7cf4019e)
    (cherry picked from commit e7fd435d3d4e888d9894d8c212c29ae6e2768f74)

 sys/kern/kern_linker.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2024-01-15 10:31:48 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=445eb90240ecbd095d8cf865af6773022e8dd750

commit 445eb90240ecbd095d8cf865af6773022e8dd750
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-11-07 04:45:25 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-01-15 10:31:01 +0000

    kern linker: Do not retry loading modules on EEXIST

    LINKER_LOAD_FILE() calls linker_load_dependencies() which will return
    EEXIST in case the module to be loaded has already been compiled into
    the kernel. Since the format of the module is now recognized then there
    is no need to retry loading with a different linker, otherwise the
    userland will get misleading error number ENOEXEC.

    PR:             274936
    Reviewed by:    dfr
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D42474

    (cherry picked from commit ecf710f0e04e3314a492747124166ccb7cf4019e)
    (cherry picked from commit e7fd435d3d4e888d9894d8c212c29ae6e2768f74)
    (cherry picked from commit d18326a7cf14804086550c7463be9721e8d28b64)

 sys/kern/kern_linker.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Comment 9 Zhenlei Huang freebsd_committer freebsd_triage 2024-01-15 10:36:04 UTC
Fixed in stable branches.

(In reply to Mark Linimon from comment #5)
I planned to MFC to stable/12, at that time FreeBSD 12 is not out of support.