s390x: Attestation tests
v4 cover s390x: Attestation tests
This series adds some test in s390x/uv-guest.c verifying error paths of the Request Attestation Measurement UVC.
Also adds a test in s390x/uv-host.c to verify that the
Request Attestation Measurement UVC cannot be called in guest1.
Additionally, adds a shared bit test and removes duplicated tests.
v3->v4:
* renamed PATCH 1
* moved attestation guest tests into own file
* rebased onto current master
v2->v3:
* added test for share bits as new PATCH 4/5
* added r-b from Claudio in PATCH 1/4
* replaced all u* with uint*_t
* incorporated misc feedback from Claudio
v1->v2:
* renamed 'uv_get_info(void)' to 'uv_get_query_data(void)'
* renamed various fields in 'struct uv_arcb_v1'
* added a test for invalid additional size
* added r-b from Janosch in PATCH 1/4
* added r-b from Janosch in PATCH 3/4
Steffen Eiden (5):
s390x: uv-host: Add invalid command attestation check
s390x: lib: Add QUI getter
s390x: uv-guest: remove duplicated checks
s390x: uv-guest: add share bit test
s390x: uv-guest: Add attestation tests
lib/s390x/asm/uv.h | 28 +++++- lib/s390x/uv.c | 8 ++ lib/s390x/uv.h | 1 + s390x/Makefile | 1 + s390x/pv-attest.c | 225 +++++++++++++++++++++++++++++++++++++++++++++ s390x/uv-guest.c | 49 ++++++---- s390x/uv-host.c | 1 + 7 files changed, 293 insertions(+), 20 deletions(-) create mode 100644 s390x/pv-attest.c
Signature · 1 line
2.30.2
PATCH v4 1/5 s390x: uv-host: Add invalid command attestation check
Adds an invalid command test for attestation in the uv-host.
--- lib/s390x/asm/uv.h | 23 ++++++++++++++++++++++- s390x/uv-host.c | 1 + 2 files changed, 23 insertions(+), 1 deletion(-)
lib/s390x/asm/uv.h +22 -1
@@ -1,7 +1,7 @@/* * s390x Ultravisor related definitions * -* Copyright (c) 2020 IBM Corp +* Copyright IBM Corp. 2020, 2022 * * Authors: * Janosch Frank <[email protected]>
@@ -47,6 +47,7 @@#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342#define UVC_CMD_SET_SHARED_ACCESS 0x1000#define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001 +#define UVC_CMD_ATTESTATION 0x1020/* Bits in installed uv calls */ enum uv_cmds_inst {
@@ -71,6 +72,7 @@ enum uv_cmds_inst {BIT_UVC_CMD_UNSHARE_ALL =20 ,BIT_UVC_CMD_PIN_PAGE_SHARED =21 ,BIT_UVC_CMD_UNPIN_PAGE_SHARED =22 , + BIT_UVC_CMD_ATTESTATION = 28, }; struct uv_cb_header {
@@ -178,6 +180,25 @@ struct uv_cb_cfs {u64 paddr; } __attribute__((packed)) __attribute__((aligned(8))); +/* Retrieve Attestation Measurement */ +struct uv_cb_attest { +struct uv_cb_header header;/* 0x0000 */ +uint64_t reserved08[2 ];/* 0x0008 */ +uint64_t arcb_addr;/* 0x0018 */ +uint64_t continuation_token;/* 0x0020 */ +uint8_t reserved28[6 ];/* 0x0028 */ +uint16_t user_data_length;/* 0x002e */ +uint8_t user_data[256 ];/* 0x0030 */ +uint32_t reserved130[3 ];/* 0x0130 */ +uint32_t measurement_length;/* 0x013c */ +uint64_t measurement_address;/* 0x0140 */ +uint8_t config_uid[16 ];/* 0x0148 */ +uint32_t reserved158;/* 0x0158 */ +uint32_t add_data_length;/* 0x015c */ +uint64_t add_data_address;/* 0x0160 */ +uint64_t reserved168[4 ];/* 0x0168 */ +} __attribute__((packed)) __attribute__((aligned(8))); +/* Set Secure Config Parameter */ struct uv_cb_ssc {struct uv_cb_header header;
s390x/uv-host.c +1 -0
@@ -418,6 +418,7 @@ static struct cmd_list invalid_cmds[] = { { "bogus", 0x4242, sizeof(struct uv_cb_header), -1}, { "share", UVC_CMD_SET_SHARED_ACCESS, sizeof(struct uv_cb_share), BIT_UVC_CMD_SET_SHARED_ACCESS }, { "unshare", UVC_CMD_REMOVE_SHARED_ACCESS, sizeof(struct uv_cb_share), BIT_UVC_CMD_REMOVE_SHARED_ACCESS }, + { "attest", UVC_CMD_ATTESTATION, sizeof(struct uv_cb_attest), BIT_UVC_CMD_ATTESTATION }, { NULL, 0, 0 }, };
Signature · 1 line
2.30.2
PATCH v4 2/5 s390x: lib: Add QUI getter
In reply to Steffen EidenSome tests need the information provided by the QUI UVC and lib/s390x/uv.c already has cached the qui result. Let's add a function to avoid unnecessary QUI UVCs.
--- lib/s390x/uv.c | 8 ++++++++ lib/s390x/uv.h | 1 + 2 files changed, 9 insertions(+)
lib/s390x/uv.c +8 -0
@@ -47,6 +47,14 @@ bool uv_query_test_call(unsigned int nr)return test_bit_inv (nr, uvcb_qui.inst_calls_list); } +const struct uv_cb_qui *uv_get_query_data (void ) +{ +/* Query needs to be called first */ +assert (uvcb_qui.header.rc); + +return &uvcb_qui; +} +int uv_setup (void ) {if (!test_facility (158 ))
lib/s390x/uv.h +1 -0
@@ -8,6 +8,7 @@bool uv_os_is_guest (void );bool uv_os_is_host (void );bool uv_query_test_call (unsigned int nr); +const struct uv_cb_qui *uv_get_query_data (void );void uv_init (void );int uv_setup (void );void uv_create_guest (struct vm *vm);
Signature · 1 line
2.30.2
Re: [kvm-unit-tests PATCH v4 2/5] s390x: lib: Add QUI getter
Quoted 5 lines · Steffen Eiden
Some tests need the information provided by the QUI UVC and
lib/s390x/uv.calready has cached the qui result. Let's add a function to avoid unnecessary QUI UVCs.Signed-off-by Steffen Eiden <[email protected]>
If you fix the issue below:
Quoted 10 lines
--- lib/s390x/uv.c | 8 ++++++++ lib/s390x/uv.h | 1 + 2 files changed, 9 insertions(+)lib/s390x/uv.c +0
-0
lib/s390x/uv.c bool uv_query_test_call(unsigned int nr) · line 53
Quoted 7 lines
lib/s390x/uv.c +4
-0@@ -47,6 +47,14 @@ bool uv_query_test_call(unsigned int nr)return test_bit_inv (nr, uvcb_qui.inst_calls_list); } +const struct uv_cb_qui *uv_get_query_data (void ) +{ +/* Query needs to be called first */ +assert (uvcb_qui.header.rc);
uvcb_qui.header.rc == 1 || uvcb_qui.header.rc == 0x100
Quoted 19 lines
lib/s390x/uv.c +4
-0+ +return &uvcb_qui; +} +int uv_setup (void ) {if (!test_facility (158 ))lib/s390x/uv.h +1
-0@@ -8,6 +8,7 @@bool uv_os_is_guest (void );bool uv_os_is_host (void );bool uv_query_test_call (unsigned int nr); +const struct uv_cb_qui *uv_get_query_data (void );void uv_init (void );int uv_setup (void );void uv_create_guest (struct vm *vm);
PATCH v4 3/5 s390x: uv-guest: remove duplicated checks
In reply to Steffen EidenRemoving some tests which are done at other points in the code implicitly.
In lib/s390x/uc.c#setup_uv(void) the rc of the qui result is verified using asserts.
The whole test is fenced by lib/s390x/uc.c#uv_os_is_guest(void) that checks if SET and REMOVE SHARED is present.
--- s390x/uv-guest.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
s390x/uv-guest.c +7 -15
@@ -69,23 +69,15 @@ static void test_query(void) cc =uv_call (0 , (u64)&uvcb);report (cc ==1 && uvcb.header.rc ==UVC_RC_INV_LEN ,"length" ); - uvcb.header.len =sizeof (uvcb); - cc =uv_call (0 , (u64)&uvcb); -report ((!cc && uvcb.header.rc ==UVC_RC_EXECUTED ) || - (cc ==1 && uvcb.header.rc ==0x100 ), -"successful query" ); -/* -* These bits have been introduced with the very first -* Ultravisor version and are expected to always be available -* because they are basic building blocks. +* BIT_UVC_CMD_QUI, BIT_UVC_CMD_SET_SHARED_ACCESS and +* BIT_UVC_CMD_REMOVE_SHARED_ACCESS are always present as they +* have been introduced with the first Ultravisor version. +* However, we only need to check for QUI as +* SET/REMOVE SHARED are used to fence this test to be only +* executed by protected guests. */ -report (test_bit_inv (BIT_UVC_CMD_QUI , &uvcb.inst_calls_list[0 ]), -"query indicated" ); -report (test_bit_inv (BIT_UVC_CMD_SET_SHARED_ACCESS , &uvcb.inst_calls_list[0 ]), -"share indicated" ); -report (test_bit_inv (BIT_UVC_CMD_REMOVE_SHARED_ACCESS , &uvcb.inst_calls_list[0 ]), -"unshare indicated" ); +report (uv_query_test_call (BIT_UVC_CMD_QUI ),"query indicated" );report_prefix_pop (); }
Signature · 1 line
2.30.2
PATCH v4 4/5 s390x: uv-guest: add share bit test
In reply to Steffen EidenThe UV facility bits shared/unshared must both be set or none.
--- s390x/uv-guest.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
s390x/uv-guest.c +14 -0
@@ -159,6 +159,14 @@ static void test_invalid(void)report_prefix_pop (); } +static void test_share_bits (void ) +{ +bool unshare =uv_query_test_call (BIT_UVC_CMD_REMOVE_SHARED_ACCESS ); +bool share =uv_query_test_call (BIT_UVC_CMD_SET_SHARED_ACCESS ); + +report (!(share ^ unshare),"share bits" ); +} +int main (void ) {bool has_uvc =test_facility (158 );
@@ -169,6 +177,12 @@ int main(void) goto done; } +/* +* Needs to be done before the guest-fence, +* as the fence tests if both shared bits are present +*/ +test_share_bits (); +if (!uv_os_is_guest ()) {report_skip ("Not a protected guest" ); goto done;
Signature · 1 line
2.30.2
Re: [kvm-unit-tests PATCH v4 4/5] s390x: uv-guest: add share bit test
Quoted 12 lines · Steffen Eiden
The UV facility bits shared/unshared must both be set or none.
Signed-off-by Steffen Eiden <[email protected]>--- s390x/uv-guest.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)s390x/uv-guest.c +0
-0
s390x/uv-guest.c static void test_invalid(void) · line 166
Quoted 8 lines
s390x/uv-guest.c +5
-0@@ -159,6 +159,14 @@ static void test_invalid(void)report_prefix_pop (); } +static void test_share_bits (void ) +{ +bool unshare =uv_query_test_call (BIT_UVC_CMD_REMOVE_SHARED_ACCESS ); +bool share =uv_query_test_call (BIT_UVC_CMD_SET_SHARED_ACCESS ); +
report_prefix_push("query");
s390x/uv-guest.c static void test_invalid(void) · line 167
Quoted 1 line
s390x/uv-guest.c +1
-0+report (!(share ^ unshare),"share bits" );
"share bits are identical" ?
report_prefix_pop();
Quoted 18 lines
s390x/uv-guest.c +8
-0+} +int main (void ) {bool has_uvc =test_facility (158 );@@ -169,6 +177,12 @@ int main(void) goto done; } +/* +* Needs to be done before the guest-fence, +* as the fence tests if both shared bits are present +*/ +test_share_bits (); +if (!uv_os_is_guest ()) {report_skip ("Not a protected guest" ); goto done;
PATCH v4 5/5 s390x: uv-guest: Add attestation tests
In reply to Steffen EidenAdds several tests to verify correct error paths of attestation.
--- lib/s390x/asm/uv.h | 5 +- s390x/Makefile | 1 + s390x/pv-attest.c | 225 +++++++++++++++++++++++++++++++++++++++++++++ s390x/uv-guest.c | 13 ++- 4 files changed, 240 insertions(+), 4 deletions(-) create mode 100644 s390x/pv-attest.c
lib/s390x/asm/uv.h +4 -1
@@ -108,7 +108,10 @@ struct uv_cb_qui {u8 reserved88[158 -136 ];/* 0x0088 */ uint16_t max_guest_cpus;/* 0x009e */ u64 uv_feature_indications;/* 0x00a0 */ -u8 reserveda8[200 -168 ];/* 0x00a8 */ +uint8_t reserveda8[224 -168 ];/* 0x00a8 */ +uint64_t supp_att_hdr_ver;/* 0x00e0 */ +uint64_t supp_paf;/* 0x00e8 */ +uint8_t reservedf0[256 -240 ];/* 0x00f0 */ } __attribute__((packed)) __attribute__((aligned(8)));struct uv_cb_cgc {
s390x/Makefile +1 -0
@@ -29,6 +29,7 @@ tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf tests += $(TEST_DIR)/firq.elf tests += $(TEST_DIR)/epsw.elf +tests += $(TEST_DIR)/pv-attest.elf pv-tests += $(TEST_DIR)/pv-diags.elf
s390x/pv-attest.c new file +225 -0
225 lines not on this page · raw message
s390x/uv-guest.c +10 -3
@@ -2,7 +2,7 @@/* * Guest Ultravisor Call tests * -* Copyright (c) 2020 IBM Corp +* Copyright IBM Corp. 2020, 2022 * * Authors: * Janosch Frank <[email protected]>
@@ -53,6 +53,15 @@ static void test_priv(void)check_pgm_int_code (PGM_INT_CODE_PRIVILEGED_OPERATION );report_prefix_pop (); +report_prefix_push ("attest" ); + uvcb.cmd =UVC_CMD_ATTESTATION ; + uvcb.len =sizeof (struct uv_cb_attest ); +expect_pgm_int (); +enter_pstate (); +uv_call_once (0 , (uint64_t )&uvcb); +check_pgm_int_code (PGM_INT_CODE_PRIVILEGED_OPERATION ); +report_prefix_pop (); +report_prefix_pop (); }
@@ -111,8 +120,6 @@ static void test_sharing(void) cc =uv_call (0 , (u64)&uvcb);report (cc ==0 && uvcb.header.rc ==UVC_RC_EXECUTED ,"unshare" );report_prefix_pop (); - -report_prefix_pop (); } static struct {
Signature · 1 line
2.30.2
Re: [kvm-unit-tests PATCH v4 5/5] s390x: uv-guest: Add attestation tests
Quoted 45 lines · Steffen Eiden
Adds several tests to verify correct error paths of attestation.
Signed-off-by Steffen Eiden <[email protected]>--- lib/s390x/asm/uv.h | 5 +- s390x/Makefile | 1 + s390x/pv-attest.c | 225 +++++++++++++++++++++++++++++++++++++++++++++ s390x/uv-guest.c | 13 ++- 4 files changed, 240 insertions(+), 4 deletions(-)create mode 100644
s390x/pv-attest.clib/s390x/asm/uv.h +4
-1@@ -108,7 +108,10 @@ struct uv_cb_qui {u8 reserved88[158 -136 ];/* 0x0088 */ uint16_t max_guest_cpus;/* 0x009e */ u64 uv_feature_indications;/* 0x00a0 */ -u8 reserveda8[200 -168 ];/* 0x00a8 */ +uint8_t reserveda8[224 -168 ];/* 0x00a8 */ +uint64_t supp_att_hdr_ver;/* 0x00e0 */ +uint64_t supp_paf;/* 0x00e8 */ +uint8_t reservedf0[256 -240 ];/* 0x00f0 */ } __attribute__((packed)) __attribute__((aligned(8)));struct uv_cb_cgc {s390x/Makefile +1
-0@@ -29,6 +29,7 @@ tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf tests += $(TEST_DIR)/firq.elf tests += $(TEST_DIR)/epsw.elf +tests += $(TEST_DIR)/pv-attest.elf pv-tests += $(TEST_DIR)/pv-diags.elfs390x/pv-attest.c new file +0
-0@@ -0,0 +1,225 @@
[...]
Quoted 31 lines
s390x/pv-attest.c new file +31
-0+ +static void test_attest_v1 (uint64_t page) +{ +struct uv_cb_attest uvcb = { + .header.cmd =UVC_CMD_ATTESTATION , + .header.len =sizeof (uvcb), + }; +const struct uv_cb_qui *uvcb_qui =uv_get_query_data (); +struct attest_request_v1 *attest_req = (void *)page; +struct uv_arcb_v1 *arcb = &attest_req->arcb; +int cc; + +report_prefix_push ("v1" ); +if (!test_bit_inv (0 , &uvcb_qui->supp_att_hdr_ver)) { +report_skip ("Attestation version 1 not supported" ); + goto done; + } + +memset ((void *)page,0 ,PAGE_SIZE ); + +/* +* Create a minimal arcb/uvcb such that FW has everything to start +* unsealing the request. However, this unsealing will fail as the +* kvm-unit-test framework provides no cryptography functions that +* would be needed to seal such requests. +*/ + arcb->req_ver =ARCB_VERSION_1 ; + arcb->req_len =sizeof (*arcb); + arcb->nks =1 ; + arcb->sea =sizeof (arcb->meas_key); + arcb->plaint_att_flags =PAF_PHKH_ATT ;
s390x/pv-attest.c line 91
Quoted 10 lines
s390x/pv-attest.c new file +10
-0+ arcb->meas_alg_id =ARCB_MEAS_HMAC_SHA512 ; + uvcb.arcb_addr = (uint64_t )&attest_req->arcb; + uvcb.measurement_address = (uint64_t )attest_req->measurement; + uvcb.measurement_length =sizeof (attest_req->measurement); + uvcb.add_data_address = (uint64_t )attest_req->additional; + uvcb.add_data_length =sizeof (attest_req->additional); + + uvcb.continuation_token =0xff ; + cc =uv_call (0 , (uint64_t )&uvcb); +report (cc ==1 && uvcb.header.rc ==0x0101 ,"invalid continuation token" );
Please don't add the 0 to the front of the rc values.
[...]
s390x/pv-attest.c static void test_sharing(void) · line 115
Quoted 6 lines
s390x/pv-attest.c new file +0
-2@@ -111,8 +120,6 @@ static void test_sharing(void) cc =uv_call (0 , (u64)&uvcb);report (cc ==0 && uvcb.header.rc ==UVC_RC_EXECUTED ,"unshare" );report_prefix_pop (); - -report_prefix_pop ();
That's unrelated, no?
Quoted 3 lines
s390x/pv-attest.c new file +0
-0} static struct {
Re: [kvm-unit-tests PATCH v4 5/5] s390x: uv-guest: Add attestation tests
Hi Janosch,
thanks for your review.
Quoted 80 lines · Janosch Frank
Quoted 42 lines · Steffen Eiden
Adds several tests to verify correct error paths of attestation.
Signed-off-by Steffen Eiden <[email protected]>---
lib/s390x/asm/uv.h| 5 +-
s390x/Makefile | 1 +
s390x/pv-attest.c | 225 +++++++++++++++++++++++++++++++++++++++++++++ s390x/uv-guest.c | 13 ++-4 files changed, 240 insertions(+), 4 deletions(-)create mode 100644
s390x/pv-attest.clib/s390x/asm/uv.h +0
-0@@ -108,7 +108,10 @@ struct uv_cb_qui {u8 reserved88[158 - 136]; /*
0x0088*/uint16_tmax_guest_cpus; /*0x009e*/ u64 uv_feature_indications; /*0x00a0*/ - u8 reserveda8[200 - 168]; /*0x00a8*/
+ uint8_t reserveda8[224 - 168]; /*0x00a8*/ +uint64_tsupp_att_hdr_ver; /*0x00e0*/
+uint64_tsupp_paf; /*0x00e8*/
+ uint8_t reservedf0[256 - 240]; /*0x00f0*/ } __attribute__((packed)) __attribute__((aligned(8))); structuv_cb_cgc{s390x/Makefile +0
-0@@ -29,6 +29,7 @@ tests += $(TEST_DIR)/mvpg-sie.elftests += $(TEST_DIR)/spec_ex-sie.elf
tests += $(TEST_DIR)/firq.elf
tests += $(TEST_DIR)/epsw.elf
+tests += $(TEST_DIR)/pv-attest.elf
pv-tests += $(TEST_DIR)/pv-diags.elfs390x/pv-attest.c new file +0
-0@@ -0,0 +1,225 @@[...]
Quoted 36 lines
s390x/pv-attest.c new file +36
-0+ +static void test_attest_v1 (uint64_t page) +{ + struct uv_cb_attest uvcb = { + .header.cmd = UVC_CMD_ATTESTATION, + .header.len = sizeof(uvcb), + }; + const struct uv_cb_qui *uvcb_qui = uv_get_query_data(); + struct attest_request_v1 *attest_req = (void *)page; + struct uv_arcb_v1 *arcb = &attest_req->arcb; + int cc; + + report_prefix_push("v1"); + if (!test_bit_inv(0, &uvcb_qui->supp_att_hdr_ver)) { + report_skip("Attestation version 1 not supported"); + goto done; + } + + memset((void *)page, 0, PAGE_SIZE); + + /* + * Create a minimal arcb/uvcb such that FW has everything to start + * unsealing the request. However, this unsealing will fail as the + * kvm-unit-test framework provides no cryptography functions that + * would be needed to seal such requests. + */ + arcb->req_ver = ARCB_VERSION_1; + arcb->req_len = sizeof(*arcb); + arcb->nks = 1; + arcb->sea = sizeof(arcb->meas_key); + arcb->plaint_att_flags = PAF_PHKH_ATT; + arcb->meas_alg_id = ARCB_MEAS_HMAC_SHA512; + uvcb.arcb_addr = (uint64_t)&attest_req->arcb; + uvcb.measurement_address = (uint64_t)attest_req->measurement; + uvcb.measurement_length = sizeof(attest_req->measurement); + uvcb.add_data_address = (uint64_t)attest_req->additional;
Quoted 8 lines
Quoted 6 lines
+ uvcb.add_data_length =
sizeof(attest_req->additional); +
+ uvcb.continuation_token =0xff;
+ cc =uv_call(0, (uint64_t)&uvcb);
+report(cc == 1 && uvcb.header.rc == 0x0101, "invalid continuation token");Please don't add the 0 to the front of the rc values.
OK
Quoted 11 lines
[...]
s390x/pv-attest.c static void test_sharing(void) · line 115
Quoted 6 lines
s390x/pv-attest.c new file +0
-2@@ -111,8 +120,6 @@ static void test_sharing(void) cc = uv_call(0, (u64)&uvcb); report(cc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "unshare"); report_prefix_pop(); - - report_prefix_pop();That's unrelated, no?
Right, it is now unrelated. I forgot to remove that change for v4.
In the previous version this double pop would mess with the output astest_sharing was not the last test in that file (attestation test followed).
I'll add another fix patch for this.
Quoted 4 lines
s390x/pv-attest.c static void test_sharing(void) · line 124
Quoted 3 lines
s390x/pv-attest.c new file +0
-0} static struct {
Steffen