mbox series

[v9,0/4] unify the keyrings of arm64 and s390 with x86 to verify kexec'ed kernel signature

Message ID 20220704015201.59744-1-coxu@redhat.com (mailing list archive)
Headers show
Series unify the keyrings of arm64 and s390 with x86 to verify kexec'ed kernel signature | expand

Message

Coiby Xu July 4, 2022, 1:51 a.m. UTC
Currently when loading a kernel image via the kexec_file_load() system
call, x86 can make use of three keyrings i.e. the .builtin_trusted_keys,
.secondary_trusted_keys and .platform keyrings to verify a signature.
However, arm64 and s390 can only use the .builtin_trusted_keys and
.platform keyring respectively. For example, one resulting problem is
kexec'ing a kernel image  would be rejected with the error "Lockdown:
kexec: kexec of unsigned images is restricted; see man
kernel_lockdown.7".

This patch set enables arm64 and s390 to make use of the same keyrings
as x86 to verify the signature kexec'ed kernel image.

The recently introduced .machine keyring impacts the roots of trust by
linking the .machine keyring to the .secondary keyring. The roots of
trust for different keyrings are described as follows,

.builtin_trusted_keys:

Keys may be built into the kernel during build or inserted into memory
reserved for keys post build. The root of trust is based on verification
of the kernel image signature. For example, on a physical system in a
secure boot environment, this trust is rooted in hardware.

.machine:

If the end-users choose to trust the keys provided by first-stage UEFI
bootloader shim i.e. Machine Owner Keys (MOK keys), the keys will be
added to this keyring which is linked to the .secondary_trusted_keys
keyring as the same as the .builtin_trusted_keys keyring. Shim has
built-in keys from a Linux distribution or the end-users-enrolled keys.
So the root of trust of this keyring is either a Linux distribution
vendor or the end-users.

.secondary_trusted_keys:

Certificates signed by keys on the .builtin_trusted_keys, .machine, or
existing keys on the .secondary_trusted_keys keryings may be loaded
onto the .secondary_trusted_keys keyring. This establishes a signature
chain of trust based on keys loaded on either the .builtin_trusted_keys
or .machine keyrings, if configured and enabled.

.platform:

The .platform keyring consist of UEFI db and MOK keys which are used by
shim to verify the first boot kernel's image signature. If end-users
choose to trust MOK keys and the kernel has the .machine keyring
enabled, the .platform keyring only consists of UEFI db keys since the
MOK keys are added to the .machine keyring instead. Because the
end-users could also enroll their own MOK keys, the root of trust could
be hardware and the end-users.

The 3rd arm64 patch depends on the first two patches. The 4th s390 patch
can be applied independently.

I've tested the patch set on 5.19.0-rc2 and it works as expected. 

For arm64, the tests were done as follows,
  1. build 5.19.0-rc2
  2. generate keys and add them to .secondary_trusted_keys, MOK, UEFI
     db;
  3. sign different kernel images with different keys including keys
     from .builtin_trusted_key, .secondary_trusted_keys keyring, a UEFI db
     key and MOK key
  4. Without lockdown, all kernel images can be kexec'ed; with lockdown
     enabled, only the kernel image signed by the key from the
     .builtin_trusted_key keyring can be kexec'ed

For 390, I commented out the code that skips signature verification when
secure boot is not enabled since the testing machine doesn't supports
secure boot and can confirm before applying the patch, kernel images
signed by keys from .builtin_trusted_key, .secondary_trusted_keys
couldn't be kexec'ed when lockdown is enabled; after applying the patch,
those kernel images could be kexec'ed.

v9:
 - improve cover letter, subject line and commit messages, expecially
   regarding the root of trust of different keyrings and the .machine
   keyring [Mimi]
 - fix two code format issues [Mimi]
 - add test results [Mimi]

v8:
 - drop "Cc: stable@vger.kernel.org" for the first two prerequisite
   patches [Baoquan]

v7:
 - drop the Fixes tag for the 2nd patch and add patch prerequisites
   [Baoquan]
 - improve cover letter

v6:
 - integrate the first three patches of "[PATCH 0/4] Unifrom keyring
   support across architectures and functions" from Michal [1]
 - improve commit message [Baoquan, Michal]
 - directly assign kexec_kernel_verify_pe_sig to
   kexec_file_ops->verify_sig [Michal]

