Skip to content

spdm: large-transfer: set chunk capability #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 47 commits into
base: spdm-future
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
94dabab
crypto: ecdsa - Update Kconfig entry for NIST P521
l1k Aug 20, 2024
76f020d
crypto: ecdsa - Drop unused test vector elements
l1k Aug 20, 2024
43d2ff8
crypto: sig - Introduce sig_alg backend
l1k Aug 18, 2024
4a72eb9
crypto: ecdsa - Migrate to sig_alg backend
l1k Aug 18, 2024
ca1c9eb
crypto: ecrdsa - Migrate to sig_alg backend
l1k Aug 19, 2024
b632d01
crypto: rsa-pkcs1pad - Deduplicate set_{pub,priv}_key callbacks
l1k Aug 19, 2024
3b87ceb
crypto: rsassa-pkcs1 - Migrate to sig_alg backend
l1k Aug 19, 2024
5ed9dc6
crypto: rsassa-pkcs1 - Harden digest length verification
l1k Aug 20, 2024
2439812
crypto: rsassa-pkcs1 - Avoid copying hash prefix
l1k Aug 20, 2024
80b902e
crypto: virtio - Drop sign/verify operations
l1k Sep 6, 2024
70a157d
crypto: drivers - Drop sign/verify operations
l1k Aug 19, 2024
e3631c5
crypto: akcipher - Drop sign/verify operations
l1k Aug 19, 2024
347ab3a
crypto: sig - Move crypto_sig_*() API calls to include file
l1k Aug 22, 2024
4a13485
ASN.1: Clean up include statements in public headers
l1k Jul 27, 2024
5f9a30c
crypto: ecdsa - Avoid signed integer overflow on signature decoding
l1k Jul 21, 2024
1647fef
crypto: ecdsa - Move X9.62 signature decoding into template
l1k Jul 22, 2024
fe0c5bc
crypto: sig - Rename crypto_sig_maxsize() to crypto_sig_keysize()
l1k Sep 8, 2024
fa9a773
crypto: ecdsa - Move X9.62 signature size calculation into template
l1k Sep 8, 2024
8facb09
crypto: ecdsa - Support P1363 signature decoding
l1k Jul 2, 2023
4c23f8c
crypto: ecrdsa - Fix signature size calculation
l1k Sep 8, 2024
256496c
crypto: virtio - Fix kernel-doc of virtcrypto_dev_stop()
l1k Aug 29, 2024
18d6fff
crypto: virtio - Simplify RSA keysize caching
l1k Aug 26, 2024
7dc50cc
crypto: virtio - Drop superfluous ctx->tfm backpointer
l1k Aug 23, 2024
2acf779
crypto: virtio - Drop superfluous [as]kcipher_ctx pointer
l1k Sep 6, 2024
2e4f034
crypto: virtio - Drop superfluous [as]kcipher_req pointer
l1k Sep 6, 2024
99a6be9
X.509: Make certificate parser public
l1k Aug 20, 2023
100b59b
X.509: Parse Subject Alternative Name in certificates
l1k Aug 20, 2023
c13371c
X.509: Move certificate length retrieval into new helper
l1k Jan 10, 2023
f10e214
certs: Create blacklist keyring earlier
l1k Sep 24, 2023
5660d8a
spdm: Introduce library to authenticate devices
jic23 Sep 6, 2022
5ef54f2
PCI/CMA: Authenticate devices on enumeration
jic23 Sep 6, 2022
fa45b9f
PCI/CMA: Validate Subject Alternative Name in certificates
l1k Aug 20, 2023
a314ae0
PCI/CMA: Reauthenticate devices on reset and resume
l1k Jan 16, 2023
08fca60
PCI/CMA: Expose in sysfs whether devices are authenticated
l1k May 27, 2023
e420d08
PCI/CMA: Expose certificates in sysfs
l1k Jun 8, 2024
2273ba1
sysfs: Allow bin_attributes to be added to groups
l1k Mar 30, 2024
960d1dc
sysfs: Allow symlinks to be added between sibling groups
l1k Jun 11, 2024
e218643
PCI/CMA: Expose a log of received signatures in sysfs
l1k Apr 11, 2024
7fc6ce6
spdm: Limit memory consumed by log of received signatures
l1k Jun 22, 2024
4cbf47e
spdm: Authenticate devices despite invalid certificate chain
l1k Jun 22, 2024
9c3e2c1
spdm: Allow control of next requester nonce through sysfs
l1k Apr 20, 2024
e2e3887
PCI/CMA: Grant guests exclusive control of authentication
l1k Jun 8, 2023
95e2e81
spdm: Add support for measuring devices
l1k Dec 21, 2022
fb3f4e2
spdm: Add support for key exchange
l1k Dec 21, 2022
4ee99fc
spdm: Add support for mutual authentication
l1k Dec 21, 2022
2d75092
spdm: Add support for large SPDM message transfer mechanism
l1k Aug 31, 2023
bc9f23e
spdm: large-transfer: set chunk capability
twilfredo Aug 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
247 changes: 247 additions & 0 deletions Documentation/ABI/testing/sysfs-devices-spdm
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
What: /sys/devices/.../authenticated
Date: June 2024
Contact: Lukas Wunner <[email protected]>
Description:
This file contains 1 if the device authenticated successfully
with SPDM (Security Protocol and Data Model). It contains 0 if
the device failed authentication (and may thus be malicious).

