Skip to contentSkip to conversation

PCI/CMA and SPDM library

RFC PATCH Superseded Jonathan Cameron 5 participants 14 messages Aug 4, 2021 – Mar 2, 2022

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover PCI/CMA and SPDM library

This is an RFC to start discussions about how we support the Component Measurement and Authentication (CMA) ECN (pcisig.com)

CMA provides an adaptation of the data objects and underlying protocol defined in the DMTF SPDM specification to be used to authenticate and conduct run-time measurements of the state of PCI devices (kind of like IMA for devices / firmware). This is done using a Data Object Exchange (DOE) protocol described in the ECN.

The CMA ECN is available from the PCI SIG and SPDM can be found at
https://www.dmtf.org/sites/default/files/standards/documents/DSP0274_1.1.1.pdf

CMA/SPDM is focused on establishing trust of the device by:
1) Negotiate algorithms supported.
2) Retrieve and check the certificate chain from the device against a suitable signing certificate on the host.
3) Issue a challenge to the device to verify it can sign with the private key associated with the leaf certificate.
4) (Request a measurement of device state)
5) (Establish a secure channel for further measurements or other uses)
6) (Mutual authentication)

This RFC only does steps 1-3

Testing of this patch set has been conducted against QEMU emulation of the device backed by openSPDM emulation of the SPDM protocol.

https://lore.kernel.org/qemu-devel/[email protected]/

Open questions are called out in the individual patches but the big ones are probably:

1) Certificate management.
Current code uses a _cma keyring created by the kernel, into which a suitable root certificate can be inserted from userspace.

   A=$(keyctl search %:_cma  keyring _cma)
   evmctl import ecdsaca.cert.der $A

Is this an acceptable way to load the root certificates for this purpose?

The root of the device provided certificate chain is then checked against certificates on this keychain, but is itself (with the other certificates in the chain) loaded into an SPDM instance specific keychain. Currently there is no safe cleanup of this which will need to be fixed.

Using the keychain mechanism provides a very convenient way to manage these certificates and to allow userspace to read them for debug purpose etc, but is this the right use model?

Finally the leaf certificate of this chain is used to check signatures of the rest of the communications with the device.

2) ASNL1 encoder for ECDSA signature
It seems from the openSPDM implementation that for these signatures, the format is a simple pair of raw values. The kernel implementation of ECDSA signature verification assumes ASN1 encoding as seems to be used in x509 certificates. Currently I work around that by encoding the signatures so that the ECDSA code can un-encode them again and use them. This seems slightly silly, but it is minimum impact on current code. Other suggestions welcome.

3) Interface to present to drivers. Currently I'm providing just one exposed function that wraps up all the exhanges until a challenge authentication response from the device. This is done using one possible sequence. I don't think it makes sense to expose the low level components due to the underlying spdm_state updates and there only being a fixed set of valid orderings.

Future patches will raise questions around management of the measurements, but I'll leave those until I have some sort of implementation to shoot at. The 'on probe' use in the CXL driver is only one likely time when authentication would be needed.

Note I'm new to a bunch of the areas of the kernel this touches, so have probably done things that are totally wrong.

CC list is best effort to identify those who 'might' care. Please share with anyone I've missed.

Thanks,

Jonathan

Jonathan Cameron (4):
lib/asn1_encoder: Add a function to encode many byte integer values.
spdm: Introduce a library for DMTF SPDM
PCI/CMA: Initial support for Component Measurement and Authentication
ECN
cxl/pci: Add really basic CMA authentication support.

 drivers/cxl/Kconfig          |    1 +
 drivers/cxl/mem.h            |    2 +
 drivers/cxl/pci.c            |   13 +-
 drivers/pci/Kconfig          |    9 +
 drivers/pci/Makefile         |    1 +
 drivers/pci/doe.c            |    2 -
 include/linux/asn1_encoder.h |    3 +
 include/linux/pci-doe.h      |    2 +
 lib/Kconfig                  |    3 +
 lib/Makefile                 |    2 +
 lib/asn1_encoder.c           |   54 ++
 lib/spdm.c                   | 1196 ++++++++++++++++++++++++++++++++++
 12 files changed, 1285 insertions(+), 3 deletions(-)
 create mode 100644 lib/spdm.c
Signature · 1 line
2.19.1
#1 lore raw

RFC PATCH 1/4 lib/asn1_encoder: Add a function to encode many byte integer values.

An example is the encoding of ECC signatures used by the ECDSA signature verification code. A user is the new SPDM support where raw signatures are returned by the responder. These can then be encoded so that we can pass them to signature_verify()

---

Needs considerably more testing with crafted examples to hit the corner cases. For now it's enough to show how this 'might' fit together.

 include/linux/asn1_encoder.h |  3 ++
 lib/asn1_encoder.c           | 54 ++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
include/linux/asn1_encoder.h +3 -0
index 08cd0c2ad34f..30c3ebacd46c 100644
@@ -19,6 +19,9 @@ unsigned char *
 asn1_encode_tag(unsigned char *data, const unsigned char *end_data,
 		u32 tag, const unsigned char *string, int len);
 unsigned char *
+asn1_encode_integer_large_positive(unsigned char *data, const unsigned char *end_data,
+			  u32 tag, const unsigned char *integer, int len);
+unsigned char *
 asn1_encode_octet_string(unsigned char *data,
 			 const unsigned char *end_data,
 			 const unsigned char *string, u32 len);
lib/asn1_encoder.c +54 -0

60 lines not on this page · raw message

Signature · 1 line
2.19.1
#2 lore raw

RFC PATCH 2/4 spdm: Introduce a library for DMTF SPDM

In reply to Jonathan Cameron

The Security Protocol and Data Model (SPDM) defines messages, data objects and sequences for performing message exchanges between devices over various transports and physical media.

As the kernel supports several possible transports (mctp, PCI DOE) introduce a library than can in turn be used with all those transports.

There are a large number of open questions around how we do this that need to be resolved. These include:
* Key chain management
- Current approach is to use a keychain provide as part of per transport initialization for the root certificates which are assumed to be loaded into that keychain, perhaps in an initrd script.
- Each SPDM instance then has its own keychain to manage its certificates. It may make sense to drop this, but that looks like it will make a lot of the standard infrastructure harder to use.
* ECC algorithms needing ASN1 encoded signatures. I'm struggling to find any specification that actual 'requires' that choice vs raw data, so my guess is that this is a question of existing usecases (x509 certs seem to use this form, but CHALLENGE_AUTH SPDM seems to use raw data). I'm not sure whether we are better off just encoding the signature in ASN1 as currently done in this series, or if it is worth a tweaking things in the crypto layers.
* Lots of options in actual implementation to look at.

---
 lib/Kconfig  |    3 +
 lib/Makefile |    2 +
 lib/spdm.c   | 1196 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1201 insertions(+)
lib/Kconfig +3 -0
index ac3b30697b2b..0aa2fef6a592 100644
@@ -704,3 +704,6 @@ config PLDMFW
 
 config ASN1_ENCODER
        tristate
+
+config SPDM
+       tristate
lib/Makefile +2 -0
index 2cc359ec1fdd..566166d6936e 100644
@@ -282,6 +282,8 @@ obj-$(CONFIG_PERCPU_TEST) += percpu_test.o
 obj-$(CONFIG_ASN1) += asn1_decoder.o
 obj-$(CONFIG_ASN1_ENCODER) += asn1_encoder.o
 
+obj-$(CONFIG_SPDM) += spdm.o
+
 obj-$(CONFIG_FONT_SUPPORT) += fonts/
 
 hostprogs	:= gen_crc32table
lib/spdm.c new file +1196 -0

1,196 lines not on this page · raw message

Signature · 1 line
2.19.1
#3 lore raw

Re: [RFC PATCH 2/4] spdm: Introduce a library for DMTF SPDM

Quoted 92 lines · Jonathan Cameron

The Security Protocol and Data Model (SPDM) defines messages, data objects and sequences for performing message exchanges between devices over various transports and physical media.

As the kernel supports several possible transports (mctp, PCI DOE) introduce a library than can in turn be used with all those transports.

There are a large number of open questions around how we do this that need to be resolved. These include:
* Key chain management
- Current approach is to use a keychain provide as part of per transport initialization for the root certificates which are assumed to be loaded into that keychain, perhaps in an initrd script.
- Each SPDM instance then has its own keychain to manage its certificates. It may make sense to drop this, but that looks like it will make a lot of the standard infrastructure harder to use.
* ECC algorithms needing ASN1 encoded signatures. I'm struggling to find any specification that actual 'requires' that choice vs raw data, so my guess is that this is a question of existing usecases (x509 certs seem to use this form, but CHALLENGE_AUTH SPDM seems to use raw data). I'm not sure whether we are better off just encoding the signature in ASN1 as currently done in this series, or if it is worth a tweaking things in the crypto layers.
* Lots of options in actual implementation to look at.

