PCI/CMA and SPDM Library - Device attestation etc.
Subsystems (3)
v3 cover PCI/CMA and SPDM Library - Device attestation etc.
Sharing now to provide some an example of what a fully in-kernel implementation looks like before the BoF session on this topic at Linux Plumbers. The big discussion there will probably be how much of this to do in userspace vs in the kernel.
https://lpc.events/event/16/contributions/1304/
Changes since v2:
- Rebase on v6.0-rc2. DOE infrastructure now upstream so much smaller series.
- SPDM 1.2 support. Fairly minor changes for attestation. Negotiation of highest mutually supported version included with drivers using this code specifying a minimum version they will accept.
- Various fixes in particular to correctly identify ECDSA x9.62 format signature being passed to signature verify.
- Changes suggested by Lukas in his review of RFC v2.
Make spdm_state opaque outside of libspdm.c
Drop misleading _pl_
Drop non existent forwards definition of spdm_measurements_get() Add spec link.
v2 was a rebase + fixed some files I missed in v1.
v1 Cover letter:
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 (rebased version to be sent shortly).
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.
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/core/pci.c | 47 ++ drivers/cxl/cxlpci.h | 1 + drivers/cxl/port.c | 1 + drivers/pci/Kconfig | 13 + drivers/pci/Makefile | 1 + drivers/pci/cma.c | 117 +++ include/linux/asn1_encoder.h | 3 + include/linux/pci-cma.h | 21 + include/linux/spdm.h | 81 +++ lib/Kconfig | 3 + lib/Makefile | 2 + lib/asn1_encoder.c | 54 ++ lib/spdm.c | 1333 ++++++++++++++++++++++++++++++++++ 14 files changed, 1678 insertions(+) create mode 100644 drivers/pci/cma.c create mode 100644 include/linux/pci-cma.h create mode 100644 include/linux/spdm.h create mode 100644 lib/spdm.c
Signature · 1 line
2.32.0
RFC PATCH v3 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() An alternative would be to teach the ecdsa code to handle "raw" as well as X9.62 formatted signatures.
--- include/linux/asn1_encoder.h | 3 ++ lib/asn1_encoder.c | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
include/linux/asn1_encoder.h +3 -0
@@ -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.32.0
RFC PATCH v3 2/4 spdm: Introduce a library for DMTF SPDM
In reply to Jonathan CameronThe Security Protocol and Data Model (SPDM) defines messages, data objects and sequences for performing message exchanges between devices over various transports and physical media.
Currently SPDM 1.1 and SPDM 1.2 are supported. A given device driver calling into this library may select the minimum version used. A newer version may be used if both kernel and device have sufficient support.
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 use cases (x509 certs seem to use this form, but CHALLENGE_AUTH SPDM uses 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 to add raw support alongside X9.62/asn.1
* Lots of options in actual implementation to look at.
--
Since v2:
Support SPDM 1.2 based on 1.2.1 specification.
- A few new fields resulting in 1 expanded data structure, plus the prefix and rehashing step needed to build the material against which a signature is verified.
- Allow specification of minimum acceptable version. Max mutually available version of SPDM will be used. Tested by changing max supported in spdm-emu
Fix wrong encoding for ecdsa signatures. They were always x9.62 not raw. Now picked up by better checks in the kernel.
Various minor fixes for wrong length endian calls etc.
--- include/linux/spdm.h | 81 +++ lib/Kconfig | 3 + lib/Makefile | 2 + lib/spdm.c | 1333 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1419 insertions(+)
include/linux/spdm.h new file +81 -0
@@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* DMTF Security Protocol and Data Model +* https://www.dmtf.org/dsp/DSP0274 +* +* Copyright (C) 2021-22 Huawei +* Jonathan Cameron <[email protected]> +*/ + +#ifndef _SPDM_H_ +#define _SPDM_H_ + +#include <linux/types.h> + +enum spdm_base_hash_algo { + spdm_base_hash_sha_256 =0 , + spdm_base_hash_sha_384 =1 , + spdm_base_hash_sha_512 =2 , + spdm_base_hash_sha3_256 =3 , + spdm_base_hash_sha3_384 =4 , + spdm_base_hash_sha3_512 =5 , + spdm_base_hash_sm3_256 =6 , +}; + +enum spdm_meas_hash_algo { + spdm_meas_hash_raw =0 , + spdm_meas_hash_sha_256 =1 , + spdm_meas_hash_sha_384 =2 , + spdm_meas_hash_sha_512 =3 , + spdm_meas_hash_sha3_256 =4 , + spdm_meas_hash_sha3_384 =5 , + spdm_meas_hash_sha3_512 =6 , + spdm_meas_hash_sm3_257 =7 , +}; + +enum spdm_base_asym_algo { + spdm_asym_rsassa_2048 =0 , + spdm_asym_rsapss_2048 =1 , + spdm_asym_rsassa_3072 =2 , + spdm_asym_rsapss_3072 =3 , + spdm_asym_ecdsa_ecc_nist_p256 =4 , + spdm_asym_rsassa_4096 =5 , + spdm_asym_rsapss_4096 =6 , + spdm_asym_ecdsa_ecc_nist_p384 =7 , + spdm_asym_ecdsa_ecc_nist_p521 =8 , + spdm_asym_sm2_ecc_sm2_p256 =9 , + spdm_asym_eddsa_ed25519 =10 , + spdm_asym_eddsa_ed448 =11 , +}; + +struct crypto_shash ; +struct shash_desc ; +struct key ; +struct device ; + +/* +* The SPDM specification does not actually define this as the header +* but all messages have the same first 4 named fields. +* Note however that the meaning of param1 and param2 is message dependent. +*/ +struct spdm_header { +u8 version; +u8 code;/* requestresponsecode */ +u8 param1; +u8 param2; +}; + +struct spdm_exchange { +struct spdm_header *request; +size_t request_sz; +struct spdm_header *response; +size_t response_sz; +u8 code;/* Overwrites the request code */ +}; +struct spdm_state ; + +struct spdm_state *spdm_create (int (*transport_ex)(void *priv,struct spdm_exchange *spdm_ex), +void *priv,struct device *dev,struct key *keyring); + +int spdm_authenticate (struct spdm_state *spdm_state); +#endif
lib/Kconfig +3 -0
@@ -741,3 +741,6 @@ config ASN1_ENCODER config POLYNOMIAL tristate + +config SPDM + tristate
lib/Makefile +2 -0
@@ -303,6 +303,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 +1333 -0
1,333 lines not on this page · raw message
Signature · 1 line
2.32.0
RFC PATCH v3 3/4 PCI/CMA: Initial support for Component Measurement and Authentication ECN
In reply to Jonathan CameronThis 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 | 13 +++++ drivers/pci/Makefile | 1 + drivers/pci/cma.c | 117 ++++++++++++++++++++++++++++++++++++++++ include/linux/pci-cma.h | 21 ++++++++ 4 files changed, 152 insertions(+)
drivers/pci/Kconfig +13 -0
@@ -118,6 +118,19 @@ config XEN_PCIDEV_FRONTEND The PCI device frontend driver allows the kernel to import arbitrary PCI devices from a PCI backend to support PCI driver domains. +config PCI_CMA + tristate "PCI Component Measurement and Authentication" + select PCI_DOE + select ASN1_ENCODER + select SPDM + help + This enables library support for the PCI Component Measurement and + Authentication introduce in PCI r6.0 sec 6.31. A PCI DOE mailbox is + used as the transport for DMTF SPDM based attestation, measurement + and secure channel establishment. + + If built as a module will be called cma.ko. + config PCI_ATS bool
drivers/pci/Makefile +1 -0
@@ -32,6 +32,7 @@ obj-$(CONFIG_PCI_P2PDMA) += p2pdma.o obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o obj-$(CONFIG_VGA_ARB) += vgaarb.o obj-$(CONFIG_PCI_DOE) += doe.o +obj-$(CONFIG_PCI_CMA) += cma.o # Endpoint library must be initialized before its users obj-$(CONFIG_PCI_ENDPOINT) += endpoint/
drivers/pci/cma.c new file +117 -0
117 lines not on this page · raw message
include/linux/pci-cma.h new file +21 -0
@@ -0,0 +1,21 @@ +/* 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]> +*/ + +#ifndef _PCI_CMA_H_ +#define _PCI_CMA_H_ +struct pci_doe_mb ; +struct spdm_state ; +struct device ; + +struct spdm_state *pci_cma_create (struct device *dev,struct pci_doe_mb *doe); +void pci_cma_destroy (struct spdm_state *spdm_state); + +int pci_cma_authenticate (struct spdm_state *spdm_state); + +#endif
Signature · 1 line
2.32.0
kernel test robot
build botRe: [RFC PATCH v3 3/4] PCI/CMA: Initial support for Component Measurement and Authentication ECN
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Jonathan,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on helgaas-pci/next]
[also build test ERROR on linus/master v6.0-rc4 next-20220906] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jonathan-Cameron/PCI-CMA-and-SPDM-Library-Device-attestation-etc/20220906-191943 base: https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next config: mips-randconfig-r023-20220906 (https://download.01.org/0day-ci/archive/20220907/[email protected]/config) compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project c55b41d5199d2394dd6cdb8f52180d8b81d809d4)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mips64el-linux-gnuabi64
# https://github.com/intel-lab-lkp/linux/commit/694b6e0651764f4a2abe85dba7577d69d6daaba7
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jonathan-Cameron/PCI-CMA-and-SPDM-Library-Device-attestation-etc/20220906-191943 git checkout 694b6e0651764f4a2abe85dba7577d69d6daaba7
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash drivers/pci/ lib/
If you fix the issue, kindly add following tag where applicable
All errors (new ones prefixed by >>):
>> drivers/pci/cma.c:105:16: error: call to undeclared function 'keyring_alloc'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
cma_keyring = keyring_alloc("_cma",
^
>> drivers/pci/cma.c:108:10: error: use of undeclared identifier 'KEY_POS_ALL'
(KEY_POS_ALL & ~KEY_POS_SETATTR) |
^
>> drivers/pci/cma.c:108:25: error: use of undeclared identifier 'KEY_POS_SETATTR'
(KEY_POS_ALL & ~KEY_POS_SETATTR) |
^
>> drivers/pci/cma.c:109:9: error: use of undeclared identifier 'KEY_USR_VIEW'
KEY_USR_VIEW | KEY_USR_READ | KEY_USR_WRITE | KEY_USR_SEARCH,
^
>> drivers/pci/cma.c:109:24: error: use of undeclared identifier 'KEY_USR_READ'
KEY_USR_VIEW | KEY_USR_READ | KEY_USR_WRITE | KEY_USR_SEARCH,
^
>> drivers/pci/cma.c:109:39: error: use of undeclared identifier 'KEY_USR_WRITE'
KEY_USR_VIEW | KEY_USR_READ | KEY_USR_WRITE | KEY_USR_SEARCH,
^
>> drivers/pci/cma.c:109:55: error: use of undeclared identifier 'KEY_USR_SEARCH'
KEY_USR_VIEW | KEY_USR_READ | KEY_USR_WRITE | KEY_USR_SEARCH,
^
>> drivers/pci/cma.c:110:9: error: use of undeclared identifier 'KEY_ALLOC_NOT_IN_QUOTA'
KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_SET_KEEP, NULL, NULL);
^
>> drivers/pci/cma.c:110:34: error: use of undeclared identifier 'KEY_ALLOC_SET_KEEP'
KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_SET_KEEP, NULL, NULL);
^
9 errors generated.
--
In file included from lib/spdm.c:25:
>> include/keys/asymmetric-type.h:72:12: error: incomplete definition of type 'struct key'
return key->payload.data[asym_key_ids];
~~~^
include/linux/key.h:33:8: note: forward declaration of 'struct key'
struct key;
^
In file included from lib/spdm.c:25:
include/keys/asymmetric-type.h:78:12: error: incomplete definition of type 'struct key'
return key->payload.data[asym_crypto];
~~~^
include/linux/key.h:33:8: note: forward declaration of 'struct key'
struct key;
^
>> lib/spdm.c:974:24: error: call to undeclared function 'keyring_alloc'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
spdm_state->keyring = keyring_alloc(keyring_name,
^
>> lib/spdm.c:977:11: error: use of undeclared identifier 'KEY_POS_ALL'
(KEY_POS_ALL & ~KEY_POS_SETATTR) |
^
>> lib/spdm.c:977:26: error: use of undeclared identifier 'KEY_POS_SETATTR'
(KEY_POS_ALL & ~KEY_POS_SETATTR) |
^
>> lib/spdm.c:978:10: error: use of undeclared identifier 'KEY_USR_VIEW'
KEY_USR_VIEW | KEY_USR_READ,
^
>> lib/spdm.c:978:25: error: use of undeclared identifier 'KEY_USR_READ'
KEY_USR_VIEW | KEY_USR_READ,
^
>> lib/spdm.c:979:10: error: use of undeclared identifier 'KEY_ALLOC_NOT_IN_QUOTA'
KEY_ALLOC_NOT_IN_QUOTA |
^
>> lib/spdm.c:980:10: error: use of undeclared identifier 'KEY_ALLOC_SET_KEEP'
KEY_ALLOC_SET_KEEP,
^
>> lib/spdm.c:998:3: error: unknown type name 'key_ref_t'; did you mean 'key_perm_t'?
key_ref_t key2;
^~~~~~~~~
key_perm_t
include/linux/key.h:31:18: note: 'key_perm_t' declared here
typedef uint32_t key_perm_t;
^
>> lib/spdm.c:1000:10: error: call to undeclared function 'key_create_or_update'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
key2 = key_create_or_update(make_key_ref(spdm_state->keyring, 1),
^
lib/spdm.c:1003:11: error: use of undeclared identifier 'KEY_POS_ALL'
(KEY_POS_ALL & ~KEY_POS_SETATTR) |
^
lib/spdm.c:1003:26: error: use of undeclared identifier 'KEY_POS_SETATTR'
(KEY_POS_ALL & ~KEY_POS_SETATTR) |
^
lib/spdm.c:1004:10: error: use of undeclared identifier 'KEY_USR_VIEW'
KEY_USR_VIEW | KEY_USR_READ,
^
lib/spdm.c:1004:25: error: use of undeclared identifier 'KEY_USR_READ'
KEY_USR_VIEW | KEY_USR_READ,
^
lib/spdm.c:1005:10: error: use of undeclared identifier 'KEY_ALLOC_NOT_IN_QUOTA'
KEY_ALLOC_NOT_IN_QUOTA);
^
>> lib/spdm.c:1007:14: error: incompatible integer to pointer conversion passing 'key_perm_t' (aka 'unsigned int') to parameter of type 'const void *' [-Wint-conversion]
if (IS_ERR(key2)) {
^~~~
include/linux/err.h:34:60: note: passing argument to parameter 'ptr' here
static inline bool __must_check IS_ERR(__force const void *ptr)
^
lib/spdm.c:1009:17: error: incompatible integer to pointer conversion passing 'key_perm_t' (aka 'unsigned int') to parameter of type 'const void *' [-Wint-conversion]
rc = PTR_ERR(key2);
^~~~
include/linux/err.h:29:61: note: passing argument to parameter 'ptr' here
static inline long __must_check PTR_ERR(__force const void *ptr)
^
>> lib/spdm.c:1016:25: error: member reference base type 'void' is not a structure or union
key_ref_to_ptr(key2)->payload.data[asym_auth];
~~~~~~~~~~~~~~~~~~~~^ ~~~~~~~fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated.
vim +/keyring_alloc +105 drivers/pci/cma.c
102
103 __init static int cma_keyring_init(void)
104 {
> 105 cma_keyring = keyring_alloc("_cma",
106 KUIDT_INIT(0), KGIDT_INIT(0),
107 current_cred(),
> 108 (KEY_POS_ALL & ~KEY_POS_SETATTR) |
> 109 KEY_USR_VIEW | KEY_USR_READ | KEY_USR_WRITE | KEY_USR_SEARCH,
> 110 KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_SET_KEEP, NULL, NULL);Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
Re: [RFC PATCH v3 3/4] PCI/CMA: Initial support for Component Measurement and Authentication ECN
In reply to Jonathan CameronQuoted 58 lines · 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.
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/pci/Kconfig | 13 +++++ drivers/pci/Makefile | 1 + drivers/pci/cma.c | 117 ++++++++++++++++++++++++++++++++++++++++ include/linux/pci-cma.h | 21 ++++++++ 4 files changed, 152 insertions(+)drivers/pci/Kconfig +13
-0@@ -118,6 +118,19 @@ config XEN_PCIDEV_FRONTEND The PCI device frontend driver allows the kernel to import arbitrary PCI devices from a PCI backend to support PCI driver domains. +config PCI_CMA + tristate "PCI Component Measurement and Authentication" + select PCI_DOE + select ASN1_ENCODER + select SPDM + help + This enables library support for the PCI Component Measurement and + Authentication introduce in PCI r6.0 sec 6.31. A PCI DOE mailbox is + used as the transport for DMTF SPDM based attestation, measurement + and secure channel establishment. + + If built as a module will be called cma.ko. + config PCI_ATS booldrivers/pci/Makefile +1
-0@@ -32,6 +32,7 @@ obj-$(CONFIG_PCI_P2PDMA) += p2pdma.o obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o obj-$(CONFIG_VGA_ARB) += vgaarb.o obj-$(CONFIG_PCI_DOE) += doe.o +obj-$(CONFIG_PCI_CMA) += cma.o # Endpoint library must be initialized before its users obj-$(CONFIG_PCI_ENDPOINT) += endpoint/drivers/pci/cma.c new file +0
-0
drivers/pci/cma.c line 4
Quoted 4 lines
drivers/pci/cma.c new file +4
-0@@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Component Measurement and Authentication was added as an ECN to the +* PCIe r5.0 spec.
It looks like PCIe r6.0, sec 6.31? (Oh, I see that's what you mention above in the Kconfig text :)) I have absolutely no idea what CMA is about or how it works. Other than pci_doe_submit_task(), nothing here is recognizable to me as PCI-related and I can't tell what else, if anything, is connected to something in the PCIe spec.
Quoted 25 lines
drivers/pci/cma.c new file +25
-0+* 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> + +#define PCI_DOE_PROTOCOL_CMA 1 +/* Keyring that userspace can poke certs into */ +static struct key *cma_keyring; + +static void cxl_doe_task_complete (struct pci_doe_task *task) +{ +complete (task->private); +} + +static int cma_spdm_ex (void *priv,struct spdm_exchange *spdm_ex) +{ +size_t request_padded_sz, response_padded_sz; +struct completion c =COMPLETION_INITIALIZER_ONSTACK (c); +struct pci_doe_task task = { + .prot = {
drivers/pci/cma.c line 40
Quoted 10 lines
drivers/pci/cma.c new file +10
-0+ .vid = PCI_VENDOR_ID_PCI_SIG, + .type = PCI_DOE_PROTOCOL_CMA, + }, + .complete = cxl_doe_task_complete, + .private = &c, + }; +struct pci_doe_mb *doe = priv; +int rc; + +/* DOE requires that response and request are padded to a multiple of 4 bytes */
Wrap or shorten to fit in 80 columns.
Quoted 83 lines
drivers/pci/cma.c new file +77
-0+ request_padded_sz =ALIGN (spdm_ex->request_sz,sizeof (u32)); +if (request_padded_sz != spdm_ex->request_sz) { + task.request_pl =kzalloc (request_padded_sz,GFP_KERNEL ); +if (!task.request_pl) +return -ENOMEM ; +memcpy (task.request_pl, spdm_ex->request, spdm_ex->request_sz); + task.request_pl_sz = request_padded_sz; + }else { + task.request_pl = (u32 *)spdm_ex->request; + task.request_pl_sz = spdm_ex->request_sz; + } + + response_padded_sz =ALIGN (spdm_ex->response_sz,sizeof (u32)); +if (response_padded_sz != spdm_ex->response_sz) { + task.response_pl =kzalloc (response_padded_sz,GFP_KERNEL ); +if (!task.response_pl) { + rc = -ENOMEM ; + goto err_free_req; + } + task.response_pl_sz = response_padded_sz; + }else { + task.response_pl = (u32 *)spdm_ex->response; + task.response_pl_sz = spdm_ex->response_sz; + } + + rc =pci_doe_submit_task (doe, &task); +if (rc <0 ) + goto err_free_rsp; + +wait_for_completion (&c); +if (response_padded_sz != spdm_ex->response_sz) +memcpy (spdm_ex->response, task.response_pl, spdm_ex->response_sz); + + rc = task.rv; +err_free_rsp: +if (response_padded_sz != spdm_ex->response_sz) +kfree (task.response_pl); +err_free_req: +if (request_padded_sz != spdm_ex->request_sz) +kfree (task.request_pl); + +return rc; +} + +struct spdm_state *pci_cma_create (struct device *dev,struct pci_doe_mb *doe) +{ +return spdm_create (cma_spdm_ex, doe, dev, cma_keyring); +} +EXPORT_SYMBOL_GPL (pci_cma_create); + +void pci_cma_destroy (struct spdm_state *spdm_state) +{ +kfree (spdm_state); +} +EXPORT_SYMBOL_GPL (pci_cma_destroy); + +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" );include/linux/pci-cma.h new file +0
-0
include/linux/pci-cma.h line 4
Quoted 4 lines
include/linux/pci-cma.h new file +4
-0@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Component Measurement and Authentication was added as an ECN to the +* PCIe r5.0 spec.
Update as well?
Quoted 19 lines
include/linux/pci-cma.h new file +16
-0+* Copyright (C) 2021 Huawei +* Jonathan Cameron <[email protected]> +*/ + +#ifndef _PCI_CMA_H_ +#define _PCI_CMA_H_ +struct pci_doe_mb ; +struct spdm_state ; +struct device ; + +struct spdm_state *pci_cma_create (struct device *dev,struct pci_doe_mb *doe); +void pci_cma_destroy (struct spdm_state *spdm_state); + +int pci_cma_authenticate (struct spdm_state *spdm_state); + +#endif Signature · 1 line
2.32.0
Re: [RFC PATCH v3 3/4] PCI/CMA: Initial support for Component Measurement and Authentication ECN
Quoted 14 lines · Bjorn Helgaas
drivers/pci/cma.c line 4
Quoted 7 lines · Jonathan Cameron
drivers/pci/cma.c new file +4
-0@@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Component Measurement and Authentication was added as an ECN to the +* PCIe r5.0 spec. It looks like PCIe r6.0, sec 6.31? (Oh, I see that's what you mention above in the
Kconfigtext :)) I have absolutely no idea what CMA is about or how it works. Other thanpci_doe_submit_task(), nothing here is recognizable to me as PCI-related and I can't tell what else, if anything, is connected to something in the PCIe spec.
CMA is an adaption of the SPDM spec to PCIe.
Basically this is about authenticating PCI devices:
The device presents a certificate chain to the host;
The host needs to trust the root of that certificate chain; The host sends a nonce to the device;
The device signs the nonce with its private key, sends it back; The host verifies the signature matches the certificate (= public key).
The protocol to perform this authentication is called SPDM:
https://www.dmtf.org/sites/default/files/standards/documents/DSP0274_1.2.1.pdf
Various other specs besides PCIe have adopted SPDM (e.g. CXL).
One transport over which the SPDM message exchanges are sent is PCI DOE, which appears in v6.0.
So-called measurements can be retrieved after authentication was completed successfully: E.g. a signed hash of the firmware. Thereby, the host can verify the device is in a trusted state.
"Attestation" appears to be a fancy terminus technicus which encompasses authentication and validation of measurements.
Authentication forms the basis for IDE (PCI TLP encryption, PCIe r6.0 sec 6.33). Encryption is useless without authentication because it's otherwise susceptible to man-in-the-middle attacks.
Authentication also forms the basis for TDISP (Trusted I/O virtualization, recently accepted as an ECN).
There was an SPDM BoF at Plumbers last week:
https://lpc.events/event/16/contributions/1304/attachments/1029/1974/LPC2022-SPDM-BoF-v4.pdf
https://lpc.events/event/16/abstracts/1301/
The outcome is that we'll be working towards a minimal CMA implementation which is capable of authenticating PCI devices and presenting the result in sysfs. There might be a global policy knob in sysfs to control handling of devices for which authentication failed (e.g. forbid binding to drivers). Features such as a per-device policy can later be added on top if need be. We'll need to rework DOE handling such that the PCI core scans all DOE mailboxes on device enumeration to look for one capable of SPDM and perform authentication. We'll seek to upstream this though the PCI tree. That's my summary in brief, Jonathan or Dan may have amendments or corrections to make. :)
Thanks,
Lukas
Re: [RFC PATCH v3 3/4] PCI/CMA: Initial support for Component Measurement and Authentication ECN
Quoted 37 lines · Lukas Wunner
Quoted 14 lines · Bjorn Helgaas
drivers/pci/cma.c line 4
Quoted 7 lines · Jonathan Cameron
drivers/pci/cma.c new file +4
-0@@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Component Measurement and Authentication was added as an ECN to the +* PCIe r5.0 spec. It looks like PCIe r6.0, sec 6.31? (Oh, I see that's what you mention above in the
Kconfigtext :)) I have absolutely no idea what CMA is about or how it works. Other thanpci_doe_submit_task(), nothing here is recognizable to me as PCI-related and I can't tell what else, if anything, is connected to something in the PCIe spec.CMA is an adaption of the SPDM spec to PCIe.
Basically this is about authenticating PCI devices:
The device presents a certificate chain to the host;
The host needs to trust the root of that certificate chain; The host sends a nonce to the device;
The device signs the nonce with its private key, sends it back; The host verifies the signature matches the certificate (= public key).The protocol to perform this authentication is called SPDM:
https://www.dmtf.org/sites/default/files/standards/documents/DSP0274_1.2.1.pdfVarious other specs besides PCIe have adopted SPDM (e.g. CXL).
One transport over which the SPDM message exchanges are sent is PCI DOE, which appears in v6.0.
So-called measurements can be retrieved after authentication was completed successfully: E.g. a signed hash of the firmware. Thereby, the host can verify the device is in a trusted state.
Quoted 6 lines
"Attestation" appears to be a fancy terminus technicus which encompasses authentication and validation of measurements.
Authentication forms the basis for IDE (PCI TLP encryption, PCIe r6.0 sec 6.33). Encryption is useless without authentication because it's otherwise susceptible to man-in-the-middle attacks.
I would also add that attestation is useful without encryption. The Thunderclap [1] class of vulnerabilities is concerned with malicious devices impersonating legitimate ones. Where validating that the device you think you are talking to also passes a challenge response with a certificate chain you trust helps to mitigate that attack vector. IDE is interesting because it is "persistent attestation". Whereas SPDM is a point in time validation, IDE helps protect against swapping out the device after the initial SPDM attestation. That event would be signaled by error handling, making device swap out and interposer attacks more difficult. I.e. you would need to silence the device swap out and any upstream device that flags the error.
If Linux adds SPDM support for the value of attestation then I submit IDE should be considered next.
RFC PATCH v3 4/4 cxl/pci: Add really basic CMA authentication support.
In reply to Jonathan CameronThis 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.
---
May still need to force non async probe as done in earlier versions.
drivers/cxl/Kconfig | 1 + drivers/cxl/core/pci.c | 47 ++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlpci.h | 1 + drivers/cxl/port.c | 1 + 4 files changed, 50 insertions(+)
drivers/cxl/Kconfig +1 -0
@@ -3,6 +3,7 @@ menuconfig CXL_BUS tristate "CXL (Compute Express Link) Devices Support" depends on PCI select PCI_DOE + select PCI_CMA help CXL is a bus that is electrically compatible with PCI Express, but layers three protocols on that signalling (CXL.io, CXL.cache, and
drivers/cxl/core/pci.c +47 -0
57 lines not on this page · raw message
drivers/cxl/cxlpci.h +1 -0
@@ -75,4 +75,5 @@ int devm_cxl_port_enumerate_dports(struct cxl_port *port);struct cxl_dev_state ;int cxl_hdm_decode_init (struct cxl_dev_state *cxlds,struct cxl_hdm *cxlhdm);void read_cdat_data (struct cxl_port *port); +void cxl_cma_init (struct cxl_port *port);#endif /* __CXL_PCI_H__ */
drivers/cxl/port.c +1 -0
@@ -55,6 +55,7 @@ static int cxl_port_probe(struct device *dev)/* Cache the data early to ensure is_visible() works */ read_cdat_data (port); +cxl_cma_init (port);get_device (&cxlmd->dev); rc =devm_add_action_or_reset (dev, schedule_detach, cxlmd);
Signature · 1 line
2.32.0