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

modprobe fails loading dependencies #351

Closed
smokku opened this issue Jun 2, 2022 · 5 comments
Closed

modprobe fails loading dependencies #351

smokku opened this issue Jun 2, 2022 · 5 comments

Comments

@smokku
Copy link

smokku commented Jun 2, 2022

While trying to load a module, modprobe fails to load dependency modules:

# modprobe -v /lib/modules/5.16.11-zen-gfbc389882a61/kernel/drivers/gpu/drm/tiny/bochs.ko
queuing /lib/modules/5.16.11-zen-gfbc389882a61/kernel/drivers/gpu/drm/tiny/bochs.ko
probing by module name
go_prob'ing bochs
loaded kernel/drivers/gpu/drm/ttm/ttm.ko '(null)': Bad address
modprobe: can't load module ttm (kernel/drivers/gpu/drm/ttm/ttm.ko): Bad address

When I try to load the dependency module, it works fine:

# modprobe -v kernel/drivers/gpu/drm/ttm/ttm.ko
queuing kernel/drivers/gpu/drm/ttm/ttm.ko
probing by module name
go_prob'ing ttm
loaded kernel/drivers/gpu/drm/ttm/ttm.ko ' ': No error information

The difference is that the second attempt uses a string instead of NULL as options:

loaded kernel/drivers/gpu/drm/ttm/ttm.ko '(null)': Bad address
---
loaded kernel/drivers/gpu/drm/ttm/ttm.ko ' ': No error information

It looks like syscall(__NR_finit_module does not like NULL flags.

With the following patch modprobe works fine:

---
 toys/pending/modprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/toys/pending/modprobe.c b/toys/pending/modprobe.c
index 45f8ea21..8188efaa 100644
--- a/toys/pending/modprobe.c
+++ b/toys/pending/modprobe.c
@@ -350,7 +350,7 @@ static int rm_mod(char *modules)
 // of flags, and don't need to support loading from stdin.
 static int ins_mod(char *modules, char *flags)
 {
-  int fd = xopenro(modules), rc = syscall(__NR_finit_module, fd, flags, 0);
+  int fd = xopenro(modules), rc = syscall(__NR_finit_module, fd, flags ? flags : "", 0);
 
   xclose(fd);
   return rc;
-- 
2.36.1
# modprobe -v /lib/modules/5.16.11-zen-gfbc389882a61/kernel/drivers/gpu/drm/tiny/bochs.ko
queuing /lib/modules/5.16.11-zen-gfbc389882a61/kernel/drivers/gpu/drm/tiny/bochs.ko
probing by module name
go_prob'ing bochs
loaded kernel/drivers/gpu/drm/ttm/ttm.ko '(null)': No error information
loaded kernel/drivers/gpu/drm/drm_ttm_helper.ko '(null)': No error information
loaded kernel/drivers/gpu/drm/drm_vram_helper.ko '(null)': No error information
loaded kernel/drivers/gpu/drm/tiny/bochs.ko ' ': No error information
@apprehensions
Copy link

can reproduce, facing this when trying to load graphics drivers.

how has this not been fixed yet?

@landley
Copy link
Owner

landley commented Oct 7, 2022

Because the systems I build use static kernels, and Android has a daemon use a module loading library instead of doing it from the command line. I have a TODO item to add module support to scripts/mkroot.sh but haven't done it yet. (It's behind "get 'make tests' running under mkroot", which means running under toysh. I tend not to run questionable stuff as root on my development machine, so "set up test environment for this" was the todo item, and it got buried.)

Thanks for the poke, I'll bump the priority up on the todo list...

@landley
Copy link
Owner

landley commented Oct 9, 2022

Slightly different variant applied as commit 56d89e5

@smokku
Copy link
Author

smokku commented Oct 9, 2022

Slightly different variant applied

My first fix was done this way. But this is just a workaround at a call site and does not fix the real issue with the syscall.

Every other user of ins_mod() might be tripped by the same bug.

@landley
Copy link
Owner

landley commented Oct 9, 2022

There are no other users, it's a static function in a "pending" command.

https://github.com/landley/toybox/blob/master/toys/pending/README

https://landley.net/toybox/cleanup.html

@landley landley closed this as completed Jan 8, 2023
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

No branches or pull requests

3 participants