Message ID | 20230922145505.4044003-1-kpsingh@kernel.org (mailing list archive) |
---|---|
Headers | show |
Series | Reduce overhead of LSMs with static calls | expand |
On Fri, Sep 22, 2023 at 04:55:00PM +0200, KP Singh wrote: > # Performance improvement > > With this patch-set some syscalls with lots of LSM hooks in their path > benefitted at an average of ~3% and I/O and Pipe based system calls benefitting > the most. > > Here are the results of the relevant Unixbench system benchmarks with BPF LSM > and SELinux enabled with default policies enabled with and without these > patches. > > Benchmark Delta(%): (+ is better) > =============================================================================== > Execl Throughput +1.9356 > File Write 1024 bufsize 2000 maxblocks +6.5953 > Pipe Throughput +9.5499 > Pipe-based Context Switching +3.0209 > Process Creation +2.3246 > Shell Scripts (1 concurrent) +1.4975 > System Call Overhead +2.7815 > System Benchmarks Index Score (Partial Only): +3.4859 > > In the best case, some syscalls like eventfd_create benefitted to about ~10%. > The full analysis can be viewed at https://kpsingh.ch/lsm-perf Ship it! ;) Thanks for continuing to work on this; this is a classic case for static_call. -Kees
On Fri, Sep 22, 2023 at 04:55:00PM +0200, KP Singh wrote: > Since we know the address of the enabled LSM callbacks at compile time and only > the order is determined at boot time, the LSM framework can allocate static > calls for each of the possible LSM callbacks and these calls can be updated once > the order is determined at boot. > Any plans to further depessimize the state by not calling into these modules if not configured? For example Debian has a milipede: CONFIG_LSM="landlock,lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" Everything is enabled (but not configured). In particular tomoyo is quite nasty, rolling with big memsets only to find it is not even enabled.
On Fri, Sep 22, 2023 at 8:42 PM Mateusz Guzik <mjguzik@gmail.com> wrote: > > On Fri, Sep 22, 2023 at 04:55:00PM +0200, KP Singh wrote: > > Since we know the address of the enabled LSM callbacks at compile time and only > > the order is determined at boot time, the LSM framework can allocate static > > calls for each of the possible LSM callbacks and these calls can be updated once > > the order is determined at boot. > > > > Any plans to further depessimize the state by not calling into these > modules if not configured? > > For example Debian has a milipede: > CONFIG_LSM="landlock,lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" > > Everything is enabled (but not configured). If it's not configured, we won't generate static call slots and even if they are in the CONFIG_LSM (or lsm=) they are simply ignored. - KP > > In particular tomoyo is quite nasty, rolling with big memsets only to > find it is not even enabled.
On 9/23/23, KP Singh <kpsingh@kernel.org> wrote: > On Fri, Sep 22, 2023 at 8:42 PM Mateusz Guzik <mjguzik@gmail.com> wrote: >> >> On Fri, Sep 22, 2023 at 04:55:00PM +0200, KP Singh wrote: >> > Since we know the address of the enabled LSM callbacks at compile time >> > and only >> > the order is determined at boot time, the LSM framework can allocate >> > static >> > calls for each of the possible LSM callbacks and these calls can be >> > updated once >> > the order is determined at boot. >> > >> >> Any plans to further depessimize the state by not calling into these >> modules if not configured? >> >> For example Debian has a milipede: >> CONFIG_LSM="landlock,lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" >> >> Everything is enabled (but not configured). > > If it's not configured, we won't generate static call slots and even > if they are in the CONFIG_LSM (or lsm=) they are simply ignored. > Maybe there is a terminology mismatch here, so let me be more specific with tomoyo as an example. In debian you have: CONFIG_SECURITY_TOMOYO=y CONFIG_LSM, as per above, includes it on the list. At the same time debian does not ship any tooling to configure tomoyo -- it is compiled into the kernel but not configured to enforce anything. On stock kernel this results in tons of calls to tomoyo_init_request_info, which are quite expensive due to an avoidable memset thrown in, and which always return tomoyo_init_request_info. Does not look like your patch whacks this problem.
On 9/23/23, Mateusz Guzik <mjguzik@gmail.com> wrote: > On 9/23/23, KP Singh <kpsingh@kernel.org> wrote: >> On Fri, Sep 22, 2023 at 8:42 PM Mateusz Guzik <mjguzik@gmail.com> wrote: >>> >>> On Fri, Sep 22, 2023 at 04:55:00PM +0200, KP Singh wrote: >>> > Since we know the address of the enabled LSM callbacks at compile time >>> > and only >>> > the order is determined at boot time, the LSM framework can allocate >>> > static >>> > calls for each of the possible LSM callbacks and these calls can be >>> > updated once >>> > the order is determined at boot. >>> > >>> >>> Any plans to further depessimize the state by not calling into these >>> modules if not configured? >>> >>> For example Debian has a milipede: >>> CONFIG_LSM="landlock,lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" >>> >>> Everything is enabled (but not configured). >> >> If it's not configured, we won't generate static call slots and even >> if they are in the CONFIG_LSM (or lsm=) they are simply ignored. >> > > Maybe there is a terminology mismatch here, so let me be more specific > with tomoyo as an example. > > In debian you have: > CONFIG_SECURITY_TOMOYO=y > > CONFIG_LSM, as per above, includes it on the list. > > At the same time debian does not ship any tooling to configure tomoyo > -- it is compiled into the kernel but not configured to enforce > anything. > > On stock kernel this results in tons of calls to > tomoyo_init_request_info, which are quite expensive due to an > avoidable memset thrown in, and which always return > tomoyo_init_request_info. > Erm, which always return TOMOYO_CONFIG_DISABLED. > Does not look like your patch whacks this problem. > So I am asking if there are plans to make these modules get out of the way if they have nothing to do, like tomoyo in the example above. Of course preferably distros would not make these weird configs, but I suspect this ship has sailed.
On Sat, Sep 23, 2023 at 07:15:05PM +0200, Mateusz Guzik wrote: > On 9/23/23, Mateusz Guzik <mjguzik@gmail.com> wrote: > > On 9/23/23, KP Singh <kpsingh@kernel.org> wrote: > >> On Fri, Sep 22, 2023 at 8:42 PM Mateusz Guzik <mjguzik@gmail.com> wrote: > >>> > >>> On Fri, Sep 22, 2023 at 04:55:00PM +0200, KP Singh wrote: > >>> > Since we know the address of the enabled LSM callbacks at compile time > >>> > and only > >>> > the order is determined at boot time, the LSM framework can allocate > >>> > static > >>> > calls for each of the possible LSM callbacks and these calls can be > >>> > updated once > >>> > the order is determined at boot. > >>> > > >>> > >>> Any plans to further depessimize the state by not calling into these > >>> modules if not configured? > >>> > >>> For example Debian has a milipede: > >>> CONFIG_LSM="landlock,lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" > >>> > >>> Everything is enabled (but not configured). > >> > >> If it's not configured, we won't generate static call slots and even > >> if they are in the CONFIG_LSM (or lsm=) they are simply ignored. > >> > > > > Maybe there is a terminology mismatch here, so let me be more specific > > with tomoyo as an example. > > > > In debian you have: > > CONFIG_SECURITY_TOMOYO=y > > > > CONFIG_LSM, as per above, includes it on the list. > > > > At the same time debian does not ship any tooling to configure tomoyo > > -- it is compiled into the kernel but not configured to enforce > > anything. > > > > On stock kernel this results in tons of calls to > > tomoyo_init_request_info, which are quite expensive due to an > > avoidable memset thrown in, and which always return > > tomoyo_init_request_info. > > > > Erm, which always return TOMOYO_CONFIG_DISABLED. > > > Does not look like your patch whacks this problem. > > > > So I am asking if there are plans to make these modules get out of the > way if they have nothing to do, like tomoyo in the example above. > > Of course preferably distros would not make these weird configs, but I > suspect this ship has sailed. This is an artifact of the existing stacking behavior (and solving it, if needed, can be done in parallel to this series). Specifically it seems Tomoyo is in the "lsm=" list when it shouldn't be. That said, I've long advocated[1] for a way to explicitly disable LSMs without affecting operational ordering. I think it would be very nice to be able to boot with something like: lsm=!yama to disable Yama. Or for your case, "lsm=!tomoyo". Right now, you have to figure out what the lsm list is, and then create a new one with the LSM you want disabled removed from the list. i.e. with v6.2 and later check the boot log, and you'll see: LSM: initializing lsm=lockdown,capability,landlock,yama,integrity,apparmor If you wanted to boot with Yama removed, you'd then pass: lsm=lockdown,capability,landlock,integrity,apparmor As a boot param. But I think this is fragile since now any new LSMs will be by-default disabled once a sysadmin overrides the "lsm" list. Note that booting with "lsm.debug=1" will show even more details. See commit 86ef3c735ec8 ("LSM: Better reporting of actual LSMs at boot"). So, if a distro has no support for an LSM but they want it _available_ in the kernel, they should leave it built in, but remove it from the "lsm=" list. That's a reasonable bug to file against a distro... -Kees [1] https://lore.kernel.org/linux-security-module/202210171111.21E3983165@keescook/
On 9/24/23, Kees Cook <keescook@chromium.org> wrote: > That said, I've long advocated[1] for a way to explicitly disable LSMs > without affecting operational ordering. I think it would be very nice to > be able to boot with something like: > > lsm=!yama > > to disable Yama. Or for your case, "lsm=!tomoyo". Right now, you have to > figure out what the lsm list is, and then create a new one with the > LSM you want disabled removed from the list. i.e. with v6.2 and later > check the boot log, and you'll see: > > LSM: initializing lsm=lockdown,capability,landlock,yama,integrity,apparmor > > If you wanted to boot with Yama removed, you'd then pass: > > lsm=lockdown,capability,landlock,integrity,apparmor > > As a boot param. But I think this is fragile since now any new LSMs will > be by-default disabled once a sysadmin overrides the "lsm" list. Note > that booting with "lsm.debug=1" will show even more details. See commit > 86ef3c735ec8 ("LSM: Better reporting of actual LSMs at boot"). > > So, if a distro has no support for an LSM but they want it _available_ > in the kernel, they should leave it built in, but remove it from the > "lsm=" list. That's a reasonable bug to file against a distro... > Maybe I once more expressed myself poorly, I meant to say stock Debian does not ship any tooling for tomoyo, but the kernel has support compiled in. Ultimately, after stacking got implemented, it was inevitable diestros like Debian will enable whatever modules and expect them to not be a problem if not configured by userspace. I don't think any form of messing with CONFIG_LSM is a viable option, even if you make it a boot param. What should happen instead is that modules which are not given any config don't get in the way.
On Mon, Sep 25, 2023 at 10:08:39PM +0200, Mateusz Guzik wrote: > On 9/24/23, Kees Cook <keescook@chromium.org> wrote: > > That said, I've long advocated[1] for a way to explicitly disable LSMs > > without affecting operational ordering. I think it would be very nice to > > be able to boot with something like: > > > > lsm=!yama > > > > to disable Yama. Or for your case, "lsm=!tomoyo". Right now, you have to > > figure out what the lsm list is, and then create a new one with the > > LSM you want disabled removed from the list. i.e. with v6.2 and later > > check the boot log, and you'll see: > > > > LSM: initializing lsm=lockdown,capability,landlock,yama,integrity,apparmor > > > > If you wanted to boot with Yama removed, you'd then pass: > > > > lsm=lockdown,capability,landlock,integrity,apparmor > > > > As a boot param. But I think this is fragile since now any new LSMs will > > be by-default disabled once a sysadmin overrides the "lsm" list. Note > > that booting with "lsm.debug=1" will show even more details. See commit > > 86ef3c735ec8 ("LSM: Better reporting of actual LSMs at boot"). > > > > So, if a distro has no support for an LSM but they want it _available_ > > in the kernel, they should leave it built in, but remove it from the > > "lsm=" list. That's a reasonable bug to file against a distro... > > > > Maybe I once more expressed myself poorly, I meant to say stock Debian > does not ship any tooling for tomoyo, but the kernel has support > compiled in. If there is no tooling Debian should either not build the support into the kernel or should leave it out of the CONFIG_LSM list. > Ultimately, after stacking got implemented, it was inevitable diestros > like Debian will enable whatever modules and expect them to not be a > problem if not configured by userspace. > > I don't think any form of messing with CONFIG_LSM is a viable option, > even if you make it a boot param. > > What should happen instead is that modules which are not given any > config don't get in the way. Right -- this is an open problem, and I think we can solve it using the static_call system (much like how the BPF LSM is doing it). -Kees