Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3395000rdh; Mon, 27 Nov 2023 13:08:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxVmR1mPn+ZyAdRyfJE1wFQGIXbUHcI7kpcDOuqPj9yyBcd7L+j9Yw36j1DOQGgPl09DFa X-Received: by 2002:a17:902:9b8a:b0:1cf:cdda:8e84 with SMTP id y10-20020a1709029b8a00b001cfcdda8e84mr5573002plp.26.1701119312347; Mon, 27 Nov 2023 13:08:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701119312; cv=none; d=google.com; s=arc-20160816; b=Rv+6yv2PV9aTDpc6yOFBgJ3fNoRmUtvgtyVajWMwMdRADk5RMbJmjANlL1LVZJGcDe Pr5+eJ13zgjuCnzcMY7l8DFBJjaPdjxH9sNySMNWUQJHAeceF9+tFmO8ndqNIpg2zUmB 1QP0uNnyGmfLhM/shV0uHq7+DKzgm02QsMGSn5x6E14CHonB72cmWxo0n1v1HznTDHbO jTplpeWdBlZGVq511sH87KZM6mbvSqNcLTPJTUL8jfZLD8/nnhhYHxxixn8hj81uU4ah v7xMWh8taqMy3ld4aS+76kJ9SgQ9EMj7rTyy8kTD0rnCtV8Y/jXIYb01P9+vsvXv6IY0 Yimg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=4LopCIk+VbSRPrGHln6ohxeSl7MfENo2tZiIppXReWQ=; fh=/Aqzg51eNQmi2L7RUOUlPUcy5/p17/bUqT4vjvE+pNc=; b=zXBaSP4vtWwssz7XAa7++Zq+jmgzaTNglojCMdNBvvQ111YtDk88qBKVCLPEweH/Gw NsJ1ZFCZ4jZrvOj2dwESskI7q+vyUhuyCz7+m+2ubuYd1idEP58IyvGjKJEB3V7EpO/Q 0GbLoXQudLU2qcwi/JMct5AEoGODuTrr+QyvElvE0N8FDM/dHTcVuQN/bH/XpiIbIMIH drxcFnnR99aeU+eRZBPkm7h5nLe+pT/llXxlATI0SHw0JGoKUx54DJr2ZoU9/QmS2QNo y2L0BTWgQHK+qSnJQWxM/3eS060K6BRSDjq/6eJch6ny0eQATfyDIIr/jNPnI0hC8EyO vPWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=cbR2bmBg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id je18-20020a170903265200b001b973681493si9972144plb.16.2023.11.27.13.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 13:08:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=cbR2bmBg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id C47B780F9269; Mon, 27 Nov 2023 13:08:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231950AbjK0VIK (ORCPT + 99 others); Mon, 27 Nov 2023 16:08:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjK0VIJ (ORCPT ); Mon, 27 Nov 2023 16:08:09 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29FDE191; Mon, 27 Nov 2023 13:08:16 -0800 (PST) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARKAmpx001569; Mon, 27 Nov 2023 21:08:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pp1; bh=4LopCIk+VbSRPrGHln6ohxeSl7MfENo2tZiIppXReWQ=; b=cbR2bmBgmZTnms5y3cdrfMs2wWuK2efgBrf3dZN/JSn08sEjrK9bzdoVmuQ1g6ksgkf6 mxl/ifeSOPqfZe7LOO152c7A0wVHNiwKBG/YPZrozyxHwrTf9IAtCI0h2TvKnxoAcg0a i8zLvKMZ0DZGHEKIITmUHcPBXlr2UrvfGNDssx4FbSbYVlvz+8eq3lPPdYDt2nLv45wV OGLMmWmcZ8yZ9x6azZiC97YnjI7cRIWLsJdjM5Wpvs3ej37DYpnRaB5cUdWAnUwI/NAw QTWOnsUQNQzxNO98hetfK5b7tPqAd8HTjqwbgqseAuDt4qCVkc+G2t0tf43XQpR1g314 qw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un0mdkgm8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 21:08:11 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ARKBNTe004677; Mon, 27 Nov 2023 21:08:11 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3un0mdkgke-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 21:08:11 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARJWQiN009176; Mon, 27 Nov 2023 21:08:09 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([172.16.1.74]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3ukumybjd3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Nov 2023 21:08:09 +0000 Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3ARL89qI17892090 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 21:08:09 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E7A1F5805D; Mon, 27 Nov 2023 21:08:08 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2413058052; Mon, 27 Nov 2023 21:08:08 +0000 (GMT) Received: from [9.47.158.152] (unknown [9.47.158.152]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 27 Nov 2023 21:08:08 +0000 (GMT) Message-ID: Date: Mon, 27 Nov 2023 16:08:07 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 6/8] tpm: TPM2B formatted buffers Content-Language: en-US To: Jarkko Sakkinen , linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, James Bottomley , William Roberts , David Howells , Jason Gunthorpe , Mimi Zohar , Mario Limonciello , Jerry Snitselaar References: <20231124020237.27116-1-jarkko@kernel.org> <20231124020237.27116-7-jarkko@kernel.org> From: Stefan Berger In-Reply-To: <20231124020237.27116-7-jarkko@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: xOHUTHP6x6ahT23qLkSvmsjkl4sx1t1n X-Proofpoint-GUID: XU5Okn9GBCsD6m9LPskvoqo-KqBsw7_M Content-Transfer-Encoding: 7bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-27_19,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270147 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 27 Nov 2023 13:08:23 -0800 (PST) On 11/23/23 21:02, Jarkko Sakkinen wrote: > Declare tpm_buf_init_sized() and tpm_buf_reset_sized() for creating TPM2B > formatted buffers. These buffers are also known as sized buffers in the > specifications and literature. > > Signed-off-by: Jarkko Sakkinen Reviewed-by: Stefan Berger > --- > v2: [2021-11-21] Refine the API according to the comments for > https://lore.kernel.org/linux-integrity/20231024011531.442587-5-jarkko@kernel.org/ > --- > drivers/char/tpm/tpm-buf.c | 38 +++++++++++++++++++++++++++++++++++--- > include/linux/tpm.h | 4 ++++ > 2 files changed, 39 insertions(+), 3 deletions(-) > > diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c > index 3f39893f3bb1..099b4a56c5d5 100644 > --- a/drivers/char/tpm/tpm-buf.c > +++ b/drivers/char/tpm/tpm-buf.c > @@ -47,6 +47,36 @@ void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal) > } > EXPORT_SYMBOL_GPL(tpm_buf_reset); > > +/** > + * tpm_buf_init_sized() - Allocate and initialize a sized (TPM2B) buffer > + * @buf: A @tpm_buf > + * > + * Return: 0 or -ENOMEM > + */ > +int tpm_buf_init_sized(struct tpm_buf *buf) > +{ > + buf->data = (u8 *)__get_free_page(GFP_KERNEL); > + if (!buf->data) > + return -ENOMEM; > + > + tpm_buf_reset_sized(buf); > + return 0; > +} > +EXPORT_SYMBOL_GPL(tpm_buf_init_sized); > + > +/** > + * tpm_buf_reset_sized() - Initialize a sized buffer > + * @buf: A &tpm_buf > + */ > +void tpm_buf_reset_sized(struct tpm_buf *buf) > +{ > + buf->flags = TPM_BUF_TPM2B; > + buf->length = 2; > + buf->data[0] = 0; > + buf->data[1] = 0; > +} > +EXPORT_SYMBOL_GPL(tpm_buf_reset_sized); > + > void tpm_buf_destroy(struct tpm_buf *buf) > { > free_page((unsigned long)buf->data); > @@ -72,8 +102,6 @@ EXPORT_SYMBOL_GPL(tpm_buf_length); > */ > void tpm_buf_append(struct tpm_buf *buf, const u8 *new_data, u16 new_length) > { > - struct tpm_header *head = (struct tpm_header *)buf->data; > - > /* Return silently if overflow has already happened. */ > if (buf->flags & TPM_BUF_OVERFLOW) > return; > @@ -86,7 +114,11 @@ void tpm_buf_append(struct tpm_buf *buf, const u8 *new_data, u16 new_length) > > memcpy(&buf->data[buf->length], new_data, new_length); > buf->length += new_length; > - head->length = cpu_to_be32(buf->length); > + > + if (buf->flags & TPM_BUF_TPM2B) > + ((__be16 *)buf->data)[0] = cpu_to_be16(buf->length - 2); > + else > + ((struct tpm_header *)buf->data)->length = cpu_to_be32(buf->length); > } > EXPORT_SYMBOL_GPL(tpm_buf_append); > > diff --git a/include/linux/tpm.h b/include/linux/tpm.h > index 1d7b39b5c383..715db4a91c1f 100644 > --- a/include/linux/tpm.h > +++ b/include/linux/tpm.h > @@ -300,6 +300,8 @@ struct tpm_header { > enum tpm_buf_flags { > /* the capacity exceeded: */ > TPM_BUF_OVERFLOW = BIT(0), > + /* TPM2B format: */ > + TPM_BUF_TPM2B = BIT(1), > }; > > /* > @@ -328,6 +330,8 @@ struct tpm2_hash { > > int tpm_buf_init(struct tpm_buf *buf, u16 tag, u32 ordinal); > void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal); > +int tpm_buf_init_sized(struct tpm_buf *buf); > +void tpm_buf_reset_sized(struct tpm_buf *buf); > void tpm_buf_destroy(struct tpm_buf *buf); > u32 tpm_buf_length(struct tpm_buf *buf); > void tpm_buf_append(struct tpm_buf *buf, const u8 *new_data, u16 new_length);