kmod: make request_module() return an error when autoloading is disabled
Subsystems (2)
PATCH 1/1 kmod: make request_module() return an error when autoloading is disabled
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting /proc/sys/kernel/modprobe to the empty string. This can be preferable to setting it to a nonexistent file since it avoids the overhead of an attempted execve(), avoids potential deadlocks, and avoids the call to security_kernel_module_request() and thus on SELinux-based systems eliminates the need to write SELinux rules to dontaudit module_request.
However, when module autoloading is disabled in this way, request_module() returns 0. This is broken because callers expect 0 to mean that the module was successfully loaded.
Apparently this was never noticed because this method of disabling module autoloading isn't used much, and also most callers don't use the return value of request_module() since it's always necessary to check whether the module registered its functionality or not anyway. But improperly returning 0 can indeed confuse a few callers, for example get_fs_type() in fs/filesystems.c where it causes a WARNING to be hit:
if (!fs && (request_module("fs-%.*s", len, name) == 0)) {
fs = __get_fs_type(name, len);
WARN_ONCE(!fs, "request_module fs-%.*s succeeded, but still no fs?\n", len, name);
}This is easily reproduced with:
echo > /proc/sys/kernel/modprobe
mount -t NONEXISTENT none /
It causes:
request_module fs-NONEXISTENT succeeded, but still no fs? WARNING: CPU: 1 PID: 1106 at fs/filesystems.c:275 get_fs_type+0xd6/0xf0 [...]
Arguably this warning is broken and should be removed, since the module could have been unloaded already. However, request_module() should also correctly return an error when it fails. So let's make it return -ENOENT, which matches the error when the modprobe binary doesn't exist.
--- kernel/kmod.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kmod.c +2 -2
@@ -120,7 +120,7 @@ static int call_modprobe(char *module_name, int wait)* invoke it. * * If module auto-loading support is disabled then this function -* becomes a no-operation. +* simply returns -ENOENT. */ int __request_module (bool wait,const char *fmt, ...) {
@@ -137,7 +137,7 @@ int __request_module(bool wait, const char *fmt, ...)WARN_ON_ONCE (wait &¤t_is_async ());if (!modprobe_path[0 ]) -return 0 ; +return -ENOENT ;va_start (args, fmt); ret =vsnprintf (module_name,MODULE_NAME_LEN , fmt, args);
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Quoted 5 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can be preferable
preferable but ... not documented. Or was this documented or recommended somewhere?
Quoted 9 lines
to setting it to a nonexistent file since it avoids the overhead of an attempted
execve(), avoids potential deadlocks, and avoids the call tosecurity_kernel_module_request()and thus on SELinux-based systems eliminates the need to write SELinux rules to dontauditmodule_request.However, when module autoloading is disabled in this way,
request_module()returns 0. This is broken because callers expect 0 to mean that the module was successfully loaded.
However this is implicitly not true. For instance, as Neil recently chased down -- blacklisting a module today returns 0 as well, and so this corner case is implicitly set to return 0.
Quoted 4 lines
Apparently this was never noticed because this method of disabling module autoloading isn't used much, and also most callers don't use the return value of
request_module()since it's always necessary to check whether the module registered its functionality or not anyway.
Right, the de-facto practice of verification of a module to be loaded is for each caller to ensure with whatever heuristic it needs to ensure the module is loaded.
Quoted 11 lines
But
improperly returning 0 can indeed confuse a few callers, for exampleget_fs_type()infs/filesystems.cwhere it causes a WARNING to be hit:if (!fs && (request_module("fs-%.*s", len, name) == 0)) { fs = __get_fs_type(name, len); WARN_ONCE(!fs, "request_module fs-%.*s succeeded, but still no fs?\n", len, name); }This is easily reproduced with:
Quoted 8 lines
echo >
/proc/sys/kernel/modprobe
mount -t NONEXISTENT none /It causes:
request_module fs-NONEXISTENT succeeded, but still no fs? WARNING: CPU: 1 PID: 1106 at fs/filesystems.c:275 get_fs_type+0xd6/0xf0 [...]
Thanks for reporting this.
Quoted 2 lines
Arguably this warning is broken and should be removed, since the module could have been unloaded already.
No, the warning is present *because* debuggins issues for when the module which did not load is a rootfs is *really* hard to debug. Then, if the culprit of the issue is a userspace modprobe bug (it happens) this makes debugging *very* difficult as you won't know what failed at all, you just get a silent failed boot.
Quoted 3 lines
However,
request_module()should also
correctly return an error when it fails. So let's make it return-ENOENT, which matches the error when the modprobe binary doesn't exist.
This is a user experience change though, and I wouldn't have on my radar who would use this, and expects the old behaviour. Josh, would you by chance?
I'd like this to be more an RFC first so we get vetted parties to review. I take it this and Neil's case are cases we should revisit now, properly document as we didn't before, ensure we don't break anything, and also extend the respective kmod selftests to ensure we don't break these corner cases in the future.
Quoted 38 lines
Cc Alexei Starovoitov <[email protected]>Cc Andrew Morton <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Jeff Vander Stoep <[email protected]>Cc Jessica Yu <[email protected]>Cc Kees Cook <[email protected]>Cc Luis Chamberlain <[email protected]>Signed-off-by Eric Biggers <[email protected]>--- kernel/kmod.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/kmod.c +2
-2@@ -120,7 +120,7 @@ static int call_modprobe(char *module_name, int wait)* invoke it. * * If module auto-loading support is disabled then this function -* becomes a no-operation. +* simply returns -ENOENT. */ int __request_module (bool wait,const char *fmt, ...) {@@ -137,7 +137,7 @@ int __request_module(bool wait, const char *fmt, ...)WARN_ON_ONCE (wait &¤t_is_async ());if (!modprobe_path[0 ]) -return 0 ; +return -ENOENT ;va_start (args, fmt); ret =vsnprintf (module_name,MODULE_NAME_LEN , fmt, args);Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Quoted 15 lines · Luis Chamberlain
Quoted 5 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can be preferablepreferable but ... not documented. Or was this documented or recommended somewhere?
Quoted 5 lines
to setting it to a nonexistent file since it avoids the overhead of an attempted
execve(), avoids potential deadlocks, and avoids the call tosecurity_kernel_module_request()and thus on SELinux-based systems eliminates the need to write SELinux rules to dontauditmodule_request.
Not that I know of, though I didn't look too hard. proc(5) mentions /proc/sys/kernel/modprobe but doesn't mention the empty string case.
In any case, it's been supported for a long time, and it's useful for the reasons I mentioned.
Quoted 8 lines
Quoted 4 lines
However, when module autoloading is disabled in this way,
request_module()returns 0. This is broken because callers expect 0 to mean that the module was successfully loaded.However this is implicitly not true. For instance, as Neil recently chased down -- blacklisting a module today returns 0 as well, and so this corner case is implicitly set to return 0.
That sounds like another similar bug, but in the modprobe program instead of in the kernel. Do you have a link to the discussion about it?
Quoted 23 lines
Quoted 12 lines
But
improperly returning 0 can indeed confuse a few callers, for exampleget_fs_type()infs/filesystems.cwhere it causes a WARNING to be hit:if (!fs && (request_module("fs-%.*s", len, name) == 0)) { fs = __get_fs_type(name, len); WARN_ONCE(!fs, "request_module fs-%.*s succeeded, but still no fs?\n", len, name); }This is easily reproduced with:
Quoted 8 lines
echo >
/proc/sys/kernel/modprobe
mount -t NONEXISTENT none /It causes:
request_module fs-NONEXISTENT succeeded, but still no fs? WARNING: CPU: 1 PID: 1106 at fs/filesystems.c:275 get_fs_type+0xd6/0xf0 [...]Thanks for reporting this.
Quoted 8 lines
Quoted 2 lines
Arguably this warning is broken and should be removed, since the module could have been unloaded already.
No, the warning is present *because* debuggins issues for when the module which did not load is a rootfs is *really* hard to debug. Then, if the culprit of the issue is a userspace modprobe bug (it happens) this makes debugging *very* difficult as you won't know what failed at all, you just get a silent failed boot.
I meant that it's broken to use WARN_ON(), because it's a userspace triggerable condition. WARN_ON() is for kernel bugs only. Of course, if it's a useful warning, it can still be left in as pr_warn().
Quoted 8 lines
Quoted 3 lines
However,
request_module()should also
correctly return an error when it fails. So let's make it return-ENOENT, which matches the error when the modprobe binary doesn't exist.This is a user experience change though, and I wouldn't have on my radar who would use this, and expects the old behaviour. Josh, would you by chance?
Quoted 5 lines
I'd like this to be more an RFC first so we get vetted parties to review. I take it this and Neil's case are cases we should revisit now, properly document as we didn't before, ensure we don't break anything, and also extend the respective kmod selftests to ensure we don't break these corner cases in the future.
This patch only affects kernel internals, not the userspace API. So I don't see why it would be controversial? I already went through all callers of request_module() that check its return value, and they all appear to work better with -ENOENT, since they assume that 0 means the module was loaded.
Incorrectly returning 0 typically causes unnecessary work (checking again whether the module's functionality is available) or misleading log messages. In fact, I can't think of a situation where kernel code would *want* 0 returned in this case, as it's ambiguous with the module being successfully loaded.
Sure, I'll check whether it would be possible to add a test for this case in lib/test_kmod.c and tools/testing/selftests/kmod/.
- Eric
Quoted 17 lines · Eric Biggers
Quoted 15 lines · Luis Chamberlain
Quoted 5 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can be preferablepreferable but ... not documented. Or was this documented or recommended somewhere?
Quoted 5 lines
to setting it to a nonexistent file since it avoids the overhead of an attempted
execve(), avoids potential deadlocks, and avoids the call tosecurity_kernel_module_request()and thus on SELinux-based systems eliminates the need to write SELinux rules to dontauditmodule_request.
Quoted 5 lines
Not that I know of, though I didn't look too hard. proc(5) mentions
/proc/sys/kernel/modprobebut doesn't mention the empty string case.In any case, it's been supported for a long time, and it's useful for the reasons I mentioned.
Sure. I think then its important to document it as such then, or perhaps make a kconfig option which sets this to empty and document it on the kconfig entry.
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
However, when module autoloading is disabled in this way,
request_module()returns 0. This is broken because callers expect 0 to mean that the module was successfully loaded.However this is implicitly not true. For instance, as Neil recently chased down -- blacklisting a module today returns 0 as well, and so this corner case is implicitly set to return 0.
That sounds like another similar bug, but in the modprobe program instead of in the kernel. Do you have a link to the discussion about it?
Nothing public yet AFAICT.
Quoted 25 lines
Quoted 25 lines
Quoted 11 lines
But
improperly returning 0 can indeed confuse a few callers, for exampleget_fs_type()infs/filesystems.cwhere it causes a WARNING to be hit:if (!fs && (request_module("fs-%.*s", len, name) == 0)) { fs = __get_fs_type(name, len); WARN_ONCE(!fs, "request_module fs-%.*s succeeded, but still no fs?\n", len, name); }This is easily reproduced with:
Quoted 8 lines
echo >
/proc/sys/kernel/modprobe
mount -t NONEXISTENT none /It causes:
request_module fs-NONEXISTENT succeeded, but still no fs? WARNING: CPU: 1 PID: 1106 at fs/filesystems.c:275 get_fs_type+0xd6/0xf0 [...]Thanks for reporting this.
Quoted 2 lines
Arguably this warning is broken and should be removed, since the module could have been unloaded already.
Quoted 8 lines
Quoted 5 lines
No, the warning is present *because* debuggins issues for when the module which did not load is a rootfs is *really* hard to debug. Then, if the culprit of the issue is a userspace modprobe bug (it happens) this makes debugging *very* difficult as you won't know what failed at all, you just get a silent failed boot.
I meant that it's broken to use
WARN_ON(), because it's a userspace triggerable condition.
This and the blacklist case are now two known cases, so yes I'a agree now. It was not widely known before.
Quoted 2 lines
WARN_ON()is for kernel bugs only. Of course, if it's a useful warning, it can still be left in aspr_warn().
I'll send a patch.
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
However,
request_module()should also
correctly return an error when it fails. So let's make it return-ENOENT, which matches the error when the modprobe binary doesn't exist.This is a user experience change though, and I wouldn't have on my radar who would use this, and expects the old behaviour. Josh, would you by chance?
Quoted 7 lines
Quoted 5 lines
I'd like this to be more an RFC first so we get vetted parties to review. I take it this and Neil's case are cases we should revisit now, properly document as we didn't before, ensure we don't break anything, and also extend the respective kmod selftests to ensure we don't break these corner cases in the future.
This patch only affects kernel internals, not the userspace API.
Ah yes, in that case this seems fine with me.
Quoted 4 lines
So I don't see
why it would be controversial? I already went through all callers ofrequest_module()that check its return value, and they all appear to work better with-ENOENT, since they assume that 0 means the module was loaded.
Thanks for doing that, but I note that getting 0 is not assurance either. The de-facto best practive for the request_module() call is to do your own in place verifier.
Quoted 2 lines
Incorrectly returning 0 typically causes unnecessary work (checking again whether the module's functionality is available) or misleading log messages.
Yes but returning 0 cannot be relied upon today for assuming the module is loaded. *If* we revisit that decision and want the kernel to do a generic verifier, then yes, we can get rid of all the caller specific verfifiers, but not today.
Quoted 3 lines
In
fact, I can't think of a situation where kernel code would *want* 0 returned in this case, as it's ambiguous with the module being successfully loaded.
Unfortunately that's just how the API (to my mind silly) grew out to.
Quoted 2 lines
Sure, I'll check whether it would be possible to add a test for this case in
lib/test_kmod.candtools/testing/selftests/kmod/.
Thanks!
Luis
Quoted 21 lines · Luis Chamberlain
Quoted 20 lines · Eric Biggers
Quoted 15 lines · Luis Chamberlain
Quoted 5 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can be preferablepreferable but ... not documented. Or was this documented or recommended somewhere?
Quoted 5 lines
to setting it to a nonexistent file since it avoids the overhead of an attempted
execve(), avoids potential deadlocks, and avoids the call tosecurity_kernel_module_request()and thus on SELinux-based systems eliminates the need to write SELinux rules to dontauditmodule_request.Not that I know of, though I didn't look too hard. proc(5) mentions
/proc/sys/kernel/modprobebut doesn't mention the empty string case.
Quoted 6 lines
Quoted 2 lines
In any case, it's been supported for a long time, and it's useful for the reasons I mentioned.
Sure. I think then its important to document it as such then, or perhaps make a kconfig option which sets this to empty and document it on the kconfig entry.
I'll send a man-pages patch to document it in proc(5).
Most users, including the one I have in mind, should just be able to run 'echo > /proc/sys/kernel/modprobe' early in the boot process. So I don't think the need for a kconfig option to control the default value has been clearly demonstrated yet. You're certainly welcome to send a patch for it if you believe it would be useful, though.
Quoted 9 lines
Quoted 4 lines
So I don't see
why it would be controversial? I already went through all callers ofrequest_module()that check its return value, and they all appear to work better with-ENOENT, since they assume that 0 means the module was loaded.Thanks for doing that, but I note that getting 0 is not assurance either. The de-facto best practive for the
request_module()call is to do your own in place verifier.
Quoted 8 lines
Quoted 2 lines
Incorrectly returning 0 typically causes unnecessary work (checking again whether the module's functionality is available) or misleading log messages.
Yes but returning 0 cannot be relied upon today for assuming the module is loaded. *If* we revisit that decision and want the kernel to do a generic verifier, then yes, we can get rid of all the caller specific verfifiers, but not today.
Sure, I understand all that; I think we're actually on the same page. Even if we make the return value of request_module() completely correct, nothing stops another process from loading or unloading the module immediately afterwards.
However, callers do sometimes use the return value opportunisticly, like to log an appropriate message or to return early if module loading failed. Those seem like relatively appropriate uses. The thing which you really can't do, which I didn't see anyone doing, is use 'ret == 0' as a signal to go ahead and run code that will crash if the module has been unloaded already.
- Eric
Quoted 29 lines · Eric Biggers
Quoted 21 lines · Luis Chamberlain
Quoted 20 lines · Eric Biggers
Quoted 15 lines · Luis Chamberlain
Quoted 5 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can be preferablepreferable but ... not documented. Or was this documented or recommended somewhere?
Quoted 5 lines
to setting it to a nonexistent file since it avoids the overhead of an attempted
execve(), avoids potential deadlocks, and avoids the call tosecurity_kernel_module_request()and thus on SELinux-based systems eliminates the need to write SELinux rules to dontauditmodule_request.Not that I know of, though I didn't look too hard. proc(5) mentions
/proc/sys/kernel/modprobebut doesn't mention the empty string case.Quoted 6 lines
Quoted 2 lines
In any case, it's been supported for a long time, and it's useful for the reasons I mentioned.
Sure. I think then its important to document it as such then, or perhaps make a kconfig option which sets this to empty and document it on the kconfig entry.
Quoted 7 lines
I'll send a man-pages patch to document it in proc(5).
Most users, including the one I have in mind, should just be able to run 'echo >
/proc/sys/kernel/modprobe' early in the boot process. So I don't think the need for a kconfig option to control the default value has been clearly demonstrated yet. You're certainly welcome to send a patch for it if you believe it would be useful, though.
When doing a rewrite of some of this code I did wonder who would use this and clear it out. A kconfig entry would remove any doubt over its use and would allow one to skip the userspace / early init requirement to empty it out, therefore actually being safer because you are not racing against modules being loaded.
Is avoiding the race more suitable for your needs than echo'ing early on boot?
Luis
Quoted 38 lines · Luis Chamberlain
Quoted 29 lines · Eric Biggers
Quoted 21 lines · Luis Chamberlain
Quoted 20 lines · Eric Biggers
Quoted 15 lines · Luis Chamberlain
Quoted 5 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can be preferablepreferable but ... not documented. Or was this documented or recommended somewhere?
Quoted 5 lines
to setting it to a nonexistent file since it avoids the overhead of an attempted
execve(), avoids potential deadlocks, and avoids the call tosecurity_kernel_module_request()and thus on SELinux-based systems eliminates the need to write SELinux rules to dontauditmodule_request.Not that I know of, though I didn't look too hard. proc(5) mentions
/proc/sys/kernel/modprobebut doesn't mention the empty string case.Quoted 6 lines
Quoted 2 lines
In any case, it's been supported for a long time, and it's useful for the reasons I mentioned.
Sure. I think then its important to document it as such then, or perhaps make a kconfig option which sets this to empty and document it on the kconfig entry.
Quoted 7 lines
I'll send a man-pages patch to document it in proc(5).
Most users, including the one I have in mind, should just be able to run 'echo >
/proc/sys/kernel/modprobe' early in the boot process. So I don't think the need for a kconfig option to control the default value has been clearly demonstrated yet. You're certainly welcome to send a patch for it if you believe it would be useful, though.
Quoted 8 lines
When doing a rewrite of some of this code I did wonder who would use this and clear it out. A kconfig entry would remove any doubt over its use and would allow one to skip the userspace / early init requirement to empty it out, therefore actually being safer because you are not racing against modules being loaded.
Is avoiding the race more suitable for your needs than echo'ing early on boot?
Maybe. It would avoid the chance of races, but I haven't seen any yet. Also, our userspace has to support old kernels, so we still need the 'echo > /proc/sys/kernel/modprobe' anyway. If that turns out to be good enough, then it makes things easier for everyone.
If setting the default at build time turns out to be needed, then sure in that case I'll send a patch that adds a kconfig option to do that. But I'm first trying to use the existing kernel functionality.
Also, a kconfig option isn't really a substitute for documenting this existing sysctl. We still need to document it properly in proc(5) and Documentation/admin-guide/sysctl/kernel.rst.
- Eric
Quoted 53 lines · Eric Biggers
Quoted 38 lines · Luis Chamberlain
Quoted 29 lines · Eric Biggers
Quoted 21 lines · Luis Chamberlain
Quoted 20 lines · Eric Biggers
Quoted 15 lines · Luis Chamberlain
Quoted 5 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can be preferablepreferable but ... not documented. Or was this documented or recommended somewhere?
Quoted 5 lines
to setting it to a nonexistent file since it avoids the overhead of an attempted
execve(), avoids potential deadlocks, and avoids the call tosecurity_kernel_module_request()and thus on SELinux-based systems eliminates the need to write SELinux rules to dontauditmodule_request.Not that I know of, though I didn't look too hard. proc(5) mentions
/proc/sys/kernel/modprobebut doesn't mention the empty string case.Quoted 6 lines
Quoted 2 lines
In any case, it's been supported for a long time, and it's useful for the reasons I mentioned.
Sure. I think then its important to document it as such then, or perhaps make a kconfig option which sets this to empty and document it on the kconfig entry.
Quoted 7 lines
I'll send a man-pages patch to document it in proc(5).
Most users, including the one I have in mind, should just be able to run 'echo >
/proc/sys/kernel/modprobe' early in the boot process. So I don't think the need for a kconfig option to control the default value has been clearly demonstrated yet. You're certainly welcome to send a patch for it if you believe it would be useful, though.Quoted 8 lines
When doing a rewrite of some of this code I did wonder who would use this and clear it out. A kconfig entry would remove any doubt over its use and would allow one to skip the userspace / early init requirement to empty it out, therefore actually being safer because you are not racing against modules being loaded.
Is avoiding the race more suitable for your needs than echo'ing early on boot?
Maybe. It would avoid the chance of races, but I haven't seen any yet. Also, our userspace has to support old kernels, so we still need the 'echo >
/proc/sys/kernel/modprobe' anyway. If that turns out to be good enough, then it makes things easier for everyone.
Quoted 7 lines
If setting the default at build time turns out to be needed, then sure in that case I'll send a patch that adds a kconfig option to do that. But I'm first trying to use the existing kernel functionality.
Also, a kconfig option isn't really a substitute for documenting this existing sysctl. We still need to document it properly in proc(5) and
Documentation/admin-guide/sysctl/kernel.rst.
Yes, sure. Whatever mechanism you find *suitable* I think you may the shiny best new user of it, and so given all that is shared now, I'm sure you will document do what is needed. Whatever guidance you can provide based on your experience is of huge value to this little corner of the kernel.
I just wanted to do away with unclear tribal knowledge and ensure we support / test whatever you do well moving forward.
Luis
Quoted 10 lines · Luis Chamberlain
Quoted 3 lines · Eric Biggers
However,
request_module()should also
correctly return an error when it fails. So let's make it return-ENOENT, which matches the error when the modprobe binary doesn'texist.
This is a user experience change though, and I wouldn't have on my radar
who would use this, and expects the old behaviour. Josh, would you by chance?
I don't think this affects userspace. But I'd suggest Ben Hutchings (CCed).
Quoted 5 lines · Josh Triplett
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · Eric Biggers
However,
request_module()should also
correctly return an error when it fails. So let's make it return-ENOENT, which matches the error when the modprobe binary doesn't
Quoted 8 lines
Quoted 6 lines
exist.
This is a user experience change though, and I wouldn't have on my radar
who would use this, and expects the old behaviour. Josh, would you by chance?I don't think this affects userspace. But I'd suggest Ben Hutchings (CCed).
It doesn't, so yes no verififcation needed. Thanks the quick response though!
Luis
Quoted 4 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can be
Hunh. I've never seen that before. :) I've always used;
echo 1 > /proc/sys/kernel/modules_disabled
Regardless,
-Kees
Quoted 76 lines
preferable to setting it to a nonexistent file since it avoids the overhead of an attempted
execve(), avoids potential deadlocks, and avoids the call tosecurity_kernel_module_request()and thus on SELinux-based systems eliminates the need to write SELinux rules to dontauditmodule_request.However, when module autoloading is disabled in this way,
request_module()returns 0. This is broken because callers expect 0 to mean that the module was successfully loaded.Apparently this was never noticed because this method of disabling module autoloading isn't used much, and also most callers don't use the return value of
request_module()since it's always necessary to check whether the module registered its functionality or not anyway. But improperly returning 0 can indeed confuse a few callers, for exampleget_fs_type()infs/filesystems.cwhere it causes a WARNING to be hit:if (!fs && (request_module("fs-%.*s", len, name) == 0)) { fs = __get_fs_type(name, len); WARN_ONCE(!fs, "request_module fs-%.*s succeeded, but still no fs?\n", len, name); }This is easily reproduced with:
echo >
/proc/sys/kernel/modprobe
mount -t NONEXISTENT none /It causes:
request_module fs-NONEXISTENT succeeded, but still no fs? WARNING: CPU: 1 PID: 1106 at fs/filesystems.c:275 get_fs_type+0xd6/0xf0 [...]Arguably this warning is broken and should be removed, since the module could have been unloaded already. However,
request_module()should also correctly return an error when it fails. So let's make it return-ENOENT, which matches the error when the modprobe binary doesn't exist.Cc Alexei Starovoitov <[email protected]>Cc Andrew Morton <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Jeff Vander Stoep <[email protected]>Cc Jessica Yu <[email protected]>Cc Kees Cook <[email protected]>Cc Luis Chamberlain <[email protected]>Signed-off-by Eric Biggers <[email protected]>--- kernel/kmod.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/kmod.c +2
-2@@ -120,7 +120,7 @@ static int call_modprobe(char *module_name, int wait)* invoke it. * * If module auto-loading support is disabled then this function -* becomes a no-operation. +* simply returns -ENOENT. */ int __request_module (bool wait,const char *fmt, ...) {@@ -137,7 +137,7 @@ int __request_module(bool wait, const char *fmt, ...)WARN_ON_ONCE (wait &¤t_is_async ());if (!modprobe_path[0 ]) -return 0 ; +return -ENOENT ;va_start (args, fmt); ret =vsnprintf (module_name,MODULE_NAME_LEN , fmt, args);Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Signature · 1 line
Kees Cook
Quoted 6 lines · Kees Cook
Quoted 4 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can be
Quoted 8 lines
Hunh. I've never seen that before. :) I've always used;
echo 1 >
/proc/sys/kernel/modules_disabledRegardless,
Reviewed-by Kees Cook <[email protected]>
modules_disabled is different because it disables *all* module loading, not just autoloading.
- Eric
Quoted 11 lines · Eric Biggers
Quoted 10 lines · Kees Cook
Quoted 4 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can beHunh. I've never seen that before. :) I've always used;
echo 1 >
/proc/sys/kernel/modules_disabled
Quoted 7 lines
Quoted 4 lines
Regardless,
Reviewed-by Kees Cook <[email protected]>
modules_disabledis different because it disables *all* module loading, not just autoloading.
Yes, quite true. Some day I'd love to revisit this series to improve autoloading sanity checking:
https://github.com/KSPP/linux/issues/24
Signature · 1 line
Kees Cook
Quoted 11 lines · Eric Biggers
Quoted 10 lines · Kees Cook
Quoted 4 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can beHunh. I've never seen that before. :) I've always used;
echo 1 >
/proc/sys/kernel/modules_disabled
Quoted 7 lines
Quoted 4 lines
Regardless,
Reviewed-by Kees Cook <[email protected]>
modules_disabledis different because it disables *all* module loading, not just autoloading.
Clarifying this on your patch would be useful, otherwise its lost tribal knowledge.
LUis
Quoted 14 lines · Luis Chamberlain
Quoted 13 lines · Eric Biggers
Quoted 12 lines · Kees Cook
Quoted 4 lines · Eric Biggers
From: Eric Biggers <[email protected]>
It's long been possible to disable kernel module autoloading completely by setting
/proc/sys/kernel/modprobeto the empty string. This can beHunh. I've never seen that before. :) I've always used;
echo 1 >
/proc/sys/kernel/modules_disabledRegardless,
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Reviewed-by Kees Cook <[email protected]>
modules_disabledis different because it disables *all* module loading, not just autoloading.Clarifying this on your patch would be useful, otherwise its lost tribal knowledge.
I think it would be more useful to improve the documentation in proc(5) and Documentation/admin-guide/sysctl/kernel.rst. People shouldn't have to read random kernel commit messages to find the documentation.
I'll send out patches for those.
- Eric