---
 lib/Kconfig  |    3 +
 lib/Makefile |    2 +
 lib/spdm.c   | 1196 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1201 insertions(+)
lib/Kconfig +3 -0
index ac3b30697b2b..0aa2fef6a592 100644
@@ -704,3 +704,6 @@ config PLDMFW
 
 config ASN1_ENCODER
        tristate
+
+config SPDM
+       tristate
lib/Makefile +2 -0
index 2cc359ec1fdd..566166d6936e 100644
@@ -282,6 +282,8 @@ obj-$(CONFIG_PERCPU_TEST) += percpu_test.o
 obj-$(CONFIG_ASN1) += asn1_decoder.o
 obj-$(CONFIG_ASN1_ENCODER) += asn1_encoder.o
 
+obj-$(CONFIG_SPDM) += spdm.o
+
 obj-$(CONFIG_FONT_SUPPORT) += fonts/
 
 hostprogs      := gen_crc32table
lib/spdm.c new file +29 -0
new file mode 100644
index 000000000000..3ce2341647f8
@@ -0,0 +1,1196 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * DMTF Security Protocol and Data Model
+ *
+ * Copyright (C) 2021 Huawei
+ *     Jonathan Cameron <[email protected]>
+ */
+
+#include <linux/asn1_encoder.h>
+#include <linux/asn1_ber_bytecode.h>
+#include <linux/bitfield.h>
+#include <linux/cred.h>
+#include <linux/dev_printk.h>
+#include <linux/digsig.h>
+#include <linux/idr.h>
+#include <linux/key.h>
+#include <linux/module.h>
+#include <linux/random.h>
+#include <linux/spdm.h>
+
+#include <crypto/akcipher.h>
+#include <crypto/hash.h>
+#include <crypto/public_key.h>
+#include <keys/asymmetric-type.h>
+#include <keys/user-type.h>
+#include <asm/unaligned.h>
+
+/*
+ * Todo

lib/spdm.c line 39

Quoted 10 lines
lib/spdm.c new file +10 -0
+ * - Secure channel setup.
+ * - Multiple slot support.
+ * - Measurement support (over secure channel or within CHALLENGE_AUTH.
+ * - Support more core algorithms (not CMA does not require them, but may use
+ *   them if present.
+ * - Extended algorithm, support.
+ */
+/*
+ * Discussions points
+ * 1. Worth adding an SPDM layer around a transport layer?

I came here to say yes to this question. I am seeing interest in SPDM outside of a DOE transport.

Hope to find my way back to testing these bits out soon...

#4 lore raw

RE: [RFC PATCH 2/4] spdm: Introduce a library for DMTF SPDM

Hi Jonathan,

I'd like to test this patch with a custom transport but there's a reference to spdm.h that isn't here. Also, have you looked at measurement support yet? Thanks.

David

Quoted 133 lines

-----Original Message-----
From: Dan Williams <[email protected]>
Sent: Friday, February 18, 2022 2:06 PM
To: Jonathan Cameron <[email protected]>
Cc: [email protected]; Linux PCI <[email protected]>; open list:KEYS-TRUSTED <[email protected]>; Chris Browy <[email protected]>; Linuxarm <[email protected]>; Lorenzo Pieralisi <[email protected]>; Bjorn Helgaas <[email protected]>; Jeremy Kerr <[email protected]>; Box, David E <[email protected]>
Subject: Re: [RFC PATCH 2/4] spdm: Introduce a library for DMTF SPDM

Quoted 3 lines · Jonathan Cameron

The Security Protocol and Data Model (SPDM) defines messages, data objects and sequences for performing message exchanges between

devices

Quoted 4 lines

over various transports and physical media.

As the kernel supports several possible transports (mctp, PCI DOE) introduce a library than can in turn be used with all those

transports.

Quoted 5 lines

There are a large number of open questions around how we do this that need to be resolved. These include:
* Key chain management
- Current approach is to use a keychain provide as part of per

transport

Quoted 4 lines

initialization for the root certificates which are assumed to be loaded into that keychain, perhaps in an initrd script.
- Each SPDM instance then has its own keychain to manage its certificates. It may make sense to drop this, but that looks

like it

Quoted 2 lines

will make a lot of the standard infrastructure harder to use.
* ECC algorithms needing ASN1 encoded signatures. I'm struggling

to find

Quoted 1 line

any specification that actual 'requires' that choice vs raw data,

so my

Quoted 1 line

guess is that this is a question of existing usecases (x509 certs

seem

Quoted 2 lines

to use this form, but CHALLENGE_AUTH SPDM seems to use raw data). I'm not sure whether we are better off just encoding the

signature in

Quoted 1 line

ASN1 as currently done in this series, or if it is worth a

tweaking

Quoted 8 lines

things in the crypto layers.
* Lots of options in actual implementation to look at.

---
 lib/Kconfig  |    3 +
 lib/Makefile |    2 +
 lib/spdm.c   | 1196

++++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 54 lines
 3 files changed, 1201 insertions(+)
lib/Kconfig index renamed from lib/Kconfig +0 -0

ac3b30697b2b..0aa2fef6a592 100644

lib/Kconfig +3 -0
@@ -704,3 +704,6 @@ config PLDMFW
 
 config ASN1_ENCODER
        tristate
+
+config SPDM
+       tristate
lib/Makefile index renamed from lib/Makefile +0 -0

2cc359ec1fdd..566166d6936e 100644

lib/Makefile +2 -0
@@ -282,6 +282,8 @@ obj-$(CONFIG_PERCPU_TEST) += percpu_test.o
 obj-$(CONFIG_ASN1) += asn1_decoder.o
 obj-$(CONFIG_ASN1_ENCODER) += asn1_encoder.o
 
+obj-$(CONFIG_SPDM) += spdm.o
+
 obj-$(CONFIG_FONT_SUPPORT) += fonts/
 
 hostprogs      := gen_crc32table
lib/spdm.c new file +22 -0
new file mode 100644
index 000000000000..3ce2341647f8
@@ -0,0 +1,1196 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * DMTF Security Protocol and Data Model
+ *
+ * Copyright (C) 2021 Huawei
+ *     Jonathan Cameron <[email protected]>
+ */
+
+#include <linux/asn1_encoder.h>
+#include <linux/asn1_ber_bytecode.h>
+#include <linux/bitfield.h>
+#include <linux/cred.h>
+#include <linux/dev_printk.h>
+#include <linux/digsig.h>
+#include <linux/idr.h>
+#include <linux/key.h>
+#include <linux/module.h>
+#include <linux/random.h>
+#include <linux/spdm.h>
+
+#include <crypto/akcipher.h>
+#include <crypto/hash.h>

lib/spdm.c line 32

