platform/x86/intel/sdsi: Add ioctl SPDM transport
Subsystems (3)
David E. Box
maintainerPATCH v4 1/3 platform/x86/intel/sdsi: Add ioctl SPDM transport
Intel On Demand adds attestation and firmware measurement retrieval services through use of the protocols defined the Security Protocols and Data Measurement (SPDM) specification. SPDM messages exchanges are used to authenticate On Demand hardware and to retrieve signed measurements of the NVRAM state used to track feature provisioning and the NVRAM state used for metering services. These allow software to verify the authenticity of the On Demand hardware as well as the integrity of the reported silicon configuration.
Add an ioctl interface for sending SPDM messages through the On Demand mailbox. Provides commands to get a list of SPDM enabled devices, get the message size limits for SPDM Requesters and Responders, and perform an SPDM message exchange.
---
V4
- In sdsi_spdm_do_command(), change rsp_size from u32 to int to catch error from sdsi_spdm_exchange(). Reported by lkp.
- Use SPDM_HEADER_SIZE in sdsi_spdm_do_command()
V3
- Use %zu format for size_t
- Simplify return in sdsi_spdm_ioctl()
V2
- Move size < 4 check into sdsi_spdm_exchange() and add comment clarifying return values of that function.
- Use SZ_4K and add helpers
- Use devm_kasprintf()
- Remove unnecessary parens
- Use --attest for long option
.../userspace-api/ioctl/ioctl-number.rst | 1 + MAINTAINERS | 1 + drivers/platform/x86/intel/sdsi.c | 209 +++++++++++++++++- include/uapi/linux/intel_sdsi.h | 81 +++++++ 4 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 include/uapi/linux/intel_sdsi.h
Documentation/userspace-api/ioctl/ioctl-number.rst +1 -0
@@ -384,6 +384,7 @@ Code Seq# Include File Comments <mailto:[email protected]> 0xF8 all arch/x86/include/uapi/asm/amd_hsmp.h AMD HSMP EPYC system management interface driver <mailto:[email protected]> +0xFC all linux/intel_sdsi.h 0xFD all linux/dm-ioctl.h 0xFE all linux/isst_if.h ==== ===== ======================================================= ================================================================
MAINTAINERS +1 -0
@@ -11343,6 +11343,7 @@ INTEL SDSI DRIVER M: David E. Box <[email protected]> S: Supported F: drivers/platform/x86/intel/sdsi.c +F: include/uapi/linux/intel_sdsi.h F: tools/arch/x86/intel_sdsi/ F: tools/testing/selftests/drivers/sdsi/
drivers/platform/x86/intel/sdsi.c +208 -1
275 lines not on this page · raw message
include/uapi/linux/intel_sdsi.h new file +81 -0
81 lines not on this page · raw message
base-commit: c3f38fa61af77b49866b006939479069cd451173
Signature · 1 line
2.34.1
David E. Box
maintainerPATCH v4 2/3 tools/arch/x86/intel_sdsi: Rework Makefile
In preparation for more source files, rework the Makefile to handle prerequisites more generically, making it easier to isolate future changes. Also update PHONY targets.
---
V4 - No change.
V3 - No change.
V2 - New Patch.
tools/arch/x86/intel_sdsi/Makefile | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
tools/arch/x86/intel_sdsi/Makefile +14 -10
@@ -1,21 +1,25 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Intel Software Defined Silicon provisioning tool - -intel_sdsi: intel_sdsi.c - -CFLAGS = -Wextra - +include ../../../scripts/Makefile.include BINDIR ?= /usr/sbin -override CFLAGS += -O2 -Wall +SRCS = intel_sdsi.c -%: %.c - $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) +OBJS = $(SRCS:.c=.o) + +override CFLAGS += -O2 -Wall -Wextra + +intel_sdsi: $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $@ + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ -.PHONY : clean clean : - @rm -f intel_sdsi + @rm -f intel_sdsi $(OBJS) install : intel_sdsi install -d $(DESTDIR)$(BINDIR) install -m 755 -p intel_sdsi $(DESTDIR)$(BINDIR)/intel_sdsi + +.PHONY : clean install
Signature · 1 line
2.34.1
David E. Box
maintainerPATCH v4 3/3 tools/arch/x86/intel_sdsi: Add attestation support
In reply to David E. BoxAdd 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
---
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
tools/arch/x86/intel_sdsi/Makefile +7 -4
@@ -3,20 +3,23 @@ include ../../../scripts/Makefile.include BINDIR ?= /usr/sbin -SRCS = intel_sdsi.c +SRCS = intel_sdsi.c spdm.c OBJS = $(SRCS:.c=.o) -override CFLAGS += -O2 -Wall -Wextra +override CFLAGS += -O2 -Wall -Wextra -I../../../include -intel_sdsi: $(OBJS) +intel_sdsi: intel_sdsi.h $(OBJS) $(CC) $(CFLAGS) $(OBJS) -o $@ +intel_sdsi.h: ../../../../include/uapi/linux/intel_sdsi.h + ln -sf ../../../../include/uapi/linux/intel_sdsi.h $@ + %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ clean : - @rm -f intel_sdsi $(OBJS) + @rm -f intel_sdsi intel_sdsi.h $(OBJS) install : intel_sdsi install -d $(DESTDIR)$(BINDIR)
tools/arch/x86/intel_sdsi/intel_sdsi.c +71 -1
137 lines not on this page · raw message
tools/arch/x86/intel_sdsi/spdm.c new file +476 -0
476 lines not on this page · raw message
tools/arch/x86/intel_sdsi/spdm.h new file +13 -0
@@ -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); +
Signature · 1 line
2.34.1
Ilpo Järvinen
maintainerRe: [PATCH V4 3/3] tools/arch/x86/intel_sdsi: Add attestation support
Quoted 46 lines · David E. Box
Add support in the
intel_sdsitool to perform SPDMGET_DIGESTSandGET_CERTIFICATEcommands. Output is sent to stdout.Example reading the certificate chain from socket 0:
intel_sdsi-d 1 -attestget_certificate| openssl x509 -inform DER -nout -textSigned-off-by David E. Box <[email protected]>---
V4 - No changeV3 - No change
V2 - Remove unnecessary struct packing
- Remove newline fromperror()
- Add message options in --help output
- Use newSDSI_SPDM_BUF_SIZEfrom uapi header
- Inspdm_get_certificate:
- Initialize remainder length to the minimum of the actual size or the maximum buffer size.
- Addold_remainderto test that the remaining certificate length is less than the previous lengthtools/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.ctools/arch/x86/intel_sdsi/spdm.c new file +12
-0@@ -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. +*/
tools/arch/x86/intel_sdsi/spdm.c line 22
Quoted 10 lines
tools/arch/x86/intel_sdsi/spdm.c new file +10
-0+ +#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. :-(
tools/arch/x86/intel_sdsi/spdm.c line 112
Quoted 6 lines
tools/arch/x86/intel_sdsi/spdm.c new file +6
-0+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)
tools/arch/x86/intel_sdsi/spdm.c line 451
Quoted 9 lines
tools/arch/x86/intel_sdsi/spdm.c new file +9
-0+ 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?
Quoted 34 lines
tools/arch/x86/intel_sdsi/spdm.c new file +25
-0+ + 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; +}tools/arch/x86/intel_sdsi/spdm.h new file +3
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <stdint.h> +
tools/arch/x86/intel_sdsi/spdm.h line 13
Quoted 10 lines
tools/arch/x86/intel_sdsi/spdm.h new file +10
-0+#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.
Signature · 1 line
i.
Quoted 9 lines · David E. Box
Intel On Demand adds attestation and firmware measurement retrieval services through use of the protocols defined the Security Protocols and Data Measurement (SPDM) specification. SPDM messages exchanges are used to authenticate On Demand hardware and to retrieve signed measurements of the NVRAM state used to track feature provisioning and the NVRAM state used for metering services. These allow software to verify the authenticity of the On Demand hardware as well as the integrity of the reported silicon configuration.
Quoted 4 lines
Add an ioctl interface for sending SPDM messages through the On Demand mailbox. Provides commands to get a list of SPDM enabled devices, get the message size limits for SPDM Requesters and Responders, and perform an SPDM message exchange.
I've amended the in-kernel SPDM implementation to expose signatures received from the device in sysfs, together with all ancillary data necessary to re-verify signatures from user space (transcript, hash algorithm, etc). It is also possible to set the next requester nonce from user space if the kernel is mistrusted to always use a fresh nonce.
See the two top-most commits on this branch:
https://github.com/l1k/linux/commits/doe
I intend to submit these patches by end of June. There are two things still missing before I can resubmit: Exposure of certificate chains in sysfs (currently a WIP) and expiration of older signatures (to limit the amount of memory consumed for their storage). After submission, I intend to forward-port your measurement patch in Q3.
I recall S3M folks rejected use of the in-kernel SPDM implementation for SDSi because it previously didn't allow for re-verification of signatures by user space. Perhaps with the added functionality they'll reconsider?
Thanks,
Lukas
David E. Box
maintainerHi Lukas,
Quoted 37 lines · Lukas Wunner
Quoted 37 lines · David E. Box
Quoted 13 lines
Quoted 13 lines
Intel On Demand adds attestation and firmware measurement retrieval services through use of the protocols defined the Security Protocols and Data Measurement (SPDM) specification. SPDM messages exchanges are used to
authenticate On Demand hardware and to retrieve signed measurements of the
NVRAM state used to track feature provisioning and the NVRAM state used for
metering services. These allow software to verify the authenticity of the
On Demand hardware as well as the integrity of the reported silicon configuration.Quoted 6 lines
Quoted 6 lines
Add an ioctl interface for sending SPDM messages through the On Demand mailbox. Provides commands to get a list of SPDM enabled devices, get the
message size limits for SPDM Requesters and Responders, and perform an SPDM
message exchange.I've amended the in-kernel SPDM implementation to expose signatures received from the device in sysfs, together with all ancillary data necessary to re-verify signatures from user space (transcript, hash algorithm, etc). It is also possible to set the next requester nonce from user space if the kernel is mistrusted to always use a fresh nonce.
See the two top-most commits on this branch:
https://github.com/l1k/linux/commits/doe
I intend to submit these patches by end of June. There are two things still missing before I can resubmit: Exposure of certificate chains in sysfs (currently a WIP) and expiration of older signatures (to limit the amount of memory consumed for their storage). After submission, I intend to forward-port your measurement patch in Q3.
Quoted 3 lines
Quoted 3 lines
I recall S3M folks rejected use of the in-kernel SPDM implementation for SDSi because it previously didn't allow for re-verification of signatures by user space.
Yes, this was the main reason for not going with the in-kernel solution.
Quoted 1 line
Quoted 1 line
Perhaps with the added functionality they'll reconsider?
Q3 is too late for their needs. They want to proceed with the driver solution. We can push for using the in-kernel solution when it is upstreamed. I think this will be possible when they extend support beyond SPDM v1.0.
David
Quoted 4 lines
Quoted 4 lines
Thanks,
Lukas
Quoted 16 lines · David E. Box
Quoted 11 lines · Lukas Wunner
Quoted 11 lines · David E. Box
Quoted 3 lines
Quoted 3 lines
Intel On Demand adds attestation and firmware measurement retrieval services through use of the protocols defined the Security Protocols and Data Measurement (SPDM) specification.
I've amended the in-kernel SPDM implementation to expose signatures received from the device in sysfs, together with all ancillary data necessary to re-verify signatures from user space (transcript, hash algorithm, etc). It is also possible to set the next requester nonce from user space if the kernel is mistrusted to always use a fresh nonce.
Quoted 3 lines
Quoted 3 lines
I recall S3M folks rejected use of the in-kernel SPDM implementation for SDSi because it previously didn't allow for re-verification of signatures by user space.
Quoted 8 lines
Yes, this was the main reason for not going with the in-kernel solution.
Quoted 1 line
Quoted 1 line
Perhaps with the added functionality they'll reconsider?
Q3 is too late for their needs. They want to proceed with the driver solution. We can push for using the in-kernel solution when it is upstreamed. I think this will be possible when they extend support beyond SPDM v1.0.
Fair enough. I've submitted v2 of the in-kernel SPDM library yesterday:
https://lore.kernel.org/all/[email protected]/
It would be good to know if the ABI for exposure of certificates and signatures makes sense and would integrate easily with SDSi user space tooling. Or if it does not, how I should change it. So I'd love to hear feedback. The ABI documentation is contained in these patches:
* [PATCH v2 12/18] PCI/CMA: Expose certificates in sysfs
https://lore.kernel.org/all/e42905e3e5f1d5be39355e833fefc349acb0b03c.1719771133.git.lukas@wunner.de/
* [PATCH v2 15/18] PCI/CMA: Expose a log of received signatures in sysfs
https://lore.kernel.org/all/77f549685f994981c010aebb1e9057aa3555b18a.1719771133.git.lukas@wunner.de/
* [PATCH v2 16/18] spdm: Limit memory consumed by log of received signatures
https://lore.kernel.org/all/2e6ee6670a5d450bc880e77a892ea0227a2cc3b4.1719771133.git.lukas@wunner.de/
* [PATCH v2 17/18] spdm: Authenticate devices despite invalid certificate chain
https://lore.kernel.org/all/dff8bcb091a3123e1c7c685f8149595e39bbdb8f.1719771133.git.lukas@wunner.de/
* [PATCH v2 18/18] spdm: Allow control of next requester nonce through sysfs
https://lore.kernel.org/all/ee3248f9f8d60cff9106a5a46c5f5d53ac81e60a.1719771133.git.lukas@wunner.de/
This doesn't yet contain measurement retrieval, which I understand is needed for SDSi. I intend to add it this (third) quarter.
Thanks,
Lukas
Ilpo Järvinen
maintainerQuoted 45 lines · David E. Box
Intel On Demand adds attestation and firmware measurement retrieval services through use of the protocols defined the Security Protocols and Data Measurement (SPDM) specification. SPDM messages exchanges are used to authenticate On Demand hardware and to retrieve signed measurements of the NVRAM state used to track feature provisioning and the NVRAM state used for metering services. These allow software to verify the authenticity of the On Demand hardware as well as the integrity of the reported silicon configuration.
Add an ioctl interface for sending SPDM messages through the On Demand mailbox. Provides commands to get a list of SPDM enabled devices, get the message size limits for SPDM Requesters and Responders, and perform an SPDM message exchange.
Signed-off-by David E. Box <[email protected]>---
V4
- Insdsi_spdm_do_command(), changersp_sizefrom u32 to int to catch error fromsdsi_spdm_exchange(). Reported by lkp.
- UseSPDM_HEADER_SIZEinsdsi_spdm_do_command()
V3
- Use %zu format forsize_t
- Simplify return insdsi_spdm_ioctl()V2
- Move size < 4 check intosdsi_spdm_exchange()and add comment clarifying return values of that function.
- UseSZ_4Kand add helpers
- Usedevm_kasprintf()
- Remove unnecessary parens
- Use --attest for long option.../userspace-api/ioctl/ioctl-number.rst | 1 + MAINTAINERS | 1 + drivers/platform/x86/intel/sdsi.c | 209 +++++++++++++++++- include/uapi/linux/intel_sdsi.h | 81 +++++++ 4 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 include/uapi/linux/intel_sdsi.hinclude/uapi/linux/intel_sdsi.h new file +0
-0
include/uapi/linux/intel_sdsi.h line 57
Quoted 9 lines
include/uapi/linux/intel_sdsi.h new file +8
-0+/** +* struct sdsi_spdm_message - The SPDM message sent and received from the device +* @spdm_version: Supported SPDM version +* @request_response_code: The SPDM message code for requests and responses +* @param1: Parameter 1 +* @param2: Parameter 2 +* @buffer: SDPM message specific buffer +*
Extra newline here.
Quoted 5 lines
+ */
include/uapi/linux/intel_sdsi.h new file +4
-0+struct sdsi_spdm_message { +SPDM_HEADER ; +__u8 buffer[SZ_4K -SPDM_HEADER_SIZE ]; +};
Signature · 1 line
i.