Re: [RFC PATCH 0/2] ima: uncompressed module appraisal support

From: Eric Snowberg
Date: Thu Feb 06 2020 - 16:41:18 EST



> On Feb 6, 2020, at 1:22 PM, Nayna <nayna@xxxxxxxxxxxxxxxxxx> wrote:
>
>
> On 2/6/20 11:42 AM, Eric Snowberg wrote:
>> When booting with either "ima_policy=secure_boot module.sig_enforce=1"
>> or building a kernel with CONFIG_IMA_ARCH_POLICY and booting with
>> "ima_policy=secure_boot", module loading behaves differently based on if
>> the module is compressed or not. Originally when appraising a module
>> with ima it had to be uncompressed and ima signed. Recent changes in 5.4
>> have allowed internally signed modules to load [1]. But this only works
>> if the internally signed module is compressed. The uncompressed module
>> that is internally signed must still be ima signed. This patch series
>> tries to bring the two in line.
>
> We (Mimi and I) have been trying to understand the cover letter. It seems "by internally signed" you are referring to modules signed with build time generated keys.

I am referring to any module that includes an appended signature. They could be signed at build time or anytime afterwards using /usr/src/kernels/$(uname -r)/scripts/sign-file. As long as the public key is contained in the builtin kernel trusted keyring.


> Our interpretation of the cover letter is that IMA originally did not support appended signatures and now does.

Correct, before the changes added to 5.4 [1], it was not possible to have a digital signature based appraisal policy that worked with a compressed module. This is because you canât ima sign a compressed module, since the signature would be lost by the time it gets to the init_module syscall. With the changes in [1] you can, if you include âmodsigâ to your policy, which allows the appended module to be checked instead.


> Since the modules are signed with build time generated keys, the signature verification still fails, as the keys are only available on the .builtin keyring and not the .ima keyring.

Currently the upstream code will fail if the module is uncompressed. If you compress the same module it will load with the current upstream code.

> Lastly, there is nothing in these patches that indicate that the kernel modules being compressed/uncompressed is related to the signature verification.
>

Basically if you have the following setup:

Kernel built with CONFIG_IMA_ARCH_POLICY or kernel booted with module.sig_enforce=1 along with the following ima policy:

appraise func=MODULE_CHECK appraise_type=imasig|modsig

If you have a module foo.ko that contains a valid appended signature but is not ima signed, it will fail to load. Now if the enduser simply compresses the same foo.ko, making it foo.ko.xz. The module will load.

Modules can be loaded thru two different syscalls, finit_module and init_module. The changes added in [1] work if you use the init_module syscall. My change adds support when the finit_module syscall gets used instead.


[1] https://patchwork.kernel.org/cover/10986023