Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 659530 - module loading should check args
Summary: module loading should check args
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: OpenRC (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: OpenRC Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 659352
  Show dependency tree
 
Reported: 2018-06-28 19:31 UTC by Robin Johnson
Modified: 2018-10-23 22:08 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2018-06-28 19:31:09 UTC
If loading a module that is already loading, and the module parameters for modprobe don't match the parameters set for the load.

In the case of bug 659352, the initramfs loaded the bonding module, and then when /etc/init.d/modules loaded later, it tried to modprobe again, with specific params, and the effective result was that the param was not set.

Proposal:
1. Before loading a module, check if it's already loaded.
2. If not loaded, load with params.
3. If loaded, check params.
4. If param matches, no error.
5. If param does NOT match new setting, print an error.
Comment 1 William Hubbs gentoo-dev 2018-06-29 21:58:51 UTC
It looks like steps 1 and 2 above can be handled by the --first-time
switch for modprobe. This switch causes modprobe to refuse to load the
module if it is already loaded and exit with an error.

Unfortunately, I do not see a standard way to see which parameters were
used when a module was loaded, apparently because some modules don't
store their parameters in /sys/module/<modname>/parameters/*.

Would you be ok with us just complaining if a module is already loaded?
I think the only other option would be to unload and reload the module,
but I think that wouldn't be a good idea.

What do  you think?

[1]
https://serverfault.com/questions/62316/how-do-i-list-loaded-linux-module-parameter-values
Comment 2 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2018-06-30 07:10:37 UTC
(In reply to William Hubbs from comment #1)
> Unfortunately, I do not see a standard way to see which parameters were
> used when a module was loaded, apparently because some modules don't
> store their parameters in /sys/module/<modname>/parameters/*.
What modules did you find like that? That would take doing in the kernel, because modparams have been exposed by default in sysfs for a long time.
Comment 3 William Hubbs gentoo-dev 2018-06-30 17:51:25 UTC
(In reply to Robin Johnson from comment #2)
> (In reply to William Hubbs from comment #1)
> > Unfortunately, I do not see a standard way to see which parameters were
> > used when a module was loaded, apparently because some modules don't
> > store their parameters in /sys/module/<modname>/parameters/*.
> What modules did you find like that? That would take doing in the kernel,
> because modparams have been exposed by default in sysfs for a long time.

I haven't looked at any specific modules, I've just been researching ways to find out what the options are that modules are loaded with.

This one seems to imply that modules can decide which parameters are exported to /sys/module/<modname>/parameters.

[2] https://www.linuxquestions.org/questions/linux-general-1/show-options-that-kernel-module-was-loaded-with-624228/
Comment 4 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2018-06-30 18:20:56 UTC
(In reply to William Hubbs from comment #3)
> I haven't looked at any specific modules, I've just been researching ways to
> find out what the options are that modules are loaded with.
> 
> This one seems to imply that modules can decide which parameters are
> exported to /sys/module/<modname>/parameters.
Ok, I went and checked the ~2500 modules I had built on my laptop. Loaded all of them, compared modinfo output to sysfs. 

I got ~2300 unique module parameters total.
Of that:
~2100 are available at module load time.
~200 can only be set AFTER the module is loaded (this was a surprise to me, they show up in sysfs but NOT modinfo).

Of the ~2100 that are available at module load time, ~1850 are exposed in sysfs.

So here's my proposed code idea:

When loading a module with parameters given:
1. If a matching file in /parameters/ exists, verify against it.
2. Throw warning if mismatch (also handles type conversion cases for bool N=>0, and int/hex).
3. If the file in /parameters/ does NOT exist, just throw a warning that we are unable to verify the parameters.

The bonding module in the original bug turns out to be an example of a module that does not expose the set parameters to sysfs.
Comment 5 William Hubbs gentoo-dev 2018-06-30 19:14:13 UTC
Here is a related question I posed on IRC.

Kernel modules can be loaded from any or all of these three places.

1. an initramfs
2. settings in the modules-load.d directories
3. settings in conf.d

Is it reasonable for options 2 and 3 to complain about loading modules that are already loaded, regardless of what the parameters passed to the modules are?
Comment 6 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2018-06-30 19:17:14 UTC
(In reply to William Hubbs from comment #5)
> Is it reasonable for options 2 and 3 to complain about loading modules that
> are already loaded, regardless of what the parameters passed to the modules
> are?
Yes, I think a non-fatal ewarn there is reasonable.
Comment 7 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2018-10-23 21:10:14 UTC
(In reply to William Hubbs from comment #5)
> Here is a related question I posed on IRC.
> 
> Kernel modules can be loaded from any or all of these three places.
> 
> 1. an initramfs
> 2. settings in the modules-load.d directories
> 3. settings in conf.d
> 
> Is it reasonable for options 2 and 3 to complain about loading modules that
> are already loaded, regardless of what the parameters passed to the modules
> are?

Don't forget autoloading via udev, etc.
Comment 8 William Hubbs gentoo-dev 2018-10-23 22:08:05 UTC
This commit, which will be part of 0.39, generates non-fatal errors if
the boot sequence loads a module that is already loaded.

https://github.com/openrc/openrc/commit/d70b1c55b67b44b98c23ceed25bc428481f7e00a