Writing "re" to this file causes reauthentication.
That may be opportune after updating the device keyring.
The device keyring of the PCI bus is named ".cma"
(Component Measurement and Authentication).

Reauthentication may also be necessary after device identity
has mutated, e.g. after downloading firmware to an FPGA device.

The file is not visible if authentication is unsupported
by the device.

If the kernel could not determine whether authentication is
supported because memory was low or communication with the
device was not working, the file is visible but accessing it
fails with error code ENOTTY.

This prevents downgrade attacks where an attacker consumes
memory or disturbs communication in order to create the
appearance that a device does not support authentication.

The reason why authentication support could not be determined
is apparent from "dmesg". To re-probe authentication support
of PCI devices, exercise the "remove" and "rescan" attributes.


What: /sys/devices/.../certificates/
What: /sys/devices/.../certificates/slot[0-7]
Date: June 2024
Contact: Lukas Wunner <[email protected]>
Description:
The "certificates" directory provides access to the certificate
chains contained in the up to 8 slots of a device.

A certificate chain is the concatenation of one or more ASN.1
DER-encoded X.509 v3 certificates (SPDM 1.0.0 sec 4.9.2.1).
It can be examined as follows::

# openssl storeutl -text certificates/slot0

A common use case is to add the first certificate in a chain
to the keyring of trusted root certificates (".cma" in this
example) after comparing its fingerprint to the one provided
by the device manufacturer::

# openssl x509 -in certificates/slot0 -fingerprint -nocert
# keyctl padd asymmetric "" %:.cma < certificates/slot0
# echo re > authenticated

The file size of each slot is always 65535 bytes (the maximum
size of a certificate chain per SPDM 1.0.0 table 18), even if
the certificate chain in the slot is actually smaller.

Unprovisioned slots are represented as empty files.

Unsupported slots (introduced by SPDM 1.3 margin no 366) are
not visible. If the device only supports SPDM version 1.2 or
earlier, all 8 slots are assumed to be supported and therefore
visible.

The kernel learns which slots are supported when authenticating
the device for the first time. Hence, no slots are visible
until at least one authentication attempt has been performed.

SPDM doesn't support on-demand retrieval of certificate chains,
so the kernel caches them when (re-)authenticating the device.
SPDM allows provisioning slots behind the kernel's back by
sending a SET_CERTIFICATE request through a different transport
(e.g. via MCTP from a Baseboard Management Controller).
SPDM does not specify how to notify the kernel of such events,
so unless reauthentication is manually initiated to update the
kernel's cache, the "slot[0-7]" files may contain stale data.