Quoted 10 lines
lib/spdm.c new file +10 -0
+#include <crypto/public_key.h>
+#include <keys/asymmetric-type.h>
+#include <keys/user-type.h>
+#include <asm/unaligned.h>
+
+/*
+ * Todo
+ * - Secure channel setup.
+ * - Multiple slot support.
+ * - Measurement support (over secure channel or within

CHALLENGE_AUTH.

lib/spdm.c line 33

Quoted 1 line
lib/spdm.c new file +1 -0
+ * - Support more core algorithms (not CMA does not require them,

but may use

lib/spdm.c line 39

Quoted 6 lines
lib/spdm.c new file +6 -0
+ *   them if present.
+ * - Extended algorithm, support.
+ */
+/*
+ * Discussions points
+ * 1. Worth adding an SPDM layer around a transport layer?

I came here to say yes to this question. I am seeing interest in SPDM outside of a DOE transport.

Hope to find my way back to testing these bits out soon...

#5 lore raw

Re: [RFC PATCH 2/4] spdm: Introduce a library for DMTF SPDM

Quoted 4 lines · David E

Hi Jonathan,

I'd like to test this patch with a custom transport but there's a reference to spdm.h that isn't here. Also, have you looked at measurement support yet? Thanks.

Hi David,

I messed this up.

Some discussion of this took place on the linaro open discussions list and I posted a version there to enable some testing which has the missing file. Note I only did minimal testing against that tree and have had one verbal report of a minor bug (without details...)

https://op-lists.linaro.org/archives/list/[email protected]/thread/5QU65B6Q74B3B4ESR7W5HER5HQ6WF4EQ/

It's rather dated now so I'll do a rebase and post this hopefully later this week given you are interested.

Note I haven't done any work on this for some time...

Curious though - what transport are people looking at?
I was planning to do MCTP over VDM at somepoint, but are we talking something truely custom? If so any plans to upstream as I'd love a second transport to prove out the layering?

Thanks,

Jonathan

Quoted 136 lines

David

Quoted 133 lines

-----Original Message-----
From: Dan Williams <[email protected]>
Sent: Friday, February 18, 2022 2:06 PM
To: Jonathan Cameron <[email protected]>
Cc: [email protected]; Linux PCI <[email protected]>; open list:KEYS-TRUSTED <[email protected]>; Chris Browy <[email protected]>; Linuxarm <[email protected]>; Lorenzo Pieralisi <[email protected]>; Bjorn Helgaas <[email protected]>; Jeremy Kerr <[email protected]>; Box, David E <[email protected]>
Subject: Re: [RFC PATCH 2/4] spdm: Introduce a library for DMTF SPDM

Quoted 3 lines · Jonathan Cameron

The Security Protocol and Data Model (SPDM) defines messages, data objects and sequences for performing message exchanges between

devices

Quoted 4 lines

over various transports and physical media.

As the kernel supports several possible transports (mctp, PCI DOE) introduce a library than can in turn be used with all those

transports.

Quoted 5 lines

There are a large number of open questions around how we do this that need to be resolved. These include:
* Key chain management
- Current approach is to use a keychain provide as part of per

transport

Quoted 4 lines

initialization for the root certificates which are assumed to be loaded into that keychain, perhaps in an initrd script.
- Each SPDM instance then has its own keychain to manage its certificates. It may make sense to drop this, but that looks

like it

Quoted 2 lines

will make a lot of the standard infrastructure harder to use.
* ECC algorithms needing ASN1 encoded signatures. I'm struggling

to find

Quoted 1 line

any specification that actual 'requires' that choice vs raw data,

so my

Quoted 1 line

guess is that this is a question of existing usecases (x509 certs

seem

Quoted 2 lines

to use this form, but CHALLENGE_AUTH SPDM seems to use raw data). I'm not sure whether we are better off just encoding the

signature in

Quoted 1 line

ASN1 as currently done in this series, or if it is worth a

tweaking

Quoted 8 lines

things in the crypto layers.
* Lots of options in actual implementation to look at.

---
 lib/Kconfig  |    3 +
 lib/Makefile |    2 +
 lib/spdm.c   | 1196  

++++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 54 lines
 3 files changed, 1201 insertions(+)
lib/Kconfig index renamed from lib/Kconfig +0 -0

ac3b30697b2b..0aa2fef6a592 100644

lib/Kconfig +3 -0
@@ -704,3 +704,6 @@ config PLDMFW
 
 config ASN1_ENCODER
        tristate
+
+config SPDM
+       tristate
lib/Makefile index renamed from lib/Makefile +0 -0

2cc359ec1fdd..566166d6936e 100644

lib/Makefile +2 -0
@@ -282,6 +282,8 @@ obj-$(CONFIG_PERCPU_TEST) += percpu_test.o
 obj-$(CONFIG_ASN1) += asn1_decoder.o
 obj-$(CONFIG_ASN1_ENCODER) += asn1_encoder.o
 
+obj-$(CONFIG_SPDM) += spdm.o
+
 obj-$(CONFIG_FONT_SUPPORT) += fonts/
 
 hostprogs      := gen_crc32table
lib/spdm.c new file +22 -0
new file mode 100644
index 000000000000..3ce2341647f8
@@ -0,0 +1,1196 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * DMTF Security Protocol and Data Model
+ *
+ * Copyright (C) 2021 Huawei
+ *     Jonathan Cameron <[email protected]>
+ */
+
+#include <linux/asn1_encoder.h>
+#include <linux/asn1_ber_bytecode.h>
+#include <linux/bitfield.h>
+#include <linux/cred.h>
+#include <linux/dev_printk.h>
+#include <linux/digsig.h>
+#include <linux/idr.h>
+#include <linux/key.h>
+#include <linux/module.h>
+#include <linux/random.h>
+#include <linux/spdm.h>
+
+#include <crypto/akcipher.h>
+#include <crypto/hash.h>

lib/spdm.c line 32

Quoted 10 lines
lib/spdm.c new file +10 -0
+#include <crypto/public_key.h>
+#include <keys/asymmetric-type.h>
+#include <keys/user-type.h>
+#include <asm/unaligned.h>
+
+/*
+ * Todo
+ * - Secure channel setup.
+ * - Multiple slot support.
+ * - Measurement support (over secure channel or within  

CHALLENGE_AUTH.

lib/spdm.c line 33

Quoted 1 line
lib/spdm.c new file +1 -0
+ * - Support more core algorithms (not CMA does not require them,  

but may use

lib/spdm.c line 39

Quoted 6 lines
lib/spdm.c new file +6 -0
+ *   them if present.
+ * - Extended algorithm, support.
+ */
+/*
+ * Discussions points
+ * 1. Worth adding an SPDM layer around a transport layer?  

I came here to say yes to this question. I am seeing interest in SPDM outside of a DOE transport.

Hope to find my way back to testing these bits out soon...

#6 lore raw

Re: [RFC PATCH 2/4] spdm: Introduce a library for DMTF SPDM

Quoted 29 lines · Jonathan Cameron
Quoted 6 lines · David E

Hi Jonathan,

I'd like to test this patch with a custom transport but there's a reference to spdm.h that isn't here. Also, have you looked at measurement support yet? Thanks.

Hi David,

I messed this up.

Some discussion of this took place on the linaro open discussions list
and I posted a version there to enable some testing which has the missing file.
Note I only did minimal testing against that tree and have had one verbal report
of a minor bug (without details...)

https://op-lists.linaro.org/archives/list/[email protected]/thread/5QU65B6Q74B3B4ESR7W5HER5HQ6WF4EQ/

It's rather dated now so I'll do a rebase and post this hopefully later
this week given you are interested.
Note I haven't done any work on this for some time...

Quoted 4 lines

Curious though - what transport are people looking at?
I was planning to do MCTP over VDM at somepoint, but are we talking something truely custom? If so any plans to upstream as I'd love a second transport to prove out the layering?

Thanks for the link. Definitely interested so please do cc me on future patches. I'm particularly interested in the SPDM library since I'm looking at this for use with a device specific transport. I'll let you know if/when there's something to upstream. Thanks.

David

Quoted 161 lines

Thanks,

Jonathan

Quoted 153 lines

David

Quoted 150 lines

-----Original Message-----
From: Dan Williams <[email protected]>
Sent: Friday, February 18, 2022 2:06 PM
To: Jonathan Cameron <[email protected]>
Cc: [email protected]; Linux PCI < [email protected]>;
open list:KEYS-TRUSTED <[email protected]>; Chris Browy <[email protected]>; Linuxarm <[email protected]>; Lorenzo
Pieralisi <[email protected]>; Bjorn Helgaas <[email protected]>; Jeremy Kerr <[email protected]>; Box, David
E <[email protected]>
Subject: Re: [RFC PATCH 2/4] spdm: Introduce a library for DMTF SPDM

Quoted 4 lines · Jonathan Cameron

The Security Protocol and Data Model (SPDM) defines messages, data
objects and sequences for performing message exchanges between

devices

Quoted 5 lines

over various transports and physical media.

As the kernel supports several possible transports (mctp, PCI DOE)
introduce a library than can in turn be used with all those

transports.

Quoted 6 lines

There are a large number of open questions around how we do this that
need to be resolved. These include:
* Key chain management
- Current approach is to use a keychain provide as part of
per

transport

Quoted 6 lines

initialization for the root certificates which are assumed
to be
loaded into that keychain, perhaps in an initrd script.
- Each SPDM instance then has its own keychain to manage its certificates. It may make sense to drop this, but that
looks

like it

Quoted 4 lines

will make a lot of the standard infrastructure harder to
use.
* ECC algorithms needing ASN1 encoded signatures. I'm
struggling

to find

Quoted 2 lines

any specification that actual 'requires' that choice vs raw
data,

so my

Quoted 2 lines

guess is that this is a question of existing usecases (x509
certs

seem

Quoted 3 lines

to use this form, but CHALLENGE_AUTH SPDM seems to use raw
data).
I'm not sure whether we are better off just encoding the

signature in

Quoted 2 lines

ASN1 as currently done in this series, or if it is worth
a

tweaking

Quoted 8 lines

things in the crypto layers.
* Lots of options in actual implementation to look at.

---
 lib/Kconfig  |    3 +
 lib/Makefile |    2 +
 lib/spdm.c   | 1196  

++++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 54 lines
 3 files changed, 1201 insertions(+)
lib/Kconfig index renamed from lib/Kconfig +0 -0

ac3b30697b2b..0aa2fef6a592 100644

lib/Kconfig +3 -0
@@ -704,3 +704,6 @@ config PLDMFW
 
 config ASN1_ENCODER
        tristate
+
+config SPDM
+       tristate
lib/Makefile index renamed from lib/Makefile +0 -0

2cc359ec1fdd..566166d6936e 100644

lib/Makefile +2 -0
@@ -282,6 +282,8 @@ obj-$(CONFIG_PERCPU_TEST) += percpu_test.o
 obj-$(CONFIG_ASN1) += asn1_decoder.o
 obj-$(CONFIG_ASN1_ENCODER) += asn1_encoder.o
 
+obj-$(CONFIG_SPDM) += spdm.o
+
 obj-$(CONFIG_FONT_SUPPORT) += fonts/
 
 hostprogs      := gen_crc32table
lib/spdm.c new file +22 -0
new file mode 100644
index 000000000000..3ce2341647f8
@@ -0,0 +1,1196 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * DMTF Security Protocol and Data Model
+ *
+ * Copyright (C) 2021 Huawei
+ *     Jonathan Cameron <[email protected]>
+ */
+
+#include <linux/asn1_encoder.h>
+#include <linux/asn1_ber_bytecode.h>
+#include <linux/bitfield.h>
+#include <linux/cred.h>
+#include <linux/dev_printk.h>
+#include <linux/digsig.h>
+#include <linux/idr.h>
+#include <linux/key.h>
+#include <linux/module.h>
+#include <linux/random.h>
+#include <linux/spdm.h>
+
+#include <crypto/akcipher.h>
+#include <crypto/hash.h>

