From patchwork Thu Feb 27 12:20:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Grimm X-Patchwork-Id: 1245842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48SsxJ3FvMz9sP7 for ; Thu, 27 Feb 2020 23:51:32 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48SsxJ14MlzDr5l for ; Thu, 27 Feb 2020 23:51:32 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=grimm@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 48SsKF0B1kzDqjd for ; Thu, 27 Feb 2020 23:23:44 +1100 (AEDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01RCLkgG118148 for ; Thu, 27 Feb 2020 07:23:43 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ydq6j5nwh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 27 Feb 2020 07:23:43 -0500 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 01RCLmHd118278 for ; Thu, 27 Feb 2020 07:23:43 -0500 Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ydq6j5nvv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Feb 2020 07:23:42 -0500 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 01RCFKpL009543; Thu, 27 Feb 2020 12:23:41 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma03wdc.us.ibm.com with ESMTP id 2ydcmkw5ca-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Feb 2020 12:23:41 +0000 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01RCNd7m12648750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Feb 2020 12:23:39 GMT Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 276556A04D; Thu, 27 Feb 2020 12:23:39 +0000 (GMT) Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 331AA6A051; Thu, 27 Feb 2020 12:23:38 +0000 (GMT) Received: from alain.ibm.com (unknown [9.80.218.175]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 27 Feb 2020 12:23:38 +0000 (GMT) From: Ryan Grimm To: oohall@gmail.com Date: Thu, 27 Feb 2020 07:20:41 -0500 Message-Id: <20200227122042.32692-16-grimm@linux.ibm.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200227122042.32692-1-grimm@linux.ibm.com> References: <20200227122042.32692-1-grimm@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-02-27_03:2020-02-26, 2020-02-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 spamscore=0 impostorscore=0 suspectscore=1 bulkscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 malwarescore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002270100 Subject: [Skiboot] [RFC PATCH v4 15/16] ultravisor: Pickup wraping key data from mambo X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: janani@us.ibm.com, suka@us.ibm.com, skiboot@lists.ozlabs.org Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" From: Michael Anderson Signed-off-by: Michael Anderson --- external/mambo/skiboot.tcl | 77 ++++++++++++++++++++++++++++++++++++++ include/ultravisor.h | 2 + platforms/mambo/uv.c | 39 +++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 platforms/mambo/uv.c diff --git a/external/mambo/skiboot.tcl b/external/mambo/skiboot.tcl index f6e0ee9e..b4bf75c2 100644 --- a/external/mambo/skiboot.tcl +++ b/external/mambo/skiboot.tcl @@ -95,6 +95,9 @@ mconfig net_mac MAMBO_NET_MAC 00:11:22:33:44:55 # Net: What is the name of the tap device mconfig net_tapdev MAMBO_NET_TAPDEV "tap0" +# TPM Wrapping Directory for key files +mconfig wrapkey_dir WRAPKEY_DIR none + # Enable (default) or disable the "speculation-policy-favor-security" setting, # set to 0 to disable. When enabled it causes Linux's RFI flush to be enabled. mconfig speculation_policy_favor_security MAMBO_SPECULATION_POLICY_FAVOR_SECURITY 1 @@ -333,6 +336,80 @@ foreach pmem_size $pmem_sizes { # PMEM_VOLATILE set pmem_start [pmem_node_add $pmem_root $pmem_start $pmem_size] } +# +# Add files to simulate TPM wrapping keys. +# wrapping-key-policy-a +# wrapping-key-policy-b +# wrapping-key-passwd +# wrapping-key-publicname +# + +proc add_key_prop { k_file node p_name } { + set key_list [list] + set f [open $k_file r] + + while {1} { + set key_byte [read $f 2] + if {[eof $f]} { + close $f + break + } + lappend key_list $key_byte + } + + mysim of addprop $node byte_array $p_name $key_list +} + +if { $mconf(wrapkey_dir) != "none" } { + set tpm_node [ mysim of addchild $root_node "tpm_sim" "" ] + mysim of addprop $tpm_node string "compatible" "uv,tpm_sim" + + # policy-a.txt + if {[file exists $mconf(wrapkey_dir)/policy-a.txt]} { + puts "Using policy-a.txt" + add_key_prop $mconf(wrapkey_dir)/policy-a.txt $tpm_node "wrapping-key-policy-a" + } else { + puts "ERROR: Could not find policy-a.txt in : $mconf(wrapkey_dir)" + exit + } + + # policy-b.txt + if {[file exists $mconf(wrapkey_dir)/policy-b.txt]} { + puts "Using policy-b.txt" + add_key_prop $mconf(wrapkey_dir)/policy-b.txt $tpm_node "wrapping-key-policy-b" + } else { + puts "ERROR: Could not find policy-b.txt in : $mconf(wrapkey_dir)" + exit + } + + # wrapping-key-passwd + if {[file exists $mconf(wrapkey_dir)/wrapping-key-passwd.txt]} { + puts "Using wrapping-key-passwd.txt" + add_key_prop $mconf(wrapkey_dir)/wrapping-key-passwd.txt $tpm_node "wrapping-key-passwd" + } else { + puts "ERROR: Could not find wrapping-key-passwd.txt in : $mconf(wrapkey_dir)" + exit + } + + # wrapping-key-publicname + if {[file exists $mconf(wrapkey_dir)/wrapping-key-publicname.txt]} { + puts "Using wrapping-key-publicname.txt" + add_key_prop $mconf(wrapkey_dir)/wrapping-key-publicname.txt $tpm_node "wrapping-key-publicname" + } else { + puts "ERROR: Could not find wrapping-key-publicname.txt in : $mconf(wrapkey_dir)" + exit + } + + # wrapping-key-handle + if {[file exists $mconf(wrapkey_dir)/wrapping-key-handle.txt]} { + puts "Using wrapping-key-handle.txt" + add_key_prop $mconf(wrapkey_dir)/wrapping-key-handle.txt $tpm_node "wrapping-key-handle" + } else { + puts "ERROR: Could not find wrapping-key-handle.txt in : $mconf(wrapkey_dir)" + exit + } + +} # Default NVRAM is blank and will be formatted by Skiboot if no file is provided set fake_nvram_start $cpio_end diff --git a/include/ultravisor.h b/include/ultravisor.h index 347b085d..faa1d16b 100644 --- a/include/ultravisor.h +++ b/include/ultravisor.h @@ -24,6 +24,8 @@ int start_ultravisor(void *fdt); void uv_preload_image(void); void init_uv(void); +int add_wrapping_key_mambo(void *fdt); + static inline int uv_xscom_read(u64 partid, u64 pcb_addr, u64 *val) { unsigned long retbuf[UCALL_BUFSIZE]; diff --git a/platforms/mambo/uv.c b/platforms/mambo/uv.c new file mode 100644 index 00000000..2519d240 --- /dev/null +++ b/platforms/mambo/uv.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: Apache-2.0 +/* Copyright 2016-2017 IBM Corp. */ + +const char *wrap_key_prop_str[] = { + "wrapping-key-passwd", + "wrapping-key-publicname", + "wrapping-key-policy-a", + "wrapping-key-policy-b", + NULL +}; + +int add_wrapping_key_mambo(void *fdt) +{ + struct dt_node *tpm_sim_node; + const struct dt_property *property = NULL; + int i; + + tpm_sim_node = dt_find_compatible_node(dt_root, NULL, "uv,tpm_sim"); + if (!tpm_sim_node) { + prlog(PR_INFO, "uv,tpm_sim compatible node not found\n"); + return OPAL_HARDWARE; + } + + fdt_begin_node(fdt, "ibm,uv-tpm"); + fdt_property_string(fdt, "compatible", "ibm,uv-tpm"); + + for (i = 0; wrap_key_prop_str[i] != NULL; i++) { + property = dt_find_property(tpm_sim_node, wrap_key_prop_str[i]); + if (property) { + fdt_property(fdt, wrap_key_prop_str[i], + property->prop, + property->len); + } + } + + fdt_end_node(fdt); + + return OPAL_SUCCESS; +}