What: /sys/devices/.../signatures/
What: /sys/devices/.../signatures/[0-9]*_signature
What: /sys/devices/.../signatures/[0-9]*_transcript
What: /sys/devices/.../signatures/[0-9]*_hash_algorithm
What: /sys/devices/.../signatures/[0-9]*_combined_spdm_prefix
What: /sys/devices/.../signatures/[0-9]*_certificate_chain
Date: June 2024
Contact: Lukas Wunner <[email protected]>
Description:
The "signatures" directory contains a log of signatures
received from the device to allow for their re-verification.
It is meant for remote attestation services which do not trust
the kernel to have verified the signatures correctly or which
want to apply policy constraints of their own.

Each signature is exposed as a separate file. The filename
is prefixed with a monotonically increasing, unsigned, 32 bit
number, starting at 0.

The signature is computed over the "transcript" file, which is
a concatenation of all SPDM messages exchanged with the device.
SPDM 1.2 and newer hash the transcript with "hash_algorithm"
and prepend the "combined_spdm_prefix" before computing the
signature (SPDM 1.2.0 sec 15). For SPDM 1.0 and 1.1, that step
is omitted and "combined_spdm_prefix" is an empty file.

The signature is verified against the leaf certificate in the
"certificate_chain". To save memory, "certificate_chain" is
a symbolic link to the slot used for signature generation.
If the slot has since been provisioned with a different
certificate chain, verification of the signature will fail.

In bash syntax, the signature is verified as follows::

# number of signature to verify
num=0

# split certificate chain into individual certificates
openssl storeutl -text ${num}_certificate_chain | \
csplit -z -f /tmp/cert - '/^[0-9]*: Certificate$/' '{*}'

# extract public key from leaf certificate
leaf_cert=$(\ls /tmp/cert?? | tail -1)
openssl x509 -pubkey -in ${leaf_cert} -out ${leaf_cert}.pub

# verify signature
if [ \! -s ${num}_combined_spdm_prefix ] ; then
# SPDM 1.0 and 1.1
openssl dgst -$(cat ${num}_hash_algorithm) \
-signature ${num}_signature -verify ${leaf_cert}.pub \
${num}_transcript
else
# SPDM 1.2 and newer
openssl dgst -$(cat ${num}_hash_algorithm) \
-binary -out /tmp/transcript_hashed ${num}_transcript
openssl dgst -$(cat ${num}_hash_algorithm) \
-signature ${num}_signature -verify ${leaf_cert}.pub \
${num}_combined_spdm_prefix /tmp/transcript_hashed
fi

Note: The above works for RSA signatures, but not for ECDSA.
SPDM encodes ECDSA signatures in P1363 format (concatenation of
two raw integers), whereas openssl only supports X9.62 format
(ASN.1 DER sequence of two integers). There is no command line
utility to convert between the two formats, but most popular
crypto libraries offer conversion routines:

| https://github.com/java-crypto/cross_platform_crypto/blob/main/docs/ecdsa_signature_conversion.md

The "transcript" file can be fed to a protocol dissector to
examine the SPDM messages it contains:

| https://github.com/th-duvanel/spdm-wid
| https://github.com/jyao1/wireshark-spdm
| https://github.com/DMTF/spdm-dump

Note: To ease signature verification, the "transcript" file
does not contain the trailing signature. However the signature
is part of the final CHALLENGE_AUTH or MEASUREMENT message,
so the protocol dissector needs to be fed the concatenation of
"transcript" and "signature".

Signatures are added to the log even if the kernel was unable
to verify them (e.g. due to a missing trusted root certificate
or forged signature). Thereby, remote attestation services
may make up their own mind on the signature's validity.

Because the number prefixed to the filenames is 32 bit, it
wraps around to 0 after 4,294,967,295 signatures. The kernel
avoids filename collisions on wraparound by purging old files,
subject to the limit set by "sysctl spdm.max_signatures_size"
(which defaults to 16 MiB). It is advisable to regularly save
backups on non-volatile storage to retain access to signatures
that have been purged (or across reboots)::