v5:
 - improve commit message [Baoquan]

v4:
 - fix commit reference format issue and other checkpatch.pl warnings [Baoquan]

v3:
 - s/arch_kexec_kernel_verify_pe_sig/kexec_kernel_verify_pe_sig [Eric]
 - clean up arch_kexec_kernel_verify_sig [Eric]

v2:
 - only x86_64 and arm64 need to enable PE file signature check [Dave]

[1] https://lore.kernel.org/lkml/cover.1644953683.git.msuchanek@suse.de/

Coiby Xu (3):
  kexec: clean up arch_kexec_kernel_verify_sig
  kexec, KEYS: make the code in bzImage64_verify_sig generic
  arm64: kexec_file: use more system keyrings to verify kernel image
    signature

Michal Suchanek (1):
  kexec, KEYS, s390: Make use of built-in and secondary keyring for
    signature verification

 arch/arm64/kernel/kexec_image.c       | 11 +-----
 arch/s390/kernel/machine_kexec_file.c | 18 +++++++---
 arch/x86/kernel/kexec-bzimage64.c     | 20 +----------
 include/linux/kexec.h                 |  6 ++--
 kernel/kexec_file.c                   | 51 ++++++++++++++++-----------
 5 files changed, 49 insertions(+), 57 deletions(-)

Comments

Mimi Zohar July 6, 2022, 11:35 a.m. UTC | #1
On Mon, 2022-07-04 at 09:51 +0800, Coiby Xu wrote:
> Currently when loading a kernel image via the kexec_file_load() system
> call, x86 can make use of three keyrings i.e. the .builtin_trusted_keys,
> .secondary_trusted_keys and .platform keyrings to verify a signature.
> However, arm64 and s390 can only use the .builtin_trusted_keys and
> .platform keyring respectively. For example, one resulting problem is
> kexec'ing a kernel image  would be rejected with the error "Lockdown:
> kexec: kexec of unsigned images is restricted; see man
> kernel_lockdown.7".
> 
> This patch set enables arm64 and s390 to make use of the same keyrings
> as x86 to verify the signature kexec'ed kernel image.
> 
> The recently introduced .machine keyring impacts the roots of trust by
> linking the .machine keyring to the .secondary keyring. The roots of
> trust for different keyrings are described as follows,
> 
> .builtin_trusted_keys:
> 
> Keys may be built into the kernel during build or inserted into memory
> reserved for keys post build. The root of trust is based on verification
> of the kernel image signature. For example, on a physical system in a
> secure boot environment, this trust is rooted in hardware.
> 
> .machine:
> 
> If the end-users choose to trust the keys provided by first-stage UEFI
> bootloader shim i.e. Machine Owner Keys (MOK keys), the keys will be
> added to this keyring which is linked to the .secondary_trusted_keys
> keyring as the same as the .builtin_trusted_keys keyring. Shim has
> built-in keys from a Linux distribution or the end-users-enrolled keys.
> So the root of trust of this keyring is either a Linux distribution
> vendor or the end-users.
> 
> .secondary_trusted_keys:
> 
> Certificates signed by keys on the .builtin_trusted_keys, .machine, or
> existing keys on the .secondary_trusted_keys keryings may be loaded
> onto the .secondary_trusted_keys keyring. This establishes a signature
> chain of trust based on keys loaded on either the .builtin_trusted_keys
> or .machine keyrings, if configured and enabled.
> 
> .platform:
> 
> The .platform keyring consist of UEFI db and MOK keys which are used by
> shim to verify the first boot kernel's image signature. If end-users
> choose to trust MOK keys and the kernel has the .machine keyring
> enabled, the .platform keyring only consists of UEFI db keys since the
> MOK keys are added to the .machine keyring instead. Because the
> end-users could also enroll their own MOK keys, the root of trust could
> be hardware and the end-users.
> 
> The 3rd arm64 patch depends on the first two patches. The 4th s390 patch
> can be applied independently.
> 
> I've tested the patch set on 5.19.0-rc2 and it works as expected. 
> 
> For arm64, the tests were done as follows,
>   1. build 5.19.0-rc2
>   2. generate keys and add them to .secondary_trusted_keys, MOK, UEFI
>      db;
>   3. sign different kernel images with different keys including keys
>      from .builtin_trusted_key, .secondary_trusted_keys keyring, a UEFI db
>      key and MOK key
>   4. Without lockdown, all kernel images can be kexec'ed; with lockdown
>      enabled, only the kernel image signed by the key from the
>      .builtin_trusted_key keyring can be kexec'ed