lib/spdm.c line 32

Quoted 10 lines
lib/spdm.c new file +10 -0
+#include <crypto/public_key.h>
+#include <keys/asymmetric-type.h>
+#include <keys/user-type.h>
+#include <asm/unaligned.h>
+
+/*
+ * Todo
+ * - Secure channel setup.
+ * - Multiple slot support.
+ * - Measurement support (over secure channel or within  

CHALLENGE_AUTH.

Quoted 2 lines
lib/spdm.c new file +1 -0
+ * - Support more core algorithms (not CMA does not require

them,

but may use

Quoted 6 lines

+ * them if present.
+ * - Extended algorithm, support.
+ */
+/*
+ * Discussions points
+ * 1. Worth adding an SPDM layer around a transport layer?

I came here to say yes to this question. I am seeing interest in SPDM
outside of a DOE transport.

Hope to find my way back to testing these bits out soon...

#7 lore raw

RFC PATCH 3/4 PCI/CMA: Initial support for Component Measurement and Authentication ECN

In reply to Jonathan Cameron

This currently very much a PoC. Currently the SPDM library only provides a single function to allow a challenge / authentication of the PCI EP.

SPDM exchanges must occur in one of a small set of valid squences over which the message digest used in authentication is built up. Placing that complexity in the SPDM library seems like a good way to enforce that logic, without having to do it for each transport.

---
 drivers/pci/Kconfig     | 9 +++++++++
 drivers/pci/Makefile    | 1 +
 drivers/pci/doe.c       | 2 --
 include/linux/pci-doe.h | 2 ++
 4 files changed, 12 insertions(+), 2 deletions(-)
drivers/pci/Kconfig +9 -0
index a30c59cf5e27..43e3b0d5e8cd 100644
@@ -198,6 +198,15 @@ config PCI_DOE
 	  used by a number of different protocols.
 	  DOE is defined in the Data Object Exchange ECN to the PCIe r5.0 spec.
 
+config PCI_CMA
+	tristate
+	select PCI_DOE
+	select ASN1_ENCODER
+	select SPDM
+	help
+	  This enables library support for the PCI Component Measurement and
+	  Authentication ECN. This uses DMTF SPDM 1.1
+
 choice
 	prompt "PCI Express hierarchy optimization setting"
 	default PCIE_BUS_DEFAULT
drivers/pci/Makefile +1 -0
index 1b61c1a1c232..3f6b3543d565 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_PCI_PF_STUB)	+= pci-pf-stub.o
 obj-$(CONFIG_PCI_ECAM)		+= ecam.o
 obj-$(CONFIG_PCI_P2PDMA)	+= p2pdma.o
 obj-$(CONFIG_PCI_DOE)		+= doe.o
+obj-$(CONFIG_PCI_CMA)		+= cma.o
 obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o
 
 # Endpoint library must be initialized before its users
drivers/pci/doe.c +0 -2
index 2d20f59e42c6..f6aaeed01010 100644
@@ -20,8 +20,6 @@
 /* Maximum number of DOE instances in the system */
 #define PCI_DOE_MAX_CNT 65536
 
-#define PCI_DOE_PROTOCOL_DISCOVERY 0
-
 #define PCI_DOE_BUSY_MAX_RETRIES 16
 #define PCI_DOE_POLL_INTERVAL (HZ / 128)
 
include/linux/pci-doe.h +2 -0
index bdc5f15f14ab..1347c124ed70 100644
@@ -19,6 +19,8 @@ struct pci_doe_prot {
 	u8 type;
 };
 
+#define PCI_DOE_PROTOCOL_DISCOVERY 0
+#define PCI_DOE_PROTOCOL_CMA 1
 struct workqueue_struct;
 
 enum pci_doe_state {
Signature · 1 line
2.19.1
#8 lore raw

Re: [RFC PATCH 3/4] PCI/CMA: Initial support for Component Measurement and Authentication ECN

Quoted 9 lines · On Thu, 5 Aug 2021 00:18:38 +0800 Jonathan Cameron…

This currently very much a PoC. Currently the SPDM library only provides a single function to allow a challenge / authentication of the PCI EP.

SPDM exchanges must occur in one of a small set of valid squences over which the message digest used in authentication is built up. Placing that complexity in the SPDM library seems like a good way to enforce that logic, without having to do it for each transport.

This is far more likely to work if I actually include the missing drivers/pci/cma.c I'll send a v2 next week, but in the meantime it should look like this.

From: Jonathan Cameron <[email protected]>
To: <[email protected]>
Subject: [PATCH] pci/cma: Missing file
Date: Sat, 18 Sep 2021 00:16:00 +0800
X-Mailer: git-send-email 2.19.1

---
 drivers/pci/cma.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
drivers/pci/cma.c new file +102 -0
new file mode 100644
index 000000000000..58fef73674fe
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Component Measurement and Authentication was added as an ECN to the
+ * PCIe r5.0 spec.
+ *
+ * Copyright (C) 2021 Huawei
+ *     Jonathan Cameron <[email protected]>
+ */
+
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/pci-cma.h>
+#include <linux/pci-doe.h>
+#include <linux/spdm.h>
+
+/* Keyring that userspace can poke certs into */
+static struct key *cma_keyring;
+
+static int cma_spdm_ex(void *priv, struct spdm_exchange *spdm_ex)
+{
+	size_t request_padded_sz, response_padded_sz;
+	struct pci_doe_exchange ex = {
+		.vid = PCI_VENDOR_ID_PCI_SIG,
+		.protocol = PCI_DOE_PROTOCOL_CMA,
+	};
+	struct pci_doe *doe = priv;
+	int rc;
+
+	/* DOE requires that response and request are padded to a multiple of 4 bytes */
+	request_padded_sz = ALIGN(spdm_ex->request_pl_sz, sizeof(u32));
+	if (request_padded_sz != spdm_ex->request_pl_sz) {
+		ex.request_pl = kzalloc(request_padded_sz, GFP_KERNEL);
+		if (!ex.request_pl)
+			return -ENOMEM;
+		memcpy(ex.request_pl, spdm_ex->request_pl, spdm_ex->request_pl_sz);
+		ex.request_pl_sz = request_padded_sz;
+	} else {
+		ex.request_pl = (u32 *)spdm_ex->request_pl;
+		ex.request_pl_sz = spdm_ex->request_pl_sz;
+	}
+
+	response_padded_sz = ALIGN(spdm_ex->response_pl_sz, sizeof(u32));
+	if (response_padded_sz != spdm_ex->response_pl_sz) {
+		ex.response_pl = kzalloc(response_padded_sz, GFP_KERNEL);
+		if (!ex.response_pl) {
+			rc = -ENOMEM;
+			goto err_free_req;
+		}
+		ex.response_pl_sz = response_padded_sz;
+	} else {
+		ex.response_pl = (u32 *)spdm_ex->response_pl;
+		ex.response_pl_sz = spdm_ex->response_pl_sz;
+	}
+
+	rc = pci_doe_exchange_sync(doe, &ex);
+	if (rc < 0)
+		goto err_free_rsp;
+
+	if (response_padded_sz != spdm_ex->response_pl_sz)
+		memcpy(spdm_ex->response_pl, ex.response_pl, spdm_ex->response_pl_sz);
+
+err_free_rsp:
+	if (response_padded_sz != spdm_ex->response_pl_sz)
+		kfree(ex.response_pl);
+err_free_req:
+	if (request_padded_sz != spdm_ex->request_pl_sz)
+		kfree(ex.request_pl);
+
+	return rc;
+}
+
+void pci_cma_init(struct pci_doe *doe, struct spdm_state *spdm_state)
+{
+	memset(spdm_state, 0, sizeof(*spdm_state));
+	spdm_state->transport_ex = cma_spdm_ex;
+	spdm_state->transport_priv = doe;
+	spdm_state->dev = &doe->pdev->dev;
+	spdm_state->root_keyring = cma_keyring;
+}
+EXPORT_SYMBOL_GPL(pci_cma_init);
+
+int pci_cma_authenticate(struct spdm_state *spdm_state)
+{
+	return spdm_authenticate(spdm_state);
+}
+EXPORT_SYMBOL_GPL(pci_cma_authenticate);
+
+__init static int cma_keyring_init(void)
+{
+	cma_keyring = keyring_alloc("_cma",
+				    KUIDT_INIT(0), KGIDT_INIT(0),
+				    current_cred(),
+				    (KEY_POS_ALL & ~KEY_POS_SETATTR) |
+				    KEY_USR_VIEW | KEY_USR_READ | KEY_USR_WRITE | KEY_USR_SEARCH,
+				    KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_SET_KEEP, NULL, NULL);
+	if (IS_ERR(cma_keyring))
+		pr_err("Could not allocate cma keyring\n");
+
+	return 0;
+}
+device_initcall(cma_keyring_init);
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.19.1
Quoted 65 lines
---
 drivers/pci/Kconfig     | 9 +++++++++
 drivers/pci/Makefile    | 1 +
 drivers/pci/doe.c       | 2 --
 include/linux/pci-doe.h | 2 ++
 4 files changed, 12 insertions(+), 2 deletions(-)
drivers/pci/Kconfig +9 -0
index a30c59cf5e27..43e3b0d5e8cd 100644
@@ -198,6 +198,15 @@ config PCI_DOE
 	  used by a number of different protocols.
 	  DOE is defined in the Data Object Exchange ECN to the PCIe r5.0 spec.
 
+config PCI_CMA
+	tristate
+	select PCI_DOE
+	select ASN1_ENCODER
+	select SPDM
+	help
+	  This enables library support for the PCI Component Measurement and
+	  Authentication ECN. This uses DMTF SPDM 1.1
+
 choice
 	prompt "PCI Express hierarchy optimization setting"
 	default PCIE_BUS_DEFAULT
drivers/pci/Makefile +1 -0
index 1b61c1a1c232..3f6b3543d565 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_PCI_PF_STUB)	+= pci-pf-stub.o
 obj-$(CONFIG_PCI_ECAM)		+= ecam.o
 obj-$(CONFIG_PCI_P2PDMA)	+= p2pdma.o
 obj-$(CONFIG_PCI_DOE)		+= doe.o
