From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00A41C433B4 for ; Tue, 20 Apr 2021 23:19:44 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1B30361413 for ; Tue, 20 Apr 2021 23:19:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B30361413 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:Reply-To:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Date:Cc:To:From: Subject:Message-ID:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PSKGZS9P1AcbchJ5lO/665T3EQQZuG4NVOfJwgP+btg=; b=KMvfFyPUqmlYOSU/8fA9wqQG8r HBn4YJeAS/4rKEA1Z/Z961AIgQiOccu9/pBRizYbHJQL/REp23smAHPfNGbZ5E8BO9ycCKviPs8EJ YRZ6/BE+Aei9TpnyHErn7ssa8D8BZgKVKZS4xfUVDvRLMBCYd3FSa+SvkXIj1vbeO5ERSCF0S7j0v nSIiOFLgwV2sAMQU8JnQywjitGriRFP/IiEaWoSki6tdxK1qds4YE3h9zGKBfMRJ8XTxhGuFSfKOE 9Q5dvAXLQBmzyVyWKoxkrWeetlrffztRx34SxdQinG4YomIygcze5vcutvAu37+jzoVEFaujZUOBJ STgZV9+g==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lYzcW-00DFOu-BI; Tue, 20 Apr 2021 23:17:28 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lYzcR-00DFOh-HP for linux-arm-kernel@desiato.infradead.org; Tue, 20 Apr 2021 23:17:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Content-Type:References:In-Reply-To:Date:Cc:To:Reply-To:From: Subject:Message-ID:Sender:Content-ID:Content-Description; bh=1dIihKNheRj3DD52LPeB9StYSyrd5TgRgcCXq/i15VU=; b=DV0WpOkPwiz7XTLv1zpGymWQRh Pom4875IkuN+Tijb1nz9HTei5V//Ze4sN0X60KVxwAKaYZ/Gcrm+MRbHDjzVTKG/so00CY2vj31HQ 9u1Zp8xAPH4lZHjRTnCv/Xfm+18N8kiNJklpZqypUTQ7Px7j61l4UKMmFoRCUCGWcifeIg/77rh0h SQNkMl9e0LuOuPTIG3CleIVETqzwzWRwvGEZ9REpsVokIr4V4wj5dJfhrAEzhwRQju25kRjOx/8Q1 /y61BBZPv/em4yc4QjImRKlDzQp49UHNMwXjNvFf8aQyD3QQtudvfHRB48nsKMYRugmeYPuyALxH0 DuWUiqFQ==; Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lYzcL-00CTZJ-Gk for linux-arm-kernel@lists.infradead.org; Tue, 20 Apr 2021 23:17:21 +0000 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13KN2pe7027749; Tue, 20 Apr 2021 19:17:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : reply-to : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=1dIihKNheRj3DD52LPeB9StYSyrd5TgRgcCXq/i15VU=; b=if536T0lzuNVet6LO1A4M73uVZnbs3Q5RC5RZjAbLW9v0rKYYRis5EY9Av/iHQ44qrKV vWTfN1J2xyKB6Bf1a+x+CCK6AtzB4dNY58vakUGRwRCLm4DYskuP7nbJkJ3J3aSgS9hd Gb40U8hq9vaRJvb8EzMMluA2WJ3rOZKE5DFdiYdLVrn1f4hakAZnexhGMvzfYapsmzwa HHlPjLutGr5qqNvwCmfkVrvCqCnhFoxaVuOfdnOcr8rubtUlDPYfMSSpZi0zZ6/ZyrHo do6GgHpFWtmAf05mNvdLxbH/9bELVMTobgy20EqHT3eL1M/Mr2h9kpLTAoKb7gagogzm NQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3826pbjg3w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Apr 2021 19:17:03 -0400 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13KN3Wn4030008; Tue, 20 Apr 2021 19:17:03 -0400 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com with ESMTP id 3826pbjg3k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Apr 2021 19:17:03 -0400 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13KNGjOM008572; Tue, 20 Apr 2021 23:17:02 GMT Received: from b03cxnp07027.gho.boulder.ibm.com (b03cxnp07027.gho.boulder.ibm.com [9.17.130.14]) by ppma02dal.us.ibm.com with ESMTP id 37yqaad5pd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Apr 2021 23:17:02 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13KNH1l420775312 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Apr 2021 23:17:01 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 057CB78060; Tue, 20 Apr 2021 23:17:01 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A90787805E; Tue, 20 Apr 2021 23:16:57 +0000 (GMT) Received: from jarvis.int.hansenpartnership.com (unknown [9.85.203.222]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 20 Apr 2021 23:16:57 +0000 (GMT) Message-ID: <65dcc9fa28833e6beb1eadf98b0ed3402404d693.camel@linux.ibm.com> Subject: Re: [PATCH v9 1/4] KEYS: trusted: Add generic trusted keys framework From: James Bottomley To: Sumit Garg , jarkko.sakkinen@linux.intel.com, zohar@linux.ibm.com Cc: dhowells@redhat.com, jens.wiklander@linaro.org, corbet@lwn.net, jmorris@namei.org, serge@hallyn.com, casey@schaufler-ca.com, janne.karhunen@gmail.com, daniel.thompson@linaro.org, Markus.Wamser@mixed-mode.de, lhinds@redhat.com, erpalmer@us.ibm.com, a.fatoum@pengutronix.de, keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, op-tee@lists.trustedfirmware.org Date: Tue, 20 Apr 2021 16:16:56 -0700 In-Reply-To: <20210301131127.793707-2-sumit.garg@linaro.org> References: <20210301131127.793707-1-sumit.garg@linaro.org> <20210301131127.793707-2-sumit.garg@linaro.org> User-Agent: Evolution 3.34.4 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Kxqcmd9hhCUhx8lvYAs_EcvRp6NNSOls X-Proofpoint-ORIG-GUID: HtJEB5WM4I2IjoYGEO79dIhwU6c1Xhpm X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-20_11:2021-04-20, 2021-04-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 bulkscore=0 suspectscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 clxscore=1011 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104200163 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210420_161717_708852_1E210A8A X-CRM114-Status: GOOD ( 36.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: jejb@linux.ibm.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 2021-03-01 at 18:41 +0530, Sumit Garg wrote: > Current trusted keys framework is tightly coupled to use TPM device > as an underlying implementation which makes it difficult for > implementations like Trusted Execution Environment (TEE) etc. to > provide trusted keys support in case platform doesn't posses a TPM > device. > > Add a generic trusted keys framework where underlying implementations > can be easily plugged in. Create struct trusted_key_ops to achieve > this, which contains necessary functions of a backend. > > Also, define a module parameter in order to select a particular trust > source in case a platform support multiple trust sources. In case its > not specified then implementation itetrates through trust sources > list starting with TPM and assign the first trust source as a backend > which has initiazed successfully during iteration. > > Note that current implementation only supports a single trust source > at runtime which is either selectable at compile time or during boot > via aforementioned module parameter. You never actually tested this, did you? I'm now getting EINVAL from all the trusted TPM key operations because of this patch. The reason is quite simple: this function: > index 000000000000..0db86b44605d > --- /dev/null > +++ b/security/keys/trusted-keys/trusted_core.c [...] > +static int datablob_parse(char *datablob, struct trusted_key_payload > *p) > +{ > + substring_t args[MAX_OPT_ARGS]; > + long keylen; > + int ret = -EINVAL; > + int key_cmd; > + char *c; > + > + /* main command */ > + c = strsep(&datablob, " \t"); Modifies its argument to consume tokens and separates them with NULL. so the arguments for keyctl add trusted kmk "new 34 keyhandle=0x81000001" Go into this function as datablob="new 34 keyhandle=0x81000001" After we leave it, it looks like datablob="new\034\0keyhandle=0x81000001" However here: > +static int trusted_instantiate(struct key *key, > + struct key_preparsed_payload *prep) > +{ > + struct trusted_key_payload *payload = NULL; > + size_t datalen = prep->datalen; > + char *datablob; > + int ret = 0; > + int key_cmd; > + size_t key_len; > + > + if (datalen <= 0 || datalen > 32767 || !prep->data) > + return -EINVAL; > + > + datablob = kmalloc(datalen + 1, GFP_KERNEL); > + if (!datablob) > + return -ENOMEM; > + memcpy(datablob, prep->data, datalen); > + datablob[datalen] = '\0'; > + > + payload = trusted_payload_alloc(key); > + if (!payload) { > + ret = -ENOMEM; > + goto out; > + } > + > + key_cmd = datablob_parse(datablob, payload); > + if (key_cmd < 0) { > + ret = key_cmd; > + goto out; > + } > + > + dump_payload(payload); > + > + switch (key_cmd) { > + case Opt_load: > + ret = static_call(trusted_key_unseal)(payload, > datablob); We're passing the unmodified datablob="new\034\0keyhandle=0x81000001" Into the tpm trusted_key_unseal function. However, it only sees "new" and promply gives EINVAL because you've removed the ability to process the new option from it. What should have happened is you should have moved data blob up to passed the consumed tokens, so it actually reads datablob="keyhandle=0x81000001" However, to do that you'd have to have the updated pointer passed out of your datablob_parse() above. There's also a lost !tpm2 in the check for options->keyhandle, but I suspect Jarkko lost that merging the two patches. I think what's below fixes all of this, so if you can test it for trusted_tee, I'll package it up as two separate patches fixing all of this. James --- diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c index ec3a066a4b42..7c636212429b 100644 --- a/security/keys/trusted-keys/trusted_core.c +++ b/security/keys/trusted-keys/trusted_core.c @@ -62,7 +62,7 @@ static const match_table_t key_tokens = { * * On success returns 0, otherwise -EINVAL. */ -static int datablob_parse(char *datablob, struct trusted_key_payload *p) +static int datablob_parse(char **datablob, struct trusted_key_payload *p) { substring_t args[MAX_OPT_ARGS]; long keylen; @@ -71,14 +71,14 @@ static int datablob_parse(char *datablob, struct trusted_key_payload *p) char *c; /* main command */ - c = strsep(&datablob, " \t"); + c = strsep(datablob, " \t"); if (!c) return -EINVAL; key_cmd = match_token(c, key_tokens, args); switch (key_cmd) { case Opt_new: /* first argument is key size */ - c = strsep(&datablob, " \t"); + c = strsep(datablob, " \t"); if (!c) return -EINVAL; ret = kstrtol(c, 10, &keylen); @@ -89,7 +89,7 @@ static int datablob_parse(char *datablob, struct trusted_key_payload *p) break; case Opt_load: /* first argument is sealed blob */ - c = strsep(&datablob, " \t"); + c = strsep(datablob, " \t"); if (!c) return -EINVAL; p->blob_len = strlen(c) / 2; @@ -138,7 +138,7 @@ static int trusted_instantiate(struct key *key, { struct trusted_key_payload *payload = NULL; size_t datalen = prep->datalen; - char *datablob; + char *datablob, *orig_datablob; int ret = 0; int key_cmd; size_t key_len; @@ -146,7 +146,7 @@ static int trusted_instantiate(struct key *key, if (datalen <= 0 || datalen > 32767 || !prep->data) return -EINVAL; - datablob = kmalloc(datalen + 1, GFP_KERNEL); + orig_datablob = datablob = kmalloc(datalen + 1, GFP_KERNEL); if (!datablob) return -ENOMEM; memcpy(datablob, prep->data, datalen); @@ -158,7 +158,7 @@ static int trusted_instantiate(struct key *key, goto out; } - key_cmd = datablob_parse(datablob, payload); + key_cmd = datablob_parse(&datablob, payload); if (key_cmd < 0) { ret = key_cmd; goto out; @@ -194,7 +194,7 @@ static int trusted_instantiate(struct key *key, ret = -EINVAL; } out: - kfree_sensitive(datablob); + kfree_sensitive(orig_datablob); if (!ret) rcu_assign_keypointer(key, payload); else @@ -218,7 +218,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) struct trusted_key_payload *p; struct trusted_key_payload *new_p; size_t datalen = prep->datalen; - char *datablob; + char *datablob, *orig_datablob; int ret = 0; if (key_is_negative(key)) @@ -229,7 +229,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) if (datalen <= 0 || datalen > 32767 || !prep->data) return -EINVAL; - datablob = kmalloc(datalen + 1, GFP_KERNEL); + orig_datablob = datablob = kmalloc(datalen + 1, GFP_KERNEL); if (!datablob) return -ENOMEM; @@ -241,7 +241,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) memcpy(datablob, prep->data, datalen); datablob[datalen] = '\0'; - ret = datablob_parse(datablob, new_p); + ret = datablob_parse(&datablob, new_p); if (ret != Opt_update) { ret = -EINVAL; kfree_sensitive(new_p); @@ -265,7 +265,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) rcu_assign_keypointer(key, new_p); call_rcu(&p->rcu, trusted_rcu_free); out: - kfree_sensitive(datablob); + kfree_sensitive(orig_datablob); return ret; } diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trusted-keys/trusted_tpm1.c index 4e5c50138f92..bc702ba0a596 100644 --- a/security/keys/trusted-keys/trusted_tpm1.c +++ b/security/keys/trusted-keys/trusted_tpm1.c @@ -747,6 +747,9 @@ static int getoptions(char *c, struct trusted_key_payload *pay, opt->hash = tpm2 ? HASH_ALGO_SHA256 : HASH_ALGO_SHA1; + if (!c) + return 0; + while ((p = strsep(&c, " \t"))) { if (*p == '\0' || *p == ' ' || *p == '\t') continue; @@ -944,7 +947,7 @@ static int trusted_tpm_unseal(struct trusted_key_payload *p, char *datablob) goto out; dump_options(options); - if (!options->keyhandle) { + if (!options->keyhandle && !tpm2) { ret = -EINVAL; goto out; } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel