Skip to content

Commit

Permalink
kern linker: Do not touch userrefs of the kernel file
Browse files Browse the repository at this point in the history
A nonzero `userrefs` of a linker file indicates that the file, either
loaded from kldload(2) or preloaded, can be unloaded via kldunload(2).
As for the kernel file, it can be unloaded by the loader but should not
be after initialization.

This change fixes regression from d9ce8a4 which incidentally
increases `userrefs` of the kernel file.

Reviewed by:	dfr, dab, jhb
Fixes:	d9ce8a4 kern_linker: Handle module-loading failures in preloaded .ko files
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D42530
  • Loading branch information
gmshake committed Mar 26, 2024
1 parent f43ff3e commit 39450eb
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sys/kern/kern_linker.c
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,9 @@ linker_preload_finish(void *arg)

sx_xlock(&kld_sx);
TAILQ_FOREACH_SAFE(lf, &linker_files, link, nlf) {
if (lf == linker_kernel_file)
continue;

/*
* If all of the modules in this file failed to load, unload
* the file and return an error of ENOEXEC. (Parity with
Expand Down

0 comments on commit 39450eb

Please sign in to comment.