[RFC 0/6] lib: Rust implementation of SPDM

Alistair Francis posted 6 patches 1 week ago
MAINTAINERS                     |   6 +
drivers/pci/Kconfig             |   2 +-
lib/Kconfig                     |  47 ++-
lib/Makefile                    |   1 +
lib/rspdm/Makefile              |  11 +
lib/rspdm/consts.rs             | 123 +++++++
lib/rspdm/lib.rs                | 146 +++++++++
lib/rspdm/req-sysfs.c           | 174 ++++++++++
lib/rspdm/state.rs              | 556 ++++++++++++++++++++++++++++++++
lib/rspdm/sysfs.rs              |  27 ++
lib/rspdm/validator.rs          | 301 +++++++++++++++++
rust/bindgen_static_functions   |   4 +
rust/bindings/bindings_helper.h |   2 +
13 files changed, 1384 insertions(+), 16 deletions(-)
create mode 100644 lib/rspdm/Makefile
create mode 100644 lib/rspdm/consts.rs
create mode 100644 lib/rspdm/lib.rs
create mode 100644 lib/rspdm/req-sysfs.c
create mode 100644 lib/rspdm/state.rs
create mode 100644 lib/rspdm/sysfs.rs
create mode 100644 lib/rspdm/validator.rs
[RFC 0/6] lib: Rust implementation of SPDM
Posted by Alistair Francis 1 week ago
Security Protocols and Data Models (SPDM) [1] is used for authentication,
attestation and key exchange. SPDM is generally used over a range of
transports, such as PCIe, MCTP/SMBus/I3C, ATA, SCSI, NVMe or TCP.

From the kernels perspective SPDM is used to authenticate and attest devices.
In this threat model a device is considered untrusted until it can be verified
by the kernel and userspace using SPDM. As such SPDM data is untrusted data
that can be mallicious.

The SPDM specification is also complex, with the 1.2.1 spec being almost 200
pages and the 1.3.0 spec being almost 250 pages long.

As such we have the kernel parsing untrusted responses from a complex
specification, which sounds like a possible exploit vector.

As such this series implements a SPDM requester in Rust.

This is very similar to Lukas' implementation [2]. This series applies on top
of Lukas' tree [3] and is heavily based on Lukas' work. At build time a user can
choose to use either the Rust of the C SPDM implementation. The two are
interchangable, although you can only use one at a time.

To help with maintaining compatibility it's designed in a way to match Lukas'
design and the state struct stores the same information, although in a Rust
struct instead of the original C one.

The Rust implementation currently supports less features, but my end goal
is to consolidate to a single Rust implementation eventually. That will
probably have to wait until Rust in the kernel is no longer experimental
as SPDM is looking to be an important feature to support for all platforms.

This series is based on the latest rust-next tree.

This seris depends on the Untrusted abstraction work [4].

This seris also depends on the recent bindgen support for static inlines  [5].

The entire tree can be seen here: https://github.com/alistair23/linux/tree/alistair/spdm-rust

based-on: https://lore.kernel.org/all/cover.1719771133.git.lukas@wunner.de/
based-on: https://lore.kernel.org/rust-for-linux/20240925205244.873020-1-benno.lossin@proton.me/
based-on: https://lore.kernel.org/all/20241114005631.818440-1-alistair@alistair23.me/

1: https://www.dmtf.org/standards/spdm
2: https://lore.kernel.org/all/cover.1719771133.git.lukas@wunner.de/
3: https://github.com/l1k/linux/commits/spdm-future/
4: https://lore.kernel.org/rust-for-linux/20240925205244.873020-1-benno.lossin@proton.me/
5: https://lore.kernel.org/all/20241114005631.818440-1-alistair@alistair23.me/

Alistair Francis (6):
  rust: bindings: Support SPDM bindings
  drivers: pci: Change CONFIG_SPDM to a dependency
  lib: rspdm: Initial commit of Rust SPDM
  lib: rspdm: Support SPDM get_version
  lib: rspdm: Support SPDM get_capabilities
  lib: rspdm: Support SPDM negotiate_algorithms

 MAINTAINERS                     |   6 +
 drivers/pci/Kconfig             |   2 +-
 lib/Kconfig                     |  47 ++-
 lib/Makefile                    |   1 +
 lib/rspdm/Makefile              |  11 +
 lib/rspdm/consts.rs             | 123 +++++++
 lib/rspdm/lib.rs                | 146 +++++++++
 lib/rspdm/req-sysfs.c           | 174 ++++++++++
 lib/rspdm/state.rs              | 556 ++++++++++++++++++++++++++++++++
 lib/rspdm/sysfs.rs              |  27 ++
 lib/rspdm/validator.rs          | 301 +++++++++++++++++
 rust/bindgen_static_functions   |   4 +
 rust/bindings/bindings_helper.h |   2 +
 13 files changed, 1384 insertions(+), 16 deletions(-)
 create mode 100644 lib/rspdm/Makefile
 create mode 100644 lib/rspdm/consts.rs
 create mode 100644 lib/rspdm/lib.rs
 create mode 100644 lib/rspdm/req-sysfs.c
 create mode 100644 lib/rspdm/state.rs
 create mode 100644 lib/rspdm/sysfs.rs
 create mode 100644 lib/rspdm/validator.rs

-- 
2.47.0