Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use kmod library to load modules in init script #2034

Conversation

katiewasnothere
Copy link
Contributor

@katiewasnothere katiewasnothere commented Feb 22, 2024

This PR allows for loading kernel modules in the init binary that is run during UVM boot. This is necessary for running certain distros of linux since many builtin modules have been moved out into their own .ko files. We use the same library, libkmod, that is used by programs like systemd and dracut to accomplish this.

We could alternatively manually call the __NR_finit_module syscall with each .ko file that we find to load the modules. However, some modules have dependencies on other modules being loaded first, which would require us to manually track the dependency graph of modules. When you run depmod in a system, a series of files such as modules.dep are created under /lib/modules/<uname -r>. These files contain information about the modules, such as their dependencies. However, the man page specifically mentions that these files should not be read or used by any additional utilities as they may be subject to change in the future. libkmod handles dependencies internally.

WARNING: libkmod does not allow for static compilation, so we have to remove the static ldflag for building the init binary. This is a breaking change with older versions of hcsshim, since now we MUST have certain files present in the UVM for the init to run. If those files are not present, we will simply fail to start the UVM with an unintuitive error message.

Future work:

  • Supporting allowlists and denylists to better control what should and shouldn't be loaded at boot time.

@katiewasnothere katiewasnothere requested a review from a team as a code owner February 22, 2024 21:19
@katiewasnothere katiewasnothere force-pushed the kabaldau/kmod_load_modules_init branch 4 times, most recently from 0f9eaf9 to df8108b Compare February 27, 2024 21:05
@helsaawy helsaawy self-assigned this Feb 28, 2024
@msscotb msscotb self-assigned this Feb 28, 2024
init/init.c Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
- Update Makefile to use libkmod when building init and remove static compilation

Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
@katiewasnothere katiewasnothere merged commit df34d1d into microsoft:main Mar 20, 2024
19 checks passed
@katiewasnothere katiewasnothere deleted the kabaldau/kmod_load_modules_init branch March 20, 2024 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants