Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759229AbbFBNTW (ORCPT ); Tue, 2 Jun 2015 09:19:22 -0400 Received: from mout.gmx.net ([212.227.17.22]:55888 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759200AbbFBNTL (ORCPT ); Tue, 2 Jun 2015 09:19:11 -0400 MIME-Version: 1.0 Message-ID: From: "Peter Huewe" To: "Jarkko Sakkinen" Cc: jgunthorpe@obsidianresearch.com, safford@us.ibm.com, "Jarkko Sakkinen" , "Marcel Selhorst" , "moderated list:TPM DEVICE DRIVER" , "open list" Subject: Aw: [PATCH] tpm: introduce struct tpm_buf Content-Type: text/plain; charset=UTF-8 Date: Tue, 2 Jun 2015 15:18:54 +0200 Importance: normal Sensitivity: Normal In-Reply-To: <1433250262-17200-1-git-send-email-jarkko.sakkinen@linux.intel.com> References: <1433250262-17200-1-git-send-email-jarkko.sakkinen@linux.intel.com> X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K0:dlE2Ts18s0HOHSUB12OIUe3Et/QMfUerF8O9mUAKVj2 9th0fQ1uO2NTLkTtc8IBNK/KqIZnZHvNbKBHELOILshgxVGDto oaO+ZIFWnizjOyOVFX5zcnUtXIq7JNyJu2Bgo4RimTEq6zBMIE QewTWlejNiTAQlBhj6m73eaPFohSjb3oXjmFILEJUf4SjyWOe1 etyI2Ok9E5JgMGvtVvi9mB2g2YYaQlKx4ohhgUIWlSCqd8GF8e iTuJe89p1vF7c/LbnrRW4XETC6wE0tCLaAv8xYskZuLix77xeB xB/18U= X-UI-Out-Filterresults: notjunk:1;V01:K0:1IT4l2bQZSE=:RqL03v5L/mWPBn9ANlztM9 RVEkEEnRD4XnjdTTJPyeOjwKqKD1I9eAjuQ9bSt06NMqGBf1peE+2dIztSVlQ2j6ph4UP9eT2 omV1mY3HPMbH4vXJboqpEcRRXqPf8pmsowj1oFkYptNikESwD4fBB21cBfuWrZzoJQ8Ow00e2 nTJix8TxyK+9ouAEtJyFhc8oWYPcTmdJXy6Hc/YjSheWh7rEC6Sn3YuQPKZXs0WQnh+PB6+qr 0RKwdxO7yUoic59b2HxDRt4N2vLIHhbY0kz8N8bVOYStZJpQgceW5Mw60hv/xqHpKcHxwDMJO 6yrgtzhcEOZBjyA7Z6orOnsNti4MB3g6ICz9VBrLRCTVa3Oipyrs2+i0yDa80w6C+H51skomS v5xvjSWNiI9iQHTT2yx7imvWyWhL8gi7KEI1DFgov8wQT21xHgnkC9bEkdq6azA++VrYBv3La oKbkJa/Y0A== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1968 Lines: 65 Hi, > Betreff: [PATCH] tpm: introduce struct tpm_buf > This patch introduces struct tpm_buf that provides a string buffer for > constructing TPM commands. This allows to construct variable sized TPM > commands. This feature is needed for TPM 2.0 commands in order to allow > policy authentication and algorithmic agility. > > The commands in the tpm2-cmd.c have been updated to use struct tpm_buf. > Lots of awkward length calculations could be dropped because the buffer > knows its length. > > The code is is along the lines of the string buffer code in > security/trusted/trusted.h. > > --- a/drivers/char/tpm/tpm.h > +++ b/drivers/char/tpm/tpm.h > @@ -382,6 +382,93 @@ struct tpm_cmd_t { > tpm_cmd_params params; > } __packed; > > +/* A string buffer type for constructing TPM commands. This is based on the > + * code in security/keys/trusted.h. > + */ > + > +#define TPM_BUF_SIZE 512 Where does 512 come from? What about longer commands? Isn't TPM_BUF_SIZE defined elsewhere as 4096? > > + > +struct tpm_buf { > + u8 data[TPM_BUF_SIZE]; > +}; > + > +static inline void tpm_buf_append(struct tpm_buf *buf, > + const unsigned char *data, > + unsigned int len) > +{ > + struct tpm_input_header *head = (struct tpm_input_header *) buf->data; > + > + BUG_ON((len + tpm_buf_length(buf)) > TPM_BUF_SIZE); > + > + memcpy(&buf->data[tpm_buf_length(buf)], data, len); > + head->length = cpu_to_be32(tpm_buf_length(buf) + len); > +} > + > +static inline void tpm_buf_store(struct tpm_buf *buf, > + unsigned int pos, > + const unsigned char *data, > + unsigned int len) > +{ > + BUG_ON((pos + len) > TPM_BUF_SIZE); > + > + memcpy(&buf->data[pos], data, len); Isn't the updating of the length missing? > +} Thanks, Peter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/