# tar -u -h -f /path/to/signatures.tar signatures/

The ctime of each file is the reception time of the signature.
However if the signature was received before the device became
registered in sysfs, the ctime is the registration time of the
device.


What: /sys/devices/.../signatures/[0-9]*_type
Date: June 2024
Contact: Lukas Wunner <[email protected]>
Description:
This file contains the type of event that led to signature
generation. It is one of (sans quotes):

"responder-challenge_auth signing"
"responder-measurements signing"


What: /sys/devices/.../signatures/[0-9]*_requester_nonce
What: /sys/devices/.../signatures/[0-9]*_responder_nonce
Date: June 2024
Contact: Lukas Wunner <[email protected]>
Description:
These files contain the 32 byte nonce chosen by requester and
responder. They allow remote attestation services to verify
freshness (uniqueness) of the nonces. Nonces used more than
once can be identified with::

# hexdump -e '32/1 "%02x" "\n"' [0-9]*_nonce | sort | \
uniq -c | grep -v '^ 1'

Remote attestation services may also want to verify that the
entropy of the nonces is acceptable::

# ent 0_requester_nonce

Note: The nonces are also contained in the "transcript", but
their offsets within the transcript are variable. It would be
necessary to parse the SPDM messages in the transcript to find
and extract the nonces, which is cumbersome. That's why they
are exposed as separate files.


What: /sys/devices/.../signatures/next_requester_nonce
Date: June 2024
Contact: Lukas Wunner <[email protected]>
Description:
If you do not trust the kernel to always use a fresh nonce,
write 32 bytes to this file to set the requester nonce used
in the next SPDM authentication or measurement sequence.

Meant for remote attestation services. You are responsible
for providing a nonce with sufficient entropy. The kernel
only uses the nonce once, so provide a new one every time
you reauthenticate or measure the device. If you do not
provide a nonce, the kernel generates a random one.

After the nonce has been consumed, it becomes readable as
the newest [0-9]*_requester_nonce, which proves its usage::

# dd if=/dev/random bs=32 count=1 | \
tee signatures/next_requester_nonce | hexdump
0000000 e0 77 91 54 bd 56 99 c2 ea 4f 0b 1a 7f ba 6e 59
0000010 8f ee f6 b2 26 82 58 34 9e e5 8c 8a 31 58 29 7e

# echo re > authenticated

# hexdump $(\ls -t signatures/[0-9]*_requester_nonce | head -1)
0000000 e0 77 91 54 bd 56 99 c2 ea 4f 0b 1a 7f ba 6e 59
0000010 8f ee f6 b2 26 82 58 34 9e e5 8c 8a 31 58 29 7e
2 changes: 2 additions & 0 deletions Documentation/admin-guide/sysctl/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ kernel/ global kernel info / tuning
net/ networking stuff, for documentation look in:
<Documentation/networking/>
proc/ <empty>
spdm/ Security Protocol and Data Model (SPDM)
sunrpc/ SUN Remote Procedure Call (NFS)
vm/ memory management tuning
buffer and cache management
Expand All @@ -93,6 +94,7 @@ really like to hear about it :-)
fs
kernel
net
spdm
sunrpc
user
vm
33 changes: 33 additions & 0 deletions Documentation/admin-guide/sysctl/spdm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.. SPDX-License-Identifier: GPL-2.0

=================================
Documentation for /proc/sys/spdm/
=================================

Copyright (C) 2024 Intel Corporation

This directory allows tuning Security Protocol and Data Model (SPDM)
parameters. SPDM enables device authentication, measurement, key
exchange and encrypted sessions.

max_signatures_size
===================

Maximum amount of memory occupied by the log of signatures (per device,
in bytes, 16 MiB by default).

The log is meant for re-verification of signatures by remote attestation
services which do not trust the kernel to have verified the signatures
correctly or which want to apply policy constraints of their own.
A signature is computed over the transcript (a concatenation of all
SPDM messages exchanged with the device during an authentication or
measurement sequence). The transcript can be a few kBytes or up to
several MBytes in size, hence this parameter prevents the log from
consuming too much memory.