+obj-$(CONFIG_PCI_CMA)		+= cma.o
 obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o
 
 # Endpoint library must be initialized before its users
drivers/pci/doe.c +0 -2
index 2d20f59e42c6..f6aaeed01010 100644
@@ -20,8 +20,6 @@
 /* Maximum number of DOE instances in the system */
 #define PCI_DOE_MAX_CNT 65536
 
-#define PCI_DOE_PROTOCOL_DISCOVERY 0
-
 #define PCI_DOE_BUSY_MAX_RETRIES 16
 #define PCI_DOE_POLL_INTERVAL (HZ / 128)
 
include/linux/pci-doe.h +2 -0
index bdc5f15f14ab..1347c124ed70 100644
@@ -19,6 +19,8 @@ struct pci_doe_prot {
 	u8 type;
 };
 
+#define PCI_DOE_PROTOCOL_DISCOVERY 0
+#define PCI_DOE_PROTOCOL_CMA 1
 struct workqueue_struct;
 
 enum pci_doe_state {
#9 lore raw

RFC PATCH 4/4 cxl/pci: Add really basic CMA authentication support.

In reply to Jonathan Cameron

This is just for purposes of poking the CMA / SPDM code. What exactly the model in the driver looks like is still to be worked out.

Note the PROBE_FORCE_SYNCHRONOUS is a workaround to avoid warnings about trying to load an additional crypto module whilst doing an asychronous probe.

---
 drivers/cxl/Kconfig |  1 +
 drivers/cxl/mem.h   |  2 ++
 drivers/cxl/pci.c   | 13 ++++++++++++-
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/cxl/Kconfig +1 -0
index e2bca26eb879..c726cc9adddb 100644
@@ -17,6 +17,7 @@ config CXL_MEM
 	tristate "CXL.mem: Memory Devices"
 	default CXL_BUS
 	select PCI_DOE
+	select PCI_CMA
 	help
 	  The CXL.mem protocol allows a device to act as a provider of
 	  "System RAM" and/or "Persistent Memory" that is fully coherent
drivers/cxl/mem.h +2 -0
index f626aa7eb389..cb8c2dfda277 100644
@@ -57,6 +57,7 @@ struct cxl_memdev {
  * @pdev: The PCI device associated with this CXL device.
  * @cxlmd: Logical memory device chardev / interface
  * @table_doe: Data exchange object mailbox used to read tables
+ * @cma_doe: Component measurement and authentication mailbox
  * @regs: Parsed register blocks
  * @payload_size: Size of space for payload
  *                (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register)
@@ -73,6 +74,7 @@ struct cxl_mem {
 	struct cxl_memdev *cxlmd;
 
 	struct pci_doe *table_doe;
+	struct pci_doe *cma_doe;
 	struct cxl_regs regs;
 
 	size_t payload_size;
drivers/cxl/pci.c +12 -1
index 471bddc9d167..e6ca84cc6fff 100644
@@ -2,10 +2,12 @@
 /* Copyright(c) 2020 Intel Corporation. All rights reserved. */
 #include <uapi/linux/cxl_mem.h>
 #include <linux/security.h>
+#include <linux/pci-cma.h>
 #include <linux/debugfs.h>
 #include <linux/module.h>
 #include <linux/sizes.h>
 #include <linux/mutex.h>
+#include <linux/spdm.h>
 #include <linux/list.h>
 #include <linux/cdev.h>
 #include <linux/idr.h>
@@ -1723,6 +1725,7 @@ static int cxl_mem_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	struct cxl_memdev *cxlmd;
 	struct cxl_mem *cxlm;
+	struct spdm_state spdm_state;
 	int rc, irqs;
 
 	rc = pcim_enable_device(pdev);
@@ -1770,6 +1773,14 @@ static int cxl_mem_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	cxlm->table_doe = pci_doe_find(pdev, PCI_DVSEC_VENDOR_ID_CXL,
 				       CXL_DOE_PROTOCOL_TABLE_ACCESS);
 
+	cxlm->cma_doe = pci_doe_find(pdev, PCI_VENDOR_ID_PCI_SIG,
+				     PCI_DOE_PROTOCOL_CMA);
+
+	pci_cma_init(cxlm->cma_doe, &spdm_state);
+	rc = pci_cma_authenticate(&spdm_state);
+	if (rc)
+		return rc;
+
 	rc = cxl_mem_setup_regs(cxlm);
 	if (rc)
 		return rc;
@@ -1808,7 +1819,7 @@ static struct pci_driver cxl_mem_driver = {
 	.id_table		= cxl_mem_pci_tbl,
 	.probe			= cxl_mem_probe,
 	.driver	= {
-		.probe_type	= PROBE_PREFER_ASYNCHRONOUS,
+		.probe_type	= PROBE_FORCE_SYNCHRONOUS,
 	},
 };
 
Signature · 1 line
2.19.1
#10 lore raw
In reply to Jonathan Cameron
Quoted 22 lines · On Thu, 5 Aug 2021 00:18:35 +0800 Jonathan Cameron…

This is an RFC to start discussions about how we support the Component Measurement and Authentication (CMA) ECN (pcisig.com)

CMA provides an adaptation of the data objects and underlying protocol defined in the DMTF SPDM specification to be used to authenticate and conduct run-time measurements of the state of PCI devices (kind of like IMA for devices / firmware). This is done using a Data Object Exchange (DOE) protocol described in the ECN.

The CMA ECN is available from the PCI SIG and SPDM can be found at
https://www.dmtf.org/sites/default/files/standards/documents/DSP0274_1.1.1.pdf

CMA/SPDM is focused on establishing trust of the device by:
1) Negotiate algorithms supported.
2) Retrieve and check the certificate chain from the device against a suitable signing certificate on the host.
3) Issue a challenge to the device to verify it can sign with the private key associated with the leaf certificate.
4) (Request a measurement of device state)
5) (Establish a secure channel for further measurements or other uses)
6) (Mutual authentication)

Quoted 4 lines

This RFC only does steps 1-3