Just confirming, for arm64, this patch set allows verifying the
kexec'ed kernel image signature using keys on either the .platform or
.secondary_trusted_keys keyrings.

thanks,

Mimi

> 
> For 390, I commented out the code that skips signature verification when
> secure boot is not enabled since the testing machine doesn't supports
> secure boot and can confirm before applying the patch, kernel images
> signed by keys from .builtin_trusted_key, .secondary_trusted_keys
> couldn't be kexec'ed when lockdown is enabled; after applying the patch,
> those kernel images could be kexec'ed.
Will Deacon July 6, 2022, 11:48 a.m. UTC | #2
On Wed, Jul 06, 2022 at 07:35:36AM -0400, Mimi Zohar wrote:
> On Mon, 2022-07-04 at 09:51 +0800, Coiby Xu wrote:
> > Currently when loading a kernel image via the kexec_file_load() system
> > call, x86 can make use of three keyrings i.e. the .builtin_trusted_keys,
> > .secondary_trusted_keys and .platform keyrings to verify a signature.
> > However, arm64 and s390 can only use the .builtin_trusted_keys and
> > .platform keyring respectively. For example, one resulting problem is
> > kexec'ing a kernel image  would be rejected with the error "Lockdown:
> > kexec: kexec of unsigned images is restricted; see man
> > kernel_lockdown.7".
> > 
> > This patch set enables arm64 and s390 to make use of the same keyrings
> > as x86 to verify the signature kexec'ed kernel image.

[...]

> > For arm64, the tests were done as follows,
> >   1. build 5.19.0-rc2
> >   2. generate keys and add them to .secondary_trusted_keys, MOK, UEFI
> >      db;
> >   3. sign different kernel images with different keys including keys
> >      from .builtin_trusted_key, .secondary_trusted_keys keyring, a UEFI db
> >      key and MOK key
> >   4. Without lockdown, all kernel images can be kexec'ed; with lockdown
> >      enabled, only the kernel image signed by the key from the
> >      .builtin_trusted_key keyring can be kexec'ed
> 
> Just confirming, for arm64, this patch set allows verifying the
> kexec'ed kernel image signature using keys on either the .platform or
> .secondary_trusted_keys keyrings.

It looks like this series is ready to go, but it's not clear who should
pick it up. Eric -- would you be the best person? Otherwise, I'm happy to
take it via the arm64 tree (on its own branch) if that would be helpful.

Thanks,

Will
Mimi Zohar July 6, 2022, 2:33 p.m. UTC | #3
On Wed, 2022-07-06 at 12:48 +0100, Will Deacon wrote:
> On Wed, Jul 06, 2022 at 07:35:36AM -0400, Mimi Zohar wrote:
> > On Mon, 2022-07-04 at 09:51 +0800, Coiby Xu wrote:
> > > Currently when loading a kernel image via the kexec_file_load() system
> > > call, x86 can make use of three keyrings i.e. the .builtin_trusted_keys,
> > > .secondary_trusted_keys and .platform keyrings to verify a signature.
> > > However, arm64 and s390 can only use the .builtin_trusted_keys and
> > > .platform keyring respectively. For example, one resulting problem is
> > > kexec'ing a kernel image  would be rejected with the error "Lockdown:
> > > kexec: kexec of unsigned images is restricted; see man
> > > kernel_lockdown.7".
> > > 
> > > This patch set enables arm64 and s390 to make use of the same keyrings
> > > as x86 to verify the signature kexec'ed kernel image.
> 
> [...]
> 
> > > For arm64, the tests were done as follows,
> > >   1. build 5.19.0-rc2
> > >   2. generate keys and add them to .secondary_trusted_keys, MOK, UEFI
> > >      db;
> > >   3. sign different kernel images with different keys including keys
> > >      from .builtin_trusted_key, .secondary_trusted_keys keyring, a UEFI db
> > >      key and MOK key
> > >   4. Without lockdown, all kernel images can be kexec'ed; with lockdown
> > >      enabled, only the kernel image signed by the key from the
> > >      .builtin_trusted_key keyring can be kexec'ed
> > 
> > Just confirming, for arm64, this patch set allows verifying the
> > kexec'ed kernel image signature using keys on either the .platform or
> > .secondary_trusted_keys keyrings.
> 
> It looks like this series is ready to go, but it's not clear who should
> pick it up. Eric -- would you be the best person? Otherwise, I'm happy to
> take it via the arm64 tree (on its own branch) if that would be helpful.