The kernel always stores the most recent signature in the log even if it
exceeds ``max_signatures_size``. Additionally as many older signatures
are kept in the log as this limit allows.

If you reduce the limit, signatures are purged immediately to free up
memory.
2 changes: 1 addition & 1 deletion Documentation/crypto/api-akcipher.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Asymmetric Cipher API
:doc: Generic Public Key API

.. kernel-doc:: include/crypto/akcipher.h
:functions: crypto_alloc_akcipher crypto_free_akcipher crypto_akcipher_set_pub_key crypto_akcipher_set_priv_key crypto_akcipher_maxsize crypto_akcipher_encrypt crypto_akcipher_decrypt crypto_akcipher_sign crypto_akcipher_verify
:functions: crypto_alloc_akcipher crypto_free_akcipher crypto_akcipher_set_pub_key crypto_akcipher_set_priv_key crypto_akcipher_maxsize crypto_akcipher_encrypt crypto_akcipher_decrypt

Asymmetric Cipher Request Handle
--------------------------------
Expand Down
15 changes: 15 additions & 0 deletions Documentation/crypto/api-sig.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Asymmetric Signature Algorithm Definitions
------------------------------------------

.. kernel-doc:: include/crypto/sig.h
:functions: sig_alg

Asymmetric Signature API
------------------------

.. kernel-doc:: include/crypto/sig.h
:doc: Generic Public Key Signature API

.. kernel-doc:: include/crypto/sig.h
:functions: crypto_alloc_sig crypto_free_sig crypto_sig_set_pubkey crypto_sig_set_privkey crypto_sig_keysize crypto_sig_maxsize crypto_sig_digestsize crypto_sig_sign crypto_sig_verify

1 change: 1 addition & 0 deletions Documentation/crypto/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Programming Interface
api-digest
api-rng
api-akcipher
api-sig
api-kpp
2 changes: 2 additions & 0 deletions Documentation/crypto/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ the aforementioned cipher types:

- CRYPTO_ALG_TYPE_AKCIPHER Asymmetric cipher

- CRYPTO_ALG_TYPE_SIG Asymmetric signature

- CRYPTO_ALG_TYPE_PCOMPRESS Enhanced version of
CRYPTO_ALG_TYPE_COMPRESS allowing for segmented compression /
decompression instead of performing the operation on one segment
Expand Down
14 changes: 14 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -20836,6 +20836,20 @@ M: Security Officers <[email protected]>
S: Supported
F: Documentation/process/security-bugs.rst

SECURITY PROTOCOL AND DATA MODEL (SPDM)
M: Jonathan Cameron <[email protected]>
M: Lukas Wunner <[email protected]>
L: [email protected]
L: [email protected]
L: [email protected]
S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/devsec/spdm.git
F: Documentation/ABI/testing/sysfs-devices-spdm
F: Documentation/admin-guide/sysctl/spdm.rst
F: drivers/pci/cma*
F: include/linux/spdm.h
F: lib/spdm/

SECURITY SUBSYSTEM
M: Paul Moore <[email protected]>
M: James Morris <[email protected]>
Expand Down
4 changes: 2 additions & 2 deletions certs/blacklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ static int restrict_link_for_blacklist(struct key *dest_keyring,
* Initialise the blacklist
*
* The blacklist_init() function is registered as an initcall via
* device_initcall(). As a result if the blacklist_init() function fails for
* arch_initcall(). As a result if the blacklist_init() function fails for
* any reason the kernel continues to execute. While cleanly returning -ENODEV
* could be acceptable for some non-critical kernel parts, if the blacklist
* keyring fails to load it defeats the certificate/key based deny list for
Expand Down Expand Up @@ -356,7 +356,7 @@ static int __init blacklist_init(void)
/*
* Must be initialised before we try and load the keys into the keyring.
*/
device_initcall(blacklist_init);
arch_initcall(blacklist_init);

#ifdef CONFIG_SYSTEM_REVOCATION_LIST
/*
Expand Down
Loading