Testing of this patch set has been conducted against QEMU emulation of the device backed by openSPDM emulation of the SPDM protocol.

Note testing also works with libspdm and libspdm-emu from
https://github.com/DMTF/spdm-emu with no modifications.

The openSPDM modifications Chris and team made were all associated with the host end and are not needed for this code (the QEMU part is still needed to provide the DOE emulation and forward the traffic to spdm_responder_emu)

I should also have mentioned this series is on top of the recently posted DOE series rebased onto the linux-cxl next git tree. I'm not really expecting anyone to test it at this stage, but if desired I can push a full tree out somewhere with this in place.

Jonathan

Quoted 81 lines

https://lore.kernel.org/qemu-devel/[email protected]/

Open questions are called out in the individual patches but the big ones are probably:

1) Certificate management.
Current code uses a _cma keyring created by the kernel, into which a suitable root certificate can be inserted from userspace.

   A=$(keyctl search %:_cma  keyring _cma)
   evmctl import ecdsaca.cert.der $A

Is this an acceptable way to load the root certificates for this purpose?

The root of the device provided certificate chain is then checked against certificates on this keychain, but is itself (with the other certificates in the chain) loaded into an SPDM instance specific keychain. Currently there is no safe cleanup of this which will need to be fixed.

Using the keychain mechanism provides a very convenient way to manage these certificates and to allow userspace to read them for debug purpose etc, but is this the right use model?

Finally the leaf certificate of this chain is used to check signatures of the rest of the communications with the device.

2) ASNL1 encoder for ECDSA signature
It seems from the openSPDM implementation that for these signatures, the format is a simple pair of raw values. The kernel implementation of ECDSA signature verification assumes ASN1 encoding as seems to be used in x509 certificates. Currently I work around that by encoding the signatures so that the ECDSA code can un-encode them again and use them. This seems slightly silly, but it is minimum impact on current code. Other suggestions welcome.

3) Interface to present to drivers. Currently I'm providing just one exposed function that wraps up all the exhanges until a challenge authentication response from the device. This is done using one possible sequence. I don't think it makes sense to expose the low level components due to the underlying spdm_state updates and there only being a fixed set of valid orderings.

Future patches will raise questions around management of the measurements, but I'll leave those until I have some sort of implementation to shoot at. The 'on probe' use in the CXL driver is only one likely time when authentication would be needed.

Note I'm new to a bunch of the areas of the kernel this touches, so have probably done things that are totally wrong.

CC list is best effort to identify those who 'might' care. Please share with anyone I've missed.

Thanks,

Jonathan

Jonathan Cameron (4):
lib/asn1_encoder: Add a function to encode many byte integer values.
spdm: Introduce a library for DMTF SPDM
PCI/CMA: Initial support for Component Measurement and Authentication
ECN
cxl/pci: Add really basic CMA authentication support.

 drivers/cxl/Kconfig          |    1 +
 drivers/cxl/mem.h            |    2 +
 drivers/cxl/pci.c            |   13 +-
 drivers/pci/Kconfig          |    9 +
 drivers/pci/Makefile         |    1 +
 drivers/pci/doe.c            |    2 -
 include/linux/asn1_encoder.h |    3 +
 include/linux/pci-doe.h      |    2 +
 lib/Kconfig                  |    3 +
 lib/Makefile                 |    2 +
 lib/asn1_encoder.c           |   54 ++
 lib/spdm.c                   | 1196 ++++++++++++++++++++++++++++++++++
 12 files changed, 1285 insertions(+), 3 deletions(-)
 create mode 100644 lib/spdm.c
#11 lore raw
Quoted 33 lines · On Thu, 5 Aug 2021 17:43:46 +0100 Jonathan Cameron…
Quoted 22 lines · On Thu, 5 Aug 2021 00:18:35 +0800 Jonathan Cameron…

This is an RFC to start discussions about how we support the Component Measurement and Authentication (CMA) ECN (pcisig.com)

CMA provides an adaptation of the data objects and underlying protocol defined in the DMTF SPDM specification to be used to authenticate and conduct run-time measurements of the state of PCI devices (kind of like IMA for devices / firmware). This is done using a Data Object Exchange (DOE) protocol described in the ECN.

The CMA ECN is available from the PCI SIG and SPDM can be found at
https://www.dmtf.org/sites/default/files/standards/documents/DSP0274_1.1.1.pdf

CMA/SPDM is focused on establishing trust of the device by:
1) Negotiate algorithms supported.
2) Retrieve and check the certificate chain from the device against a suitable signing certificate on the host.
3) Issue a challenge to the device to verify it can sign with the private key associated with the leaf certificate.
4) (Request a measurement of device state)
5) (Establish a secure channel for further measurements or other uses)
6) (Mutual authentication)

Quoted 4 lines

This RFC only does steps 1-3

Testing of this patch set has been conducted against QEMU emulation of the device backed by openSPDM emulation of the SPDM protocol.

Note testing also works with libspdm and libspdm-emu from
https://github.com/DMTF/spdm-emu with no modifications.

Quoted 8 lines

The openSPDM modifications Chris and team made were all associated with the host end and are not needed for this code (the QEMU part is still needed to provide the DOE emulation and forward the traffic to spdm_responder_emu)

I should also have mentioned this series is on top of the recently posted DOE series rebased onto the linux-cxl next git tree. I'm not really expecting anyone to test it at this stage, but if desired I can push a full tree out somewhere with this in place.

A couple of updates:

1. This topic is on the agenda for the linaro-open-discussions call tomorrow.
https://linaro.atlassian.net/wiki/spaces/LOD/overview
It's a public call and anyone interested is welcome to join in. Time is rather unfriendly for US based people unfortunately. I'll throw together some sort of overview / open questions slide deck which will be posted on that page. Note related topics on plumbers microconf agenda later in the month - I'll share details of that once known.

2. Related to that I had a request for trees as the base of the various series are not obvious (involved a bunch of rebases of various other patch sets)

https://github.com/hisilicon/kernel-dev/tree/doe-spdm-v1 rebased to 5.14-rc7
https://github.com/hisilicon/qemu/tree/cxl-hacks rebased to qemu/master as of Friday

For qemu side of things you need to be running spdm_responder_emu --trans PCI_DOE from https://github.com/DMTF/spdm-emu first (that will act as server to qemu acting as a client). Various parameters allow you to change the algorithms advertised and the kernel code should work for all the ones CMA mandates (but nothing beyond that for now).

For the cxl device the snippet of qemu commandline needed is:
-device cxl-type3,bus=root_port13,memdev=cxl-mem1,lsa=cxl-mem1, id=cxl-pmem0,size=2G,spdm=true

Otherwise much the same as https://people.kernel.org/jic23/ (instructions written to enable testing of the DOE patches this built on).

Build at least the cxl_pci driver as a module as we need to poke the certificate into the keychain before that (find the cert in spdm_emu tree).
Instructions to do that with keyctl and evmctl are in the cover letter of the patch series.

Hopefully I'll find some time soonish to update that blog post with instructions.

Thanks,

Jonathan

Quoted 85 lines

Jonathan

Quoted 81 lines

https://lore.kernel.org/qemu-devel/[email protected]/

Open questions are called out in the individual patches but the big ones are probably:

1) Certificate management.
Current code uses a _cma keyring created by the kernel, into which a suitable root certificate can be inserted from userspace.

   A=$(keyctl search %:_cma  keyring _cma)
   evmctl import ecdsaca.cert.der $A

Is this an acceptable way to load the root certificates for this purpose?

The root of the device provided certificate chain is then checked against certificates on this keychain, but is itself (with the other certificates in the chain) loaded into an SPDM instance specific keychain. Currently there is no safe cleanup of this which will need to be fixed.

Using the keychain mechanism provides a very convenient way to manage these certificates and to allow userspace to read them for debug purpose etc, but is this the right use model?

Finally the leaf certificate of this chain is used to check signatures of the rest of the communications with the device.

2) ASNL1 encoder for ECDSA signature
It seems from the openSPDM implementation that for these signatures, the format is a simple pair of raw values. The kernel implementation of ECDSA signature verification assumes ASN1 encoding as seems to be used in x509 certificates. Currently I work around that by encoding the signatures so that the ECDSA code can un-encode them again and use them. This seems slightly silly, but it is minimum impact on current code. Other suggestions welcome.

3) Interface to present to drivers. Currently I'm providing just one exposed function that wraps up all the exhanges until a challenge authentication response from the device. This is done using one possible sequence. I don't think it makes sense to expose the low level components due to the underlying spdm_state updates and there only being a fixed set of valid orderings.

Future patches will raise questions around management of the measurements, but I'll leave those until I have some sort of implementation to shoot at. The 'on probe' use in the CXL driver is only one likely time when authentication would be needed.

Note I'm new to a bunch of the areas of the kernel this touches, so have probably done things that are totally wrong.

