* Per-process flag set via prctl() to deny module loading?
@ 2023-04-10 10:06 Topi Miettinen
2023-04-10 13:36 ` Tycho Andersen
2023-04-10 18:37 ` Greg KH
0 siblings, 2 replies; 6+ messages in thread
From: Topi Miettinen @ 2023-04-10 10:06 UTC (permalink / raw)
To: linux-modules, Kernel Hardening, linux-hardening@vger.kernel.org,
linux-kernel@vger.kernel.org
I'd propose to add a per-process flag to irrevocably deny any loading of
kernel modules for the process and its children. The flag could be set
(but not unset) via prctl() and for unprivileged processes, only when
NoNewPrivileges is also set. This would be similar to CAP_SYS_MODULE,
but unlike capabilities, there would be no issues with namespaces since
the flag isn't namespaced.
The implementation should be very simple.
Preferably the flag, when configured, would be set by systemd, Firejail
and maybe also container managers. The expectation would be that the
permission to load modules would be retained only by udev and where SUID
needs to be allowed (NoNewPrivileges unset).
-Topi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Per-process flag set via prctl() to deny module loading?
2023-04-10 10:06 Per-process flag set via prctl() to deny module loading? Topi Miettinen
@ 2023-04-10 13:36 ` Tycho Andersen
2023-04-10 20:47 ` Topi Miettinen
2023-04-10 18:37 ` Greg KH
1 sibling, 1 reply; 6+ messages in thread
From: Tycho Andersen @ 2023-04-10 13:36 UTC (permalink / raw)
To: Topi Miettinen
Cc: linux-modules, Kernel Hardening, linux-hardening@vger.kernel.org,
linux-kernel@vger.kernel.org
On Mon, Apr 10, 2023 at 01:06:00PM +0300, Topi Miettinen wrote:
> I'd propose to add a per-process flag to irrevocably deny any loading of
> kernel modules for the process and its children. The flag could be set (but
> not unset) via prctl() and for unprivileged processes, only when
> NoNewPrivileges is also set. This would be similar to CAP_SYS_MODULE, but
> unlike capabilities, there would be no issues with namespaces since the flag
> isn't namespaced.
>
> The implementation should be very simple.
>
> Preferably the flag, when configured, would be set by systemd, Firejail and
> maybe also container managers. The expectation would be that the permission
> to load modules would be retained only by udev and where SUID needs to be
> allowed (NoNewPrivileges unset).
You can do something like this today via STATIC_USERMODEHELPER without
the need for kernel patches. It is a bit heavyweight for a
general-purpose system though.
Tycho
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Per-process flag set via prctl() to deny module loading?
2023-04-10 10:06 Per-process flag set via prctl() to deny module loading? Topi Miettinen
2023-04-10 13:36 ` Tycho Andersen
@ 2023-04-10 18:37 ` Greg KH
2023-04-10 21:04 ` Topi Miettinen
1 sibling, 1 reply; 6+ messages in thread
From: Greg KH @ 2023-04-10 18:37 UTC (permalink / raw)
To: Topi Miettinen
Cc: linux-modules, Kernel Hardening, linux-hardening@vger.kernel.org,
linux-kernel@vger.kernel.org
On Mon, Apr 10, 2023 at 01:06:00PM +0300, Topi Miettinen wrote:
> I'd propose to add a per-process flag to irrevocably deny any loading of
> kernel modules for the process and its children. The flag could be set (but
> not unset) via prctl() and for unprivileged processes, only when
> NoNewPrivileges is also set. This would be similar to CAP_SYS_MODULE, but
> unlike capabilities, there would be no issues with namespaces since the flag
> isn't namespaced.
>
> The implementation should be very simple.
Patches are always welcome to be reviewed.
But note, please watch out for processes that cause devices to be found,
and then modules to be loaded that way, it's not going to be as simple
as you might have imagined...
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Per-process flag set via prctl() to deny module loading?
2023-04-10 13:36 ` Tycho Andersen
@ 2023-04-10 20:47 ` Topi Miettinen
2023-04-10 21:25 ` Tycho Andersen
0 siblings, 1 reply; 6+ messages in thread
From: Topi Miettinen @ 2023-04-10 20:47 UTC (permalink / raw)
To: Tycho Andersen
Cc: linux-modules, Kernel Hardening, linux-hardening@vger.kernel.org,
linux-kernel@vger.kernel.org
On 10.4.2023 16.36, Tycho Andersen wrote:
> On Mon, Apr 10, 2023 at 01:06:00PM +0300, Topi Miettinen wrote:
>> I'd propose to add a per-process flag to irrevocably deny any loading of
>> kernel modules for the process and its children. The flag could be set (but
>> not unset) via prctl() and for unprivileged processes, only when
>> NoNewPrivileges is also set. This would be similar to CAP_SYS_MODULE, but
>> unlike capabilities, there would be no issues with namespaces since the flag
>> isn't namespaced.
>>
>> The implementation should be very simple.
>>
>> Preferably the flag, when configured, would be set by systemd, Firejail and
>> maybe also container managers. The expectation would be that the permission
>> to load modules would be retained only by udev and where SUID needs to be
>> allowed (NoNewPrivileges unset).
>
> You can do something like this today via STATIC_USERMODEHELPER without
> the need for kernel patches. It is a bit heavyweight for a
> general-purpose system though.
So the user mode helper would be launched whenever there is a module
request and it would check whether the process is allowed to load
modules or not? Does it know which process caused the module to be
loaded and what were its credentials at that time?
-Topi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Per-process flag set via prctl() to deny module loading?
2023-04-10 18:37 ` Greg KH
@ 2023-04-10 21:04 ` Topi Miettinen
0 siblings, 0 replies; 6+ messages in thread
From: Topi Miettinen @ 2023-04-10 21:04 UTC (permalink / raw)
To: Greg KH
Cc: linux-modules, Kernel Hardening, linux-hardening@vger.kernel.org,
linux-kernel@vger.kernel.org
On 10.4.2023 21.37, Greg KH wrote:
> On Mon, Apr 10, 2023 at 01:06:00PM +0300, Topi Miettinen wrote:
>> I'd propose to add a per-process flag to irrevocably deny any loading of
>> kernel modules for the process and its children. The flag could be set (but
>> not unset) via prctl() and for unprivileged processes, only when
>> NoNewPrivileges is also set. This would be similar to CAP_SYS_MODULE, but
>> unlike capabilities, there would be no issues with namespaces since the flag
>> isn't namespaced.
>>
>> The implementation should be very simple.
>
> Patches are always welcome to be reviewed.
>
> But note, please watch out for processes that cause devices to be found,
> and then modules to be loaded that way, it's not going to be as simple
> as you might have imagined...
A very simple version would only add a simple check like
!current->allow_module_load after every !capable(CAP_SYS_MODULE). It
wouldn't block all the ways how modules could be caused to be loaded
indirectly.
I think a less simple version could also do the check at __request_module().
-Topi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Per-process flag set via prctl() to deny module loading?
2023-04-10 20:47 ` Topi Miettinen
@ 2023-04-10 21:25 ` Tycho Andersen
0 siblings, 0 replies; 6+ messages in thread
From: Tycho Andersen @ 2023-04-10 21:25 UTC (permalink / raw)
To: Topi Miettinen
Cc: linux-modules, Kernel Hardening, linux-hardening@vger.kernel.org,
linux-kernel@vger.kernel.org
On Mon, Apr 10, 2023 at 11:47:16PM +0300, Topi Miettinen wrote:
> On 10.4.2023 16.36, Tycho Andersen wrote:
> > On Mon, Apr 10, 2023 at 01:06:00PM +0300, Topi Miettinen wrote:
> > > I'd propose to add a per-process flag to irrevocably deny any loading of
> > > kernel modules for the process and its children. The flag could be set (but
> > > not unset) via prctl() and for unprivileged processes, only when
> > > NoNewPrivileges is also set. This would be similar to CAP_SYS_MODULE, but
> > > unlike capabilities, there would be no issues with namespaces since the flag
> > > isn't namespaced.
> > >
> > > The implementation should be very simple.
> > >
> > > Preferably the flag, when configured, would be set by systemd, Firejail and
> > > maybe also container managers. The expectation would be that the permission
> > > to load modules would be retained only by udev and where SUID needs to be
> > > allowed (NoNewPrivileges unset).
> >
> > You can do something like this today via STATIC_USERMODEHELPER without
> > the need for kernel patches. It is a bit heavyweight for a
> > general-purpose system though.
>
> So the user mode helper would be launched whenever there is a module request
> and it would check whether the process is allowed to load modules or not?
Yes, exactly.
> Does it know which process caused the module to be loaded and what were its
> credentials at that time?
It doesn't know which process caused the module load, which is kind of
unfortunate. It looks like you could stick it in the environment in
kernel/kmod.c:call_modprobe() without breaking too many things,
though.
Tycho
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-04-10 21:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-10 10:06 Per-process flag set via prctl() to deny module loading? Topi Miettinen
2023-04-10 13:36 ` Tycho Andersen
2023-04-10 20:47 ` Topi Miettinen
2023-04-10 21:25 ` Tycho Andersen
2023-04-10 18:37 ` Greg KH
2023-04-10 21:04 ` Topi Miettinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox