From patchwork Thu Apr 21 09:45:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffen Eiden X-Patchwork-Id: 12821388 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75B2BC433EF for ; Thu, 21 Apr 2022 09:45:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387886AbiDUJse (ORCPT ); Thu, 21 Apr 2022 05:48:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387819AbiDUJs1 (ORCPT ); Thu, 21 Apr 2022 05:48:27 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1490240A5; Thu, 21 Apr 2022 02:45:37 -0700 (PDT) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23L9ckDo011724; Thu, 21 Apr 2022 09:45:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=d6iyzaWShGXyPpjjkcAkZz1NdHZwpq/lMoyIBKZgrKU=; b=lIGDSOwXhRSVn6X0W3rC9T3dQCiVOWM5lrbH+TLW1W9nKUHeUdrmHi+MUpg5CM7jHmfQ hgsIuqmnnwDQaanB74tBy7TYHVx8Kn8uDwQrQ9FevZEE8x9guiMDO+kTCCgVADJrCXXB Lb1/yztDArkagDVGJpV8gJP7HtkE3tgTU+bT5LZSe8knYRbgEEM/EZEO++ALuAh1qGGT /O6MUmmcq+1WzbEFvyRzzJygSixlARSDEsrzJgVqPuz+vo3OxXpoeVmkek/piHP3yq0Z z0egzFqsdXkqFeJZhASsTeyZS0uBmGST9ZLboGLe1Y1U5LyPigB2Oxd7i/7O+DmZXsgk qg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fjff3ht07-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:37 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 23L9jbv4019904; Thu, 21 Apr 2022 09:45:37 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fjff3hsy5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:36 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23L9dCfs003562; Thu, 21 Apr 2022 09:45:32 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03fra.de.ibm.com with ESMTP id 3ffne961ye-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:32 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23L9jT5F58065162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Apr 2022 09:45:29 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A9E0F11C04A; Thu, 21 Apr 2022 09:45:29 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E7A8611C04C; Thu, 21 Apr 2022 09:45:28 +0000 (GMT) Received: from linux7.. (unknown [9.114.12.92]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 21 Apr 2022 09:45:28 +0000 (GMT) From: Steffen Eiden To: Thomas Huth , Janosch Frank , Claudio Imbrenda , David Hildenbrand Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v4 1/5] s390x: uv-host: Add invalid command attestation check Date: Thu, 21 Apr 2022 09:45:23 +0000 Message-Id: <20220421094527.32261-2-seiden@linux.ibm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220421094527.32261-1-seiden@linux.ibm.com> References: <20220421094527.32261-1-seiden@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ko5gCJXi1N__Il245Fd3hHWc_vwKSWgN X-Proofpoint-ORIG-GUID: ZRX7lUaFkyYGe48wqciHV--Sb1ElNJ3u X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-20_06,2022-04-20_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=999 adultscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204210052 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Adds an invalid command test for attestation in the uv-host. Signed-off-by: Steffen Eiden Reviewed-by: Janosch Frank Reviewed-by: Claudio Imbrenda --- lib/s390x/asm/uv.h | 23 ++++++++++++++++++++++- s390x/uv-host.c | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h index 70bf65c4..7c8c399d 100644 --- a/lib/s390x/asm/uv.h +++ b/lib/s390x/asm/uv.h @@ -1,7 +1,7 @@ /* * s390x Ultravisor related definitions * - * Copyright (c) 2020 IBM Corp + * Copyright IBM Corp. 2020, 2022 * * Authors: * Janosch Frank @@ -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; diff --git a/s390x/uv-host.c b/s390x/uv-host.c index d3018e3c..726bcfa5 100644 --- a/s390x/uv-host.c +++ b/s390x/uv-host.c @@ -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 }, }; From patchwork Thu Apr 21 09:45:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffen Eiden X-Patchwork-Id: 12821386 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5920C433FE for ; Thu, 21 Apr 2022 09:45:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387885AbiDUJsb (ORCPT ); Thu, 21 Apr 2022 05:48:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387839AbiDUJsZ (ORCPT ); Thu, 21 Apr 2022 05:48:25 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07D8F245BE; Thu, 21 Apr 2022 02:45:36 -0700 (PDT) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23L9SZFp004892; Thu, 21 Apr 2022 09:45:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=/pE9bxNfG6kL8HopJYYmH68KigzjetTd0Mjiknp64P8=; b=TsZSpZdShXfCbO4jQIfcGzJcF6XgV71JYOexrCy7P/7rkY/Dk2jrSFiy2fCKNiy1Go7X QlnRlq2N3K4s2i10OB9XGsg2xmKgHjfsg9gHQXFY5gxVDHDve/mlaOfd+FlwqmzjjyWT r6W1hn9fEjzdKmWe0ElJV/iSZWSE6nHdeEKZMw7QwNjU+39iuQ1fMsM7gSCPCG2wH1zO 742UUSYJQJO7HQAACyAgOcwvHEuC7sfJ7ZGwuCcq0XxVembAo6WsEEwP3SowCkuV4jqy MTvX4ldajxCT4MUL+WOzckaS4mIfuVBcvAv6VArtXLHiHdsO0V+ct4Cnlky+cDSQTQ71 mA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3fjjhfp3vx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:36 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 23L9TaJi009004; Thu, 21 Apr 2022 09:45:35 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 3fjjhfp3vf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:35 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23L9c0wm011534; Thu, 21 Apr 2022 09:45:33 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04fra.de.ibm.com with ESMTP id 3ffvt9dn55-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:33 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23L9jUmp32047584 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Apr 2022 09:45:30 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9A99111C04C; Thu, 21 Apr 2022 09:45:30 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CFBDC11C04A; Thu, 21 Apr 2022 09:45:29 +0000 (GMT) Received: from linux7.. (unknown [9.114.12.92]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 21 Apr 2022 09:45:29 +0000 (GMT) From: Steffen Eiden To: Thomas Huth , Janosch Frank , Claudio Imbrenda , David Hildenbrand Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v4 2/5] s390x: lib: Add QUI getter Date: Thu, 21 Apr 2022 09:45:24 +0000 Message-Id: <20220421094527.32261-3-seiden@linux.ibm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220421094527.32261-1-seiden@linux.ibm.com> References: <20220421094527.32261-1-seiden@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: B0zysBrGP3OW_S-vxBff1I3CqCa5rNvb X-Proofpoint-GUID: Ky2CVgtt9fjj9f1H-773coWIMA5BlHSa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-20_06,2022-04-20_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 mlxscore=0 impostorscore=0 suspectscore=0 clxscore=1015 malwarescore=0 spamscore=0 mlxlogscore=999 lowpriorityscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204210052 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Some 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. Signed-off-by: Steffen Eiden Reviewed-by: Janosch Frank --- lib/s390x/uv.c | 8 ++++++++ lib/s390x/uv.h | 1 + 2 files changed, 9 insertions(+) diff --git a/lib/s390x/uv.c b/lib/s390x/uv.c index 6fe11dff..602cbbfc 100644 --- a/lib/s390x/uv.c +++ b/lib/s390x/uv.c @@ -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)) diff --git a/lib/s390x/uv.h b/lib/s390x/uv.h index 8175d9c6..44264861 100644 --- a/lib/s390x/uv.h +++ b/lib/s390x/uv.h @@ -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); From patchwork Thu Apr 21 09:45:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffen Eiden X-Patchwork-Id: 12821387 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BE1AC43219 for ; Thu, 21 Apr 2022 09:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387883AbiDUJsc (ORCPT ); Thu, 21 Apr 2022 05:48:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387858AbiDUJs3 (ORCPT ); Thu, 21 Apr 2022 05:48:29 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72B9125C74; Thu, 21 Apr 2022 02:45:38 -0700 (PDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23L9GaAg007990; Thu, 21 Apr 2022 09:45:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=ayq88onlxV92hKR0dP6eKjRmjM6rdQBMYSPSToOWGd4=; b=KHmJGLUE+EQ8tj4Sp4BNaPrwLl26+Mt3v+l5gzKgQkcP2NgIAyU1zLvND+R/U49ZT8kn boVK8qRxDz4h8V95cmDD2ktXe71MkTKvFsLIn+WQVCqXcbC5pS4ime6fhXjGF5h9TaRO K6rC3xKaBcH7wY8a0913ldhw4Z1N7/u8OGgy0mJkrDO66F/LSlIQOVBJ2KJprwjKD7Ie Fd/s/naV2QZ8+q/DW+hvKQDvvd9+Boj0hRuri2CPUlmdOk9OvnD8jyNj8hRfIjhEMG1c 4MCMwtpcoABlO52nlUXKGgm4VbvTEFYSPCzabnNBi7nB52uIjP1k5yWJZwTuckSFVw/7 Zg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fjhsy70kn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:37 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 23L9XXj0014747; Thu, 21 Apr 2022 09:45:37 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fjhsy70k6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:37 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23L9dLYh014180; Thu, 21 Apr 2022 09:45:35 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma04ams.nl.ibm.com with ESMTP id 3ffne97mjr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:34 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23L9jg332949790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Apr 2022 09:45:42 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 81AF811C052; Thu, 21 Apr 2022 09:45:31 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C078811C04A; Thu, 21 Apr 2022 09:45:30 +0000 (GMT) Received: from linux7.. (unknown [9.114.12.92]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 21 Apr 2022 09:45:30 +0000 (GMT) From: Steffen Eiden To: Thomas Huth , Janosch Frank , Claudio Imbrenda , David Hildenbrand Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v4 3/5] s390x: uv-guest: remove duplicated checks Date: Thu, 21 Apr 2022 09:45:25 +0000 Message-Id: <20220421094527.32261-4-seiden@linux.ibm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220421094527.32261-1-seiden@linux.ibm.com> References: <20220421094527.32261-1-seiden@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: u-8RI6FLuPA_Fhp2QLN8OIX5_Y79z8EB X-Proofpoint-GUID: X7l4ikpCb0KRLAqKoMIYDMS2On0S8_h5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-20_06,2022-04-20_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 adultscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 phishscore=0 bulkscore=0 suspectscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204210052 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Removing 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. Signed-off-by: Steffen Eiden Reviewed-by: Janosch Frank --- s390x/uv-guest.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c index 99120cae..728c60aa 100644 --- a/s390x/uv-guest.c +++ b/s390x/uv-guest.c @@ -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(); } From patchwork Thu Apr 21 09:45:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffen Eiden X-Patchwork-Id: 12821389 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 782B2C433F5 for ; Thu, 21 Apr 2022 09:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387892AbiDUJsg (ORCPT ); Thu, 21 Apr 2022 05:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387881AbiDUJsa (ORCPT ); Thu, 21 Apr 2022 05:48:30 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06CFA27145; Thu, 21 Apr 2022 02:45:38 -0700 (PDT) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23L6hCfe025278; Thu, 21 Apr 2022 09:45:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=btGRwvF7AFlYnTVHmc0uCAheHymyGzGwFIweOZtQICQ=; b=ec5ZoObLLPIIhgLtz4yz4bEdX9EP5V7HOyBuW5JopEY3zaHgE8JzPKQeBLGMiO9So65s mEM1bFWBdqgCCRcsGM3OAKvAAIjA0rr9JTiLaVDyv4u0dxCersU6jXHxZ8zYX1DlvVpx q9ZnJYDFXBewYfH9ko4lj9x/B//mQltN3uN795rB/IBd3RtZu71fqd1WdDS4WdIdn8IF VQiUFatt/BGiFkSGIv11Gr+LTziKQhX7QCRkJ1kANv6JE0XHRPMb9kKRLjfmc+CAvuuf 0c8UOp/upt/1fIjprpG9lW0prq6D5guoE6HqOtOFGp3rx3xQ9+K53LFCafjyqRrZVXMn wA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3fjf52jspx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:37 +0000 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 23L9c37H009841; Thu, 21 Apr 2022 09:45:37 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 3fjf52jsph-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:37 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23L9cYlq000623; Thu, 21 Apr 2022 09:45:35 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06ams.nl.ibm.com with ESMTP id 3ffn2hyn29-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:35 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23L9Wgmd14745992 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Apr 2022 09:32:42 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 724C411C050; Thu, 21 Apr 2022 09:45:32 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A7B6911C04A; Thu, 21 Apr 2022 09:45:31 +0000 (GMT) Received: from linux7.. (unknown [9.114.12.92]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 21 Apr 2022 09:45:31 +0000 (GMT) From: Steffen Eiden To: Thomas Huth , Janosch Frank , Claudio Imbrenda , David Hildenbrand Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v4 4/5] s390x: uv-guest: add share bit test Date: Thu, 21 Apr 2022 09:45:26 +0000 Message-Id: <20220421094527.32261-5-seiden@linux.ibm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220421094527.32261-1-seiden@linux.ibm.com> References: <20220421094527.32261-1-seiden@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: pmohFkCkvBV1qNxOFUYIUHXOppppXpkx X-Proofpoint-ORIG-GUID: YyMq1S2IrsUfH5qhlJIahx0l3IenLQM0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-20_06,2022-04-20_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 spamscore=0 phishscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204210052 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The UV facility bits shared/unshared must both be set or none. Signed-off-by: Steffen Eiden --- s390x/uv-guest.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c index 728c60aa..77057bd2 100644 --- a/s390x/uv-guest.c +++ b/s390x/uv-guest.c @@ -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; From patchwork Thu Apr 21 09:45:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffen Eiden X-Patchwork-Id: 12821390 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19A54C433F5 for ; Thu, 21 Apr 2022 09:45:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387902AbiDUJsl (ORCPT ); Thu, 21 Apr 2022 05:48:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387851AbiDUJsb (ORCPT ); Thu, 21 Apr 2022 05:48:31 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 468D5275C6; Thu, 21 Apr 2022 02:45:40 -0700 (PDT) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23L85A2O010244; Thu, 21 Apr 2022 09:45:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=Hx8OvNmHZCDXkNA6N9lcxhIbKxKAVhtOS8Nop2tf8Hk=; b=mIsSye2maneQpg1BO4Mh+kVphhbmVPx7aaP+n80rNKdQUA6WMy4N86+Sx/hNkeYb7qMN IiCzWIwhlPw6DI2PF0+qjUAPGfbgmOsle7FpD/9CaA4p26JbJ6mnYnfu8PaKGPPaIkka f3lEcqf/KMBGrl9h9qRhFV1Rv1XtBGo4Gs91KLs1vpn9ALs/sVmoO8efzgwr5jkffcBK GAgY8Db9W+VWOuA2oFXjvCNDIrUm01elB3A/YEgkdP9oTIGPSupO1goh7cduiojjuzvP 2i4mddPRE6F0/84Yg+HGxcCjkLmU18bf8bghDiSElamABUHFJ7mjdlBWJ31wz4Ty3BBf Pw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fjsweknrb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:39 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 23L9jcML018886; Thu, 21 Apr 2022 09:45:38 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fjsweknqt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:38 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23L9c0wn011534; Thu, 21 Apr 2022 09:45:36 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04fra.de.ibm.com with ESMTP id 3ffvt9dn58-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 09:45:36 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23L9jXnL38469952 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Apr 2022 09:45:33 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4F64211C04A; Thu, 21 Apr 2022 09:45:33 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 986D511C050; Thu, 21 Apr 2022 09:45:32 +0000 (GMT) Received: from linux7.. (unknown [9.114.12.92]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 21 Apr 2022 09:45:32 +0000 (GMT) From: Steffen Eiden To: Thomas Huth , Janosch Frank , Claudio Imbrenda , David Hildenbrand Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v4 5/5] s390x: uv-guest: Add attestation tests Date: Thu, 21 Apr 2022 09:45:27 +0000 Message-Id: <20220421094527.32261-6-seiden@linux.ibm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220421094527.32261-1-seiden@linux.ibm.com> References: <20220421094527.32261-1-seiden@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: QF_opacOIrvt5jUfZkooj9yTBnCZ42vl X-Proofpoint-GUID: cbBqJ5y2D1rl57T-x0pz44ggMzsyocJh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-20_06,2022-04-20_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 phishscore=0 suspectscore=0 adultscore=0 clxscore=1015 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204210052 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Adds several tests to verify correct error paths of attestation. Signed-off-by: Steffen Eiden --- 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 diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h index 7c8c399d..38920461 100644 --- a/lib/s390x/asm/uv.h +++ b/lib/s390x/asm/uv.h @@ -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 { diff --git a/s390x/Makefile b/s390x/Makefile index 8ff84db5..5a49d1e7 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -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 diff --git a/s390x/pv-attest.c b/s390x/pv-attest.c new file mode 100644 index 00000000..e31780a3 --- /dev/null +++ b/s390x/pv-attest.c @@ -0,0 +1,225 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Retrieve Attestation Measurement Utravisor Call tests + * + * Copyright IBM Corp. 2022 + * + * Authors: + * Steffen Eiden + */ + +#include +#include +#include +#include +#include +#include +#include + +#define ARCB_VERSION_NONE 0 +#define ARCB_VERSION_1 0x0100 +#define ARCB_MEAS_NONE 0 +#define ARCB_MEAS_HMAC_SHA512 1 +#define MEASUREMENT_SIZE_HMAC_SHA512 64 +#define PAF_PHKH_ATT (1ULL << 61) +#define ADDITIONAL_SIZE_PAF_PHKH_ATT 32 +/* arcb with one key slot and no nonce */ +struct uv_arcb_v1 { + uint64_t reserved0; /* 0x0000 */ + uint32_t req_ver; /* 0x0008 */ + uint32_t req_len; /* 0x000c */ + uint8_t iv[12]; /* 0x0010 */ + uint32_t reserved1c; /* 0x001c */ + uint8_t reserved20[7]; /* 0x0020 */ + uint8_t nks; /* 0x0027 */ + int32_t reserved28; /* 0x0028 */ + uint32_t sea; /* 0x002c */ + uint64_t plaint_att_flags; /* 0x0030 */ + uint32_t meas_alg_id; /* 0x0038 */ + uint32_t reserved3c; /* 0x003c */ + uint8_t cpk[160]; /* 0x0040 */ + uint8_t key_slot[80]; /* 0x00e0 */ + uint8_t meas_key[64]; /* 0x0130 */ + uint8_t tag[16]; /* 0x0170 */ +} __attribute__((packed)); + +struct attest_request_v1 { + struct uv_arcb_v1 arcb; + uint8_t measurement[MEASUREMENT_SIZE_HMAC_SHA512]; + uint8_t additional[ADDITIONAL_SIZE_PAF_PHKH_ATT]; +}; + +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; + 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"); + uvcb.continuation_token = 0; + + uvcb.user_data_length = sizeof(uvcb.user_data) + 1; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x0102, "invalid user data size"); + uvcb.user_data_length = 0; + + uvcb.arcb_addr = get_ram_size() + PAGE_SIZE; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x0103, "invalid address arcb"); + uvcb.arcb_addr = page; + + /* 0104 - 0105 need an unseal-able request */ + + arcb->req_ver = ARCB_VERSION_NONE; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x0106, "unsupported version"); + arcb->req_ver = ARCB_VERSION_1; + + arcb->req_len += 1; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x0107, "arcb too big"); + arcb->req_len -= 1; + + /* + * The arcb needs to grow as well if number of key slots (nks) + * is increased. However, this is not the case and there is no explicit + * 'too many/less nks for that arcb size' error code -> expect 0x0107 + */ + arcb->nks = 2; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x0107, "too many nks for arcb"); + arcb->nks = 1; + + arcb->nks = 0; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x0108, "invalid num key slots"); + arcb->nks = 1; + + /* + * Possible valid size (when using nonce). + * However, req_len too small to host a nonce + */ + arcb->sea = 80; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x0109, "encrypted size too big"); + arcb->sea = 17; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x0109, "encrypted size too small"); + arcb->sea = 64; + + arcb->plaint_att_flags = uvcb_qui->supp_paf ^ GENMASK_ULL(63, 0); + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x010a, "invalid flag"); + arcb->plaint_att_flags = PAF_PHKH_ATT; + + arcb->meas_alg_id = ARCB_MEAS_NONE; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x010b, "invalid measurement algorithm"); + arcb->meas_alg_id = ARCB_MEAS_HMAC_SHA512; + + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x010c, "unable unseal"); + + uvcb.measurement_length = 0; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x010d, "invalid measurement size"); + uvcb.measurement_length = sizeof(attest_req->measurement); + + uvcb.add_data_length = 0; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x010e, "invalid additional size"); + uvcb.add_data_length = sizeof(attest_req->additional); + +done: + report_prefix_pop(); +} + +static void test_attest(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(); + int cc; + + /* Verify that the UV supports at least one header version */ + report(uvcb_qui->supp_att_hdr_ver, "has hdr support"); + + memset((void *)page, 0, PAGE_SIZE); + + uvcb.header.len -= 1; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc && uvcb.header.rc == UVC_RC_INV_LEN, "uvcb too small"); + uvcb.header.len += 1; + + uvcb.header.len += 1; + cc = uv_call(0, (uint64_t)&uvcb); + report(cc && uvcb.header.rc == UVC_RC_INV_LEN, "uvcb too large"); + uvcb.header.len -= 1; +} + +int main(void) +{ + bool has_uvc = test_facility(158); + uint64_t page; + + + report_prefix_push("attestation"); + if (!has_uvc) { + report_skip("Ultravisor call facility is not available"); + goto done; + } + + if (!uv_os_is_guest()) { + report_skip("Not a protected guest"); + goto done; + } + + if (!uv_query_test_call(BIT_UVC_CMD_ATTESTATION)) { + report_skip("Attestation not supported."); + goto done; + } + + page = (uint64_t)alloc_page(); + /* The privilege check is done in uv-guest.c */ + test_attest(page); + test_attest_v1(page); + free_page((void *)page); +done: + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c index 77057bd2..c3a90614 100644 --- a/s390x/uv-guest.c +++ b/s390x/uv-guest.c @@ -2,7 +2,7 @@ /* * Guest Ultravisor Call tests * - * Copyright (c) 2020 IBM Corp + * Copyright IBM Corp. 2020, 2022 * * Authors: * Janosch Frank @@ -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 {