CC list is best effort to identify those who 'might' care. Please share with anyone I've missed.

Thanks,

Jonathan

Jonathan Cameron (4):
lib/asn1_encoder: Add a function to encode many byte integer values.
spdm: Introduce a library for DMTF SPDM
PCI/CMA: Initial support for Component Measurement and Authentication
ECN
cxl/pci: Add really basic CMA authentication support.

 drivers/cxl/Kconfig          |    1 +
 drivers/cxl/mem.h            |    2 +
 drivers/cxl/pci.c            |   13 +-
 drivers/pci/Kconfig          |    9 +
 drivers/pci/Makefile         |    1 +
 drivers/pci/doe.c            |    2 -
 include/linux/asn1_encoder.h |    3 +
 include/linux/pci-doe.h      |    2 +
 lib/Kconfig                  |    3 +
 lib/Makefile                 |    2 +
 lib/asn1_encoder.c           |   54 ++
 lib/spdm.c                   | 1196 ++++++++++++++++++++++++++++++++++
 12 files changed, 1285 insertions(+), 3 deletions(-)
 create mode 100644 lib/spdm.c
#12 lore raw
Quoted 32 lines · Jonathan Cameron
Quoted 25 lines · On Thu, 5 Aug 2021 17:43:46 +0100 Jonathan Cameron…
Quoted 22 lines · On Thu, 5 Aug 2021 00:18:35 +0800 Jonathan Cameron…

This is an RFC to start discussions about how we support the Component Measurement and Authentication (CMA) ECN (pcisig.com)

CMA provides an adaptation of the data objects and underlying protocol defined in the DMTF SPDM specification to be used to authenticate and conduct run-time measurements of the state of PCI devices (kind of like IMA for devices / firmware). This is done using a Data Object Exchange (DOE) protocol described in the ECN.

The CMA ECN is available from the PCI SIG and SPDM can be found at
https://www.dmtf.org/sites/default/files/standards/documents/DSP0274_1.1.1.pdf

CMA/SPDM is focused on establishing trust of the device by:
1) Negotiate algorithms supported.
2) Retrieve and check the certificate chain from the device against a suitable signing certificate on the host.
3) Issue a challenge to the device to verify it can sign with the private key associated with the leaf certificate.
4) (Request a measurement of device state)
5) (Establish a secure channel for further measurements or other uses)
6) (Mutual authentication)

Quoted 1 line
Quoted 1 line
Quoted 1 line

This RFC only does steps 1-3

Could you describe the additional software beyond step 3 that is required to complete the IDE Key Management protocol post SPDM secure session establishment (see PCIe base 6.0r0.9.pdf, Figure 6-59 IDE_KM Example) to reach IDE establishment and run regular applications using IDE streams. The goal is to do more complete testing of some real CXL devices to the point of running user applications over IDE streams to access HDM memory.

Quoted 139 lines
Quoted 7 lines
Quoted 3 lines

Testing of this patch set has been conducted against QEMU emulation of the device backed by openSPDM emulation of the SPDM protocol.

Note testing also works with libspdm and libspdm-emu from
https://github.com/DMTF/spdm-emu with no modifications.

Quoted 8 lines

The openSPDM modifications Chris and team made were all associated with the host end and are not needed for this code (the QEMU part is still needed to provide the DOE emulation and forward the traffic to spdm_responder_emu)

I should also have mentioned this series is on top of the recently posted DOE series rebased onto the linux-cxl next git tree. I'm not really expecting anyone to test it at this stage, but if desired I can push a full tree out somewhere with this in place.

A couple of updates:

1. This topic is on the agenda for the linaro-open-discussions call tomorrow.
https://linaro.atlassian.net/wiki/spaces/LOD/overview
It's a public call and anyone interested is welcome to join in. Time is rather unfriendly for US based people unfortunately. I'll throw together some sort of overview / open questions slide deck which will be posted on that page. Note related topics on plumbers microconf agenda later in the month - I'll share details of that once known.

2. Related to that I had a request for trees as the base of the various series are not obvious (involved a bunch of rebases of various other patch sets)

https://github.com/hisilicon/kernel-dev/tree/doe-spdm-v1 rebased to 5.14-rc7
https://github.com/hisilicon/qemu/tree/cxl-hacks rebased to qemu/master as of Friday

For qemu side of things you need to be running spdm_responder_emu --trans PCI_DOE from https://github.com/DMTF/spdm-emu first (that will act as server to qemu acting as a client). Various parameters allow you to change the algorithms advertised and the kernel code should work for all the ones CMA mandates (but nothing beyond that for now).

For the cxl device the snippet of qemu commandline needed is:
-device cxl-type3,bus=root_port13,memdev=cxl-mem1,lsa=cxl-mem1, id=cxl-pmem0,size=2G,spdm=true

Otherwise much the same as https://people.kernel.org/jic23/ (instructions written to enable testing of the DOE patches this built on).

Build at least the cxl_pci driver as a module as we need to poke the certificate into the keychain before that (find the cert in spdm_emu tree).
Instructions to do that with keyctl and evmctl are in the cover letter of the patch series.

Hopefully I'll find some time soonish to update that blog post with instructions.

Thanks,

Jonathan

Quoted 85 lines

Jonathan

Quoted 81 lines

https://lore.kernel.org/qemu-devel/[email protected]/

Open questions are called out in the individual patches but the big ones are probably:

1) Certificate management.
Current code uses a _cma keyring created by the kernel, into which a suitable root certificate can be inserted from userspace.

  A=$(keyctl search %:_cma  keyring _cma)
  evmctl import ecdsaca.cert.der $A

Is this an acceptable way to load the root certificates for this purpose?

The root of the device provided certificate chain is then checked against certificates on this keychain, but is itself (with the other certificates in the chain) loaded into an SPDM instance specific keychain. Currently there is no safe cleanup of this which will need to be fixed.

Using the keychain mechanism provides a very convenient way to manage these certificates and to allow userspace to read them for debug purpose etc, but is this the right use model?

Finally the leaf certificate of this chain is used to check signatures of the rest of the communications with the device.

2) ASNL1 encoder for ECDSA signature
It seems from the openSPDM implementation that for these signatures, the format is a simple pair of raw values. The kernel implementation of ECDSA signature verification assumes ASN1 encoding as seems to be used in x509 certificates. Currently I work around that by encoding the signatures so that the ECDSA code can un-encode them again and use them. This seems slightly silly, but it is minimum impact on current code. Other suggestions welcome.

3) Interface to present to drivers. Currently I'm providing just one exposed function that wraps up all the exhanges until a challenge authentication response from the device. This is done using one possible sequence. I don't think it makes sense to expose the low level components due to the underlying spdm_state updates and there only being a fixed set of valid orderings.

Future patches will raise questions around management of the measurements, but I'll leave those until I have some sort of implementation to shoot at. The 'on probe' use in the CXL driver is only one likely time when authentication would be needed.

Note I'm new to a bunch of the areas of the kernel this touches, so have probably done things that are totally wrong.

CC list is best effort to identify those who 'might' care. Please share with anyone I've missed.

Thanks,

Jonathan

Jonathan Cameron (4):
lib/asn1_encoder: Add a function to encode many byte integer values.
spdm: Introduce a library for DMTF SPDM
PCI/CMA: Initial support for Component Measurement and Authentication
ECN
cxl/pci: Add really basic CMA authentication support.

drivers/cxl/Kconfig          |    1 +
drivers/cxl/mem.h            |    2 +
drivers/cxl/pci.c            |   13 +-
drivers/pci/Kconfig          |    9 +
drivers/pci/Makefile         |    1 +
drivers/pci/doe.c            |    2 -
include/linux/asn1_encoder.h |    3 +
include/linux/pci-doe.h      |    2 +
lib/Kconfig                  |    3 +
lib/Makefile                 |    2 +
lib/asn1_encoder.c           |   54 ++
lib/spdm.c                   | 1196 ++++++++++++++++++++++++++++++++++
12 files changed, 1285 insertions(+), 3 deletions(-)

create mode 100644 lib/spdm.c

#13 lore raw
Quoted 30 lines · On Wed, 17 Nov 2021 12:46:48 -0500 Chris Browy <[email protected]> wrote:
Quoted 30 lines · Jonathan Cameron
Quoted 25 lines · On Thu, 5 Aug 2021 17:43:46 +0100 Jonathan Cameron…
Quoted 22 lines · On Thu, 5 Aug 2021 00:18:35 +0800 Jonathan Cameron…

This is an RFC to start discussions about how we support the Component Measurement and Authentication (CMA) ECN (pcisig.com)

CMA provides an adaptation of the data objects and underlying protocol defined in the DMTF SPDM specification to be used to authenticate and conduct run-time measurements of the state of PCI devices (kind of like IMA for devices / firmware). This is done using a Data Object Exchange (DOE) protocol described in the ECN.