Unless Eric is interested, I was asked to pick this patch set up.

thanks,

Mimi
Coiby Xu July 7, 2022, 2:10 p.m. UTC | #4
Hi Mimi,

On Wed, Jul 06, 2022 at 10:33:50AM -0400, Mimi Zohar wrote:
>On Wed, 2022-07-06 at 12:48 +0100, Will Deacon wrote:
[..]
>> It looks like this series is ready to go, but it's not clear who should
>> pick it up. Eric -- would you be the best person? Otherwise, I'm happy to
>> take it via the arm64 tree (on its own branch) if that would be helpful.
>
>Unless Eric is interested, I was asked to pick this patch set up.

Thanks! FYI, Andrew has queued up Naveen's patch set "[PATCH 0/2] kexec:
Drop __weak attributes from functions" though:
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/log/?h=mm-nonmm-unstable

With Naveen's patch set, "[PATCH v9 1/4] kexec: clean up
arch_kexec_kernel_verify_sig"" can be dropped. If you need me to send a
new version, please let me know.

>
>thanks,
>
>Mimi
>
Mimi Zohar July 7, 2022, 10:28 p.m. UTC | #5
On Thu, 2022-07-07 at 22:10 +0800, Coiby Xu wrote:
> Hi Mimi,
> 
> On Wed, Jul 06, 2022 at 10:33:50AM -0400, Mimi Zohar wrote:
> >On Wed, 2022-07-06 at 12:48 +0100, Will Deacon wrote:
> [..]
> >> It looks like this series is ready to go, but it's not clear who should
> >> pick it up. Eric -- would you be the best person? Otherwise, I'm happy to
> >> take it via the arm64 tree (on its own branch) if that would be helpful.
> >
> >Unless Eric is interested, I was asked to pick this patch set up.
> 
> Thanks! FYI, Andrew has queued up Naveen's patch set "[PATCH 0/2] kexec:
> Drop __weak attributes from functions" though:
> https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/log/?h=mm-nonmm-unstable
> 
> With Naveen's patch set, "[PATCH v9 1/4] kexec: clean up
> arch_kexec_kernel_verify_sig"" can be dropped. If you need me to send a
> new version, please let me know.

I'm not quite sure how to handle the prerequisite patches being in
Andrew's tree, without his creating a branch with just the two commits.

thanks,

Mimi
Coiby Xu July 14, 2022, 1:48 p.m. UTC | #6
On Thu, Jul 07, 2022 at 06:28:50PM -0400, Mimi Zohar wrote:
>On Thu, 2022-07-07 at 22:10 +0800, Coiby Xu wrote:
>> Hi Mimi,
>>
>> On Wed, Jul 06, 2022 at 10:33:50AM -0400, Mimi Zohar wrote:
>> >On Wed, 2022-07-06 at 12:48 +0100, Will Deacon wrote:
>> [..]
>> >> It looks like this series is ready to go, but it's not clear who should
>> >> pick it up. Eric -- would you be the best person? Otherwise, I'm happy to
>> >> take it via the arm64 tree (on its own branch) if that would be helpful.
>> >
>> >Unless Eric is interested, I was asked to pick this patch set up.
>>
>> Thanks! FYI, Andrew has queued up Naveen's patch set "[PATCH 0/2] kexec:
>> Drop __weak attributes from functions" though:
>> https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/log/?h=mm-nonmm-unstable
>>
>> With Naveen's patch set, "[PATCH v9 1/4] kexec: clean up
>> arch_kexec_kernel_verify_sig"" can be dropped. If you need me to send a
>> new version, please let me know.
>
>I'm not quite sure how to handle the prerequisite patches being in
>Andrew's tree, without his creating a branch with just the two commits.

FYI, I just sent v10 based on Naveen's patch set and it targets
next-integrity since Mimi is going to pick it up.

>
>thanks,
>
>Mimi
>