linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "David E. Box" <david.e.box@linux.intel.com>
Cc: linux-doc@vger.kernel.org, Hans de Goede <hdegoede@redhat.com>,
	 LKML <linux-kernel@vger.kernel.org>,
	platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH V4 3/3] tools/arch/x86/intel_sdsi: Add attestation support
Date: Sat, 6 Jul 2024 17:03:32 +0300 (EEST)	[thread overview]
Message-ID: <93ff0003-817c-a424-df05-b05b42eaebff@linux.intel.com> (raw)
In-Reply-To: <20240608034247.181843-3-david.e.box@linux.intel.com>

On Fri, 7 Jun 2024, David E. Box wrote:

> Add support in the intel_sdsi tool to perform SPDM GET_DIGESTS and
> GET_CERTIFICATE commands. Output is sent to stdout.
> 
> Example reading the certificate chain from socket 0:
> 
> intel_sdsi -d 1 -attest get_certificate | openssl x509 -inform DER -nout -text
> 
> Signed-off-by: David E. Box <david.e.box@linux.intel.com>
> ---
> V4 - No change
> 
> V3 - No change
> 
> V2 - Remove unnecessary struct packing
>    - Remove newline from perror()
>    - Add message options in --help output
>    - Use new SDSI_SPDM_BUF_SIZE from uapi header
>    - In spdm_get_certificate:
>         - Initialize remainder length to the minimum of the actual size
>           or the maximum buffer size.
>         - Add old_remainder to test that the remaining certificate
>           length is less than the previous length
> 
>  tools/arch/x86/intel_sdsi/Makefile     |  11 +-
>  tools/arch/x86/intel_sdsi/intel_sdsi.c |  72 +++-
>  tools/arch/x86/intel_sdsi/spdm.c       | 476 +++++++++++++++++++++++++
>  tools/arch/x86/intel_sdsi/spdm.h       |  13 +
>  4 files changed, 567 insertions(+), 5 deletions(-)
>  create mode 100644 tools/arch/x86/intel_sdsi/spdm.c
>  create mode 100644 tools/arch/x86/intel_sdsi/spdm.h
> 

> +++ b/tools/arch/x86/intel_sdsi/spdm.c
> @@ -0,0 +1,476 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * spdm: Lightweight Security Protocol and Data Model (SPDM) specification
> + * support code for performing attestation commands using the Intel On
> + * Demand driver ioctl interface. Intel On Demand currently supports
> + * SPDM version 1.0
> + *
> + * See the SPDM v1.0 specification at:
> + * https://www.dmtf.org/sites/default/files/standards/documents/DSP0274_1.0.1.pdf
> + *
> + * Copyright (C) 2024 Intel Corporation. All rights reserved.
> + */
> +
> +#include<linux/bits.h>
> +
> +#include<fcntl.h>
> +#include<stdio.h>
> +#include<stdlib.h>
> +#include<stdint.h>
> +#include<string.h>
> +#include<unistd.h>
> +#include<sys/ioctl.h>

All missing spaces. :-(

> +static int sdsi_process_ioctl(int ioctl_no, void *info, uint8_t dev_no)
> +{
> +	char pathname[14];
> +	int fd, ret;
> +
> +	ret = snprintf(pathname, 14, "%s%d", SDSI_DEV_PATH, dev_no);

sizeof(pathname)

> +	remainder_length = size < SDSI_SPDM_BUF_SIZE ? size : SDSI_SPDM_BUF_SIZE;
> +	old_remainder = remainder_length;
> +
> +	while (remainder_length) {
> +		uint16_t length;
> +
> +		length = remainder_length < SDSI_SPDM_BUF_SIZE ?
> +				remainder_length : SDSI_SPDM_BUF_SIZE;
> +		offset += portion_length;

The way bound check interplay with old_remainder and remainder_length in 
this code is quite convoluted and could contain some problems.

Would it work if old_remainder is set only here and the bound check 
before the loop is replaced with a plain remainder_length = size 
assignment?

> +
> +		ret = get_certificate_portion(dev_no, offset, length,
> +					      &portion_length,
> +					      &remainder_length,
> +					      c->chain);
> +		if (ret < 0)
> +			goto free_cert_chain;
> +
> +		if (!(remainder_length < old_remainder)) {
> +			fprintf(stderr, "Bad GET_CERTIFICATE length\n");
> +			ret = -1;
> +			goto free_cert_chain;
> +		}
> +
> +		old_remainder = remainder_length;
> +	}
> +
> +	c->len = offset + portion_length;
> +	return 0;
> +
> +free_cert_chain:
> +	free(c->chain);
> +	c->chain = NULL;
> +	return ret;
> +}
> diff --git a/tools/arch/x86/intel_sdsi/spdm.h b/tools/arch/x86/intel_sdsi/spdm.h
> new file mode 100644
> index 000000000000..aa7e08ffb872
> --- /dev/null
> +++ b/tools/arch/x86/intel_sdsi/spdm.h
> @@ -0,0 +1,13 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#include <stdint.h>
> +
> +#define TPM_ALG_SHA_384_SIZE 48
> +
> +struct cert_chain {
> +	void *chain;
> +	size_t len;
> +};
> +
> +int spdm_get_digests(int dev_no, uint8_t digest[TPM_ALG_SHA_384_SIZE]);
> +int spdm_get_certificate(int dev_no, struct cert_chain *c);
> +

Trailing newline.

-- 
 i.


  reply	other threads:[~2024-07-06 14:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-08  3:42 [PATCH V4 1/3] platform/x86/intel/sdsi: Add ioctl SPDM transport David E. Box
2024-06-08  3:42 ` [PATCH V4 2/3] tools/arch/x86/intel_sdsi: Rework Makefile David E. Box
2024-06-08  3:42 ` [PATCH V4 3/3] tools/arch/x86/intel_sdsi: Add attestation support David E. Box
2024-07-06 14:03   ` Ilpo Järvinen [this message]
2024-06-08 12:46 ` [PATCH V4 1/3] platform/x86/intel/sdsi: Add ioctl SPDM transport Lukas Wunner
2024-06-14 21:17   ` David E. Box
2024-07-01  8:09     ` Lukas Wunner
2024-07-06 14:05 ` Ilpo Järvinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=93ff0003-817c-a424-df05-b05b42eaebff@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=david.e.box@linux.intel.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).