s390x queue
Subsystems (2)
The following changes since commit fe11f459f640cd08f35c21f9d403517951bfd671:
Merge tag 'fixes-pr-v1' of https://gitlab.com/marcandre.lureau/qemu into staging (2026-08-25 06:48:55 -0700)
are available in the Git repository at:
https://gitlab.com/efarman/qemu.git tags/s390x-20260826
for you to fetch changes up to 5c3c500cddbdea58bb76515847d1d515621dcf0b:
pc-bios/s390-ccw.img: update s390x bios (2026-08-26 07:05:48 -0400)
----------------------------------------------------------------
New s390x features for 11.2
- hardening fixes in css/sclp code
- enable secure IPL
- regenerate s390-ccw.img
----------------------------------------------------------------
Christian Borntraeger (2):
s390x/sclp: pv: only copy the original SCCB buffer s390x/css: Fix css stsch detection to go beyond 8192 devices
Collin L. Walling (2):
s390x/diag: Introduce DIAG 508 for secure IPL operations s390x/diag: Implement DIAG 508 subcode 1 for signature verification
Eric Farman (1):
pc-bios/s390-ccw.img: update s390x bios
Zhuoying Cai (32):
Add boot-certs to s390-ccw-virtio machine type option crypto/x509-utils: Refactor with GNUTLS fallback crypto/x509-utils: Add helper functions for certificate store hw/s390x/ipl: Create certificate store
s390x/diag: Introduce DIAG 320 for Certificate Store Facility s390x/diag: Refactor address validation check from diag308_parm_check s390x/diag: Implement DIAG 320 subcode 1 crypto/x509-utils: Add helper functions for DIAG 320 subcode 2 s390x/diag: Implement DIAG 320 subcode 2
hw/s390x: Define finite size for single entry VCEntry crypto/x509-utils: Add helper functions for DIAG 508 subcode 1 s390x/diag: Generalize s390_ipl_read/write to accept void * s390x/ipl: Introduce IPL Information Report Block (IIRB) pc-bios/s390-ccw: Define memory for IPLB and convert IPLB to pointers hw/s390x/ipl: Add IPIB flags to IPL Parameter Block hw/s390x/ipl: Rework s390_ipl_map_iplb_chain for certificate storage
s390x: Guest support for Secure-IPL Facility pc-bios/s390-ccw: Refactor zipl_run()
pc-bios/s390-ccw: Rework zipl_load_segment function pc-bios/s390-ccw: Introduce ZiplBootMode enum for IPL mode selection pc-bios/s390-ccw: Add signature verification for secure IPL in audit
mode
pc-bios/s390-ccw: Add signed component address overlap checks
s390x: Guest support for Secure-IPL Code Loading Attributes Facility
(SCLAF)
pc-bios/s390-ccw: Add additional security checks for secure boot Add secure-boot to s390-ccw-virtio machine type option hw/s390x/ipl: Set IPIB flags for secure IPL pc-bios/s390-ccw: Handle true secure IPL mode hw/s390x/ipl: Handle secure boot with multiple boot devices tests/functional/s390x: Add secure IPL functional test docs/specs: Add secure IPL documentation docs/system/s390x: Add secure IPL documentation
MAINTAINERS: Add secure IPL files to S390-ccw boot group
MAINTAINERS | 5 + crypto/meson.build | 2 +- crypto/x509-utils.c | 409 +++++++++++++++ docs/specs/index.rst | 1 + docs/specs/s390x-secure-ipl.rst | 197 ++++++++ docs/system/s390x/secure-ipl.rst | 184 +++++++ docs/system/target-s390x.rst | 1 + hw/s390x/cert-store.c | 244 +++++++++ hw/s390x/cert-store.h | 38 ++ hw/s390x/css.c | 3 +- hw/s390x/ipl.c | 128 ++++- hw/s390x/ipl.h | 29 +- hw/s390x/meson.build | 1 + hw/s390x/s390-virtio-ccw.c | 70 +++ hw/s390x/sclp.c | 4 +- include/crypto/x509-utils.h | 113 +++++ include/hw/s390x/ipl/diag308.h | 34 ++ include/hw/s390x/ipl/diag320.h | 118 +++++ include/hw/s390x/ipl/diag508.h | 45 ++ include/hw/s390x/ipl/qipl.h | 113 ++++- include/hw/s390x/s390-virtio-ccw.h | 5 + include/hw/s390x/sclp.h | 6 +- pc-bios/s390-ccw.img | Bin 104216 -> 112408 bytes pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/bootmap.c | 108 +++- pc-bios/s390-ccw/bootmap.h | 22 + pc-bios/s390-ccw/iplb.h | 9 +- pc-bios/s390-ccw/jump2ipl.c | 13 +- pc-bios/s390-ccw/main.c | 59 ++- pc-bios/s390-ccw/netmain.c | 8 +- pc-bios/s390-ccw/s390-ccw.h | 27 + pc-bios/s390-ccw/sclp.c | 27 + pc-bios/s390-ccw/sclp.h | 7 + pc-bios/s390-ccw/secure-ipl.c | 561 +++++++++++++++++++++ pc-bios/s390-ccw/secure-ipl.h | 183 +++++++ qapi/machine-s390x.json | 23 + qapi/pragma.json | 1 + qemu-options.hx | 10 +- target/s390x/cpu_features.c | 7 + target/s390x/cpu_features.h | 1 + target/s390x/cpu_features_def.h.inc | 5 + target/s390x/cpu_models.c | 7 + target/s390x/diag.c | 576 +++++++++++++++++++++- target/s390x/gen-features.c | 7 + target/s390x/kvm/kvm.c | 34 ++ target/s390x/s390x-internal.h | 4 + target/s390x/tcg/misc_helper.c | 14 + tests/functional/s390x/meson.build | 2 + tests/functional/s390x/test_secure_ipl.py | 172 +++++++ 49 files changed, 3539 insertions(+), 100 deletions(-) create mode 100644 docs/specs/s390x-secure-ipl.rst create mode 100644 docs/system/s390x/secure-ipl.rst create mode 100644 hw/s390x/cert-store.c create mode 100644 hw/s390x/cert-store.h create mode 100644 include/hw/s390x/ipl/diag308.h create mode 100644 include/hw/s390x/ipl/diag320.h create mode 100644 include/hw/s390x/ipl/diag508.h create mode 100644 pc-bios/s390-ccw/secure-ipl.c create mode 100644 pc-bios/s390-ccw/secure-ipl.h create mode 100755 tests/functional/s390x/test_secure_ipl.py
Signature · 1 line
2.55.0
[PULL 09/37] s390x/diag: Implement DIAG 320 subcode 1
From: Zhuoying Cai <[email protected]>
DIAG 320 subcode 1 provides information needed to determine the amount of storage to store one or more certificates from the certificate store.
Upon successful completion, this subcode returns information of the current cert store, such as the number of certificates stored and allowed in the cert store, amount of space may need to be allocate to store a certificate, etc for verification-certificate blocks (VCBs).
The subcode value is denoted by setting the left-most bit of an 8-byte field.
The verification-certificate-storage-size block (VCSSB) contains the output data when the operation completes successfully. A VCSSB length of 4 indicates that no certificate are available in the cert store.
--- docs/specs/s390x-secure-ipl.rst | 12 +++++++ hw/s390x/cert-store.h | 3 +- include/hw/s390x/ipl/diag320.h | 57 ++++++++++++++++++++++++++++++ target/s390x/diag.c | 61 ++++++++++++++++++++++++++++++++- 4 files changed, 130 insertions(+), 3 deletions(-)
docs/specs/s390x-secure-ipl.rst +12 -0
@@ -30,3 +30,15 @@ Subcode 0 - query installed subcodes Returns a 256-bit installed subcodes mask (ISM) stored in the installed subcodes block (ISB). This mask indicates which subcodes are currently installed and available for use. + +Subcode 1 - query verification certificate storage information + Provides the information required to determine the amount of memory needed + to store one or more verification-certificates (VCs) from the certificate + store (CS). + + Upon successful completion, this subcode returns various storage size values + for verification-certificate blocks (VCBs). + + The output is returned in the verification-certificate-storage-size block + (VCSSB). A VCSSB length of 4 indicates that no certificates are available + in the CS.
hw/s390x/cert-store.h +1 -2
@@ -11,10 +11,9 @@#define HW_S390_CERT_STORE_H #include "hw/s390x/ipl/qipl.h" +#include "hw/s390x/ipl/diag320.h" #include "crypto/x509-utils.h" -#define CERT_NAME_MAX_LEN 64 -#define CERT_KEY_ID_LEN QCRYPTO_HASH_DIGEST_LEN_SHA256#define CERT_HASH_LEN QCRYPTO_HASH_DIGEST_LEN_SHA256
include/hw/s390x/ipl/diag320.h +57 -0
67 lines not on this page · raw message
target/s390x/diag.c +60 -1
85 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 19/37] hw/s390x/ipl: Add IPIB flags to IPL Parameter Block
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Add IPIB flags to IPL Parameter Block to determine if IPL needs to perform securely and if IPL Information Report Block (IIRB) exists.
Move DIAG308 flags to a separated header file and add flags for secure IPL. Move IPLB length related definitions to include/hw/s390x/ipl/qipl.h and add a maximum length constant to support secure IPL.
Secure boot in audit mode will perform if certificate(s) exist in the key store. IIRB will exist and results of verification will be stored in IIRB.
To ensure proper alignment of the IIRB and prevent overlap, set iplb->len to the maximum length of the IPLB, allowing alignment constraints to be determined based on its size.
--- hw/s390x/ipl.c | 36 ++++++++++++++++++++++++++++++++++ hw/s390x/ipl.h | 24 ----------------------- include/hw/s390x/ipl/diag308.h | 34 ++++++++++++++++++++++++++++++++ include/hw/s390x/ipl/qipl.h | 13 +++++++++++- 4 files changed, 82 insertions(+), 25 deletions(-) create mode 100644 include/hw/s390x/ipl/diag308.h
hw/s390x/ipl.c +36 -0
@@ -462,6 +462,34 @@ S390IPLCertificateStore *s390_ipl_get_certificate_store(void)return &ipl->cert_store; } +static bool s390_has_certificate (void ) +{ +S390IPLState *ipl =get_ipl_device (); + +return ipl->cert_store.count >0 ; +} + +static void s390_set_secure_boot_flags (IplParameterBlock *iplb, +bool audit_mode) +{ +if (!audit_mode) { +return ; + } + +/* +* For audit mode, enable the IPL Information +* Report (IPLIR) flag so that the firmware generates an IPL +* Information Report Block (IIRB). +* +* Results of secure boot will be stored in IIRB. +* +* Extend the IPL parameter block to its maximum length to ensure +* sufficient space for the BIOS to populate the IIRB. +*/ + iplb->hdr_flags |=DIAG308_IPIB_FLAGS_IPLIR ; + iplb->len =cpu_to_be32 (S390_IPLB_MAX_LEN ); +} +static bool s390_build_iplb (DeviceState *dev_st,IplParameterBlock *iplb) {CcwDevice *ccw_dev =NULL ;
@@ -518,6 +546,8 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)s390_ipl_convert_loadparm ((char *)lp, iplb->loadparm); iplb->flags |=DIAG308_FLAGS_LP_VALID ; +s390_set_secure_boot_flags (iplb,s390_has_certificate ()); +return true; }
@@ -654,6 +684,12 @@ void s390_ipl_update_diag308(IplParameterBlock *iplb) }else { ipl->iplb = *iplb; ipl->iplb_valid = true; + +/* +* The kernel does not preserve secure boot flags across a reboot. +* Re-apply them here based on the current machine configuration. +*/ +s390_set_secure_boot_flags (&ipl->iplb,s390_has_certificate ()); }update_machine_ipl_properties (iplb);
hw/s390x/ipl.h +0 -24
@@ -23,7 +23,6 @@#include "qom/object.h" #include "target/s390x/kvm/pv.h" -#define DIAG308_FLAGS_LP_VALID 0x80#define MAX_BOOT_DEVS 8/* Max number of devices that may have a bootindex */ void s390_ipl_convert_loadparm (char *ascii_lp,uint8_t *ebcdic_lp);
@@ -90,29 +89,6 @@ struct S390IPLState { };QEMU_BUILD_BUG_MSG (offsetof(S390IPLState , iplb) &3 ,"alignment of iplb wrong" ); -#define DIAG_308_RC_OK 0x0001 -#define DIAG_308_RC_NO_CONF 0x0102 -#define DIAG_308_RC_INVALID 0x0402 -#define DIAG_308_RC_NO_PV_CONF 0x0902 -#define DIAG_308_RC_INVAL_FOR_PV 0x0a02 - -#define DIAG308_RESET_MOD_CLR 0 -#define DIAG308_RESET_LOAD_NORM 1 -#define DIAG308_LOAD_CLEAR 3 -#define DIAG308_LOAD_NORMAL_DUMP 4 -#define DIAG308_SET 5 -#define DIAG308_STORE 6 -#define DIAG308_PV_SET 8 -#define DIAG308_PV_STORE 9 -#define DIAG308_PV_START 10 - -#define S390_IPLB_HEADER_LEN 8 -#define S390_IPLB_MIN_PV_LEN 148 -#define S390_IPLB_MIN_CCW_LEN 200 -#define S390_IPLB_MIN_FCP_LEN 384 -#define S390_IPLB_MIN_PCI_LEN 376 -#define S390_IPLB_MIN_QEMU_SCSI_LEN 200 -static inline bool iplb_valid_len (IplParameterBlock *iplb) {return be32_to_cpu (iplb->len) <=sizeof (IplParameterBlock);
include/hw/s390x/ipl/diag308.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* S/390 DIAGNOSE 308 definitions and structures +* +* Copyright 2025 IBM Corp. +* Author(s): Zhuoying Cai <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef S390X_DIAG308_H +#define S390X_DIAG308_H + +#define DIAG_308_RC_OK 0x0001 +#define DIAG_308_RC_NO_CONF 0x0102 +#define DIAG_308_RC_INVALID 0x0402 +#define DIAG_308_RC_NO_PV_CONF 0x0902 +#define DIAG_308_RC_INVAL_FOR_PV 0x0a02 + +#define DIAG308_RESET_MOD_CLR 0 +#define DIAG308_RESET_LOAD_NORM 1 +#define DIAG308_LOAD_CLEAR 3 +#define DIAG308_LOAD_NORMAL_DUMP 4 +#define DIAG308_SET 5 +#define DIAG308_STORE 6 +#define DIAG308_PV_SET 8 +#define DIAG308_PV_STORE 9 +#define DIAG308_PV_START 10 + +#define DIAG308_FLAGS_LP_VALID 0x80 + +#define DIAG308_IPIB_FLAGS_SIPL 0x40 +#define DIAG308_IPIB_FLAGS_IPLIR 0x20 + +#endif
include/hw/s390x/ipl/qipl.h +12 -1
@@ -12,6 +12,8 @@#ifndef S390X_QIPL_H #define S390X_QIPL_H +#include "diag308.h" +/* Boot Menu flags */ #define QIPL_FLAG_BM_OPTS_CMD 0x80#define QIPL_FLAG_BM_OPTS_ZIPL 0x40
@@ -33,6 +35,14 @@ typedef enum S390IplType S390IplType;#define QEMU_DEFAULT_IPL S390_IPL_TYPE_CCW +#define S390_IPLB_HEADER_LEN 8 +#define S390_IPLB_MIN_PV_LEN 148 +#define S390_IPLB_MIN_CCW_LEN 200 +#define S390_IPLB_MIN_FCP_LEN 384 +#define S390_IPLB_MIN_PCI_LEN 376 +#define S390_IPLB_MIN_QEMU_SCSI_LEN 200 +#define S390_IPLB_MAX_LEN 4096 +#define MAX_CERTIFICATES 64/* largest supported block size - same as VIRTIO_DASD_DEFAULT_BLOCK_SIZE */ #define VIRTIO_MAX_BLOCK_SIZE 4096
@@ -127,7 +137,8 @@ typedef struct IplBlockPci IplBlockPci;union IplParameterBlock {struct {uint32_t len; -uint8_t reserved0[3 ]; +uint8_t hdr_flags; +uint8_t reserved0[2 ];uint8_t version;uint32_t blk0_len;uint8_t pbt;
Signature · 1 line
2.55.0
[PULL 08/37] s390x/diag: Refactor address validation check from diag308_parm_check
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Create a function to validate the address parameter of DIAGNOSE.
Refactor the function for reuse in the next patch, which allows address validation in read or write operation of DIAGNOSE.
--- target/s390x/diag.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
target/s390x/diag.c +7 -3
@@ -26,6 +26,12 @@#include "qemu/error-report.h" +static inline bool diag_parm_addr_valid (uint64_t addr,size_t size,bool write) +{ +return address_space_access_valid (&address_space_memory, addr, + size, write,MEMTXATTRS_UNSPECIFIED ); +} +int handle_diag_288 (CPUS390XState *env,uint64_t r1,uint64_t r3) {uint64_t func = env->regs[r1];
@@ -65,9 +71,7 @@ static int diag308_parm_check(CPUS390XState *env, uint64_t r1, uint64_t addr,s390_program_interrupt (env,PGM_SPECIFICATION , ra);return -1 ; } -if (!address_space_access_valid (&address_space_memory, addr, -sizeof (IplParameterBlock), write, -MEMTXATTRS_UNSPECIFIED )) { +if (!diag_parm_addr_valid (addr,sizeof (IplParameterBlock), write)) {s390_program_interrupt (env,PGM_ADDRESSING , ra);return -1 ; }
Signature · 1 line
2.55.0
[PULL 20/37] hw/s390x/ipl: Rework s390_ipl_map_iplb_chain for certificate storage
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Rework s390_ipl_map_iplb_chain to always allocate maximum memory for the IPLB chain, regardless of the number of boot devices. This space is also used to store certificates during secure boot, providing a safe location for certificates until the kernel reads them during boot.
Rename next_iplb to ipl_data to better reflect its multiple purposes:
storing both IPLB chains and certificate data.
--- hw/s390x/ipl.c | 18 ++++++++++++++---- hw/s390x/ipl.h | 2 -- include/hw/s390x/ipl/qipl.h | 5 ++++- pc-bios/s390-ccw/iplb.h | 4 ++-- 4 files changed, 20 insertions(+), 9 deletions(-)
hw/s390x/ipl.c +14 -4
@@ -426,10 +426,9 @@ static S390PCIBusDevice *s390_get_pci_device(DeviceState *dev_st, int *devtype)return pbdev; } -static uint64_t s390_ipl_map_iplb_chain (IplParameterBlock *iplb_chain) +static uint64_t s390_ipl_map_iplb_chain (IplParameterBlock *iplb_chain,uint16_t count) {S390IPLState *ipl =get_ipl_device (); -uint16_t count =be16_to_cpu (ipl->qipl.chain_len);uint64_t len =sizeof (IplParameterBlock) * count;uint64_t chain_addr =find_iplb_chain_addr (ipl->bios_start_addr, count);
@@ -593,7 +592,7 @@ void s390_rebuild_iplb(uint16_t dev_index, IplParameterBlock *iplb)static bool s390_init_all_iplbs (S390IPLState *ipl) {int iplb_num =0 ; -IplParameterBlock iplb_chain[7 ]; +IplParameterBlock iplb_chain[MAX_BOOT_DEVS -1 ] = {0 };DeviceState *dev_st =get_boot_device (0 );Object *machine =qdev_get_machine ();
@@ -639,13 +638,24 @@ static bool s390_init_all_iplbs(S390IPLState *ipl) dev_st =get_boot_device (i);s390_build_iplb (dev_st, &iplb_chain[i -1 ]); } + } - ipl->qipl.next_iplb =cpu_to_be64 (s390_ipl_map_iplb_chain (iplb_chain)); +/* +* Allocate maximum space for IPLB chain and/or certificate storage. +* Once a valid boot device is found, this space will be used to store +* certificates if secure boot is enabled. +*/ +if (iplb_num >1 ||s390_has_certificate ()) { + ipl->qipl.ipl_data =cpu_to_be64 (s390_ipl_map_iplb_chain (iplb_chain, +MAX_BOOT_DEVS -1 )); }return iplb_num; } +QEMU_BUILD_BUG_MSG (sizeof (IplParameterBlock) * (MAX_BOOT_DEVS -1 ) !=CERT_BUF_SIZE , +"certificate buffer size is wrong" ); +static void update_machine_ipl_properties (IplParameterBlock *iplb) {Object *machine =qdev_get_machine ();
hw/s390x/ipl.h +0 -2
@@ -23,8 +23,6 @@#include "qom/object.h" #include "target/s390x/kvm/pv.h" -#define MAX_BOOT_DEVS 8/* Max number of devices that may have a bootindex */ -void s390_ipl_convert_loadparm (char *ascii_lp,uint8_t *ebcdic_lp);void s390_ipl_fmt_loadparm (uint8_t *loadparm,char *str,Error **errp);void s390_rebuild_iplb (uint16_t index,IplParameterBlock *iplb);
include/hw/s390x/ipl/qipl.h +4 -1
@@ -43,7 +43,10 @@ typedef enum S390IplType S390IplType;#define S390_IPLB_MIN_QEMU_SCSI_LEN 200#define S390_IPLB_MAX_LEN 4096 +#define MAX_BOOT_DEVS 8/* Max number of devices that may have a bootindex */ +#define MAX_CERTIFICATES 64 +#define CERT_BUF_SIZE ((MAX_BOOT_DEVS - 1) * 4096)/* largest supported block size - same as VIRTIO_DASD_DEFAULT_BLOCK_SIZE */ #define VIRTIO_MAX_BLOCK_SIZE 4096#define MAX_COMP_ENTRIES ((VIRTIO_MAX_BLOCK_SIZE - 32) / 32)
@@ -63,7 +66,7 @@ struct QemuIplParameters {uint32_t boot_menu_timeout;uint8_t reserved3[2 ];uint16_t chain_len; -uint64_t next_iplb; +uint64_t ipl_data; }QEMU_PACKED ;typedef struct QemuIplParameters QemuIplParameters ;
pc-bios/s390-ccw/iplb.h +2 -2
@@ -61,11 +61,11 @@ static inline bool load_next_iplb(void) } qipl.index++; - next_iplb = (IplParameterBlock *) qipl.next_iplb; + next_iplb = (IplParameterBlock *) qipl.ipl_data;memcpy (iplb, next_iplb,sizeof (IplParameterBlock)); qipl.chain_len--; - qipl.next_iplb = qipl.next_iplb +sizeof (IplParameterBlock); + qipl.ipl_data = qipl.ipl_data +sizeof (IplParameterBlock);return true; }
Signature · 1 line
2.55.0
[PULL 01/37] s390x/sclp: pv: only copy the original SCCB buffer
In reply to Eric FarmanFrom: Christian Borntraeger <[email protected]>
With variable length and EXTENDED_LENGTH_SCCB, some callbacks might change the length field. For example read SCP info might write a new length into the SCCB header. We must not use that new length for the buffer copy, since the buffer was allocated with the original length. Only the length field in the work SCCB is changed, to indicate the "necessary" size. Using the new length reads past the allocation, so tools like ASAN might detect a buffer overrun.
Secure guests do not have EXTENDED_LENGTH_SCCB, and the ultravisor checks and sanitizes the length field, so no qemu heap contents are exposed to the guest and the non pv-path already has the same header.length.
--- hw/s390x/sclp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/s390x/sclp.c +1 -1
@@ -287,7 +287,7 @@ int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code) sclp_c->execute (sclp, work_sccb, code); out_write:s390_cpu_pv_mem_write (env_archcpu (env),0 , work_sccb, -be16_to_cpu (work_sccb->h.length)); +be16_to_cpu (header.length)); sclp_c->service_interrupt (sclp,SCLP_PV_DUMMY_ADDR );return 0 ; }
Signature · 1 line
2.55.0
[PULL 07/37] s390x/diag: Introduce DIAG 320 for Certificate Store Facility
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
DIAGNOSE 320 is introduced to support Certificate Store (CS) Facility, which includes operations such as query certificate storage information and provide certificates in the certificate store.
Currently, only subcode 0 is supported with this patch, which is used to query the Installed Subcodes Mask (ISM).
This subcode is only supported when the CS facility is enabled.
Availability of CS facility is determined by byte 134 bit 5 of the SCLP Read Info block. Byte 134's facilities cannot be represented without the availability of the extended-length-SCCB, so add it as a check for consistency.
Note: secure IPL is not available for Secure Execution (SE) guests, as their images are already integrity protected, and an additional protection of the kernel by secure IPL is not necessary.
This feature is available starting with the gen16 CPU model.
--- docs/specs/s390x-secure-ipl.rst | 12 +++++++++ include/hw/s390x/ipl/diag320.h | 20 ++++++++++++++ target/s390x/cpu_features.c | 1 + target/s390x/cpu_features_def.h.inc | 1 + target/s390x/cpu_models.c | 2 ++ target/s390x/diag.c | 42 +++++++++++++++++++++++++++++ target/s390x/gen-features.c | 3 +++ target/s390x/kvm/kvm.c | 16 +++++++++++ target/s390x/s390x-internal.h | 2 ++ target/s390x/tcg/misc_helper.c | 7 +++++ 10 files changed, 106 insertions(+) create mode 100644 include/hw/s390x/ipl/diag320.h
docs/specs/s390x-secure-ipl.rst +12 -0
@@ -18,3 +18,15 @@ PEM Base64 data. Note: A maximum of 64 certificates are allowed to be stored in the certificate store. + +DIAGNOSE function code 'X'320' - Certificate Store Facility +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +DIAGNOSE 'X'320' is used to provide support for guest code to directly +query the s390 certificate store. Guest code may be the s390-ccw BIOS or +the guest kernel. + +Subcode 0 - query installed subcodes + Returns a 256-bit installed subcodes mask (ISM) stored in the installed + subcodes block (ISB). This mask indicates which subcodes are currently + installed and available for use.
include/hw/s390x/ipl/diag320.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* S/390 DIAGNOSE 320 definitions and structures +* +* Copyright 2025 IBM Corp. +* Author(s): Zhuoying Cai <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef S390X_DIAG320_H +#define S390X_DIAG320_H + +#define DIAG_320_SUBC_QUERY_ISM 0 + +#define DIAG_320_RC_OK 0x0001 +#define DIAG_320_RC_NOT_SUPPORTED 0x0102 + +#define DIAG_320_ISM_QUERY_SUBCODES 0x80000000 + +#endif
target/s390x/cpu_features.c +1 -0
@@ -147,6 +147,7 @@ void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,break ;case S390_FEAT_TYPE_SCLP_FAC134 :clear_be_bit (s390_feat_def (S390_FEAT_DIAG_318 )->bit, data); +clear_be_bit (s390_feat_def (S390_FEAT_CERT_STORE )->bit, data);break ;case S390_FEAT_TYPE_SCLP_FAC139 :clear_be_bit (s390_feat_def (S390_FEAT_SIE_ASTFLEIE2 )->bit, data);
target/s390x/cpu_features_def.h.inc +1 -0
@@ -138,6 +138,7 @@ DEF_FEAT(SIE_IBS, "ibs", SCLP_CONF_CHAR_EXT, 10, "SIE: Interlock-and-broadcast-s /* Features exposed via SCLP SCCB Facilities byte 134 (bit numbers relative to byte-134) */ DEF_FEAT(DIAG_318, "diag318", SCLP_FAC134, 0, "Control program name and version codes") +DEF_FEAT(CERT_STORE, "cstore", SCLP_FAC134, 5, "Certificate Store functions") /* Features exposed via SCLP SCCB Facilities byte 139 (bit numbers relative to byte-139) */ DEF_FEAT(SIE_ASTFLEIE2, "astfleie2", SCLP_FAC139, 1, "SIE: ASTFLE interpretation execution facility 2")
target/s390x/cpu_models.c +2 -0
@@ -248,6 +248,7 @@ bool s390_has_feat(S390Feat feat)if (s390_is_pv ()) {switch (feat) {case S390_FEAT_DIAG_318 : +case S390_FEAT_CERT_STORE :case S390_FEAT_HPMA2 :case S390_FEAT_SIE_F2 :case S390_FEAT_SIE_SKEY :
@@ -506,6 +507,7 @@ static void check_consistency(const S390CPUModel *model) { S390_FEAT_PTFF_STOUE, S390_FEAT_MULTIPLE_EPOCH }, { S390_FEAT_AP_QUEUE_INTERRUPT_CONTROL, S390_FEAT_AP }, { S390_FEAT_DIAG_318, S390_FEAT_EXTENDED_LENGTH_SCCB }, + { S390_FEAT_CERT_STORE, S390_FEAT_EXTENDED_LENGTH_SCCB }, { S390_FEAT_NNPA, S390_FEAT_VECTOR }, { S390_FEAT_RDP, S390_FEAT_LOCAL_TLB_CLEARING }, { S390_FEAT_UV_FEAT_AP, S390_FEAT_AP },
target/s390x/diag.c +42 -0
51 lines not on this page · raw message
target/s390x/gen-features.c +3 -0
@@ -721,6 +721,7 @@ static uint16_t full_GEN16_GA1[] = {S390_FEAT_UV_FEAT_AP ,S390_FEAT_UV_FEAT_AP_INTR ,S390_FEAT_SIE_ASTFLEIE2 , + S390_FEAT_CERT_STORE, }; static uint16_t full_GEN17_GA1[] = {
@@ -920,6 +921,8 @@ static uint16_t qemu_MAX[] = {S390_FEAT_KIMD_SHA_512 ,S390_FEAT_KLMD_SHA_512 ,S390_FEAT_PRNO_TRNG , +S390_FEAT_EXTENDED_LENGTH_SCCB , + S390_FEAT_CERT_STORE, };/****** END FEATURE DEFS ******/
target/s390x/kvm/kvm.c +16 -0
@@ -99,6 +99,7 @@#define DIAG_TIMEREVENT 0x288#define DIAG_IPL 0x308#define DIAG_SET_CONTROL_PROGRAM_CODES 0x318 +#define DIAG_CERT_STORE 0x320#define DIAG_KVM_HYPERCALL 0x500#define DIAG_KVM_BREAKPOINT 0x501
@@ -1531,6 +1532,16 @@ static void handle_diag_318(S390CPU *cpu, struct kvm_run *run) } } +static void kvm_handle_diag_320 (S390CPU *cpu,struct kvm_run *run) +{ +uint64_t r1, r3; + + r1 = (run->s390_sieic.ipa &0x00f0 ) >>4 ; + r3 = run->s390_sieic.ipa &0x000f ; + +handle_diag_320 (&cpu->env, r1, r3,RA_IGNORED ); +} +#define DIAG_KVM_CODE_MASK 0x000000000000ffffstatic int handle_diag (S390CPU *cpu,struct kvm_run *run,uint32_t ipb)
@@ -1561,6 +1572,9 @@ static int handle_diag(S390CPU *cpu, struct kvm_run *run, uint32_t ipb)case DIAG_KVM_BREAKPOINT : r =handle_sw_breakpoint (cpu, run);break ; +case DIAG_CERT_STORE : +kvm_handle_diag_320 (cpu, run); +break ;default :trace_kvm_insn_diag (func_code);kvm_s390_program_interrupt (cpu,PGM_SPECIFICATION );
@@ -2472,6 +2486,8 @@ bool kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)set_bit (S390_FEAT_DIAG_318 , model->features); } +set_bit (S390_FEAT_CERT_STORE , model->features); +/* Test for Ultravisor features that influence secure guest behavior */ query_uv_feat_guest (model->features);
target/s390x/s390x-internal.h +2 -0
@@ -388,6 +388,8 @@ int handle_diag_288(CPUS390XState *env, uint64_t r1, uint64_t r3);/* Return whether a CPU reset is pending */ bool handle_diag_308 (CPUS390XState *env,uint64_t r1,uint64_t r3,uintptr_t ra); +void handle_diag_320 (CPUS390XState *env,uint64_t r1,uint64_t r3, +uintptr_t ra);/* translate.c */
target/s390x/tcg/misc_helper.c +7 -0
@@ -147,6 +147,13 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num)/* time bomb (watchdog) */ r =handle_diag_288 (env, r1, r3);break ; +case 0x320 : +/* cert store */ +bql_lock (); +handle_diag_320 (env, r1, r3,GETPC ()); +bql_unlock (); + r =0 ; +break ;default : r =-1 ;break ;
Signature · 1 line
2.55.0
[PULL 25/37] pc-bios/s390-ccw: Add signature verification for secure IPL in audit mode
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Enable secure IPL in audit mode, which performs signature verification, but any error does not terminate the boot process. Only warnings will be logged to the console instead.
Secure IPL in audit mode requires at least one certificate provided in the key store along with necessary facilities (Secure IPL Facility, Certificate Store Facility and secure IPL extension support).
Note: Secure IPL in audit mode is implemented for the SCSI scheme of virtio-blk/virtio-scsi devices.
--- docs/system/s390x/secure-ipl.rst | 15 ++ hw/s390x/ipl.c | 9 + pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/bootmap.c | 28 +++ pc-bios/s390-ccw/bootmap.h | 9 + pc-bios/s390-ccw/jump2ipl.c | 7 + pc-bios/s390-ccw/main.c | 19 +- pc-bios/s390-ccw/s390-ccw.h | 20 ++ pc-bios/s390-ccw/sclp.c | 27 +++ pc-bios/s390-ccw/sclp.h | 6 + pc-bios/s390-ccw/secure-ipl.c | 369 +++++++++++++++++++++++++++++++ pc-bios/s390-ccw/secure-ipl.h | 119 ++++++++++ 12 files changed, 628 insertions(+), 2 deletions(-) create mode 100644 pc-bios/s390-ccw/secure-ipl.c create mode 100644 pc-bios/s390-ccw/secure-ipl.h
docs/system/s390x/secure-ipl.rst +15 -0
@@ -39,3 +39,18 @@ Configuration: .. code-block:: shell qemu-system-s390x -machine s390-ccw-virtio ... + +Audit Mode +^^^^^^^^^^ + +When the certificate store is populated with at least one certificate +and no additional secure IPL parameters are provided on the command +line, then secure IPL will proceed in "audit mode". All secure IPL +operations will be performed with signature verification errors reported +as non-disruptive warnings. + +Configuration: + +.. code-block:: shell + + qemu-system-s390x -machine s390-ccw-virtio,boot-certs.0.path=/.../qemu/certs,boot-certs.1.path=/another/path/cert.pem ...
hw/s390x/ipl.c +9 -0
@@ -828,6 +828,15 @@ void s390_ipl_prepare_cpu(S390CPU *cpu) cpu->env.psw.addr = ipl->bios_start_addr;if (!ipl->iplb_valid) { ipl->iplb_valid =s390_init_all_iplbs (ipl); + +/* +* Secure IPL without specifying a boot device. +* IPLB is not generated if no boot device is defined. +*/ +if (s390_has_certificate () && !ipl->iplb_valid) { +error_report ("No boot device defined for Secure IPL" ); +exit (1 ); + } }else { ipl->qipl.chain_len =0 ; }
pc-bios/s390-ccw/Makefile +1 -1
@@ -35,7 +35,7 @@ QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o netmain.o \ virtio.o virtio-net.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o \ - virtio-ccw.o clp.o pci.o virtio-pci.o + virtio-ccw.o clp.o pci.o virtio-pci.o secure-ipl.o SLOF_DIR := $(SRC_PATH)/../../roms/SLOF
pc-bios/s390-ccw/bootmap.c +28 -0
@@ -10,11 +10,13 @@#include <string.h> #include <stdio.h> +#include <stdlib.h> #include "s390-ccw.h" #include "s390-arch.h" #include "bootmap.h" #include "virtio.h" #include "bswap.h" +#include "secure-ipl.h" #ifdef DEBUG /* #define DEBUG_FALLBACK */
@@ -712,6 +714,9 @@ static int zipl_run(ScsiBlockPtr *pte)ComponentHeader *header;ComponentEntry *entry;uint8_t tmp_sec[MAX_SECTOR_SIZE ]; +IplDeviceComponentList comp_list = {0 }; +IplSignatureCertificateList cert_list = {0 }; +uint8_t *tmp_cert_buf =NULL ;int rc;if (virtio_read (pte->blockno, tmp_sec)) {
@@ -738,6 +743,9 @@ static int zipl_run(ScsiBlockPtr *pte)case ZIPL_BOOT_MODE_NORMAL : rc =zipl_run_normal (&entry, tmp_sec);break ; +case ZIPL_BOOT_MODE_SECURE_AUDIT : + rc =zipl_run_secure (&entry, tmp_sec, &comp_list, &cert_list, &tmp_cert_buf); +break ;default :panic ("Unknown boot mode" ); }
@@ -748,10 +756,18 @@ static int zipl_run(ScsiBlockPtr *pte)if (entry->component_type !=ZIPL_COMP_ENTRY_EXEC ) {puts ("No EXEC entry" ); +free (tmp_cert_buf);return -EINVAL ; }write_reset_psw (entry->compdat.load_psw); + +if (boot_mode ==ZIPL_BOOT_MODE_SECURE_AUDIT ) { +update_cert_list (&cert_list); +update_iirb (&comp_list, &cert_list); +free (tmp_cert_buf); + } +jump_to_IPL_code (0 );return -1 ;/* should not return */ }
@@ -1107,6 +1123,18 @@ static int zipl_load_vscsi(void)* IPL starts here */ +ZiplBootMode get_boot_mode (uint8_t hdr_flags) +{ +bool sipl_set = hdr_flags &DIAG308_IPIB_FLAGS_SIPL ; +bool iplir_set = hdr_flags &DIAG308_IPIB_FLAGS_IPLIR ; + +if (!sipl_set && iplir_set) { +return ZIPL_BOOT_MODE_SECURE_AUDIT ; + } + +return ZIPL_BOOT_MODE_NORMAL ; +} +void zipl_load (void ) {VDev *vdev =virtio_get_device ();
pc-bios/s390-ccw/bootmap.h +9 -0
@@ -88,9 +88,18 @@ typedef struct BootMapTable {BootMapPointer entry[]; } __attribute__ ((packed)) BootMapTable; +#define DER_SIGNATURE_FORMAT 1 + +typedef struct SignatureInformation { +uint8_t format; +uint8_t reserved[3 ]; +uint32_t sig_len; +}SignatureInformation ; +typedef union ComponentEntryData {uint64_t load_psw;uint64_t load_addr; +SignatureInformation sig_info; }ComponentEntryData ; typedef struct ComponentEntry {
pc-bios/s390-ccw/jump2ipl.c +7 -0
@@ -75,6 +75,13 @@ int jump_to_IPL_code(uint64_t address) "diag %%r1,%%r1,0x308\n\t" : : : "1", "memory");puts ("IPL code jump failed" ); + +/* +* A failed jump only occurs in extreme conditions, so abort the IPL entirely. +* This also prevents attempts to boot from the chain area if it has been +* overwritten with component data. +*/ + qipl.chain_len =0 ;return -1 ; }
pc-bios/s390-ccw/main.c +18 -1
@@ -20,6 +20,7 @@#include "dasd-ipl.h" #include "clp.h" #include "virtio-pci.h" +#include "secure-ipl.h" static SubChannelId blk_schid = { .one =1 };static char loadparm_str[LOADPARM_LEN +1 ];
@@ -386,6 +387,8 @@ static void probe_boot_device(void)void main (void ) { +int vcssb_len; + iplb = &ipl_blocks.iplb;copy_qipl ();
@@ -397,7 +400,21 @@ void main(void)probe_boot_device (); } - boot_mode =ZIPL_BOOT_MODE_NORMAL ; + boot_mode =get_boot_mode (iplb->hdr_flags); +switch (boot_mode) { +case ZIPL_BOOT_MODE_SECURE_AUDIT : +if (!secure_ipl_supported ()) { +panic ("Unable to boot in audit mode" ); + } + + vcssb_len =zipl_secure_get_vcssb (); +if (vcssb_len ==0 ) { +panic ("Failed to query certificate storage information!" ); + } +break ; +default : +break ; + }while (have_iplb) {boot_setup ();
pc-bios/s390-ccw/s390-ccw.h +20 -0
@@ -40,6 +40,22 @@ typedef unsigned long long u64; ((b) == 0 ? (a) : (MIN(a, b))))#endif +/* +* Round number down to multiple. Requires that d be a power of 2. +* Works even if d is a smaller type than n. +*/ +#ifndef ROUND_DOWN +#define ROUND_DOWN (n, d) ((n) & -(0 ? (n) : (d))) +#endif + +/* +* Round number up to multiple. Requires that d be a power of 2. +* Works even if d is a smaller type than n. +*/ +#ifndef ROUND_UP +#define ROUND_UP (n, d) ROUND_DOWN((n) + (d) - 1, (d)) +#endif +#define ARRAY_SIZE (a) (sizeof(a) / sizeof((a)[0]))#include "cio.h"
@@ -64,6 +80,8 @@ void sclp_print(const char *string);void sclp_set_write_mask (uint32_t receive_mask,uint32_t send_mask);void sclp_setup (void );void sclp_get_loadparm_ascii (char *loadparm); +bool sclp_is_diag320_on (void ); +bool sclp_is_fac_ipl_flag_on (uint16_t fac_ipl_flag);int sclp_read (char *str,size_t count);/* bootmap.c */
@@ -71,9 +89,11 @@ void zipl_load(void);typedef enum ZiplBootMode {ZIPL_BOOT_MODE_NORMAL =0 , +ZIPL_BOOT_MODE_SECURE_AUDIT =1 , }ZiplBootMode ;extern ZiplBootMode boot_mode; +ZiplBootMode get_boot_mode (uint8_t hdr_flags);/* jump2ipl.c */ void write_reset_psw (uint64_t psw);
pc-bios/s390-ccw/sclp.c +27 -0
@@ -113,6 +113,33 @@ void sclp_get_loadparm_ascii(char *loadparm) } } +bool sclp_is_diag320_on (void ) +{ +ReadInfo *sccb = (void *)_sccb; + +memset ((char *)_sccb,0 ,sizeof (ReadInfo)); + sccb->h.length =SCCB_SIZE ; +if (!sclp_service_call (SCLP_CMDW_READ_SCP_INFO , sccb)) { +return sccb->fac134 &SCCB_FAC134_DIAG320_BIT ; + } + +return 0 ; +} + +/* check if specified IPL facility flag is enabled */ +bool sclp_is_fac_ipl_flag_on (uint16_t fac_ipl_flag) +{ +ReadInfo *sccb = (void *)_sccb; + +memset ((char *)_sccb,0 ,sizeof (ReadInfo)); + sccb->h.length =SCCB_SIZE ; +if (!sclp_service_call (SCLP_CMDW_READ_SCP_INFO , sccb)) { +return sccb->fac_ipl & fac_ipl_flag; + } + +return 0 ; +} +int sclp_read (char *str,size_t count) {ReadEventData *sccb = (void *)_sccb;
pc-bios/s390-ccw/sclp.h +6 -0
@@ -50,6 +50,8 @@ typedef struct SCCBHeader { } __attribute__((packed)) SCCBHeader;#define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader)) +#define SCCB_FAC134_DIAG320_BIT 0x4 +#define SCCB_FAC_IPL_SIPL_BIT 0x4000 typedef struct ReadInfo { SCCBHeader h;
@@ -57,6 +59,10 @@ typedef struct ReadInfo {uint8_t rnsize;uint8_t reserved[13 ];uint8_t loadparm[LOADPARM_LEN ]; +uint8_t reserved1[102 ]; +uint8_t fac134; +uint8_t reserved2; +uint16_t fac_ipl; } __attribute__((packed)) ReadInfo; typedef struct SCCB {
pc-bios/s390-ccw/secure-ipl.c new file +369 -0
369 lines not on this page · raw message
pc-bios/s390-ccw/secure-ipl.h new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 22/37] pc-bios/s390-ccw: Refactor zipl_run()
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Refactor to enhance readability before enabling secure IPL in later patches.
--- pc-bios/s390-ccw/bootmap.c | 54 ++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 20 deletions(-)
pc-bios/s390-ccw/bootmap.c +34 -20
@@ -676,12 +676,42 @@ static int zipl_load_segment(ComponentEntry *entry)return 0 ; } +static int zipl_run_normal (ComponentEntry **entry_ptr,const uint8_t *tmp_sec) +{ +ComponentEntry *entry = *entry_ptr; + +while (entry->component_type ==ZIPL_COMP_ENTRY_LOAD || + entry->component_type ==ZIPL_COMP_ENTRY_SIGNATURE ) { + +/* Secure boot is off, so we skip signature entries */ +if (entry->component_type ==ZIPL_COMP_ENTRY_SIGNATURE ) { + entry++; +continue ; + } + +if (zipl_load_segment (entry)) { +return -1 ; + } + + entry++; + +if ((uint8_t *)&entry[1 ] > tmp_sec +MAX_SECTOR_SIZE ) { +puts ("Wrong entry value" ); +return -EINVAL ; + } + } + + *entry_ptr = entry; +return 0 ; +} +/* Run a zipl program */ static int zipl_run (ScsiBlockPtr *pte) {ComponentHeader *header;ComponentEntry *entry;uint8_t tmp_sec[MAX_SECTOR_SIZE ]; +int rc;if (virtio_read (pte->blockno, tmp_sec)) {puts ("Cannot read header" );
@@ -702,25 +732,10 @@ static int zipl_run(ScsiBlockPtr *pte)/* Load image(s) into RAM */ entry = (ComponentEntry *)(&header[1 ]); -while (entry->component_type ==ZIPL_COMP_ENTRY_LOAD || - entry->component_type ==ZIPL_COMP_ENTRY_SIGNATURE ) { - -/* We don't support secure boot yet, so we skip signature entries */ -if (entry->component_type ==ZIPL_COMP_ENTRY_SIGNATURE ) { - entry++; -continue ; - } -if (zipl_load_segment (entry)) { -return -1 ; - } - - entry++; - -if ((uint8_t *)(&entry[1 ]) > (tmp_sec +MAX_SECTOR_SIZE )) { -puts ("Wrong entry value" ); -return -EINVAL ; - } + rc =zipl_run_normal (&entry, tmp_sec); +if (rc) { +return rc; }if (entry->component_type !=ZIPL_COMP_ENTRY_EXEC ) {
@@ -728,10 +743,9 @@ static int zipl_run(ScsiBlockPtr *pte)return -EINVAL ; } -/* should not return */ write_reset_psw (entry->compdat.load_psw);jump_to_IPL_code (0 ); -return -1 ; +return -1 ;/* should not return */ }static int ipl_scsi (void )
Signature · 1 line
2.55.0
[PULL 11/37] s390x/diag: Implement DIAG 320 subcode 2
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
DIAG 320 subcode 2 provides verification-certificates (VCs) that are in the certificate store. Only X509 certificates in DER format and SHA-256 hash type are recognized.
The subcode value is denoted by setting the second-left-most bit of an 8-byte field.
The Verification Certificate Block (VCB) contains the output data when the operation completes successfully. It includes a common header followed by zero or more Verification Certificate Entries (VCEs), depending on the VCB input length and the VC range (from the first VC index to the last VC index) in the certificate store.
Each VCE contains information about a certificate retrieved from the S390IPLCertificateStore, such as the certificate name, key type, key ID length, hash length, and the raw certificate data.
The key ID and hash are extracted from the raw certificate by the crypto API.
Note: SHA2-256 VC hash type is required for retrieving the hash (fingerprint) of the certificate.
--- docs/specs/s390x-secure-ipl.rst | 24 +++ include/hw/s390x/ipl/diag320.h | 38 ++++ target/s390x/diag.c | 316 +++++++++++++++++++++++++++++++- 3 files changed, 377 insertions(+), 1 deletion(-)
docs/specs/s390x-secure-ipl.rst +24 -0
@@ -42,3 +42,27 @@ Subcode 1 - query verification certificate storage information The output is returned in the verification-certificate-storage-size block (VCSSB). A VCSSB length of 4 indicates that no certificates are available in the CS. + +Subcode 2 - store verification certificates + Provides VCs that are in the certificate store. + + The output is provided in a VCB, which includes a common header followed by + zero or more verification-certificate entries (VCEs). + + The instruction expects the cert store to maintain an origin of 1 for the + index (i.e. a retrieval of the first certificate in the store should be + denoted by setting first-VC to 1). + + The first-VC and last-VC fields of the VCB specify the index range of + VCs to be stored in the VCB. Certs are stored sequentially, starting + with first-VC index. As each cert is stored, a "stored count" is + incremented. If there is not enough space to store all certs requested + by the index range, a "remaining count" will be recorded and no more + certificates will be stored. + + Each VCE contains a header followed by information extracted from a + certificate within the certificate store. The information includes: + key-id, hash, and certificate data. This information is stored + contiguously in a VCE (with zero-padding). Following the header, the + key-id is immediately stored. The hash and certificate data follow and + may be accessed via the respective offset fields stored in the VCE.
include/hw/s390x/ipl/diag320.h +38 -0
@@ -12,19 +12,45 @@#define DIAG_320_SUBC_QUERY_ISM 0#define DIAG_320_SUBC_QUERY_VCSI 1 +#define DIAG_320_SUBC_STORE_VC 2#define DIAG_320_RC_OK 0x0001#define DIAG_320_RC_NOT_SUPPORTED 0x0102#define DIAG_320_RC_INVAL_VCSSB_LEN 0x0202 +#define DIAG_320_RC_INVAL_VCB_LEN 0x0204 +#define DIAG_320_RC_BAD_RANGE 0x0302#define DIAG_320_ISM_QUERY_SUBCODES 0x80000000#define DIAG_320_ISM_QUERY_VCSI 0x40000000 +#define DIAG_320_ISM_STORE_VC 0x20000000#define VCSSB_NO_VC 4#define VCSSB_LEN_VALID 128#define CERT_NAME_MAX_LEN 64 +/* +* If the VCE flags indicate an invalid certificate, +* the VCE length is set to 72, containing only the +* first five fields of VCEntry. +*/ +#define VCE_INVALID_LEN 72 + +#define DIAG_320_VCE_FLAGS_VALID 0x80 + +typedef enum Diag320VceKeyType { +DIAG_320_VCE_KEYTYPE_SELF_DESCRIBING =0 , +DIAG_320_VCE_KEYTYPE_ECDSA_P521 =1 , +}Diag320VceKeyType ; + +typedef enum Diag320VceFormat { +DIAG_320_VCE_FORMAT_X509_DER =1 , +}Diag320VceFormat ; + +typedef enum Diag320VceHashType { +DIAG_320_VCE_HASHTYPE_SHA2_256 =1 , +}Diag320VceHashType ; +struct VCStorageSizeBlock {uint32_t length;uint8_t reserved0[3 ];
@@ -60,6 +86,12 @@ struct VCEntryHeader { };typedef struct VCEntryHeader VCEntryHeader ; +struct VCEntry { +VCEntryHeader vce_hdr; +uint8_t cert_buf[]; +}; +typedef struct VCEntry VCEntry ; +struct VCBlockHeader {uint32_t in_len;uint32_t reserved0;
@@ -74,4 +106,10 @@ struct VCBlockHeader { };typedef struct VCBlockHeader VCBlockHeader ; +struct VCBlock { +VCBlockHeader vcb_hdr; +uint8_t vce_buf[]; +}; +typedef struct VCBlock VCBlock ; +#endif
target/s390x/diag.c +315 -1
349 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 27/37] s390x: Guest support for Secure-IPL Code Loading Attributes Facility (SCLAF)
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
The secure-IPL-code-loading-attributes facility (SCLAF) provides additional security during secure IPL.
Availability of SCLAF is determined by byte 136 bit 3 of the SCLP Read SCP Info.
This feature is available starting with the gen16 CPU model.
--- docs/specs/s390x-secure-ipl.rst | 18 ++++++++++++++++++ target/s390x/cpu_features.c | 2 ++ target/s390x/cpu_features_def.h.inc | 1 + target/s390x/cpu_models.c | 3 +++ target/s390x/gen-features.c | 2 ++ target/s390x/kvm/kvm.c | 1 + 6 files changed, 27 insertions(+)
docs/specs/s390x-secure-ipl.rst +18 -0
@@ -122,3 +122,21 @@ The guest kernel uses the contents in the IIRB for: * Boot logging: reports which components were loaded and verified. * kexec operations: builds the next kernel’s IPL report from the existing one. * Keying: installs IPL certificates into the platform trusted keyring. + +Secure Code Loading Attributes Facility +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The Secure Code Loading Attributes Facility (SCLAF) enhances system security +during the IPL by enforcing additional verification rules. + +When SCLAF is available, its behavior depends on the IPL mode. It introduces +verification of both signed and unsigned components to help ensure that only +authorized code is loaded during the IPL process. Any errors detected by SCLAF +are reported in the IIRB. + +Unsigned components are restricted to load addresses at or above absolute +storage address ``0x2000``. + +Signed components must include a Secure Code Loading Attribute Block (SCLAB), +which is appended at the very end of the component. The SCLAB defines security +attributes for handling the signed code.
target/s390x/cpu_features.c +2 -0
@@ -120,6 +120,7 @@ void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,* - All SIE facilities because SIE is not available * - DIAG318 * - Secure IPL Facility +* - Secure IPL Code Loading Attributes Facility * * As VMs can move in and out of protected mode the CPU model * doesn't protect us from that problem because it is only
@@ -152,6 +153,7 @@ void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,break ;case S390_FEAT_TYPE_SCLP_FAC_IPL :clear_be_bit (s390_feat_def (S390_FEAT_SIPL )->bit, data); +clear_be_bit (s390_feat_def (S390_FEAT_SCLAF )->bit, data);break ;case S390_FEAT_TYPE_SCLP_FAC139 :clear_be_bit (s390_feat_def (S390_FEAT_SIE_ASTFLEIE2 )->bit, data);
target/s390x/cpu_features_def.h.inc +1 -0
@@ -142,6 +142,7 @@ DEF_FEAT(CERT_STORE, "cstore", SCLP_FAC134, 5, "Certificate Store functions") /* Features exposed via SCLP SCCB Facilities byte 136 - 137 (bit numbers relative to byte-136) */ DEF_FEAT(SIPL, "sipl", SCLP_FAC_IPL, 1, "Secure-IPL facility") +DEF_FEAT(SCLAF, "sclaf", SCLP_FAC_IPL, 3, "Secure-IPL-code-loading-attributes facility") /* Features exposed via SCLP SCCB Facilities byte 139 (bit numbers relative to byte-139) */ DEF_FEAT(SIE_ASTFLEIE2, "astfleie2", SCLP_FAC139, 1, "SIE: ASTFLE interpretation execution facility 2")
target/s390x/cpu_models.c +3 -0
@@ -264,6 +264,7 @@ bool s390_has_feat(S390Feat feat)case S390_FEAT_SIE_PFMFI :case S390_FEAT_SIE_IBS :case S390_FEAT_SIPL : +case S390_FEAT_SCLAF :case S390_FEAT_CONFIGURATION_TOPOLOGY :case S390_FEAT_SIE_ASTFLEIE2 :return false;
@@ -510,6 +511,8 @@ static void check_consistency(const S390CPUModel *model) { S390_FEAT_DIAG_318, S390_FEAT_EXTENDED_LENGTH_SCCB }, { S390_FEAT_CERT_STORE, S390_FEAT_EXTENDED_LENGTH_SCCB }, { S390_FEAT_SIPL, S390_FEAT_EXTENDED_LENGTH_SCCB }, + { S390_FEAT_SCLAF, S390_FEAT_EXTENDED_LENGTH_SCCB }, + { S390_FEAT_SCLAF, S390_FEAT_SIPL }, { S390_FEAT_NNPA, S390_FEAT_VECTOR }, { S390_FEAT_RDP, S390_FEAT_LOCAL_TLB_CLEARING }, { S390_FEAT_UV_FEAT_AP, S390_FEAT_AP },
target/s390x/gen-features.c +2 -0
@@ -723,6 +723,7 @@ static uint16_t full_GEN16_GA1[] = {S390_FEAT_SIE_ASTFLEIE2 ,S390_FEAT_CERT_STORE ,S390_FEAT_SIPL , + S390_FEAT_SCLAF, }; static uint16_t full_GEN17_GA1[] = {
@@ -925,6 +926,7 @@ static uint16_t qemu_MAX[] = {S390_FEAT_EXTENDED_LENGTH_SCCB ,S390_FEAT_CERT_STORE ,S390_FEAT_SIPL , + S390_FEAT_SCLAF, };/****** END FEATURE DEFS ******/
target/s390x/kvm/kvm.c +1 -0
@@ -2504,6 +2504,7 @@ bool kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)/* Some Secure IPL facilities are emulated by QEMU */ set_bit (S390_FEAT_SIPL , model->features); +set_bit (S390_FEAT_SCLAF , model->features);/* Test for Ultravisor features that influence secure guest behavior */ query_uv_feat_guest (model->features);
Signature · 1 line
2.55.0
[PULL 17/37] s390x/ipl: Introduce IPL Information Report Block (IIRB)
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
The IPL information report block (IIRB) contains information used to locate IPL records and to report the results of signature verification of one or more secure components of the load device.
IIRB is stored immediately following the IPL Parameter Block. Results on component verification in any case (failure or success) are stored.
The IIRB data is reserved and protected by the guest kernel during early boot to prevent it from being overwritten before the certificate data is permanently saved.
--- docs/specs/s390x-secure-ipl.rst | 21 +++++++++++ include/hw/s390x/ipl/qipl.h | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+)
docs/specs/s390x-secure-ipl.rst +21 -0
@@ -101,3 +101,24 @@ Subcode 1 - perform signature verification * ``0x0302``: PKCS#7 format signature is invalid * ``0x0402``: signature-verification failed * ``0x0502``: length of Diag508SigVerifBlock is invalid + +IPL Information Report Block +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The IPL Parameter Block (IPLB), utilized for IPL operation, is extended with an +IPL Information Report Block (IIRB), which contains the results from secure IPL +operations such as: + +* component data +* verification results +* certificate data + +During early boot, the guest kernel reserves the memory region +containing the IIRB. This preserves the data while the guest kernel is +operating and during re-IPL. + +The guest kernel uses the contents in the IIRB for: + +* Boot logging: reports which components were loaded and verified. +* kexec operations: builds the next kernel’s IPL report from the existing one. +* Keying: installs IPL certificates into the platform trusted keyring.
include/hw/s390x/ipl/qipl.h +62 -0
72 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 28/37] pc-bios/s390-ccw: Add additional security checks for secure boot
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Add additional checks to ensure that components do not overlap with signed components when loaded into memory.
Add additional checks to ensure the load addresses of unsigned components are greater than or equal to 0x2000.
When the secure IPL code loading attributes facility (SCLAF) is installed, all signed components must contain a secure code loading attributes block (SCLAB).
The SCLAB provides further validation of information on where to load the signed binary code from the load device, and where to start the execution of the loaded OS code.
When SCLAF is installed, its content must be evaluated during secure IPL.
Add IPL Information Error Indicators (IIEI) and Component Error Indicators (CEI) for IPL Information Report Block (IIRB).
When SCLAF is installed, additional secure boot checks are performed during zipl and store results of verification into IIRB.
--- include/hw/s390x/ipl/qipl.h | 29 +++++- pc-bios/s390-ccw/sclp.h | 1 + pc-bios/s390-ccw/secure-ipl.c | 179 +++++++++++++++++++++++++++++++++- pc-bios/s390-ccw/secure-ipl.h | 51 ++++++++++ 4 files changed, 255 insertions(+), 5 deletions(-)
include/hw/s390x/ipl/qipl.h +27 -2
@@ -172,10 +172,20 @@ struct IplInfoReportBlockHeader { };typedef struct IplInfoReportBlockHeader IplInfoReportBlockHeader ; +/* IPL Info Error Indicators */ +#define S390_IIEI_NO_SIGNED_COMP 0x8000/* bit 0 */ +#define S390_IIEI_NO_SCLAB 0x4000/* bit 1 */ +#define S390_IIEI_NO_GLOBAL_SCLAB 0x2000/* bit 2 */ +#define S390_IIEI_MORE_GLOBAL_SCLAB 0x1000/* bit 3 */ +#define S390_IIEI_FOUND_UNSIGNED_COMP 0x800/* bit 4 */ +#define S390_IIEI_MORE_SIGNED_COMP 0x400/* bit 5 */ +struct IplInfoBlockHeader {uint32_t len;uint8_t type; -uint8_t reserved1[11 ]; +uint8_t reserved1[3 ]; +uint16_t iiei; +uint8_t reserved2[6 ]; };typedef struct IplInfoBlockHeader IplInfoBlockHeader ;
@@ -199,13 +209,28 @@ typedef struct IplSignatureCertificateList IplSignatureCertificateList;#define S390_IPL_DEV_COMP_FLAG_SC 0x80#define S390_IPL_DEV_COMP_FLAG_CSV 0x40 +/* IPL Device Component Error Indicators */ +#define S390_CEI_INVALID_SCLAB 0x80000000/* bit 0 */ +#define S390_CEI_INVALID_SCLAB_LEN 0x40000000/* bit 1 */ +#define S390_CEI_INVALID_SCLAB_FORMAT 0x20000000/* bit 2 */ +#define S390_CEI_UNMATCHED_SCLAB_LOAD_ADDR 0x10000000/* bit 3 */ +#define S390_CEI_UNMATCHED_SCLAB_LOAD_PSW 0x8000000/* bit 4 */ +#define S390_CEI_INVALID_LOAD_PSW 0x4000000/* bit 5 */ +#define S390_CEI_NUC_NOT_IN_GLOBAL_SCLAB 0x2000000/* bit 6 */ +#define S390_CEI_SCLAB_OLA_NOT_ONE 0x1000000/* bit 7 */ +#define S390_CEI_SC_NOT_IN_GLOBAL_SCLAB 0x800000/* bit 8 */ +#define S390_CEI_SCLAB_LOAD_ADDR_NOT_ZERO 0x400000/* bit 9 */ +#define S390_CEI_SCLAB_LOAD_PSW_NOT_ZERO 0x200000/* bit 10 */ +#define S390_CEI_INVALID_UNSIGNED_ADDR 0x100000/* bit 11 */ +struct IplDeviceComponentEntry {uint64_t addr;uint64_t len;uint8_t flags;uint8_t reserved1[5 ];uint16_t cert_index; -uint8_t reserved2[8 ]; +uint32_t cei; +uint8_t reserved2[4 ]; };typedef struct IplDeviceComponentEntry IplDeviceComponentEntry ;
pc-bios/s390-ccw/sclp.h +1 -0
@@ -52,6 +52,7 @@ typedef struct SCCBHeader {#define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader))#define SCCB_FAC134_DIAG320_BIT 0x4#define SCCB_FAC_IPL_SIPL_BIT 0x4000 +#define SCCB_FAC_IPL_SCLAF_BIT 0x1000 typedef struct ReadInfo { SCCBHeader h;
pc-bios/s390-ccw/secure-ipl.c +176 -3
215 lines not on this page · raw message
pc-bios/s390-ccw/secure-ipl.h +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 06/37] hw/s390x/ipl: Create certificate store
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Create a certificate store for boot certificates used for secure IPL.
Load certificates from the boot-certs parameter of s390-ccw-virtio machine type option into the cert store.
Currently, only X.509 certificates in PEM format are supported, as the QEMU command line accepts certificates in PEM format only.
The raw Base64 data is stored, as well as the certificate's size. The binary (DER) size is stored as well, which may later be utilized for secure boot (signature verification).
--- docs/specs/index.rst | 1 + docs/specs/s390x-secure-ipl.rst | 20 +++ hw/s390x/cert-store.c | 238 ++++++++++++++++++++++++++++++++ hw/s390x/cert-store.h | 39 ++++++ hw/s390x/ipl.c | 10 ++ hw/s390x/ipl.h | 3 + hw/s390x/meson.build | 1 + include/hw/s390x/ipl/qipl.h | 2 + 8 files changed, 314 insertions(+) create mode 100644 docs/specs/s390x-secure-ipl.rst create mode 100644 hw/s390x/cert-store.c create mode 100644 hw/s390x/cert-store.h
docs/specs/index.rst +1 -0
@@ -41,3 +41,4 @@ guest hardware that is specific to QEMU. riscv-aia aspeed-intc iommu-testdev + s390x-secure-ipl
docs/specs/s390x-secure-ipl.rst new file +20 -0
@@ -0,0 +1,20 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +s390 Certificate Store and Functions +------------------------------------ + +s390 Certificate Store +^^^^^^^^^^^^^^^^^^^^^^ + +A certificate store is implemented for s390-ccw guests to retain within +memory all certificates provided by the user via the command-line, which +are expected to be stored somewhere on the host's file system. The store +will keep track of the number of certificates, their respective size, +and a summation of the sizes. + +Each certificate is stored in an S390IPLCertificate struct, which has a +name (converted to EBCDIC), size fields of PEM and DER data, and the raw +PEM Base64 data. + +Note: A maximum of 64 certificates are allowed to be stored in the certificate +store.
hw/s390x/cert-store.c new file +238 -0
238 lines not on this page · raw message
hw/s390x/cert-store.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* S390 certificate store +* +* Copyright 2025 IBM Corp. +* Author(s): Zhuoying Cai <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_S390_CERT_STORE_H +#define HW_S390_CERT_STORE_H + +#include "hw/s390x/ipl/qipl.h" +#include "crypto/x509-utils.h" + +#define CERT_NAME_MAX_LEN 64 + +#define CERT_KEY_ID_LEN QCRYPTO_HASH_DIGEST_LEN_SHA256 +#define CERT_HASH_LEN QCRYPTO_HASH_DIGEST_LEN_SHA256 + +struct S390IPLCertificate { +uint8_t name[CERT_NAME_MAX_LEN ]; +size_t size; +size_t der_size; +uint8_t *raw; +}; +typedef struct S390IPLCertificate S390IPLCertificate ; + +struct S390IPLCertificateStore { +uint16_t count; +size_t largest_cert_size; +size_t total_bytes; +S390IPLCertificate certs[MAX_CERTIFICATES ]; +}; +typedef struct S390IPLCertificateStore S390IPLCertificateStore ; + +void s390_ipl_create_cert_store (S390IPLCertificateStore *cert_store); + +#endif
hw/s390x/ipl.c +10 -0
@@ -38,6 +38,7 @@#include "qemu/option.h" #include "qemu/ctype.h" #include "standard-headers/linux/virtio_ids.h" +#include "cert-store.h" #define KERN_IMAGE_START 0x010000UL#define LINUX_MAGIC_ADDR 0x010008UL
@@ -454,6 +455,13 @@ void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp) } } +S390IPLCertificateStore *s390_ipl_get_certificate_store (void ) +{ +S390IPLState *ipl =get_ipl_device (); + +return &ipl->cert_store; +} +static bool s390_build_iplb (DeviceState *dev_st,IplParameterBlock *iplb) {CcwDevice *ccw_dev =NULL ;
@@ -768,6 +776,8 @@ void s390_ipl_prepare_cpu(S390CPU *cpu) cpu->env.psw.addr = ipl->start_addr; cpu->env.psw.mask =IPL_PSW_MASK ; +s390_ipl_create_cert_store (&ipl->cert_store); +if (!ipl->kernel || ipl->iplb_valid) { cpu->env.psw.addr = ipl->bios_start_addr;if (!ipl->iplb_valid) {
hw/s390x/ipl.h +3 -0
@@ -13,6 +13,7 @@#ifndef HW_S390_IPL_H #define HW_S390_IPL_H +#include "cert-store.h" #include "target/s390x/cpu.h" #include "exec/target_page.h" #include "system/address-spaces.h"
@@ -35,6 +36,7 @@ int s390_ipl_pv_unpack(struct S390PVResponse *pv_resp);void s390_ipl_prepare_cpu (S390CPU *cpu);IplParameterBlock *s390_ipl_get_iplb (void );IplParameterBlock *s390_ipl_get_iplb_pv (void ); +S390IPLCertificateStore *s390_ipl_get_certificate_store (void );enum s390_reset {/* default is a reset not triggered by a CPU e.g. issued by QMP */
@@ -63,6 +65,7 @@ struct S390IPLState {IplParameterBlock iplb;IplParameterBlock iplb_pv;QemuIplParameters qipl; +S390IPLCertificateStore cert_store;uint64_t start_addr;uint64_t compat_start_addr;uint64_t bios_start_addr;
hw/s390x/meson.build +1 -0
@@ -17,6 +17,7 @@ s390x_ss.add(files( 'sclpcpu.c', 'sclpquiesce.c', 'tod.c', + 'cert-store.c', )) s390x_ss.add(when: 'CONFIG_KVM', if_true: files( 'tod-kvm.c',
include/hw/s390x/ipl/qipl.h +2 -0
@@ -33,6 +33,8 @@ typedef enum S390IplType S390IplType;#define QEMU_DEFAULT_IPL S390_IPL_TYPE_CCW +#define MAX_CERTIFICATES 64 +/* * The QEMU IPL Parameters will be stored at absolute address * 204 (0xcc) which means it is 32-bit word aligned but not
Signature · 1 line
2.55.0
[PULL 16/37] s390x/diag: Implement DIAG 508 subcode 1 for signature verification
In reply to Eric FarmanFrom: Collin Walling <[email protected]>
DIAG 508 subcode 1 performs signature-verification on signed components. A signed component may be a Linux kernel image, or any other signed binary. **Verification of initrd is not supported.**
The instruction call expects two item-pairs: an address of a device component, an address of the analogous signature file (in PKCS#7 DER format), and their respective lengths. All of this data should be encapsulated within a Diag508SigVerifBlock.
The DIAG handler will read from the provided addresses to retrieve the necessary data, parse the signature file, then perform the signature-verification. Because there is no way to correlate a specific certificate to a component, each certificate in the store is tried until either verification succeeds, or all certs have been exhausted.
A return code of 1 indicates success, and the index and length of the corresponding certificate will be set in the Diag508SigVerifBlock. The following values indicate failure:
0x0102: no certificates are available in the store 0x0202: component data is invalid 0x0302: PKCS#7 format signature is invalid 0x0402: signature-verification failed 0x0502: length of Diag508SigVerifBlock is invalid
--- docs/specs/s390x-secure-ipl.rst | 17 +++++ include/hw/s390x/ipl/diag508.h | 30 +++++++++ target/s390x/diag.c | 114 +++++++++++++++++++++++++++++++- 3 files changed, 160 insertions(+), 1 deletion(-)
docs/specs/s390x-secure-ipl.rst +17 -0
@@ -84,3 +84,20 @@ that requires assistance from QEMU. Subcode 0 - query installed subcodes Returns a 64-bit mask indicating which subcodes are supported. + +Subcode 1 - perform signature verification + Perform signature-verification on a signed component, using certificates + from the certificate store and leveraging qcrypto libraries to perform + this operation. + + Note: verification of initrd is not supported. + + A return code of 1 indicates success, and the index and length of the + corresponding certificate will be set in the Diag508SigVerifBlock. + The following values indicate failure: + + * ``0x0102``: no certificates are available in the store + * ``0x0202``: component data is invalid + * ``0x0302``: PKCS#7 format signature is invalid + * ``0x0402``: signature-verification failed + * ``0x0502``: length of Diag508SigVerifBlock is invalid
include/hw/s390x/ipl/diag508.h +30 -0
@@ -11,5 +11,35 @@#define S390X_DIAG508_H #define DIAG_508_SUBC_QUERY_SUBC 0x0000 +#define DIAG_508_SUBC_SIG_VERIF 0x8000 + +#define DIAG_508_RC_OK 0x0001 +#define DIAG_508_RC_NO_CERTS 0x0102 +#define DIAG_508_RC_INVAL_COMP_DATA 0x0202 +#define DIAG_508_RC_INVAL_PKCS7_SIG 0x0302 +#define DIAG_508_RC_FAIL_VERIF 0x0402 +#define DIAG_508_RC_INVAL_LEN 0x0502 + +/* +* Maximum component and signature sizes for current secure boot implementation +* Not architecturally defined and may need to revisit if increased +*/ +#define DIAG_508_MAX_COMP_LEN 0x10000000 +#define DIAG_508_MAX_SIG_LEN 4096 + +struct Diag508SigVerifBlock { +uint32_t length; +uint8_t reserved0[3 ]; +uint8_t version; +uint32_t reserved[2 ]; +uint8_t cert_store_index; +uint8_t reserved1[7 ]; +uint64_t cert_len; +uint64_t comp_len; +uint64_t comp_addr; +uint64_t sig_len; +uint64_t sig_addr; +}; +typedef struct Diag508SigVerifBlock Diag508SigVerifBlock ;#endif
target/s390x/diag.c +113 -1
135 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 35/37] docs/system/s390x: Add secure IPL documentation
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Add documentation for secure IPL
--- docs/system/s390x/secure-ipl.rst | 103 +++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+)
docs/system/s390x/secure-ipl.rst +103 -0
@@ -1,5 +1,22 @@ .. SPDX-License-Identifier: GPL-2.0-or-later +s390 Secure IPL +=============== + +Secure IPL, also known as secure boot, enables s390-ccw virtual machines to +verify the integrity of guest kernels. + +For technical details of this feature, see the +:doc:`specs document </specs/s390x-secure-ipl>`. + +This document explains how to use secure IPL with s390x in QEMU. It covers +the command line options for providing certificates and enabling secure IPL, +the different IPL modes (Normal, Audit, and Secure), and system requirements. + +A quickstart guide is provided to demonstrate how to generate certificates, +sign images, and start a guest in Secure Mode. + + Secure IPL Command Line Options -------------------------------
@@ -79,3 +96,89 @@ Configuration: .. code-block:: shell qemu-system-s390x -machine s390-ccw-virtio,secure-boot=on,boot-certs.0.path=/.../qemu/certs,boot-certs.1.path=/another/path/cert.pem ... + + +Constraints +----------- + +The following constraints apply when attempting to boot an s390x guest in secure +mode: + +- z16 or "qemu" CPU model +- certificates must be in X.509 PEM format +- only support for SCSI scheme of virtio-blk/virtio-scsi devices +- a boot device must be specified +- any unsupported devices (e.g., ECKD and VFIO) or non-eligible devices (e.g., + network) will cause the entire boot process to terminate early, with an error + logged to the console. + + +Secure IPL Quickstart +--------------------- + +Build QEMU with gnutls enabled +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: shell + + ./configure … --enable-gnutls + +Generate certificate (e.g. via certtool) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +A private key is required before generating a certificate. This key must be kept +secure and confidential. + +Use an RSA private key for signing. + +.. code-block:: shell + + certtool --generate-privkey > key.pem + +A self-signed certificate requires the organization name. Use the ``cert.info`` +template to pre-fill values and avoid interactive prompts from certtool. + +.. code-block:: shell + + cat > cert.info <<EOF + cn = "My Name" + expiration_days = 365 + cert_signing_key + EOF + + certtool --generate-self-signed \ + --load-privkey key.pem \ + --template cert.info \ + --hash=SHA256 \ + --outfile cert.pem + +Sign Images (e.g. via sign-file) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- signing must be performed on a guest filesystem +- sign-file script used in the example below is located within the kernel source + repo + +.. code-block:: shell + + ./sign-file sha256 key.pem cert.pem /boot/vmlinuz-… + ./sign-file sha256 key.pem cert.pem /usr/lib/s390-tools/stage3.bin + +Note: re-signing a component will not verify correctly; the existing signature +must be stripped before a new one is applied. + +Run zipl with secure boot enabled +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- zipl must be performed on a guest filesystem + +.. code-block:: shell + + zipl --secure 1 -V + +Command line options for starting the guest +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: shell + + qemu-system-s390x -machine s390-ccw-virtio,secure-boot=on,boot-certs.0.path=cert.pem ...
Signature · 1 line
2.55.0
[PULL 21/37] s390x: Guest support for Secure-IPL Facility
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Introduce Secure-IPL (SIPL) facility.
Use fac_ipl to represent bytes 136 and 137 for IPL device facilities of the SCLP Read SCP Info.
Availability of SIPL facility is determined by byte 136 bit 1 of the SCLP Read SCP Info. Byte 136's facilities cannot be represented without the availability of the extended-length-SCCB, so add it as a check for consistency.
Secure IPL is not available for guests under protected virtualization.
This feature is available starting with the gen16 CPU model.
--- hw/s390x/sclp.c | 2 ++ include/hw/s390x/sclp.h | 6 ++++-- target/s390x/cpu_features.c | 4 ++++ target/s390x/cpu_features.h | 1 + target/s390x/cpu_features_def.h.inc | 3 +++ target/s390x/cpu_models.c | 2 ++ target/s390x/gen-features.c | 2 ++ target/s390x/kvm/kvm.c | 3 +++ 8 files changed, 21 insertions(+), 2 deletions(-)
hw/s390x/sclp.c +2 -0
@@ -146,6 +146,8 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)if (s390_has_feat (S390_FEAT_EXTENDED_LENGTH_SCCB )) {s390_get_feat_block (S390_FEAT_TYPE_SCLP_FAC134 , &read_info->fac134); +s390_get_feat_block (S390_FEAT_TYPE_SCLP_FAC_IPL , + read_info->fac_ipl);s390_get_feat_block (S390_FEAT_TYPE_SCLP_FAC139 , &read_info->fac139); }
include/hw/s390x/sclp.h +4 -2
@@ -136,9 +136,11 @@ typedef struct ReadInfo {uint32_t hmfai;uint8_t _reserved7[134 -128 ];/* 128-133 */ uint8_t fac134; -uint8_t _reserved8[139 -135 ];/* 135-138 */ +uint8_t _reserved8; +uint8_t fac_ipl[2 ];/* 136-137 */ +uint8_t _reserved9;uint8_t fac139; -uint8_t _reserved9[144 -140 ];/* 140-143 */ +uint8_t _reserved10[144 -140 ];/* 140-143 */ struct CPUEntry entries[];/* * When the Extended-Length SCCB (ELS) feature is enabled the
target/s390x/cpu_features.c +4 -0
@@ -119,6 +119,7 @@ void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,* Some facilities are not available for CPUs in protected mode: * - All SIE facilities because SIE is not available * - DIAG318 +* - Secure IPL Facility * * As VMs can move in and out of protected mode the CPU model * doesn't protect us from that problem because it is only
@@ -149,6 +150,9 @@ void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,clear_be_bit (s390_feat_def (S390_FEAT_DIAG_318 )->bit, data);clear_be_bit (s390_feat_def (S390_FEAT_CERT_STORE )->bit, data);break ; +case S390_FEAT_TYPE_SCLP_FAC_IPL : +clear_be_bit (s390_feat_def (S390_FEAT_SIPL )->bit, data); +break ;case S390_FEAT_TYPE_SCLP_FAC139 :clear_be_bit (s390_feat_def (S390_FEAT_SIE_ASTFLEIE2 )->bit, data);break ;
target/s390x/cpu_features.h +1 -0
@@ -24,6 +24,7 @@ typedef enum {S390_FEAT_TYPE_SCLP_CONF_CHAR ,S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT ,S390_FEAT_TYPE_SCLP_FAC134 , +S390_FEAT_TYPE_SCLP_FAC_IPL ,S390_FEAT_TYPE_SCLP_FAC139 ,S390_FEAT_TYPE_SCLP_CPU , S390_FEAT_TYPE_MISC,
target/s390x/cpu_features_def.h.inc +3 -0
@@ -140,6 +140,9 @@ DEF_FEAT(SIE_IBS, "ibs", SCLP_CONF_CHAR_EXT, 10, "SIE: Interlock-and-broadcast-s DEF_FEAT(DIAG_318, "diag318", SCLP_FAC134, 0, "Control program name and version codes") DEF_FEAT(CERT_STORE, "cstore", SCLP_FAC134, 5, "Certificate Store functions") +/* Features exposed via SCLP SCCB Facilities byte 136 - 137 (bit numbers relative to byte-136) */ +DEF_FEAT(SIPL, "sipl", SCLP_FAC_IPL, 1, "Secure-IPL facility") + /* Features exposed via SCLP SCCB Facilities byte 139 (bit numbers relative to byte-139) */ DEF_FEAT(SIE_ASTFLEIE2, "astfleie2", SCLP_FAC139, 1, "SIE: ASTFLE interpretation execution facility 2")
target/s390x/cpu_models.c +2 -0
@@ -263,6 +263,7 @@ bool s390_has_feat(S390Feat feat)case S390_FEAT_SIE_CMMA :case S390_FEAT_SIE_PFMFI :case S390_FEAT_SIE_IBS : +case S390_FEAT_SIPL :case S390_FEAT_CONFIGURATION_TOPOLOGY :case S390_FEAT_SIE_ASTFLEIE2 :return false;
@@ -508,6 +509,7 @@ static void check_consistency(const S390CPUModel *model) { S390_FEAT_AP_QUEUE_INTERRUPT_CONTROL, S390_FEAT_AP }, { S390_FEAT_DIAG_318, S390_FEAT_EXTENDED_LENGTH_SCCB }, { S390_FEAT_CERT_STORE, S390_FEAT_EXTENDED_LENGTH_SCCB }, + { S390_FEAT_SIPL, S390_FEAT_EXTENDED_LENGTH_SCCB }, { S390_FEAT_NNPA, S390_FEAT_VECTOR }, { S390_FEAT_RDP, S390_FEAT_LOCAL_TLB_CLEARING }, { S390_FEAT_UV_FEAT_AP, S390_FEAT_AP },
target/s390x/gen-features.c +2 -0
@@ -722,6 +722,7 @@ static uint16_t full_GEN16_GA1[] = {S390_FEAT_UV_FEAT_AP_INTR ,S390_FEAT_SIE_ASTFLEIE2 ,S390_FEAT_CERT_STORE , + S390_FEAT_SIPL, }; static uint16_t full_GEN17_GA1[] = {
@@ -923,6 +924,7 @@ static uint16_t qemu_MAX[] = {S390_FEAT_PRNO_TRNG ,S390_FEAT_EXTENDED_LENGTH_SCCB ,S390_FEAT_CERT_STORE , + S390_FEAT_SIPL, };/****** END FEATURE DEFS ******/
target/s390x/kvm/kvm.c +3 -0
@@ -2502,6 +2502,9 @@ bool kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)set_bit (S390_FEAT_CERT_STORE , model->features); +/* Some Secure IPL facilities are emulated by QEMU */ +set_bit (S390_FEAT_SIPL , model->features); +/* Test for Ultravisor features that influence secure guest behavior */ query_uv_feat_guest (model->features);
Signature · 1 line
2.55.0
[PULL 32/37] hw/s390x/ipl: Handle secure boot with multiple boot devices
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
The current approach to enable secure boot relies on providing secure-boot and boot-certs parameters of s390-ccw-virtio machine type option, which apply to all boot devices.
With the possibility of multiple boot devices, secure boot expects all provided devices to be supported and eligible (e.g., virtio-blk/virtio-scsi using the SCSI scheme).
If multiple boot devices are provided and include an unsupported (e.g., ECKD, VFIO) or a non-eligible (e.g., Net) device, the boot process will terminate with an error logged to the console.
--- hw/s390x/ipl.c | 40 ++++++++++++++++++++++++++++++++++++++-- pc-bios/s390-ccw/main.c | 3 --- 2 files changed, 38 insertions(+), 5 deletions(-)
hw/s390x/ipl.c +38 -2
@@ -504,6 +504,37 @@ static void s390_set_secure_boot_flags(IplParameterBlock *iplb, iplb->len =cpu_to_be32 (S390_IPLB_MAX_LEN ); } +static bool s390_validate_secure_boot_device (int devtype,Error **errp) +{ +switch (devtype) { +case CCW_DEVTYPE_VFIO : +error_setg (errp,"Passthrough (vfio) CCW device does not support secure boot!" ); +return false; +case CCW_DEVTYPE_VIRTIO_NET : +error_setg (errp,"Virtio net boot device does not support secure boot!" ); +return false; +default : +return true; + } +} + +static void s390_apply_secure_boot (IplParameterBlock *iplb,int devtype, +bool secure_boot,bool audit_mode) +{ +Error *local_error =NULL ; + +if (!secure_boot && !audit_mode) { +return ; + } + +if (!s390_validate_secure_boot_device (devtype, &local_error)) { +error_report_err (local_error); +exit (1 ); + } + +s390_set_secure_boot_flags (iplb, secure_boot, audit_mode); +} +static bool s390_build_iplb (DeviceState *dev_st,IplParameterBlock *iplb) {CcwDevice *ccw_dev =NULL ;
@@ -560,14 +591,19 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)s390_ipl_convert_loadparm ((char *)lp, iplb->loadparm); iplb->flags |=DIAG308_FLAGS_LP_VALID ; -s390_set_secure_boot_flags (iplb,s390_secure_boot_enabled (), -s390_has_certificate ()); +s390_apply_secure_boot (iplb, devtype,s390_secure_boot_enabled (), +s390_has_certificate ());return true; } pbdev =s390_get_pci_device (dev_st, &devtype);if (pbdev) { +if (s390_secure_boot_enabled () ||s390_has_certificate ()) { +error_report ("Virtio pci boot device does not support secure boot!" ); +exit (1 ); + } + pci_lp =object_property_get_str (OBJECT (pbdev->pdev),"loadparm" ,NULL );if (pci_lp &&strlen (pci_lp) >0 ) { lp = pci_lp;
pc-bios/s390-ccw/main.c +0 -3
@@ -308,9 +308,6 @@ static void ipl_ccw_device(void)switch (cutype) {case CU_TYPE_DASD_3990 :case CU_TYPE_DASD_2107 : -IPL_assert ((boot_mode ==ZIPL_BOOT_MODE_NORMAL ), -"Passthrough (vfio) CCW device does not support secure boot!" ); -dasd_ipl (blk_schid, cutype);break ;case CU_TYPE_VIRTIO :
Signature · 1 line
2.55.0
[PULL 10/37] crypto/x509-utils: Add helper functions for DIAG 320 subcode 2
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Introduce new helper functions to extract certificate metadata:
qcrypto_x509_check_cert_times() - validates the certificate's validity period against the current time qcrypto_x509_get_cert_key_id() - extracts the key ID from the certificate qcrypto_x509_check_ecc_curve_p521() - determines the ECC public key algorithm uses P-521 curve
These functions provide support for metadata extraction and validity checking for X.509 certificates.
--- crypto/x509-utils.c | 236 ++++++++++++++++++++++++++++++++++++ include/crypto/x509-utils.h | 51 ++++++++ 2 files changed, 287 insertions(+)
crypto/x509-utils.c +236 -0
@@ -27,6 +27,16 @@ static const int qcrypto_to_gnutls_hash_alg_map[QCRYPTO_HASH_ALGO__MAX] = { [QCRYPTO_HASH_ALGO_RIPEMD160] = GNUTLS_DIG_RMD160, }; +static const int qcrypto_to_gnutls_keyid_flags_map[] = { + [QCRYPTO_HASH_ALGO_MD5 ] =-1 , + [QCRYPTO_HASH_ALGO_SHA1 ] =GNUTLS_KEYID_USE_SHA1 , + [QCRYPTO_HASH_ALGO_SHA224 ] =-1 , + [QCRYPTO_HASH_ALGO_SHA256 ] =GNUTLS_KEYID_USE_SHA256 , + [QCRYPTO_HASH_ALGO_SHA384 ] =-1 , + [QCRYPTO_HASH_ALGO_SHA512 ] =GNUTLS_KEYID_USE_SHA512 , + [QCRYPTO_HASH_ALGO_RIPEMD160 ] =-1 , +}; + int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size, QCryptoHashAlgo alg, uint8_t *result,
@@ -122,6 +132,210 @@ cleanup:return ret; } +int qcrypto_x509_check_cert_times (uint8_t *cert,size_t size,Error **errp) +{ +int rc; +int ret =-1 ; +gnutls_x509_crt_t crt; +gnutls_datum_t datum = {.data = cert, .size = size}; +time_t now =time (NULL ); +time_t exp_time; +time_t act_time; + +if (now == ((time_t)-1 )) { +error_setg_errno (errp, errno,"Cannot get current time" ); +return ret; + } + + rc =gnutls_x509_crt_init (&crt); +if (rc <0 ) { +error_setg (errp,"Failed to initialize certificate: %s" ,gnutls_strerror (rc)); +return ret; + } + + rc =gnutls_x509_crt_import (crt, &datum,GNUTLS_X509_FMT_PEM ); +if (rc !=0 ) { +error_setg (errp,"Failed to import certificate: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + exp_time =gnutls_x509_crt_get_expiration_time (crt); +if (exp_time == ((time_t)-1 )) { +error_setg (errp,"Failed to get certificate expiration time" ); + goto cleanup; + } +if (exp_time < now) { +error_setg (errp,"The certificate has expired" ); + goto cleanup; + } + + act_time =gnutls_x509_crt_get_activation_time (crt); +if (act_time == ((time_t)-1 )) { +error_setg (errp,"Failed to get certificate activation time" ); + goto cleanup; + } +if (act_time > now) { +error_setg (errp,"The certificate is not yet active" ); + goto cleanup; + } + + ret =0 ; + +cleanup: +gnutls_x509_crt_deinit (crt); +return ret; +} + +static int qcrypto_x509_get_pk_algorithm (uint8_t *cert,size_t size,Error **errp) +{ +int rc; +int ret =-1 ; +unsigned int bits; +gnutls_x509_crt_t crt; +gnutls_datum_t datum = {.data = cert, .size = size}; + + rc =gnutls_x509_crt_init (&crt); +if (rc <0 ) { +error_setg (errp,"Failed to initialize certificate: %s" ,gnutls_strerror (rc)); +return ret; + } + + rc =gnutls_x509_crt_import (crt, &datum,GNUTLS_X509_FMT_PEM ); +if (rc !=0 ) { +error_setg (errp,"Failed to import certificate: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + rc =gnutls_x509_crt_get_pk_algorithm (crt, &bits); +if (rc <0 ) { +error_setg (errp,"Unknown public key algorithm %d" , rc); + goto cleanup; + } + + ret = rc; + +cleanup: +gnutls_x509_crt_deinit (crt); +return ret; +} + +int qcrypto_x509_get_cert_key_id (uint8_t *cert,size_t size, +QCryptoHashAlgo hash_alg, +uint8_t **result, +size_t *resultlen, +Error **errp) +{ +int rc; +int ret =-1 ; +gnutls_x509_crt_t crt; +gnutls_datum_t datum = {.data = cert, .size = size}; + +if (hash_alg >=G_N_ELEMENTS (qcrypto_to_gnutls_hash_alg_map)) { +error_setg (errp,"Unknown hash algorithm %d" , hash_alg); +return ret; + } + +if (hash_alg >=G_N_ELEMENTS (qcrypto_to_gnutls_keyid_flags_map) || + qcrypto_to_gnutls_keyid_flags_map[hash_alg] ==-1 ) { +error_setg (errp,"Unsupported key id flag %d" , hash_alg); +return ret; + } + + rc =gnutls_x509_crt_init (&crt); +if (rc <0 ) { +error_setg (errp,"Failed to initialize certificate: %s" ,gnutls_strerror (rc)); +return ret; + } + + rc =gnutls_x509_crt_import (crt, &datum,GNUTLS_X509_FMT_PEM ); +if (rc !=0 ) { +error_setg (errp,"Failed to import certificate: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + *resultlen =gnutls_hash_get_len (qcrypto_to_gnutls_hash_alg_map[hash_alg]); +if (*resultlen ==0 ) { +error_setg (errp,"Failed to get hash algorithm length: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + *result =g_malloc0 (*resultlen); +if (gnutls_x509_crt_get_key_id (crt, + qcrypto_to_gnutls_keyid_flags_map[hash_alg], + *result, resultlen) !=0 ) { +error_setg (errp,"Failed to get key ID from certificate" ); +g_clear_pointer (result, g_free); + goto cleanup; + } + + ret =0 ; + +cleanup: +gnutls_x509_crt_deinit (crt); +return ret; +} + +static int qcrypto_x509_get_ecc_curve (uint8_t *cert,size_t size,Error **errp) +{ +int rc; +int ret =-1 ; +gnutls_x509_crt_t crt; +gnutls_datum_t datum = {.data = cert, .size = size}; +gnutls_ecc_curve_t curve_id; +gnutls_datum_t x = {.data =NULL , .size =0 }; +gnutls_datum_t y = {.data =NULL , .size =0 }; + + rc =gnutls_x509_crt_init (&crt); +if (rc <0 ) { +error_setg (errp,"Failed to initialize certificate: %s" ,gnutls_strerror (rc)); +return ret; + } + + rc =gnutls_x509_crt_import (crt, &datum,GNUTLS_X509_FMT_PEM ); +if (rc !=0 ) { +error_setg (errp,"Failed to import certificate: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + rc =gnutls_x509_crt_get_pk_ecc_raw (crt, &curve_id, &x, &y); +if (rc !=0 ) { +error_setg (errp,"Failed to get ECC public key curve: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + ret = curve_id; + +cleanup: +gnutls_x509_crt_deinit (crt); +g_free (x.data); +g_free (y.data); +return ret; +} + +int qcrypto_x509_check_ecc_curve_p521 (uint8_t *cert,size_t size,Error **errp) +{ +int algo; +int curve_id; + + algo =qcrypto_x509_get_pk_algorithm (cert, size, errp); +if (algo !=GNUTLS_PK_ECDSA ) { +return 0 ; + } + + curve_id =qcrypto_x509_get_ecc_curve (cert, size, errp); +if (curve_id ==-1 ) { +error_setg (errp,"Failed to get ECC curve" ); +return -1 ; + } + +if (curve_id ==GNUTLS_ECC_CURVE_INVALID ) { +error_setg (errp,"Invalid ECC curve" ); +return -1 ; + } + +return curve_id ==GNUTLS_ECC_CURVE_SECP521R1 ; +} +#else /* ! CONFIG_GNUTLS */ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,
@@ -143,4 +357,26 @@ int qcrypto_x509_convert_cert_der(uint8_t *cert, size_t size, return -1; } +int qcrypto_x509_check_cert_times (uint8_t *cert,size_t size,Error **errp) +{ +error_setg (errp,"GNUTLS is required to get certificate times" ); +return -1 ; +} + +int qcrypto_x509_get_cert_key_id (uint8_t *cert,size_t size, +QCryptoHashAlgo hash_alg, +uint8_t **result, +size_t *resultlen, +Error **errp) +{ +error_setg (errp,"GNUTLS is required to get key ID" ); +return -1 ; +} + +int qcrypto_x509_check_ecc_curve_p521 (uint8_t *cert,size_t size,Error **errp) +{ +error_setg (errp,"GNUTLS is required to determine ecc curve" ); +return -1 ; +} +#endif /* ! CONFIG_GNUTLS */
include/crypto/x509-utils.h +51 -0
55 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 18/37] pc-bios/s390-ccw: Define memory for IPLB and convert IPLB to pointers
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Define a memory space for both IPL Parameter Block (IPLB) and IPL Information Report Block (IIRB) since IIRB is stored immediately following IPLB.
Convert IPLB to pointer and it points to the start of the defined memory space. IIRB points to the end of IPLB.
--- include/hw/s390x/ipl/qipl.h | 6 ++++++ pc-bios/s390-ccw/iplb.h | 5 +++-- pc-bios/s390-ccw/jump2ipl.c | 6 +++--- pc-bios/s390-ccw/main.c | 34 +++++++++++++++++++--------------- pc-bios/s390-ccw/netmain.c | 8 ++++---- 5 files changed, 35 insertions(+), 24 deletions(-)
include/hw/s390x/ipl/qipl.h +6 -0
@@ -210,4 +210,10 @@ struct IplInfoReportBlock { };typedef struct IplInfoReportBlock IplInfoReportBlock ; +struct IplBlocks { +IplParameterBlock iplb; +IplInfoReportBlock iirb; +}; +typedef struct IplBlocks IplBlocks ; +#endif
pc-bios/s390-ccw/iplb.h +3 -2
@@ -20,8 +20,9 @@#include <string.h> extern QemuIplParameters qipl; -extern IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE))); +extern IplParameterBlock *iplb;extern bool have_iplb; +extern IplBlocks ipl_blocks;static inline bool manage_iplb (IplParameterBlock *iplb,bool store) {
@@ -61,7 +62,7 @@ static inline bool load_next_iplb(void) qipl.index++; next_iplb = (IplParameterBlock *) qipl.next_iplb; -memcpy (&iplb, next_iplb,sizeof (IplParameterBlock)); +memcpy (iplb, next_iplb,sizeof (IplParameterBlock)); qipl.chain_len--; qipl.next_iplb = qipl.next_iplb +sizeof (IplParameterBlock);
pc-bios/s390-ccw/jump2ipl.c +3 -3
@@ -43,11 +43,11 @@ int jump_to_IPL_code(uint64_t address)* The IPLB for QEMU SCSI type devices must be rebuilt during re-ipl. The * iplb.devno is set to the boot position of the target SCSI device. */ -if (iplb.pbt ==S390_IPL_TYPE_QEMU_SCSI ) { - iplb.devno = qipl.index; +if (iplb->pbt ==S390_IPL_TYPE_QEMU_SCSI ) { + iplb->devno = qipl.index; } -if (have_iplb && !set_iplb (&iplb)) { +if (have_iplb && !set_iplb (iplb)) {panic ("Failed to set IPLB" ); }
pc-bios/s390-ccw/main.c +19 -15
@@ -24,7 +24,9 @@static SubChannelId blk_schid = { .one =1 };static char loadparm_str[LOADPARM_LEN +1 ];QemuIplParameters qipl; -IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE))); +/* Ensure that IPLB and IIRB are page aligned and sequential in memory */ +IplBlocks ipl_blocks __attribute__((__aligned__(PAGE_SIZE))); +IplParameterBlock *iplb;bool have_iplb;static uint16_t cutype;LowCore *lowcore;/* Yes, this *is* a pointer to address 0 */
@@ -54,7 +56,7 @@ void write_iplb_location(void) {if (virtio_is_supported (virtio_get_device ()) &&virtio_get_device_type () !=VIRTIO_ID_NET ) { - lowcore->ptr_iplb =ptr2u32 (&iplb); + lowcore->ptr_iplb =ptr2u32 (iplb); } }
@@ -216,14 +218,14 @@ static void boot_setup(void)char lpmsg[] ="LOADPARM=[________]\n" ;VDev *vdev =virtio_get_device (); -if (have_iplb &&memcmp (iplb.loadparm,NO_LOADPARM ,LOADPARM_LEN ) !=0 ) { -ebcdic_to_ascii ((char *) iplb.loadparm, loadparm_str,LOADPARM_LEN ); +if (have_iplb &&memcmp (iplb->loadparm,NO_LOADPARM ,LOADPARM_LEN ) !=0 ) { +ebcdic_to_ascii ((char *) iplb->loadparm, loadparm_str,LOADPARM_LEN ); }else {sclp_get_loadparm_ascii (loadparm_str); }if (have_iplb) { - vdev->ipl_type = iplb.pbt; + vdev->ipl_type = iplb->pbt;menu_setup (vdev); }else { vdev->ipl_type =QEMU_DEFAULT_IPL ;
@@ -247,21 +249,21 @@ static bool find_boot_device(void)switch (vdev->ipl_type) {case S390_IPL_TYPE_CCW : vdev->scsi_device_selected = false; -debug_print_int ("device no. " , iplb.ccw.devno); - blk_schid.ssid = iplb.ccw.ssid &0x3 ; +debug_print_int ("device no. " , iplb->ccw.devno); + blk_schid.ssid = iplb->ccw.ssid &0x3 ;debug_print_int ("ssid " , blk_schid.ssid); - found =find_subch (iplb.ccw.devno); + found =find_subch (iplb->ccw.devno);break ;case S390_IPL_TYPE_QEMU_SCSI : vdev->scsi_device_selected = true; - vdev->selected_scsi_device.channel = iplb.scsi.channel; - vdev->selected_scsi_device.target = iplb.scsi.target; - vdev->selected_scsi_device.lun = iplb.scsi.lun; - blk_schid.ssid = iplb.scsi.ssid &0x3 ; - found =find_subch (iplb.scsi.devno); + vdev->selected_scsi_device.channel = iplb->scsi.channel; + vdev->selected_scsi_device.target = iplb->scsi.target; + vdev->selected_scsi_device.lun = iplb->scsi.lun; + blk_schid.ssid = iplb->scsi.ssid &0x3 ; + found =find_subch (iplb->scsi.devno);break ;case S390_IPL_TYPE_PCI : - found =find_fid (iplb.pci.fid); + found =find_fid (iplb->pci.fid);break ;default :puts ("Unsupported IPLB" );
@@ -380,10 +382,12 @@ static void probe_boot_device(void)void main (void ) { + iplb = &ipl_blocks.iplb; +copy_qipl ();sclp_setup ();css_setup (); - have_iplb =store_iplb (&iplb); + have_iplb =store_iplb (iplb);if (!have_iplb) {boot_setup ();probe_boot_device ();
pc-bios/s390-ccw/netmain.c +4 -4
@@ -531,11 +531,11 @@ static bool virtio_setup(void)*/ enable_mss_facility (); -if (have_iplb ||store_iplb (&iplb)) { -IPL_assert (iplb.pbt ==S390_IPL_TYPE_CCW ,"IPL_TYPE_CCW expected" ); - dev_no = iplb.ccw.devno; +if (have_iplb ||store_iplb (iplb)) { +IPL_assert (iplb->pbt ==S390_IPL_TYPE_CCW ,"IPL_TYPE_CCW expected" ); + dev_no = iplb->ccw.devno;debug_print_int ("device no. " , dev_no); - net_schid.ssid = iplb.ccw.ssid &0x3 ; + net_schid.ssid = iplb->ccw.ssid &0x3 ;debug_print_int ("ssid " , net_schid.ssid); found =find_net_dev (&schib, dev_no); }else {
Signature · 1 line
2.55.0
[PULL 30/37] hw/s390x/ipl: Set IPIB flags for secure IPL
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
If -M secure-boot=on is specified on the command line option, indicating true secure IPL enabled, set Secure-IPL bit and IPL-Information-Report bit on in IPIB Flags field, and trigger true secure IPL in the S390 BIOS.
Any error that occurs during true secure IPL will cause the IPL to terminate.
--- hw/s390x/ipl.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-)
hw/s390x/ipl.c +23 -5
@@ -468,15 +468,30 @@ static bool s390_has_certificate(void)return ipl->cert_store.count >0 ; } +static bool s390_secure_boot_enabled (void ) +{ +return S390_CCW_MACHINE (qdev_get_machine ())->secure_boot; +} +static void s390_set_secure_boot_flags (IplParameterBlock *iplb, -bool audit_mode) +bool secure_boot,bool audit_mode) { -if (!audit_mode) { +if (!secure_boot && !audit_mode) {return ; }/* -* For audit mode, enable the IPL Information +* If secure-boot is enabled, then toggle the secure IPL flags (SIPL) to +* trigger secure boot in the s390 BIOS. +* +* Boot process will terminate if any error occurs during secure boot. +*/ +if (secure_boot) { + iplb->hdr_flags |=DIAG308_IPIB_FLAGS_SIPL ; + } + +/* +* For both secure boot and audit mode, enable the IPL Information * Report (IPLIR) flag so that the firmware generates an IPL * Information Report Block (IIRB). *
@@ -545,7 +560,8 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)s390_ipl_convert_loadparm ((char *)lp, iplb->loadparm); iplb->flags |=DIAG308_FLAGS_LP_VALID ; -s390_set_secure_boot_flags (iplb,s390_has_certificate ()); +s390_set_secure_boot_flags (iplb,s390_secure_boot_enabled (), +s390_has_certificate ());return true; }
@@ -699,7 +715,9 @@ void s390_ipl_update_diag308(IplParameterBlock *iplb)* The kernel does not preserve secure boot flags across a reboot. * Re-apply them here based on the current machine configuration. */ -s390_set_secure_boot_flags (&ipl->iplb,s390_has_certificate ()); +s390_set_secure_boot_flags (&ipl->iplb, +s390_secure_boot_enabled (), +s390_has_certificate ()); }update_machine_ipl_properties (iplb);
Signature · 1 line
2.55.0
[PULL 15/37] s390x/diag: Generalize s390_ipl_read/write to accept void *
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Change the data parameter of s390_ipl_read() and s390_ipl_write() from IplParameterBlock * to void *, so the helpers can be reused beyond DIAG 308.
--- target/s390x/diag.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
target/s390x/diag.c +6 -6
@@ -83,24 +83,24 @@ static int diag308_parm_check(CPUS390XState *env, uint64_t r1, uint64_t addr, }static void s390_ipl_read (CPUS390XState *env,uint64_t addr, -IplParameterBlock *iplb,size_t size) +void *data,size_t size) {if (s390_is_pv ()) { -s390_cpu_pv_mem_read (env_archcpu (env),0 , iplb, size); +s390_cpu_pv_mem_read (env_archcpu (env),0 , data, size); }else {address_space_read (cpu_get_address_space (env_cpu (env),0 ), addr, -MEMTXATTRS_UNSPECIFIED , iplb, size); +MEMTXATTRS_UNSPECIFIED , data, size); } }static void s390_ipl_write (CPUS390XState *env,uint64_t addr, -IplParameterBlock *iplb,size_t size) +void *data,size_t size) {if (s390_is_pv ()) { -s390_cpu_pv_mem_write (env_archcpu (env),0 , iplb, size); +s390_cpu_pv_mem_write (env_archcpu (env),0 , data, size); }else {address_space_write (cpu_get_address_space (env_cpu (env),0 ), addr, -MEMTXATTRS_UNSPECIFIED , iplb, size); +MEMTXATTRS_UNSPECIFIED , data, size); } }
Signature · 1 line
2.55.0
[PULL 31/37] pc-bios/s390-ccw: Handle true secure IPL mode
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
When secure boot is enabled (-secure-boot on) and certificate(s) are provided, the boot operates in True Secure IPL mode.
Any verification error during True Secure IPL mode will cause the entire boot process to terminate.
Secure IPL in audit mode requires at least one certificate provided in the key store along with necessary facilities. If secure boot is enabled but no certificate is provided, the boot process will also terminate, as this is not a valid secure boot configuration.
Note: True Secure IPL mode is implemented for the SCSI scheme of virtio-blk/virtio-scsi devices.
--- docs/system/s390x/secure-ipl.rst | 13 +++++++++++++ hw/s390x/ipl.c | 3 ++- pc-bios/s390-ccw/bootmap.c | 6 +++++- pc-bios/s390-ccw/main.c | 7 ++++++- pc-bios/s390-ccw/s390-ccw.h | 1 + pc-bios/s390-ccw/secure-ipl.h | 3 +++ 6 files changed, 30 insertions(+), 3 deletions(-)
docs/system/s390x/secure-ipl.rst +13 -0
@@ -66,3 +66,16 @@ Configuration: .. code-block:: shell qemu-system-s390x -machine s390-ccw-virtio,boot-certs.0.path=/.../qemu/certs,boot-certs.1.path=/another/path/cert.pem ... + +Secure Mode +^^^^^^^^^^^ + +When the ``secure-boot=on`` option is set and certificates are provided, +a secure boot is performed with error reporting enabled. The boot process aborts +if any error occurs. + +Configuration: + +.. code-block:: shell + + qemu-system-s390x -machine s390-ccw-virtio,secure-boot=on,boot-certs.0.path=/.../qemu/certs,boot-certs.1.path=/another/path/cert.pem ...
hw/s390x/ipl.c +2 -1
@@ -851,7 +851,8 @@ void s390_ipl_prepare_cpu(S390CPU *cpu)* Secure IPL without specifying a boot device. * IPLB is not generated if no boot device is defined. */ -if (s390_has_certificate () && !ipl->iplb_valid) { +if ((s390_has_certificate () ||s390_secure_boot_enabled ()) && + !ipl->iplb_valid) {error_report ("No boot device defined for Secure IPL" );exit (1 ); }
pc-bios/s390-ccw/bootmap.c +5 -1
@@ -743,6 +743,7 @@ static int zipl_run(ScsiBlockPtr *pte)case ZIPL_BOOT_MODE_NORMAL : rc =zipl_run_normal (&entry, tmp_sec);break ; +case ZIPL_BOOT_MODE_SECURE :case ZIPL_BOOT_MODE_SECURE_AUDIT : rc =zipl_run_secure (&entry, tmp_sec, &comp_list, &cert_list, &tmp_cert_buf);break ;
@@ -762,7 +763,8 @@ static int zipl_run(ScsiBlockPtr *pte)write_reset_psw (entry->compdat.load_psw); -if (boot_mode ==ZIPL_BOOT_MODE_SECURE_AUDIT ) { +if (boot_mode ==ZIPL_BOOT_MODE_SECURE || + boot_mode ==ZIPL_BOOT_MODE_SECURE_AUDIT ) {update_cert_list (&cert_list);update_iirb (&comp_list, &cert_list);free (tmp_cert_buf);
@@ -1130,6 +1132,8 @@ ZiplBootMode get_boot_mode(uint8_t hdr_flags)if (!sipl_set && iplir_set) {return ZIPL_BOOT_MODE_SECURE_AUDIT ; + }else if (sipl_set && iplir_set) { +return ZIPL_BOOT_MODE_SECURE ; }return ZIPL_BOOT_MODE_NORMAL ;
pc-bios/s390-ccw/main.c +6 -1
@@ -402,15 +402,20 @@ void main(void) boot_mode =get_boot_mode (iplb->hdr_flags);switch (boot_mode) { +case ZIPL_BOOT_MODE_SECURE :case ZIPL_BOOT_MODE_SECURE_AUDIT :if (!secure_ipl_supported ()) { -panic ("Unable to boot in audit mode" ); +panic ("Unable to boot in secure/audit mode" ); } vcssb_len =zipl_secure_get_vcssb ();if (vcssb_len ==0 ) {panic ("Failed to query certificate storage information!" ); } + +if (vcssb_len ==VCSSB_NO_VC ) { +panic ("Need at least one certificate for secure boot!" ); + }break ;default :break ;
pc-bios/s390-ccw/s390-ccw.h +1 -0
@@ -90,6 +90,7 @@ void zipl_load(void);typedef enum ZiplBootMode {ZIPL_BOOT_MODE_NORMAL =0 ,ZIPL_BOOT_MODE_SECURE_AUDIT =1 , +ZIPL_BOOT_MODE_SECURE =2 , }ZiplBootMode ;extern ZiplBootMode boot_mode;
pc-bios/s390-ccw/secure-ipl.h +3 -0
@@ -59,6 +59,9 @@ static inline void zipl_secure_error(const char *message)case ZIPL_BOOT_MODE_SECURE_AUDIT :printf ("AUDIT MODE WARNING: %s\n" , message);break ; +case ZIPL_BOOT_MODE_SECURE : +panic (message); +break ;default :/* * Errors are intentionally ignored in non-secure boot modes.
Signature · 1 line
2.55.0
[PULL 36/37] MAINTAINERS: Add secure IPL files to S390-ccw boot group
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Add entries for the files introduced by the secure IPL series (cert-store, diag headers, documentation, and functional test) to the S390-ccw boot maintainer group.
--- MAINTAINERS | 5 +++++ 1 file changed, 5 insertions(+)
MAINTAINERS +5 -0
@@ -1970,10 +1970,15 @@ R: Christian Borntraeger <[email protected]> R: Jason Herne <[email protected]> S: Supported F: hw/s390x/ipl.* +F: hw/s390x/cert-store.[ch] +F: include/hw/s390x/ipl/ F: pc-bios/s390-ccw/ F: pc-bios/s390-ccw.img F: docs/devel/s390-dasd-ipl.rst +F: docs/specs/s390x-secure-ipl.rst +F: docs/system/s390x/secure-ipl.rst F: tests/functional/s390x/test_pxelinux.py +F: tests/functional/s390x/test_secure_ipl.py L: [email protected] S390 PCI
Signature · 1 line
2.55.0
[PULL 29/37] Add secure-boot to s390-ccw-virtio machine type option
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Add secure-boot as a parameter of s390-ccw-virtio machine type option.
The secure-boot=on|off parameter is implemented to enable secure IPL.
By default, secure-boot is set to false if not specified in the command line.
--- docs/system/s390x/secure-ipl.rst | 22 +++++++++++++++++----- hw/s390x/s390-virtio-ccw.c | 29 +++++++++++++++++++++++++++++ include/hw/s390x/s390-virtio-ccw.h | 2 ++ qemu-options.hx | 6 +++++- 4 files changed, 53 insertions(+), 6 deletions(-)
docs/system/s390x/secure-ipl.rst +17 -5
@@ -19,20 +19,32 @@ Note: certificate files must have a .pem extension. qemu-system-s390x -machine s390-ccw-virtio,boot-certs.0.path=/.../qemu/certs,boot-certs.1.path=/another/path/cert.pem ... +Enabling Secure IPL +^^^^^^^^^^^^^^^^^^^ + +Secure IPL is enabled by explicitly setting ``secure-boot=on``; if not +specified, secure boot is considered off. + +.. code-block:: shell + + qemu-system-s390x -machine s390-ccw-virtio,secure-boot=on|off + IPL Modes --------- Multiple IPL modes are available to differentiate between the various IPL -configurations. These modes are mutually exclusive and enabled based on the -``boot-certs`` option on the QEMU command line. +configurations. These modes are mutually exclusive and enabled based on specific +combinations of the ``secure-boot`` and ``boot-certs`` options on the QEMU +command line. Normal Mode ^^^^^^^^^^^ -The absence of certificates will attempt to IPL a guest without secure IPL -operations. No checks are performed, and no warnings/errors are reported. -This is the default mode. +The absence of both certificates and the ``secure-boot`` option will attempt to +IPL a guest without secure IPL operations. No checks are performed, and no +warnings/errors are reported. This is the default mode, and can be explicitly +enabled with ``secure-boot=off``. Configuration:
hw/s390x/s390-virtio-ccw.c +29 -0
@@ -817,6 +817,27 @@ static void machine_set_boot_certs(Object *obj, Visitor *v, const char *name, ms->boot_certs = cert_list; } +static inline bool machine_get_secure_boot (Object *obj,Error **errp) +{ +S390CcwMachineState *ms =S390_CCW_MACHINE (obj); + +return ms->secure_boot; +} + +static inline void machine_set_secure_boot (Object *obj,bool value, +Error **errp) +{ +S390CcwMachineClass *s390mc =S390_CCW_MACHINE_GET_CLASS (obj); +S390CcwMachineState *ms =S390_CCW_MACHINE (obj); + +if (!s390mc->use_secure) { +error_setg (errp,"secure-boot is not supported by this machine version" ); +return ; + } + + ms->secure_boot = value; +} +/* * S390x-specific global compatibility properties. *
@@ -843,6 +864,7 @@ static void ccw_machine_class_init(ObjectClass *oc, const void *data) s390mc->max_threads =1 ; s390mc->use_cpi = true; s390mc->use_certs = true; + s390mc->use_secure = true; mc->reset = s390_machine_reset; mc->block_default_type =IF_VIRTIO ; mc->no_cdrom =1 ;
@@ -891,6 +913,12 @@ static void ccw_machine_class_init(ObjectClass *oc, const void *data) machine_get_boot_certs, machine_set_boot_certs, NULL, NULL);object_class_property_set_description (oc,"boot-certs" ,"provide paths to a directory and/or a certificate file for secure boot" ); + +object_class_property_add_bool (oc,"secure-boot" , + machine_get_secure_boot, + machine_set_secure_boot); +object_class_property_set_description (oc,"secure-boot" , +"enable/disable secure boot" ); }static inline void s390_machine_initfn (Object *obj)
@@ -979,6 +1007,7 @@ static void ccw_machine_11_1_class_options(MachineClass *mc)S390CcwMachineClass *s390mc =S390_CCW_MACHINE_CLASS (mc); s390mc->use_certs = false; + s390mc->use_secure = false;ccw_machine_11_2_class_options (mc);compat_props_add (mc->compat_props, hw_compat_11_1, hw_compat_11_1_len);
include/hw/s390x/s390-virtio-ccw.h +2 -0
@@ -29,6 +29,7 @@ struct S390CcwMachineState {bool aes_key_wrap;bool dea_key_wrap;bool pv; +bool secure_boot;uint8_t loadparm[8 ];uint64_t memory_limit;uint64_t max_pagesize;
@@ -58,6 +59,7 @@ struct S390CcwMachineClass {int max_threads;bool use_cpi;bool use_certs; + bool use_secure; };#endif
qemu-options.hx +5 -1
@@ -47,7 +47,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " cxl-fmw.0.targets.0=firsttarget,cxl-fmw.0.targets.1=secondtarget,cxl-fmw.0.size=size[,cxl-fmw.0.interleave-granularity=granularity]\n" " sgx-epc.0.memdev=memid,sgx-epc.0.node=numaid\n" " smp-cache.0.cache=cachename,smp-cache.0.topology=topologylevel\n" - " boot-certs.0.path=/path/directory,boot-certs.1.path=/path/file provides paths to a directory and/or a certificate file\n", + " boot-certs.0.path=/path/directory,boot-certs.1.path=/path/file provides paths to a directory and/or a certificate file\n" + " secure-boot=on|off enable/disable secure boot (default=off)\n", QEMU_ARCH_ALL) SRST ``-machine [type=]name[,prop=value[,...]]``
@@ -218,6 +219,9 @@ SRST ``boot-certs.0.path=/path/directory,boot-certs.1.path=/path/file`` Provide paths to a directory and/or a certificate file on the host [s390x only]. + + ``secure-boot=on|off`` + Enables or disables secure boot on s390-ccw guest. The default is off. ERST DEF("M", HAS_ARG, QEMU_OPTION_M,
Signature · 1 line
2.55.0
[PULL 12/37] hw/s390x: Define finite size for single entry VCEntry
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Define MAX_VCENTRY_SIZE(8KB) and CERT_BUF_MAX_LEN to establish a finite size for a single entry VCEntry. Add validation in update_cert_store() to ensure certificate data does not exceed this limit.
This finite size definition is needed for proper memory allocation and will be used in a later commit to handle VCEntry structures with known size constraints.
--- hw/s390x/cert-store.c | 6 ++++++ include/hw/s390x/ipl/diag320.h | 3 +++ 2 files changed, 9 insertions(+)
hw/s390x/cert-store.c +6 -0
@@ -91,6 +91,12 @@ static int update_cert_store(S390IPLCertificateStore *cert_store, cert_buf_size =ROUND_UP (cert->der_size,4 ); data_buf_size = keyid_buf_size + hash_buf_size + cert_buf_size; +if (data_buf_size >CERT_BUF_MAX_LEN ) { +error_report ("Certificate data size %zu exceeds maximum buffer size %zu" , + data_buf_size,CERT_BUF_MAX_LEN ); +return -1 ; + } +if (cert_store->largest_cert_size < data_buf_size) { cert_store->largest_cert_size = data_buf_size; }
include/hw/s390x/ipl/diag320.h +3 -0
@@ -92,6 +92,9 @@ struct VCEntry { };typedef struct VCEntry VCEntry ; +#define MAX_VCENTRY_SIZE (8 * 1024) +#define CERT_BUF_MAX_LEN (MAX_VCENTRY_SIZE - sizeof(VCEntryHeader)) +struct VCBlockHeader {uint32_t in_len;uint32_t reserved0;
Signature · 1 line
2.55.0
[PULL 33/37] tests/functional/s390x: Add secure IPL functional test
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Add functional test for secure IPL.
--- tests/functional/s390x/meson.build | 2 + tests/functional/s390x/test_secure_ipl.py | 172 ++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100755 tests/functional/s390x/test_secure_ipl.py
tests/functional/s390x/meson.build +2 -0
@@ -2,6 +2,7 @@ test_s390x_timeouts = { 'ccw_virtio' : 420, + 'secure_ipl' : 360, } tests_s390x_system_quick = [
@@ -14,6 +15,7 @@ tests_s390x_system_thorough = [ 'ccw_virtio', 'pxelinux', 'replay', + 'secure_ipl', 'topology', 'tuxrun', ]
tests/functional/s390x/test_secure_ipl.py new file +172 -0
172 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 26/37] pc-bios/s390-ccw: Add signed component address overlap checks
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Add address range tracking and overlap checks to ensure that no component overlaps with a signed component during secure IPL.
--- pc-bios/s390-ccw/secure-ipl.c | 19 +++++++++++++++++++ pc-bios/s390-ccw/secure-ipl.h | 10 ++++++++++ 2 files changed, 29 insertions(+)
pc-bios/s390-ccw/secure-ipl.c +19 -0
@@ -193,6 +193,23 @@ static void init_lists(IplDeviceComponentList *comp_list, cert_list->ipl_info_header.len =sizeof (IplInfoBlockHeader); } +static void check_comp_overlap (IplDeviceComponentList *comp_list, +IplDeviceComponentEntry comp_entry) +{ +IplDeviceComponentEntry *comp; + +/* +* Check component's address range does not overlap with any +* signed component's address range. +*/ +for_each_rb_entry (comp, comp_list) { +if (comp->flags &S390_IPL_DEV_COMP_FLAG_SC && +intersects (comp->addr, comp->len, comp_entry.addr, comp_entry.len)) { +zipl_secure_error ("Component addresses overlap" ); + } + } +} +static int zipl_load_signature (ComponentEntry *entry,uint64_t sig) {if (entry->compdat.sig_info.format !=DER_SIGNATURE_FORMAT ) {
@@ -294,6 +311,8 @@ int zipl_run_secure(ComponentEntry **entry_ptr, const uint8_t *tmp_sec, comp_entry.addr = comp_addr; comp_entry.len = (uint64_t )comp_len; +check_comp_overlap (comp_list, comp_entry); +/* no signature present (unsigned component) */ if (!sig_entry.len) {comp_list_add (comp_list, comp_entry);
pc-bios/s390-ccw/secure-ipl.h +10 -0
@@ -116,4 +116,14 @@ static inline bool verify_signature(IplDeviceComponentEntry comp_entry, return false; } +static inline bool intersects (uint64_t addr0,uint64_t size0, +uint64_t addr1,uint64_t size1) +{ +if (addr1 > addr0) { +return addr1 - addr0 < size0; + } + +return addr0 - addr1 < size1; +} +#endif /* _PC_BIOS_S390_CCW_SECURE_IPL_H */
Signature · 1 line
2.55.0
[PULL 05/37] crypto/x509-utils: Add helper functions for certificate store
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Introduce new helper functions for x509 certificate, which will be used by the certificate store:
qcrypto_x509_convert_cert_der() - converts a certificate from PEM to DER format
These functions provide support for certificate format conversion.
--- crypto/x509-utils.c | 49 +++++++++++++++++++++++++++++++++++++ include/crypto/x509-utils.h | 21 ++++++++++++++++ 2 files changed, 70 insertions(+)
crypto/x509-utils.c +49 -0
@@ -82,6 +82,46 @@ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,return ret; } +int qcrypto_x509_convert_cert_der (uint8_t *cert,size_t size, +uint8_t **result,size_t *resultlen, +Error **errp) +{ +int ret =-1 ; +int rc; +gnutls_x509_crt_t crt; +gnutls_datum_t datum = {.data = cert, .size = size}; +gnutls_datum_t datum_der = {.data =NULL , .size =0 }; + + rc =gnutls_x509_crt_init (&crt); +if (rc <0 ) { +error_setg (errp,"Failed to initialize certificate: %s" ,gnutls_strerror (rc)); +return ret; + } + + rc =gnutls_x509_crt_import (crt, &datum,GNUTLS_X509_FMT_PEM ); +if (rc !=0 ) { +error_setg (errp,"Failed to import certificate: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + rc =gnutls_x509_crt_export2 (crt,GNUTLS_X509_FMT_DER , &datum_der); +if (rc !=0 ) { +error_setg (errp,"Failed to convert certificate to DER format: %s" , +gnutls_strerror (rc)); + goto cleanup; + } + + *resultlen = datum_der.size; + *result =g_memdup2 (datum_der.data, datum_der.size); + + ret =0 ; + +cleanup: +gnutls_x509_crt_deinit (crt); +g_free (datum_der.data); +return ret; +} +#else /* ! CONFIG_GNUTLS */ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,
@@ -94,4 +134,13 @@ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size, return -1; } +int qcrypto_x509_convert_cert_der (uint8_t *cert,size_t size, +uint8_t **result, +size_t *resultlen, +Error **errp) +{ +error_setg (errp,"GNUTLS is required to export X.509 certificate" ); +return -1 ; +} +#endif /* ! CONFIG_GNUTLS */
include/crypto/x509-utils.h +21 -0
@@ -19,4 +19,25 @@ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,size_t *resultlen, Error **errp); +/** +* qcrypto_x509_convert_cert_der +* @cert: pointer to the raw certificate data in PEM format +* @size: size of the certificate +* @result: output location for the allocated buffer for the certificate +* in DER format +* (the function allocates memory which must be freed by the caller) +* @resultlen: pointer to the size of the buffer (will be updated with the +* actual size of the DER-encoded certificate) +* @errp: error pointer +* +* Convert the given @cert from PEM to DER format. +* +* Returns: 0 on success, +* -1 on error. +*/ +int qcrypto_x509_convert_cert_der (uint8_t *cert,size_t size, +uint8_t **result, +size_t *resultlen, +Error **errp); +#endif
Signature · 1 line
2.55.0
[PULL 03/37] Add boot-certs to s390-ccw-virtio machine type option
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Introduce a new boot-certs machine type option for the s390-ccw-virtio machine. This allows users to specify one or more certificate file paths or directories to be used during secure boot.
Each entry is specified using the syntax:
boot-certs.<index>.path=/path/to/cert.pem
Multiple paths can be specify using array properties:
boot-certs.0.path=/path/to/cert.pem, boot-certs.1.path=/path/to/cert-dir, boot-certs.2.path=/path/to/another-dir...
--- docs/system/s390x/secure-ipl.rst | 20 +++++++++++++++ docs/system/target-s390x.rst | 1 + hw/s390x/s390-virtio-ccw.c | 41 ++++++++++++++++++++++++++++++ include/hw/s390x/s390-virtio-ccw.h | 3 +++ qapi/machine-s390x.json | 23 +++++++++++++++++ qapi/pragma.json | 1 + qemu-options.hx | 6 ++++- 7 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 docs/system/s390x/secure-ipl.rst
docs/system/s390x/secure-ipl.rst new file +20 -0
@@ -0,0 +1,20 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Secure IPL Command Line Options +------------------------------- + +The s390-ccw-virtio machine type supports secure IPL. These parameters allow +users to provide certificates and enable secure IPL directly via the command +line. + +Providing Certificates +^^^^^^^^^^^^^^^^^^^^^^ + +The certificate store can be populated by supplying a list of X.509 certificate +file paths or directories containing certificate files on the command-line: + +Note: certificate files must have a .pem extension. + +.. code-block:: shell + + qemu-system-s390x -machine s390-ccw-virtio,boot-certs.0.path=/.../qemu/certs,boot-certs.1.path=/another/path/cert.pem ...
docs/system/target-s390x.rst +1 -0
@@ -35,3 +35,4 @@ Architectural features s390x/bootdevices s390x/protvirt s390x/cpu-topology + s390x/secure-ipl
hw/s390x/s390-virtio-ccw.c +41 -0
71 lines not on this page · raw message
include/hw/s390x/s390-virtio-ccw.h +3 -0
@@ -14,6 +14,7 @@#include "hw/core/boards.h" #include "qom/object.h" #include "hw/s390x/sclp.h" +#include "qapi/qapi-types-machine-s390x.h" #define TYPE_S390_CCW_MACHINE "s390-ccw-machine"
@@ -31,6 +32,7 @@ struct S390CcwMachineState {uint8_t loadparm[8 ];uint64_t memory_limit;uint64_t max_pagesize; +BootCertificatesList *boot_certs;SCLPDevice *sclp; };
@@ -55,6 +57,7 @@ struct S390CcwMachineClass {/*< public >*/ int max_threads;bool use_cpi; + bool use_certs; };#endif
qapi/machine-s390x.json +23 -0
@@ -140,3 +140,26 @@ { 'event': 'SCLP_CPI_INFO_AVAILABLE', 'features': [ 'unstable' ] } + +## +# @BootCertificates: +# +# Boot certificates for secure IPL. +# +# @path: path to an X.509 certificate file or a directory containing +# certificate files. +# +# Since: 11.2 +## +{ 'struct': 'BootCertificates', + 'data': {'path': 'str'} } + +## +# @DummyBootCertificates: +# +# Not used by QMP; hack to let us use BootCertificatesList internally. +# +# Since: 11.2 +## +{ 'struct': 'DummyBootCertificates', + 'data': {'unused-boot-certs': ['BootCertificates'] } }
qapi/pragma.json +1 -0
@@ -49,6 +49,7 @@ 'DisplayProtocol', 'DriveBackupWrapper', 'DummyBlockCoreForceArrays', + 'DummyBootCertificates', 'DummyForceArrays', 'DummyVirtioForceArrays', 'HotKeyMod',
qemu-options.hx +5 -1
@@ -46,7 +46,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " memory-backend='backend-id' specifies explicitly provided backend for main RAM (default=none)\n" " cxl-fmw.0.targets.0=firsttarget,cxl-fmw.0.targets.1=secondtarget,cxl-fmw.0.size=size[,cxl-fmw.0.interleave-granularity=granularity]\n" " sgx-epc.0.memdev=memid,sgx-epc.0.node=numaid\n" - " smp-cache.0.cache=cachename,smp-cache.0.topology=topologylevel\n", + " smp-cache.0.cache=cachename,smp-cache.0.topology=topologylevel\n" + " boot-certs.0.path=/path/directory,boot-certs.1.path=/path/file provides paths to a directory and/or a certificate file\n", QEMU_ARCH_ALL) SRST ``-machine [type=]name[,prop=value[,...]]``
@@ -214,6 +215,9 @@ SRST :: -machine smp-cache.0.cache=l1d,smp-cache.0.topology=core,smp-cache.1.cache=l1i,smp-cache.1.topology=core + + ``boot-certs.0.path=/path/directory,boot-certs.1.path=/path/file`` + Provide paths to a directory and/or a certificate file on the host [s390x only]. ERST DEF("M", HAS_ARG, QEMU_OPTION_M,
Signature · 1 line
2.55.0
[PULL 04/37] crypto/x509-utils: Refactor with GNUTLS fallback
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Always compile x509-utils.c and add a fallback when GNUTLS is unavailable.
These functions will be needed in the s390x code regardless of whether GNUTLS is available.
--- crypto/meson.build | 2 +- crypto/x509-utils.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
crypto/meson.build +1 -1
@@ -22,12 +22,12 @@ crypto_ss.add(files( 'tlscredsx509.c', 'tlssession.c', 'rsakey.c', + 'x509-utils.c', )) if gnutls.found() crypto_ss.add(files( 'tlscredsbox.c', - 'x509-utils.c', )) endif
crypto/x509-utils.c +16 -0
@@ -11,6 +11,8 @@#include "qemu/osdep.h" #include "qapi/error.h" #include "crypto/x509-utils.h" + +#ifdef CONFIG_GNUTLS #include <gnutls/gnutls.h> #include <gnutls/crypto.h> #include <gnutls/x509.h>
@@ -79,3 +81,17 @@ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,gnutls_x509_crt_deinit (crt); return ret; } + +#else /* ! CONFIG_GNUTLS */ + +int qcrypto_get_x509_cert_fingerprint (uint8_t *cert,size_t size, +QCryptoHashAlgo hash, +uint8_t *result, +size_t *resultlen, +Error **errp) +{ +error_setg (errp,"GNUTLS is required to get fingerprint" ); +return -1 ; +} + +#endif /* ! CONFIG_GNUTLS */
Signature · 1 line
2.55.0
[PULL 02/37] s390x/css: Fix css stsch detection to go beyond 8192 devices
In reply to Eric FarmanFrom: Christian Borntraeger <[email protected]>
find_last_bit expects a size in bits and not in words. the calculation limits the number of guest devices to 8192. This probably does not matter in reality, its wrong anyway.
--- hw/s390x/css.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/s390x/css.c +1 -2
@@ -2023,8 +2023,7 @@ bool css_schid_final(int m, uint8_t cssid, uint8_t ssid, uint16_t schid)return true; } set = channel_subsys.css[real_cssid]->sch_set[ssid]; -return schid >find_last_bit (set->schids_used, - (MAX_SCHID +1 ) /sizeof (unsigned long )); +return schid >find_last_bit (set->schids_used, (MAX_SCHID +1 )); }unsigned int css_find_free_chpid (uint8_t cssid)
Signature · 1 line
2.55.0
[PULL 34/37] docs/specs: Add secure IPL documentation
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Add documentation for secure IPL
--- docs/specs/s390x-secure-ipl.rst | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
docs/specs/s390x-secure-ipl.rst +55 -0
@@ -1,5 +1,60 @@ .. SPDX-License-Identifier: GPL-2.0-or-later +s390 Secure IPL +=============== + +Secure IPL (a.k.a. secure boot) enables s390-ccw virtual machines to +leverage qcrypto libraries and z/Architecture emulation to verify the +integrity of signed kernels. The qcrypto libraries are used to perform +certificate validation and signature-verification, whereas the +z/Architecture emulation is used to ensure secure IPL data has not +been tampered with, convey data between QEMU and guest code, and set up +the relevant secure IPL data structures with verification results. + +To find out more about using this feature, see +:doc:`documentation </system/s390x/secure-ipl>`. + +Note that "guest code" will refer to the s390-ccw BIOS unless stated +otherwise. + +Both QEMU and guest code work in cooperation to perform secure IPL. The Secure +Code Loading Attributes Facility (SCLAF) is used to check the Secure Code +Loading Attribute Block (SCLAB) and ensure that secure IPL data has not +been tampered with. DIAGNOSE 'X'320' is invoked by guest code to query +the certificate store info and retrieve specific certificates from QEMU. +DIAGNOSE 'X'508' is used by guest code to leverage qcrypto libraries to +perform signature-verification in QEMU. Lastly, guest code generates and +appends an IPL Information Report Block (IIRB) at the end of the IPL +Parameter Block (IPLB), which is used by the kernel to store signed and +verified entries. + +The logical steps are as follows: + +- guest code reads data payload from disk (e.g. stage3 boot loader, kernel) +- guest code checks the validity of the SCLAB +- guest code invokes DIAG 508 subcode 1 and provides the payload +- QEMU handles DIAG 508 request by reading the payload and retrieving the + certificate store +- QEMU DIAG 508 utilizes handler qcrypto libraries to perform + signature-verification on the payload, attempting with each cert in the store + (until success or exhausted) +- QEMU DIAG 508 returns: + + - success: index of cert used to verify payload + - failure: error code + +- guest code is expected to respond to this operation by: + + - success: retrieves cert from store via DIAG 320 using returned index + - failure: reports with warning (audit mode), aborts with error (secure mode) + +- guest code appends IIRB at the end of the IPLB +- guest code kicks off IPL + +More information regarding the respective DIAGNOSE commands and IPL data +structures are outlined within this document. + + s390 Certificate Store and Functions ------------------------------------
Signature · 1 line
2.55.0
[PULL 14/37] crypto/x509-utils: Add helper functions for DIAG 508 subcode 1
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Introduce helper functions to support signature verification required by DIAG 508 subcode 1:
qcrypto_pkcs7_convert_sig_pem() – converts a signature from DER to PEM format qcrypto_x509_verify_sig() – verifies the provided data against the given signature
These functions enable basic signature verification support.
--- crypto/x509-utils.c | 108 ++++++++++++++++++++++++++++++++++++ include/crypto/x509-utils.h | 41 ++++++++++++++ 2 files changed, 149 insertions(+)
crypto/x509-utils.c +108 -0
@@ -16,6 +16,7 @@#include <gnutls/gnutls.h> #include <gnutls/crypto.h> #include <gnutls/x509.h> +#include <gnutls/pkcs7.h> static const int qcrypto_to_gnutls_hash_alg_map[QCRYPTO_HASH_ALGO__MAX ] = { [QCRYPTO_HASH_ALGO_MD5 ] =GNUTLS_DIG_MD5 ,
@@ -336,6 +337,96 @@ int qcrypto_x509_check_ecc_curve_p521(uint8_t *cert, size_t size, Error **errp)return curve_id ==GNUTLS_ECC_CURVE_SECP521R1 ; } +int qcrypto_pkcs7_convert_sig_pem (uint8_t *sig,size_t sig_size, +uint8_t **result,size_t *resultlen, +Error **errp) +{ +int ret =-1 ; +int rc; +gnutls_pkcs7_t signature; +gnutls_datum_t sig_datum_der = {.data = sig, .size = sig_size}; +gnutls_datum_t sig_datum_pem = {.data =NULL , .size =0 }; + + rc =gnutls_pkcs7_init (&signature); +if (rc <0 ) { +error_setg (errp,"Failed to initialize pkcs7 data: %s" ,gnutls_strerror (rc)); +return ret; + } + + rc =gnutls_pkcs7_import (signature, &sig_datum_der,GNUTLS_X509_FMT_DER ); +if (rc !=0 ) { +error_setg (errp,"Failed to import signature: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + rc =gnutls_pkcs7_export2 (signature,GNUTLS_X509_FMT_PEM , &sig_datum_pem); +if (rc !=0 ) { +error_setg (errp,"Failed to convert signature to PEM format: %s" , +gnutls_strerror (rc)); + goto cleanup; + } + + *resultlen = sig_datum_pem.size; + *result =g_memdup2 (sig_datum_pem.data, sig_datum_pem.size); + + ret =0 ; + +cleanup: +gnutls_pkcs7_deinit (signature); +g_free (sig_datum_pem.data); +return ret; +} + +int qcrypto_x509_verify_sig (uint8_t *cert,size_t cert_size, +uint8_t *comp,size_t comp_size, +uint8_t *sig,size_t sig_size,Error **errp) +{ +int rc; +int ret =-1 ; +gnutls_x509_crt_t crt =NULL ; +gnutls_pkcs7_t signature =NULL ; +gnutls_datum_t cert_datum = {.data = cert, .size = cert_size}; +gnutls_datum_t data_datum = {.data = comp, .size = comp_size}; +gnutls_datum_t sig_datum = {.data = sig, .size = sig_size}; + + rc =gnutls_x509_crt_init (&crt); +if (rc <0 ) { +error_setg (errp,"Failed to initialize certificate: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + rc =gnutls_x509_crt_import (crt, &cert_datum,GNUTLS_X509_FMT_PEM ); +if (rc !=0 ) { +error_setg (errp,"Failed to import certificate: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + rc =gnutls_pkcs7_init (&signature); +if (rc <0 ) { +error_setg (errp,"Failed to initialize pkcs7 data: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + rc =gnutls_pkcs7_import (signature, &sig_datum,GNUTLS_X509_FMT_PEM ); +if (rc !=0 ) { +error_setg (errp,"Failed to import signature: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + rc =gnutls_pkcs7_verify_direct (signature, crt,0 , &data_datum,0 ); +if (rc !=0 ) { +error_setg (errp,"Failed to verify signature: %s" ,gnutls_strerror (rc)); + goto cleanup; + } + + ret =0 ; + +cleanup: +gnutls_x509_crt_deinit (crt); +gnutls_pkcs7_deinit (signature); +return ret; +} +#else /* ! CONFIG_GNUTLS */ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,
@@ -379,4 +470,21 @@ int qcrypto_x509_check_ecc_curve_p521(uint8_t *cert, size_t size, Error **errp) return -1; } +int qcrypto_pkcs7_convert_sig_pem (uint8_t *sig,size_t sig_size, +uint8_t **result, +size_t *resultlen, +Error **errp) +{ +error_setg (errp,"GNUTLS is required to export pkcs7 signature" ); +return -1 ; +} + +int qcrypto_x509_verify_sig (uint8_t *cert,size_t cert_size, +uint8_t *comp,size_t comp_size, +uint8_t *sig,size_t sig_size,Error **errp) +{ +error_setg (errp,"GNUTLS is required for signature-verification support" ); +return -1 ; +} +#endif /* ! CONFIG_GNUTLS */
include/crypto/x509-utils.h +41 -0
45 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 23/37] pc-bios/s390-ccw: Rework zipl_load_segment function
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Change zipl_load_segment() to accept explicit blockno and address parameters instead of ComponentEntry pointer and return segment length.
Modify this function to allow the caller to specify a memory address where segment data should be loaded into.
seg_len variable is necessary to store the calculated segment length and is used during signature verification. Return the length on success, or a negative return code on failure.
Remove static qualifier and add function declaration to bootmap.h to make it accessible to other modules.
--- pc-bios/s390-ccw/bootmap.c | 14 ++++++-------- pc-bios/s390-ccw/bootmap.h | 13 +++++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-)
pc-bios/s390-ccw/bootmap.c +6 -8
@@ -615,19 +615,15 @@ static int ipl_eckd(void)* IPL a SCSI disk */ -static int zipl_load_segment (ComponentEntry *entry) +int zipl_load_segment (block_number_t blockno,uint64_t address) {const int max_entries = (MAX_SECTOR_SIZE /sizeof (ScsiBlockPtr));ScsiBlockPtr *bprs = (void *)sec;const int bprs_size =sizeof (sec); -block_number_t blockno; -uint64_t address;int i;char err_msg[] ="zIPL failed to read BPRS at 0xZZZZZZZZZZZZZZZZ" ;char *blk_no = &err_msg[30 ];/* where to print blockno in (those ZZs) */ - - blockno = entry->data.blockno; - address = entry->compdat.load_addr; +int seg_len =0 ;debug_print_int ("loading segment at block" , blockno);debug_print_int ("addr" , address);
@@ -670,10 +666,12 @@ static int zipl_load_segment(ComponentEntry *entry)puts ("zIPL load segment failed" );return -EIO ; } + + seg_len += bprs->size * (bprs[i].blockct +1 ); } }while (blockno); -return 0 ; +return seg_len; }static int zipl_run_normal (ComponentEntry **entry_ptr,const uint8_t *tmp_sec)
@@ -689,7 +687,7 @@ static int zipl_run_normal(ComponentEntry **entry_ptr, const uint8_t *tmp_sec)continue ; } -if (zipl_load_segment (entry)) { +if (zipl_load_segment (entry->data.blockno, entry->compdat.load_addr) <0 ) {return -1 ; }
pc-bios/s390-ccw/bootmap.h +13 -0
@@ -113,6 +113,19 @@ typedef struct ScsiMbr {ScsiBlockPtr pt;/* block pointer to program table */ } __attribute__ ((packed)) ScsiMbr; +/** +* zipl_load_segment +* @blockno: block number of the first BPRS describing the segment. +* @address: guest physical address at which to load the segment. +* +* Walks the BPRS chain starting at @blockno, loading each data block +* into guest memory at @address. +* +* Returns: length of the segment on success, +* negative value on error. +*/ +int zipl_load_segment (block_number_t blockno,uint64_t address); +#define ZIPL_MAGIC "zIPL"#define ZIPL_MAGIC_EBCDIC "\xa9\xc9\xd7\xd3"#define IPL1_MAGIC "\xc9\xd7\xd3\xf1"/* == "IPL1" in EBCDIC */
Signature · 1 line
2.55.0
[PULL 13/37] s390x/diag: Introduce DIAG 508 for secure IPL operations
In reply to Eric FarmanFrom: Collin Walling <[email protected]>
In order to support secure IPL (aka secure boot) for the s390-ccw BIOS, a new s390 DIAGNOSE instruction is introduced to leverage QEMU for handling operations such as signature verification and certificate retrieval.
Currently, only subcode 0 is supported with this patch, which is used to query a bitmap of which subcodes are supported.
--- docs/specs/s390x-secure-ipl.rst | 18 ++++++++++++++++++ include/hw/s390x/ipl/diag508.h | 15 +++++++++++++++ target/s390x/diag.c | 27 +++++++++++++++++++++++++++ target/s390x/kvm/kvm.c | 14 ++++++++++++++ target/s390x/s390x-internal.h | 2 ++ target/s390x/tcg/misc_helper.c | 7 +++++++ 6 files changed, 83 insertions(+) create mode 100644 include/hw/s390x/ipl/diag508.h
docs/specs/s390x-secure-ipl.rst +18 -0
@@ -66,3 +66,21 @@ Subcode 2 - store verification certificates contiguously in a VCE (with zero-padding). Following the header, the key-id is immediately stored. The hash and certificate data follow and may be accessed via the respective offset fields stored in the VCE. + + +Secure IPL Data Structures, Facilities, and Functions +----------------------------------------------------- + +DIAGNOSE function code 'X'508' - IPL extensions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +DIAGNOSE 'X'508' is reserved for guest use in order to facilitate communication +of additional IPL operations that cannot be handled by guest code, such as +signature verification for secure IPL. + +If the function code specifies 0x508, IPL extension functions are performed. +These functions are meant to provide extended functionality for s390 guest boot +that requires assistance from QEMU. + +Subcode 0 - query installed subcodes + Returns a 64-bit mask indicating which subcodes are supported.
include/hw/s390x/ipl/diag508.h new file +15 -0
@@ -0,0 +1,15 @@ +/* +* S/390 DIAGNOSE 508 definitions and structures +* +* Copyright 2025 IBM Corp. +* Author(s): Collin Walling <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef S390X_DIAG508_H +#define S390X_DIAG508_H + +#define DIAG_508_SUBC_QUERY_SUBC 0x0000 + +#endif
target/s390x/diag.c +27 -0
@@ -20,6 +20,7 @@#include "hw/s390x/cert-store.h" #include "hw/s390x/ipl.h" #include "hw/s390x/ipl/diag320.h" +#include "hw/s390x/ipl/diag508.h" #include "hw/s390x/s390-virtio-ccw.h" #include "system/kvm.h" #include "kvm/kvm_s390x.h"
@@ -618,3 +619,29 @@ void handle_diag_320(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)break ; } } + +void handle_diag_508 (CPUS390XState *env,uint64_t r1,uint64_t r3,uintptr_t ra) +{ +uint64_t subcode = env->regs[r3]; +int rc; + +if (env->psw.mask &PSW_MASK_PSTATE ) { +s390_program_interrupt (env,PGM_PRIVILEGED , ra); +return ; + } + +if ((subcode & ~0x0ffffULL ) || (r1 &1 )) { +s390_program_interrupt (env,PGM_SPECIFICATION , ra); +return ; + } + +switch (subcode) { +case DIAG_508_SUBC_QUERY_SUBC : + rc =0 ; +break ; +default : +s390_program_interrupt (env,PGM_SPECIFICATION , ra); +return ; + } + env->regs[r1 +1 ] = rc; +}
target/s390x/kvm/kvm.c +14 -0
@@ -102,6 +102,7 @@#define DIAG_CERT_STORE 0x320#define DIAG_KVM_HYPERCALL 0x500#define DIAG_KVM_BREAKPOINT 0x501 +#define DIAG_SECURE_IPL 0x508#define ICPT_INSTRUCTION 0x04#define ICPT_PROGRAM 0x08
@@ -1542,6 +1543,16 @@ static void kvm_handle_diag_320(S390CPU *cpu, struct kvm_run *run)handle_diag_320 (&cpu->env, r1, r3,RA_IGNORED ); } +static void kvm_handle_diag_508 (S390CPU *cpu,struct kvm_run *run) +{ +uint64_t r1, r3; + + r1 = (run->s390_sieic.ipa &0x00f0 ) >>4 ; + r3 = run->s390_sieic.ipa &0x000f ; + +handle_diag_508 (&cpu->env, r1, r3,RA_IGNORED ); +} +#define DIAG_KVM_CODE_MASK 0x000000000000ffffstatic int handle_diag (S390CPU *cpu,struct kvm_run *run,uint32_t ipb)
@@ -1575,6 +1586,9 @@ static int handle_diag(S390CPU *cpu, struct kvm_run *run, uint32_t ipb)case DIAG_CERT_STORE :kvm_handle_diag_320 (cpu, run);break ; +case DIAG_SECURE_IPL : +kvm_handle_diag_508 (cpu, run); +break ;default :trace_kvm_insn_diag (func_code);kvm_s390_program_interrupt (cpu,PGM_SPECIFICATION );
target/s390x/s390x-internal.h +2 -0
@@ -390,6 +390,8 @@ bool handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra);void handle_diag_320 (CPUS390XState *env,uint64_t r1,uint64_t r3,uintptr_t ra); +void handle_diag_508 (CPUS390XState *env,uint64_t r1,uint64_t r3, +uintptr_t ra);/* translate.c */
target/s390x/tcg/misc_helper.c +7 -0
@@ -154,6 +154,13 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num)bql_unlock (); r =0 ;break ; +case 0x508 : +/* secure ipl operations */ +bql_lock (); +handle_diag_508 (env, r1, r3,GETPC ()); +bql_unlock (); + r =0 ; +break ;default : r =-1 ;break ;
Signature · 1 line
2.55.0
[PULL 37/37] pc-bios/s390-ccw.img: update s390x bios
In reply to Eric FarmanRebuild the bios to include the secure IPL changes.
--- pc-bios/s390-ccw.img | Bin 104216 -> 112408 bytes 1 file changed, 0 insertions(+), 0 deletions(-)
pc-bios/s390-ccw.img binary +0 -0
Signature · 1 line
2.55.0
[PULL 24/37] pc-bios/s390-ccw: Introduce ZiplBootMode enum for IPL mode selection
In reply to Eric FarmanFrom: Zhuoying Cai <[email protected]>
Add ZiplBootMode enumeration to support multiple IPL boot configurations. Boot modes differentiate between normal boot and secure IPL operations, enabled based on boot certificates specified via the boot-certs option.
Normal Mode: IPL when no certificates are provided. No signature verification is performed.
This prepares for future secure IPL modes requiring signature verification.
--- docs/system/s390x/secure-ipl.rst | 21 +++++++++++++++++++++ pc-bios/s390-ccw/bootmap.c | 16 +++++++++++++++- pc-bios/s390-ccw/main.c | 6 ++++++ pc-bios/s390-ccw/s390-ccw.h | 6 ++++++ 4 files changed, 48 insertions(+), 1 deletion(-)
docs/system/s390x/secure-ipl.rst +21 -0
@@ -18,3 +18,24 @@ Note: certificate files must have a .pem extension. .. code-block:: shell qemu-system-s390x -machine s390-ccw-virtio,boot-certs.0.path=/.../qemu/certs,boot-certs.1.path=/another/path/cert.pem ... + + +IPL Modes +--------- + +Multiple IPL modes are available to differentiate between the various IPL +configurations. These modes are mutually exclusive and enabled based on the +``boot-certs`` option on the QEMU command line. + +Normal Mode +^^^^^^^^^^^ + +The absence of certificates will attempt to IPL a guest without secure IPL +operations. No checks are performed, and no warnings/errors are reported. +This is the default mode. + +Configuration: + +.. code-block:: shell + + qemu-system-s390x -machine s390-ccw-virtio ...
pc-bios/s390-ccw/bootmap.c +15 -1
@@ -332,6 +332,9 @@ static int run_eckd_boot_script(block_number_t bmt_block_nr,/* The S1B block number is NULL_BLOCK_NR if and only if it's an LD-IPL */ bool ldipl = (s1b_block_nr ==NULL_BLOCK_NR ); +IPL_assert ((boot_mode ==ZIPL_BOOT_MODE_NORMAL ), +"Secure boot with the ECKD scheme is not supported!" ); +if (menu_is_enabled_zipl () && !ldipl) { loadparm =eckd_get_boot_menu_index (s1b_block_nr); }
@@ -731,7 +734,14 @@ static int zipl_run(ScsiBlockPtr *pte)/* Load image(s) into RAM */ entry = (ComponentEntry *)(&header[1 ]); - rc =zipl_run_normal (&entry, tmp_sec); +switch (boot_mode) { +case ZIPL_BOOT_MODE_NORMAL : + rc =zipl_run_normal (&entry, tmp_sec); +break ; +default : +panic ("Unknown boot mode" ); + } +if (rc) {return rc; }
@@ -1102,12 +1112,16 @@ void zipl_load(void)VDev *vdev =virtio_get_device ();if (vdev->is_cdrom) { +IPL_assert ((boot_mode ==ZIPL_BOOT_MODE_NORMAL ), +"Secure boot from ISO image is not supported!" );ipl_iso_el_torito ();puts ("Failed to IPL this ISO image!" );return ; }if (virtio_get_device_type () ==VIRTIO_ID_NET ) { +IPL_assert ((boot_mode ==ZIPL_BOOT_MODE_NORMAL ), +"Virtio net boot device does not support secure boot!" );netmain ();puts ("Failed to IPL from this network!" );return ;
pc-bios/s390-ccw/main.c +6 -0
@@ -30,6 +30,7 @@ IplParameterBlock *iplb;bool have_iplb;static uint16_t cutype;LowCore *lowcore;/* Yes, this *is* a pointer to address 0 */ +ZiplBootMode boot_mode;#define LOADPARM_PROMPT "PROMPT "#define LOADPARM_EMPTY " "
@@ -306,6 +307,9 @@ static void ipl_ccw_device(void)switch (cutype) {case CU_TYPE_DASD_3990 :case CU_TYPE_DASD_2107 : +IPL_assert ((boot_mode ==ZIPL_BOOT_MODE_NORMAL ), +"Passthrough (vfio) CCW device does not support secure boot!" ); +dasd_ipl (blk_schid, cutype);break ;case CU_TYPE_VIRTIO :
@@ -393,6 +397,8 @@ void main(void)probe_boot_device (); } + boot_mode =ZIPL_BOOT_MODE_NORMAL ; +while (have_iplb) {boot_setup ();if (have_iplb &&find_boot_device ()) {
pc-bios/s390-ccw/s390-ccw.h +6 -0
@@ -69,6 +69,12 @@ int sclp_read(char *str, size_t count);/* bootmap.c */ void zipl_load (void ); +typedef enum ZiplBootMode { +ZIPL_BOOT_MODE_NORMAL =0 , +}ZiplBootMode ; + +extern ZiplBootMode boot_mode; +/* jump2ipl.c */ void write_reset_psw (uint64_t psw);int jump_to_IPL_code (uint64_t address);
Signature · 1 line
2.55.0
Richard Henderson
AppliedQuoted 10 lines · Eric Farman
The following changes since commit
fe11f459f640cd08f35c21f9d403517951bfd671:Merge tag 'fixes-pr-v1' ofhttps://gitlab.com/marcandre.lureau/qemu into staging (2026-08-25 06:48:55 -0700)are available in the Git repository at:
https://gitlab.com/efarman/qemu.git tags/s390x-20260826for you to fetch changes up to
5c3c500cddbdea58bb76515847d1d515621dcf0b:
Quoted 7 lines
pc-bios/s390-ccw.img: update s390x bios (2026-08-26 07:05:48 -0400)----------------------------------------------------------------
New s390x features for 11.2
- hardening fixes in css/sclp code
- enable secure IPL
- regenerate s390-ccw.img
Applied, thanks.
r~