The CMA ECN is available from the PCI SIG and SPDM can be found at
https://www.dmtf.org/sites/default/files/standards/documents/DSP0274_1.1.1.pdf

CMA/SPDM is focused on establishing trust of the device by:
1) Negotiate algorithms supported.
2) Retrieve and check the certificate chain from the device against a suitable signing certificate on the host.
3) Issue a challenge to the device to verify it can sign with the private key associated with the leaf certificate.
4) (Request a measurement of device state)
5) (Establish a secure channel for further measurements or other uses)
6) (Mutual authentication)

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

This RFC only does steps 1-3

Could you describe the additional software beyond step 3 that is required to complete the IDE Key Management protocol post SPDM secure session establishment (see PCIe base 6.0r0.9.pdf, Figure 6-59 IDE_KM Example) to reach IDE establishment and run

Stick to the ECN in references as that is published at least to SIG members. We shouldn't be discussing draft specs on a public list (though in this case it's the same material as the published ECN).

Quoted 3 lines

regular applications using IDE streams. The goal is to do more complete testing of some real CXL devices to the point of running user applications over IDE streams to access HDM memory.

Hi Chris,

This is off the top of my head rather than a considered answer as having a busy week. Firstly a small thing but IDE requires a different DOE protocol - it is CMA with extra stuff but technically different protocol number.
3 a) Add the kernel side messages to actually request a secure channel.
b) Hook into appropriate kernel subsystems to generate the keys.

After that is up and running (can test by doing some measurements over the now encrypted channel), then we need to do the key setup as in the IDE spec. So implement the IDE_KM protocol. That will cover EPs. If you have a switch in the path then you'll need to add emulation support for a DOE on that as well.

Now the host is interesting. You are allowed but not required to support IDE_KM on a DOE in the root port (there are lots of other options) or in RCRB. Also allowed impdef means which I suspect is going to be more common as a secure channel between components both within the SoC is a little odd. That decision may depend on whether a given vendor sees IDE establishment and maintenance as a firmware / BMC job or an OS one.

IDE_KM protocol has 6 messages and i think we would need to implement them all.

There is also the extended capability to be handled which brings more complexity. So all the stuff in figure 7-16 IDE_KM Examples (might be the same as the one you refer to...)

We've only gotten as far as mid way down the second block of exchanges. That diagram assumes host is using an impdef method, but I think we'd be better off first implementing the RP DOE approach (which will be the same as switch to EP) and that means negotiating a secure channel etc with the RP as well as the EP. Then you can program appropriate keys and jump through the various IDE_KM_KSET_GO as in the diagram.

There is quite a lot of work to be done to bring up the full flow, but, interestingly I think there will be far fewer open questions in that part of enablement than we have for earlier steps of SPDM setup, simply because it doesn't really interact with the rest of Linux so sits almost entirely in the PCI subsystem. A fun early question is how we decide it needs to be enabled at all.

Whilst I'm planning to eventually get this all in place it may take a while.

If we were making a plan...
1) Finish of SPDM stuff - so secure channel setup and ideally flesh out measurements for which I have a prototype.
2) Qemu emulation RP with IDE support (building on your team's work on EP support).
3) Bring up basic flow against that emulation.
4) Figure out what to do about key refresh...
5) Qemu emulation of switch.
6) Bring flows up against switch etc.
7) Selective IDE.
8) P2P selective IDE...
9) Retire and let the youngsters actually use it ;)

Jonathan

Quoted 141 lines
Quoted 140 lines
Quoted 8 lines
Quoted 4 lines

Testing of this patch set has been conducted against QEMU emulation of the device backed by openSPDM emulation of the SPDM protocol.

Note testing also works with libspdm and libspdm-emu from
https://github.com/DMTF/spdm-emu with no modifications.

Quoted 8 lines

The openSPDM modifications Chris and team made were all associated with the host end and are not needed for this code (the QEMU part is still needed to provide the DOE emulation and forward the traffic to spdm_responder_emu)

I should also have mentioned this series is on top of the recently posted DOE series rebased onto the linux-cxl next git tree. I'm not really expecting anyone to test it at this stage, but if desired I can push a full tree out somewhere with this in place.

A couple of updates:

1. This topic is on the agenda for the linaro-open-discussions call tomorrow.
https://linaro.atlassian.net/wiki/spaces/LOD/overview
It's a public call and anyone interested is welcome to join in. Time is rather unfriendly for US based people unfortunately. I'll throw together some sort of overview / open questions slide deck which will be posted on that page. Note related topics on plumbers microconf agenda later in the month - I'll share details of that once known.

2. Related to that I had a request for trees as the base of the various series are not obvious (involved a bunch of rebases of various other patch sets)

https://github.com/hisilicon/kernel-dev/tree/doe-spdm-v1 rebased to 5.14-rc7
https://github.com/hisilicon/qemu/tree/cxl-hacks rebased to qemu/master as of Friday

For qemu side of things you need to be running spdm_responder_emu --trans PCI_DOE from https://github.com/DMTF/spdm-emu first (that will act as server to qemu acting as a client). Various parameters allow you to change the algorithms advertised and the kernel code should work for all the ones CMA mandates (but nothing beyond that for now).

For the cxl device the snippet of qemu commandline needed is:
-device cxl-type3,bus=root_port13,memdev=cxl-mem1,lsa=cxl-mem1, id=cxl-pmem0,size=2G,spdm=true

Otherwise much the same as https://people.kernel.org/jic23/ (instructions written to enable testing of the DOE patches this built on).

Build at least the cxl_pci driver as a module as we need to poke the certificate into the keychain before that (find the cert in spdm_emu tree).
Instructions to do that with keyctl and evmctl are in the cover letter of the patch series.

Hopefully I'll find some time soonish to update that blog post with instructions.

Thanks,

Jonathan

Quoted 85 lines

Jonathan

Quoted 81 lines

https://lore.kernel.org/qemu-devel/[email protected]/

Open questions are called out in the individual patches but the big ones are probably:

1) Certificate management.
Current code uses a _cma keyring created by the kernel, into which a suitable root certificate can be inserted from userspace.

  A=$(keyctl search %:_cma  keyring _cma)
  evmctl import ecdsaca.cert.der $A

Is this an acceptable way to load the root certificates for this purpose?

The root of the device provided certificate chain is then checked against certificates on this keychain, but is itself (with the other certificates in the chain) loaded into an SPDM instance specific keychain. Currently there is no safe cleanup of this which will need to be fixed.

Using the keychain mechanism provides a very convenient way to manage these certificates and to allow userspace to read them for debug purpose etc, but is this the right use model?

Finally the leaf certificate of this chain is used to check signatures of the rest of the communications with the device.

2) ASNL1 encoder for ECDSA signature
It seems from the openSPDM implementation that for these signatures, the format is a simple pair of raw values. The kernel implementation of ECDSA signature verification assumes ASN1 encoding as seems to be used in x509 certificates. Currently I work around that by encoding the signatures so that the ECDSA code can un-encode them again and use them. This seems slightly silly, but it is minimum impact on current code. Other suggestions welcome.

3) Interface to present to drivers. Currently I'm providing just one exposed function that wraps up all the exhanges until a challenge authentication response from the device. This is done using one possible sequence. I don't think it makes sense to expose the low level components due to the underlying spdm_state updates and there only being a fixed set of valid orderings.

Future patches will raise questions around management of the measurements, but I'll leave those until I have some sort of implementation to shoot at. The 'on probe' use in the CXL driver is only one likely time when authentication would be needed.

Note I'm new to a bunch of the areas of the kernel this touches, so have probably done things that are totally wrong.

CC list is best effort to identify those who 'might' care. Please share with anyone I've missed.

Thanks,

Jonathan

Jonathan Cameron (4):
lib/asn1_encoder: Add a function to encode many byte integer values.
spdm: Introduce a library for DMTF SPDM
PCI/CMA: Initial support for Component Measurement and Authentication
ECN
cxl/pci: Add really basic CMA authentication support.

drivers/cxl/Kconfig          |    1 +
drivers/cxl/mem.h            |    2 +
drivers/cxl/pci.c            |   13 +-
drivers/pci/Kconfig          |    9 +
drivers/pci/Makefile         |    1 +
drivers/pci/doe.c            |    2 -
include/linux/asn1_encoder.h |    3 +
include/linux/pci-doe.h      |    2 +
lib/Kconfig                  |    3 +
lib/Makefile                 |    2 +
lib/asn1_encoder.c           |   54 ++
lib/spdm.c                   | 1196 ++++++++++++++++++++++++++++++++++
12 files changed, 1285 insertions(+), 3 deletions(-)

create mode 100644 lib/spdm.c