Add Nitro Secure Module support
Subsystems (4)
Alexander Graf
maintainerPATCH v4 1/2 Import CBOR library
In reply to Alexander GrafTo fully support the Nitro Secure Module communication protocol, we need to encode and decode CBOR binary data. Import an MIT licensed library from https://github.com/libmcu/cbor (commit f3d1696f886) so that we can easily consume CBOR data.
On top of the upstream code base, I added kernel module as well as kernel header path awareness and made checkpatch happy.
---
v3 -> v4:
- New in v4
--- MAINTAINERS | 8 ++ include/linux/cbor/base.h | 94 ++++++++++++++ include/linux/cbor/cbor.h | 22 ++++ include/linux/cbor/decoder.h | 42 ++++++ include/linux/cbor/encoder.h | 48 +++++++ include/linux/cbor/helper.h | 41 ++++++ include/linux/cbor/ieee754.h | 52 ++++++++ include/linux/cbor/parser.h | 32 +++++ lib/Kconfig | 3 + lib/Makefile | 2 + lib/cbor/Makefile | 12 ++ lib/cbor/common.c | 105 +++++++++++++++ lib/cbor/decoder.c | 170 ++++++++++++++++++++++++ lib/cbor/encoder.c | 218 +++++++++++++++++++++++++++++++ lib/cbor/helper.c | 175 +++++++++++++++++++++++++ lib/cbor/ieee754.c | 205 +++++++++++++++++++++++++++++ lib/cbor/parser.c | 243 +++++++++++++++++++++++++++++++++++ 17 files changed, 1472 insertions(+) create mode 100644 include/linux/cbor/base.h create mode 100644 include/linux/cbor/cbor.h create mode 100644 include/linux/cbor/decoder.h create mode 100644 include/linux/cbor/encoder.h create mode 100644 include/linux/cbor/helper.h create mode 100644 include/linux/cbor/ieee754.h create mode 100644 include/linux/cbor/parser.h create mode 100644 lib/cbor/Makefile create mode 100644 lib/cbor/common.c create mode 100644 lib/cbor/decoder.c create mode 100644 lib/cbor/encoder.c create mode 100644 lib/cbor/helper.c create mode 100644 lib/cbor/ieee754.c create mode 100644 lib/cbor/parser.c
MAINTAINERS +8 -0
@@ -4661,6 +4661,14 @@ S: Odd Fixes F: Documentation/devicetree/bindings/arm/cavium-thunder2.txt F: arch/arm64/boot/dts/cavium/thunder2-99xx* +CBOR LIBRARY +M: Alexander Graf <[email protected]> +L: [email protected] +L: The AWS Nitro Enclaves Team <[email protected]> +S: Supported +F: include/linux/cbor/ +F: lib/cbor/ + CBS/ETF/TAPRIO QDISCS M: Vinicius Costa Gomes <[email protected]> L: [email protected]
include/linux/cbor/base.h new file +94 -0
94 lines not on this page · raw message
include/linux/cbor/cbor.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: MIT */ +/* +* SPDX-FileCopyrightText: 2021 Kyunghwan Kwon <[email protected]> +*/ + +#ifndef CBOR_H +#define CBOR_H + +#if defined(__cplusplus) +extern "C" { +#endif + +#include <linux/cbor/parser.h> +#include <linux/cbor/decoder.h> +#include <linux/cbor/encoder.h> +#include <linux/cbor/helper.h> + +#if defined(__cplusplus) +} +#endif + +#endif /* CBOR_H */
include/linux/cbor/decoder.h new file +42 -0
42 lines not on this page · raw message
include/linux/cbor/encoder.h new file +48 -0
48 lines not on this page · raw message
include/linux/cbor/helper.h new file +41 -0
41 lines not on this page · raw message
include/linux/cbor/ieee754.h new file +52 -0
52 lines not on this page · raw message
include/linux/cbor/parser.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: MIT */ +/* +* SPDX-FileCopyrightText: 2021 Kyunghwan Kwon <[email protected]> +*/ + +#ifndef CBOR_PARSER_H +#define CBOR_PARSER_H + +#if defined(__cplusplus) +extern "C" { +#endif + +#include <linux/cbor/base.h> + +/** +* Parse the encoded CBOR messages into items. +* +* @param[in,out] reader reader context for the actual encoded message +* @param[in] msg CBOR encoded message +* @param[in] msgsize the @p msg size in bytes +* @param[out] nitems_parsed the number of items parsed gets stored if not null +* +* @return a code of @ref cbor_error_t +*/ +cbor_error_t cbor_parse (cbor_reader_t *reader,void const *msg,size_t msgsize, +size_t *nitems_parsed); + +#if defined(__cplusplus) +} +#endif + +#endif /* CBOR_PARSER_H */
lib/Kconfig +3 -0
@@ -764,3 +764,6 @@ config ASN1_ENCODER config POLYNOMIAL tristate + +config CBOR + tristate
lib/Makefile +2 -0
@@ -317,6 +317,8 @@ obj-$(CONFIG_ASN1_ENCODER) += asn1_encoder.o obj-$(CONFIG_FONT_SUPPORT) += fonts/ +obj-$(CONFIG_CBOR) += cbor/ + hostprogs := gen_crc32table hostprogs += gen_crc64table clean-files := crc32table.h
lib/cbor/Makefile new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_CBOR) += cbor.o + +cbor-y := \ + common.o \ + decoder.o \ + encoder.o \ + helper.o \ + parser.o \ + +cbor-$(CONFIG_CBOR_FLOAT) += ieee754.o
lib/cbor/common.c new file +105 -0
105 lines not on this page · raw message
lib/cbor/decoder.c new file +170 -0
170 lines not on this page · raw message
lib/cbor/encoder.c new file +218 -0
218 lines not on this page · raw message
lib/cbor/helper.c new file +175 -0
175 lines not on this page · raw message
lib/cbor/ieee754.c new file +205 -0
205 lines not on this page · raw message
lib/cbor/parser.c new file +243 -0
243 lines not on this page · raw message
Signature · 12 lines
2.40.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879
Alexander Graf
maintainerv4 cover Add Nitro Secure Module support
Nitro Enclaves run Linux inside as well as outside the Enclave. Outside the Enclave, we already have the nitro_enclaves driver in upstream Linux which controls a Nitro Enclave's lifecycle.
Inside the Enclave, the environment looks like a typical Firecracker microvm. In addition to standard virtio devices, an Enclave also has an additional "Nitro Secure Module" (NSM) virtio device which so far was missing an upstream Linux driver. The NSM provides access to PCRs, an attestation document as well as entropy.
To support the NSM communication protocol, Linux needs to learn to generate and parse the Concise Binary Object Representation (CBOR) format. The first patch adds support for a CBOR library. The second adds the actual NSM driver.
With these patches in place, upstream Linux has everything that's needed to run inside a Nitro Enclave.
Alex
v1 -> v2:
- Remove boilerplate
- Add uapi header
v2 -> v3:
- Move globals to device struct
- Add compat handling
- Simplify some naming
- Remove debug prints
- Use module_virtio_driver
- Ensure remove only happens on target device
- Drop use of uio.h
v3 -> v4:
- Add CBOR library
- Merge hwrng into the misc driver
- Add dependency on CBOR library
- Add internal and ioctl logic for all current NSM actions
- Use in-struct arrays instead of kvecs
- Add sysfs entries for NSM metadata
- Use dev_ print and devm_ allocation helpers
Alexander Graf (2):
Import CBOR library
misc: Add Nitro Secure Module driver
MAINTAINERS | 17 + drivers/misc/Kconfig | 13 + drivers/misc/Makefile | 1 + drivers/misc/nsm.c | 1466 ++++++++++++++++++++++++++++++++++ include/linux/cbor/base.h | 94 +++ include/linux/cbor/cbor.h | 22 + include/linux/cbor/decoder.h | 42 + include/linux/cbor/encoder.h | 48 ++ include/linux/cbor/helper.h | 41 + include/linux/cbor/ieee754.h | 52 ++ include/linux/cbor/parser.h | 32 + include/uapi/linux/nsm.h | 188 +++++ lib/Kconfig | 3 + lib/Makefile | 2 + lib/cbor/Makefile | 12 + lib/cbor/common.c | 105 +++ lib/cbor/decoder.c | 170 ++++ lib/cbor/encoder.c | 218 +++++ lib/cbor/helper.c | 175 ++++ lib/cbor/ieee754.c | 205 +++++ lib/cbor/parser.c | 243 ++++++ 21 files changed, 3149 insertions(+) create mode 100644 drivers/misc/nsm.c create mode 100644 include/linux/cbor/base.h create mode 100644 include/linux/cbor/cbor.h create mode 100644 include/linux/cbor/decoder.h create mode 100644 include/linux/cbor/encoder.h create mode 100644 include/linux/cbor/helper.h create mode 100644 include/linux/cbor/ieee754.h create mode 100644 include/linux/cbor/parser.h create mode 100644 include/uapi/linux/nsm.h create mode 100644 lib/cbor/Makefile create mode 100644 lib/cbor/common.c create mode 100644 lib/cbor/decoder.c create mode 100644 lib/cbor/encoder.c create mode 100644 lib/cbor/helper.c create mode 100644 lib/cbor/ieee754.c create mode 100644 lib/cbor/parser.c
Signature · 12 lines
2.40.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879
Alexander Graf
maintainerPATCH v4 2/2 misc: Add Nitro Secure Module driver
When running Linux inside a Nitro Enclave, the hypervisor provides a special virtio device called "NSM". This device has 3 main functions:
1) Provide attestation reports
2) Modify PCR state
3) Provide entropy
This patch adds a driver for NSM that exposes a /dev/nsm device node which user space can issue ioctls on to request attestation documents, influence PCR states, read entropy and enumerate status of the device. In addition, the driver implements a hwrng backend and exposes some of the NSM device metadata as sysfs entries.
---
v1 -> v2:
- Remove boilerplate
- Add uapi header
v2 -> v3:
- Move globals to device struct
- Add compat handling
- Simplify some naming
- Remove debug prints
- Use module_virtio_driver
- Drop use of uio.h
v3 -> v4:
- Merge hwrng into the misc driver
- Add dependency on CBOR library
- Add internal and ioctl logic for all current NSM actions
- Use in-struct arrays instead of kvecs
- Add sysfs entries for NSM metadata
- Use dev_ print and devm_ allocation helpers
--- MAINTAINERS | 9 + drivers/misc/Kconfig | 13 + drivers/misc/Makefile | 1 + drivers/misc/nsm.c | 1466 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/nsm.h | 188 +++++ 5 files changed, 1677 insertions(+) create mode 100644 drivers/misc/nsm.c create mode 100644 include/uapi/linux/nsm.h
MAINTAINERS +9 -0
@@ -15104,6 +15104,15 @@ F: include/linux/nitro_enclaves.h F: include/uapi/linux/nitro_enclaves.h F: samples/nitro_enclaves/ +NITRO SECURE MODULE (NSM) +M: Alexander Graf <[email protected]> +L: [email protected] +L: The AWS Nitro Enclaves Team <[email protected]> +S: Supported +W: https://aws.amazon.com/ec2/nitro/nitro-enclaves/ +F: drivers/misc/nsm.c +F: include/uapi/linux/nsm.h + NOHZ, DYNTICKS SUPPORT M: Frederic Weisbecker <[email protected]> M: Thomas Gleixner <[email protected]>
drivers/misc/Kconfig +13 -0
@@ -562,6 +562,19 @@ config TPS6594_PFSM This driver can also be built as a module. If so, the module will be called tps6594-pfsm. +config NSM + tristate "Nitro (Enclaves) Security Module support" + depends on VIRTIO + select HW_RANDOM + select CBOR + help + This driver provides support for the Nitro Security Module + in AWS EC2 Nitro based Enclaves. The driver exposes a /dev/nsm + device user space can use to communicate with the hypervisor. + + To compile this driver as a module, choose M here. + The module will be called nsm. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
@@ -67,3 +67,4 @@ obj-$(CONFIG_TMR_MANAGER) += xilinx_tmr_manager.o obj-$(CONFIG_TMR_INJECT) += xilinx_tmr_inject.o obj-$(CONFIG_TPS6594_ESM) += tps6594-esm.o obj-$(CONFIG_TPS6594_PFSM) += tps6594-pfsm.o +obj-$(CONFIG_NSM) += nsm.o
drivers/misc/nsm.c new file +1466 -0
1,466 lines not on this page · raw message
include/uapi/linux/nsm.h new file +188 -0
188 lines not on this page · raw message
Signature · 12 lines
2.40.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/2] Import CBOR library
In reply to Alexander GrafQuoted 4 lines · Alexander Graf
To fully support the Nitro Secure Module communication protocol, we need to encode and decode CBOR binary data. Import an MIT licensed library from https://github.com/libmcu/cbor (commit
f3d1696f886) so that we can easily consume CBOR data.
What is "CBOR"? I don't see a description of it here.
And I guess you are going to keep this in sync with upstream? Or do you really need the full library here (you #ifdef the float stuff out), does your module really need all of the functionality and complexity of this library, or can it use just a much smaller one instead?
Quoted 2 lines
On top of the upstream code base, I added kernel module as well as kernel header path awareness and made checkpatch happy.
If only the one module needs this, why not put it in the directory for the module itself, and then when/if anyone else needs it, it could be moved?
thanks,
greg k-h
Greg Kroah-Hartman
maintainerRe: [PATCH v4 2/2] misc: Add Nitro Secure Module driver
In reply to Alexander GrafQuoted 32 lines · Alexander Graf
When running Linux inside a Nitro Enclave, the hypervisor provides a special virtio device called "NSM". This device has 3 main functions:
1) Provide attestation reports
2) Modify PCR state
3) Provide entropyThis patch adds a driver for NSM that exposes a
/dev/nsmdevice node which user space can issue ioctls on to request attestation documents, influence PCR states, read entropy and enumerate status of the device. In addition, the driver implements a hwrng backend and exposes some of the NSM device metadata as sysfs entries.Originally-by Petre Eftime <[email protected]>Signed-off-by Alexander Graf <[email protected]>---
v1 -> v2:
- Remove boilerplate
- Add uapi headerv2 -> v3:
- Move globals to device struct
- Add compat handling
- Simplify some naming
- Remove debug prints
- Usemodule_virtio_driver
- Drop use ofuio.h
Quoted 7 lines
v3 -> v4:
- Merge hwrng into the misc driver
- Add dependency on CBOR library
- Add internal and ioctl logic for all current NSM actions
- Use in-struct arrays instead of kvecs
- Add sysfs entries for NSM metadata
You forgot Documentation/ABI/ entries for your new sysfs files so we can see what exactly they are and if they are sane.
thanks,
greg k-h
Alexander Graf
maintainerRe: [PATCH v4 1/2] Import CBOR library
In reply to Greg Kroah-HartmanHey Greg,
Quoted 6 lines · Greg Kroah-Hartman
Quoted 4 lines · Alexander Graf
To fully support the Nitro Secure Module communication protocol, we need to encode and decode CBOR binary data. Import an MIT licensed library from https://github.com/libmcu/cbor (commit
f3d1696f886) so that we can easily consume CBOR data.What is "CBOR"? I don't see a description of it here.
CBOR is the "Concise Binary Object Representation" (https://en.wikipedia.org/wiki/CBOR) binary format.
Quoted 5 lines
And I guess you are going to keep this in sync with upstream? Or do you really need the full library here (you #ifdef the float stuff out), does your module really need all of the functionality and complexity of this library, or can it use just a much smaller one instead?
CBOR knows a total of 9 data types:
- Unsigned integers
- Signed integers
- Binary string
- UTF-8 string
- Arrays
- Maps (like a python dictionary)
- Semantic tag
- Bools
- Floats
Out of these, the NSM communication protocol uses all except Semantic tags and Floats. The CBOR library that this patch imports does not have special handling for Semantic tags, which leaves only floats which are already #ifdef'ed out. That means there is not much to trim.
What you see here is what's needed to parse CBOR in kernel - if that's what we want to do. I'm happy to rip it out again and make it a pure user space problem to do CBOR :).
Quoted 6 lines
Quoted 3 lines
On top of the upstream code base, I added kernel module as well as kernel header path awareness and made checkpatch happy.
If only the one module needs this, why not put it in the directory for the module itself, and then when/if anyone else needs it, it could be moved?
That sounds like a great idea! Let me do that :)
Alex
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/2] Import CBOR library
Quoted 34 lines · Alexander Graf
Hey Greg,
Quoted 6 lines · Greg Kroah-Hartman
Quoted 4 lines · Alexander Graf
To fully support the Nitro Secure Module communication protocol, we need to encode and decode CBOR binary data. Import an MIT licensed library from https://github.com/libmcu/cbor (commit
f3d1696f886) so that we can easily consume CBOR data.What is "CBOR"? I don't see a description of it here.
CBOR is the "Concise Binary Object Representation"
(https://en.wikipedia.org/wiki/CBOR) binary format.Quoted 5 lines
And I guess you are going to keep this in sync with upstream? Or do you really need the full library here (you #ifdef the float stuff out), does your module really need all of the functionality and complexity of this library, or can it use just a much smaller one instead?
CBOR knows a total of 9 data types:
- Unsigned integers
- Signed integers
- Binary string
- UTF-8 string
- Arrays
- Maps (like a python dictionary)
- Semantic tag
- Bools
- Floats
Quoted 8 lines
Out of these, the NSM communication protocol uses all except Semantic tags and Floats. The CBOR library that this patch imports does not have special handling for Semantic tags, which leaves only floats which are already #ifdef'ed out. That means there is not much to trim.
What you see here is what's needed to parse CBOR in kernel - if that's what we want to do. I'm happy to rip it out again and make it a pure user space problem to do CBOR :).
Yes, why are we parsing this in the kernel? What could go wrong with adding yet-another-parser in privileged context? :)
Why does this have to be in the kernel, the data sent/recieved is over virtio, so why does the kernel have to parse it? I couldn't figure that out from the driver, yet the driver seems to have a lot of hard-coded parsing logic in it to assume specific message formats?
thanks,
greg k-h
Alexander Graf
maintainerRe: [PATCH v4 1/2] Import CBOR library
Quoted 41 lines · Greg Kroah-Hartman
Quoted 31 lines · Alexander Graf
Hey Greg,
Quoted 6 lines · Greg Kroah-Hartman
Quoted 4 lines · Alexander Graf
To fully support the Nitro Secure Module communication protocol, we need to encode and decode CBOR binary data. Import an MIT licensed library from https://github.com/libmcu/cbor (commit
f3d1696f886) so that we can easily consume CBOR data.What is "CBOR"? I don't see a description of it here.
CBOR is the "Concise Binary Object Representation"
(https://en.wikipedia.org/wiki/CBOR) binary format.Quoted 4 lines
And I guess you are going to keep this in sync with upstream? Or do you really need the full library here (you #ifdef the float stuff out), does your module really need all of the functionality and complexity of this library, or can it use just a much smaller one instead?
CBOR knows a total of 9 data types:
- Unsigned integers
- Signed integers
- Binary string
- UTF-8 string
- Arrays
- Maps (like a python dictionary)
- Semantic tag
- Bools
- FloatsQuoted 8 lines
Out of these, the NSM communication protocol uses all except Semantic tags and Floats. The CBOR library that this patch imports does not have special handling for Semantic tags, which leaves only floats which are already #ifdef'ed out. That means there is not much to trim.
What you see here is what's needed to parse CBOR in kernel - if that's what we want to do. I'm happy to rip it out again and make it a pure user space problem to do CBOR :).
Quoted 7 lines
Yes, why are we parsing this in the kernel? What could go wrong with adding yet-another-parser in privileged context? :)
Why does this have to be in the kernel, the data sent/recieved is over virtio, so why does the kernel have to parse it? I couldn't figure that out from the driver, yet the driver seems to have a lot of hard-coded parsing logic in it to assume specific message formats?
The parsing doesn't have to be in kernel and it probably shouldn't be either. V3 of the patch was punting all the parsing to user space, at which point you and Arnd said I should give it a try to do the protocol parsing in kernel space instead. That's why the parser is here.
If we conclude that all this in-kernel parsing is not worth it, I'm very happy to just go back to the the v3 ioctl interface and post v5 with hwrng merged into misc, but remove all CBOR logic again :)
Alex
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/2] Import CBOR library
Quoted 52 lines · Alexander Graf
Quoted 41 lines · Greg Kroah-Hartman
Quoted 31 lines · Alexander Graf
Hey Greg,
Quoted 6 lines · Greg Kroah-Hartman
Quoted 4 lines · Alexander Graf
To fully support the Nitro Secure Module communication protocol, we need to encode and decode CBOR binary data. Import an MIT licensed library from https://github.com/libmcu/cbor (commit
f3d1696f886) so that we can easily consume CBOR data.What is "CBOR"? I don't see a description of it here.
CBOR is the "Concise Binary Object Representation"
(https://en.wikipedia.org/wiki/CBOR) binary format.Quoted 4 lines
And I guess you are going to keep this in sync with upstream? Or do you really need the full library here (you #ifdef the float stuff out), does your module really need all of the functionality and complexity of this library, or can it use just a much smaller one instead?
CBOR knows a total of 9 data types:
- Unsigned integers
- Signed integers
- Binary string
- UTF-8 string
- Arrays
- Maps (like a python dictionary)
- Semantic tag
- Bools
- FloatsQuoted 8 lines
Out of these, the NSM communication protocol uses all except Semantic tags and Floats. The CBOR library that this patch imports does not have special handling for Semantic tags, which leaves only floats which are already #ifdef'ed out. That means there is not much to trim.
What you see here is what's needed to parse CBOR in kernel - if that's what we want to do. I'm happy to rip it out again and make it a pure user space problem to do CBOR :).
Quoted 7 lines
Yes, why are we parsing this in the kernel? What could go wrong with adding yet-another-parser in privileged context? :)
Why does this have to be in the kernel, the data sent/recieved is over virtio, so why does the kernel have to parse it? I couldn't figure that out from the driver, yet the driver seems to have a lot of hard-coded parsing logic in it to assume specific message formats?
Quoted 4 lines
The parsing doesn't have to be in kernel and it probably shouldn't be either. V3 of the patch was punting all the parsing to user space, at which point you and Arnd said I should give it a try to do the protocol parsing in kernel space instead. That's why the parser is here.
Arnd said that, not me :)
Quoted 3 lines
If we conclude that all this in-kernel parsing is not worth it, I'm very happy to just go back to the the v3 ioctl interface and post v5 with hwrng merged into misc, but remove all CBOR logic again :)
I think the less parsers we have in the kernel, the safer we are for obvious reasons. Unless you have a parser for this in rust? :)
I don't really know, having a generic interface is good, but at the expense of this api is probably not good. individual ioctls might be better if there are not going to be any other drivers for this type of thing?
it's a tough call, let's see what a unified driver, no parser, looks like, that should be pretty simple and small so maybe stick with that?
thanks,
greg k-h
Arnd Bergmann
maintainerRe: [PATCH v4 1/2] Import CBOR library
Quoted 31 lines · Greg Kroah-Hartman
Quoted 19 lines · Alexander Graf
Quoted 8 lines · Greg Kroah-Hartman
Quoted 8 lines
Out of these, the NSM communication protocol uses all except Semantic tags and Floats. The CBOR library that this patch imports does not have special handling for Semantic tags, which leaves only floats which are already #ifdef'ed out. That means there is not much to trim.
What you see here is what's needed to parse CBOR in kernel - if that's what we want to do. I'm happy to rip it out again and make it a pure user space problem to do CBOR :).
Quoted 7 lines
Yes, why are we parsing this in the kernel? What could go wrong with adding yet-another-parser in privileged context? :)
Why does this have to be in the kernel, the data sent/recieved is over virtio, so why does the kernel have to parse it? I couldn't figure that out from the driver, yet the driver seems to have a lot of hard-coded parsing logic in it to assume specific message formats?
Quoted 4 lines
The parsing doesn't have to be in kernel and it probably shouldn't be either. V3 of the patch was punting all the parsing to user space, at which point you and Arnd said I should give it a try to do the protocol parsing in kernel space instead. That's why the parser is here.
Arnd said that, not me :)
Quoted 3 lines
If we conclude that all this in-kernel parsing is not worth it, I'm very happy to just go back to the the v3 ioctl interface and post v5 with hwrng merged into misc, but remove all CBOR logic again :)
Quoted 7 lines
I think the less parsers we have in the kernel, the safer we are for obvious reasons. Unless you have a parser for this in rust? :)
I don't really know, having a generic interface is good, but at the expense of this api is probably not good. individual ioctls might be better if there are not going to be any other drivers for this type of thing?
I was definitely expecting something simpler than what was possible in the v4 patch. I had another look now, and it's clear that the ioctl interface is still not great because the variable data structures shine through for some of the calls, and even to get to this point, a whole lot of complexity is required underneath.
To get anything better, one would probably have to redesign the entire interface stack (hypervisor, kernel and userland) to use regular fixed data structures, and this seems unlikely to happen.
Arnd
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/2] Import CBOR library
Quoted 46 lines · Arnd Bergmann
Quoted 31 lines · Greg Kroah-Hartman
Quoted 19 lines · Alexander Graf
Quoted 8 lines · Greg Kroah-Hartman
Quoted 8 lines
Out of these, the NSM communication protocol uses all except Semantic tags and Floats. The CBOR library that this patch imports does not have special handling for Semantic tags, which leaves only floats which are already #ifdef'ed out. That means there is not much to trim.
What you see here is what's needed to parse CBOR in kernel - if that's what we want to do. I'm happy to rip it out again and make it a pure user space problem to do CBOR :).
Quoted 7 lines
Yes, why are we parsing this in the kernel? What could go wrong with adding yet-another-parser in privileged context? :)
Why does this have to be in the kernel, the data sent/recieved is over virtio, so why does the kernel have to parse it? I couldn't figure that out from the driver, yet the driver seems to have a lot of hard-coded parsing logic in it to assume specific message formats?
Quoted 4 lines
The parsing doesn't have to be in kernel and it probably shouldn't be either. V3 of the patch was punting all the parsing to user space, at which point you and Arnd said I should give it a try to do the protocol parsing in kernel space instead. That's why the parser is here.
Arnd said that, not me :)
Quoted 3 lines
If we conclude that all this in-kernel parsing is not worth it, I'm very happy to just go back to the the v3 ioctl interface and post v5 with hwrng merged into misc, but remove all CBOR logic again :)
Quoted 7 lines
I think the less parsers we have in the kernel, the safer we are for obvious reasons. Unless you have a parser for this in rust? :)
I don't really know, having a generic interface is good, but at the expense of this api is probably not good. individual ioctls might be better if there are not going to be any other drivers for this type of thing?
I was definitely expecting something simpler than what was possible in the v4 patch. I had another look now, and it's clear that the ioctl interface is still not great because the variable data structures shine through for some of the calls, and even to get to this point, a whole lot of complexity is required underneath.
Quoted 3 lines
To get anything better, one would probably have to redesign the entire interface stack (hypervisor, kernel and userland) to use regular fixed data structures, and this seems unlikely to happen.
Why not fix this and do it properly? What's preventing that from happening? We don't want to create an interface here that is broken, or insecure, or a pain to maintain, right?
thanks,
greg k-h
Alexander Graf
maintainerRe: [PATCH v4 1/2] Import CBOR library
Quoted 44 lines · Greg Kroah-Hartman
Quoted 42 lines · Arnd Bergmann
Quoted 28 lines · Greg Kroah-Hartman
Quoted 18 lines · Alexander Graf
Quoted 8 lines · Greg Kroah-Hartman
Quoted 8 lines
Out of these, the NSM communication protocol uses all except Semantic tags and Floats. The CBOR library that this patch imports does not have special handling for Semantic tags, which leaves only floats which are already #ifdef'ed out. That means there is not much to trim.
What you see here is what's needed to parse CBOR in kernel - if that's what we want to do. I'm happy to rip it out again and make it a pure user space problem to do CBOR :).
Quoted 7 lines
Yes, why are we parsing this in the kernel? What could go wrong with adding yet-another-parser in privileged context? :)
Why does this have to be in the kernel, the data sent/recieved is over virtio, so why does the kernel have to parse it? I couldn't figure that out from the driver, yet the driver seems to have a lot of hard-coded parsing logic in it to assume specific message formats?
Quoted 4 lines
The parsing doesn't have to be in kernel and it probably shouldn't be either. V3 of the patch was punting all the parsing to user space, at which point you and Arnd said I should give it a try to do the protocol parsing in kernel space instead. That's why the parser is here.
Arnd said that, not me :)
Quoted 3 lines
If we conclude that all this in-kernel parsing is not worth it, I'm very happy to just go back to the the v3 ioctl interface and post v5 with hwrng merged into misc, but remove all CBOR logic again :)
Quoted 7 lines
I think the less parsers we have in the kernel, the safer we are for obvious reasons. Unless you have a parser for this in rust? :)
I don't really know, having a generic interface is good, but at the expense of this api is probably not good. individual ioctls might be better if there are not going to be any other drivers for this type of thing?
I was definitely expecting something simpler than what was possible in the v4 patch. I had another look now, and it's clear that the ioctl interface is still not great because the variable data structures shine through for some of the calls, and even to get to this point, a whole lot of complexity is required underneath.
Quoted 6 lines
Quoted 3 lines
To get anything better, one would probably have to redesign the entire interface stack (hypervisor, kernel and userland) to use regular fixed data structures, and this seems unlikely to happen.
Why not fix this and do it properly? What's preventing that from happening? We don't want to create an interface here that is broken, or insecure, or a pain to maintain, right?
The interface is neither broken, insecure nor a pain to maintain. It's merely not as pretty as could be. But it's there to stay because it's what the hypervisor has been exposing for the last 2 years.
I also frankly don't think that doing static structures is any more "proper" than what this interface is doing today. It's serialized data of variable length. That's just the nature of the beast - the backing data for some of these operations *is* dynamic.
Alex
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/2] Import CBOR library
In reply to Petre EftimeQuoted 78 lines · Petre Eftime
Quoted 52 lines · Greg Kroah-Hartman
Quoted 46 lines · Arnd Bergmann
Quoted 31 lines · Greg Kroah-Hartman
Quoted 19 lines · Alexander Graf
Quoted 8 lines · Greg Kroah-Hartman
Quoted 8 lines
Out of these, the NSM communication protocol uses all except Semantic tags and Floats. The CBOR library that this patch imports does not have special handling for Semantic tags, which leaves only floats which are already #ifdef'ed out. That means there is not much to trim.
What you see here is what's needed to parse CBOR in kernel - if that's what we want to do. I'm happy to rip it out again and make it a pure user space problem to do CBOR :).
Quoted 7 lines
Yes, why are we parsing this in the kernel? What could go wrong with adding yet-another-parser in privileged context? :)
Why does this have to be in the kernel, the data sent/recieved is over virtio, so why does the kernel have to parse it? I couldn't figure that out from the driver, yet the driver seems to have a lot of hard-coded parsing logic in it to assume specific message formats?
Quoted 4 lines
The parsing doesn't have to be in kernel and it probably shouldn't be either. V3 of the patch was punting all the parsing to user space, at which point you and Arnd said I should give it a try to do the protocol parsing in kernel space instead. That's why the parser is here.
Arnd said that, not me :)
Quoted 3 lines
If we conclude that all this in-kernel parsing is not worth it, I'm very happy to just go back to the the v3 ioctl interface and post v5 with hwrng merged into misc, but remove all CBOR logic again :)
Quoted 7 lines
I think the less parsers we have in the kernel, the safer we are for obvious reasons. Unless you have a parser for this in rust? :)
I don't really know, having a generic interface is good, but at the expense of this api is probably not good. individual ioctls might be better if there are not going to be any other drivers for this type of thing?
I was definitely expecting something simpler than what was possible in the v4 patch. I had another look now, and it's clear that the ioctl interface is still not great because the variable data structures shine through for some of the calls, and even to get to this point, a whole lot of complexity is required underneath.
Quoted 3 lines
To get anything better, one would probably have to redesign the entire interface stack (hypervisor, kernel and userland) to use regular fixed data structures, and this seems unlikely to happen.
Quoted 7 lines
Why not fix this and do it properly? What's preventing that from happening? We don't want to create an interface here that is broken, or insecure, or a pain to maintain, right?
thanks,
greg k-h
I would think the proposal to have fixed structures would be a downgrade in terms of maintainability, usability and security, not an improvement.
This current interface allows the hypervisor to extend the existing functionality at any time, and the Linux kernel does not have to change anything for that to work, the application does not have to be recompiled to use the new kernel headers at any point. Adding new APIs, adding new fields to API responses, or adding optional parameters to the API is fully backwards compatible, would also not require changes in userspace, as the CBOR data structures that are not recognized can simply be skipped. This allows easy backwards compatibility in most cases, and the userspace would be able to opt in to new features only if it requires them, without forcing the upgrade if it's not required.
Quoted 4 lines
With fixed structures, then the driver would need to be more explicitly versioned and would need to be able to handle multiple versions of the API at the same time, which is both more complex, less flexible and more prone to errors.
Yes, but you are trading off the complexity of adding yet-another-protocol-parser to the kernel vs. making a strict user/kernel api, right?
Which one is correct? Can you verify that this parser really is correct and doesn't have any overflows/security issues in it? I can't, maybe someone needs to write it in rust :)
thanks,
greg k-h
Re: [PATCH v4 1/2] Import CBOR library
In reply to Greg Kroah-HartmanQuoted 52 lines · Greg Kroah-Hartman
Quoted 46 lines · Arnd Bergmann
Quoted 31 lines · Greg Kroah-Hartman
Quoted 19 lines · Alexander Graf
Quoted 8 lines · Greg Kroah-Hartman
Quoted 8 lines
Out of these, the NSM communication protocol uses all except Semantic tags and Floats. The CBOR library that this patch imports does not have special handling for Semantic tags, which leaves only floats which are already #ifdef'ed out. That means there is not much to trim.
What you see here is what's needed to parse CBOR in kernel - if that's what we want to do. I'm happy to rip it out again and make it a pure user space problem to do CBOR :).
Quoted 7 lines
Yes, why are we parsing this in the kernel? What could go wrong with adding yet-another-parser in privileged context? :)
Why does this have to be in the kernel, the data sent/recieved is over virtio, so why does the kernel have to parse it? I couldn't figure that out from the driver, yet the driver seems to have a lot of hard-coded parsing logic in it to assume specific message formats?
Quoted 4 lines
The parsing doesn't have to be in kernel and it probably shouldn't be either. V3 of the patch was punting all the parsing to user space, at which point you and Arnd said I should give it a try to do the protocol parsing in kernel space instead. That's why the parser is here.
Arnd said that, not me :)
Quoted 3 lines
If we conclude that all this in-kernel parsing is not worth it, I'm very happy to just go back to the the v3 ioctl interface and post v5 with hwrng merged into misc, but remove all CBOR logic again :)
Quoted 7 lines
I think the less parsers we have in the kernel, the safer we are for obvious reasons. Unless you have a parser for this in rust? :)
I don't really know, having a generic interface is good, but at the expense of this api is probably not good. individual ioctls might be better if there are not going to be any other drivers for this type of thing?
I was definitely expecting something simpler than what was possible in the v4 patch. I had another look now, and it's clear that the ioctl interface is still not great because the variable data structures shine through for some of the calls, and even to get to this point, a whole lot of complexity is required underneath.
Quoted 3 lines
To get anything better, one would probably have to redesign the entire interface stack (hypervisor, kernel and userland) to use regular fixed data structures, and this seems unlikely to happen.
Quoted 7 lines
Why not fix this and do it properly? What's preventing that from happening? We don't want to create an interface here that is broken, or insecure, or a pain to maintain, right?
thanks,
greg k-h
I would think the proposal to have fixed structures would be a downgrade in terms of maintainability, usability and security, not an improvement.
This current interface allows the hypervisor to extend the existing functionality at any time, and the Linux kernel does not have to change anything for that to work, the application does not have to be recompiled to use the new kernel headers at any point. Adding new APIs, adding new fields to API responses, or adding optional parameters to the API is fully backwards compatible, would also not require changes in userspace, as the CBOR data structures that are not recognized can simply be skipped. This allows easy backwards compatibility in most cases, and the userspace would be able to opt in to new features only if it requires them, without forcing the upgrade if it's not required.
With fixed structures, then the driver would need to be more explicitly versioned and would need to be able to handle multiple versions of the API at the same time, which is both more complex, less flexible and more prone to errors.
-- epetre
kernel test robot
build botRe: [PATCH v4 2/2] misc: Add Nitro Secure Module driver
In reply to Alexander Grafkernel test robot noticed the following build errors:
Hi Alexander,
kernel test robot noticed the following build errors:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on char-misc/char-misc-next char-misc/char-misc-linus soc/for-next linus/master v6.6-rc5 next-20231012] [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/Alexander-Graf/Import-CBOR-library/20231010-052529 base: char-misc/char-misc-testing patch link: https://lore.kernel.org/r/20231009212053.2007-3-graf%40amazon.com patch subject: [PATCH v4 2/2] misc: Add Nitro Secure Module driver config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20231013/[email protected]/config) compiler: powerpc64-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231013/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/asm-generic/ioctl.h:5,
from arch/powerpc/include/uapi/asm/ioctl.h:12,
from include/uapi/linux/ioctl.h:5,
from include/uapi/linux/random.h:12,
from include/linux/random.h:10,
from include/linux/nodemask.h:97,
from include/linux/list_lru.h:12,
from include/linux/fs.h:13,
from drivers/misc/nsm.c:23:
>> include/uapi/asm-generic/ioctl.h:70:9: error: initializer element is not constant
70 | (((dir) << _IOC_DIRSHIFT) | \
| ^
include/uapi/asm-generic/ioctl.h:88:33: note: in expansion of macro '_IOC'
88 | #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
| ^~~~
include/uapi/linux/nsm.h:172:33: note: in expansion of macro '_IOWR'
172 | #define NSM_IOCTL_ATTESTATION _IOWR(NSM_MAGIC, 0x6, union nsm_attestation)
| ^~~~~
drivers/misc/nsm.c:1209:11: note: in expansion of macro 'NSM_IOCTL_ATTESTATION'
1209 | { NSM_IOCTL_ATTESTATION, _fill_req_attestation, _parse_resp_attestation },
| ^~~~~~~~~~~~~~~~~~~~~
include/uapi/asm-generic/ioctl.h:70:9: note: (near initialization for 'nsm_ioctls[6].cmd')
70 | (((dir) << _IOC_DIRSHIFT) | \
| ^
include/uapi/asm-generic/ioctl.h:88:33: note: in expansion of macro '_IOC'
88 | #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
| ^~~~
include/uapi/linux/nsm.h:172:33: note: in expansion of macro '_IOWR'
172 | #define NSM_IOCTL_ATTESTATION _IOWR(NSM_MAGIC, 0x6, union nsm_attestation)
| ^~~~~
drivers/misc/nsm.c:1209:11: note: in expansion of macro 'NSM_IOCTL_ATTESTATION'
1209 | { NSM_IOCTL_ATTESTATION, _fill_req_attestation, _parse_resp_attestation },
| ^~~~~~~~~~~~~~~~~~~~~
>> include/uapi/asm-generic/ioctl.h:70:9: error: initializer element is not constant
70 | (((dir) << _IOC_DIRSHIFT) | \
| ^
include/uapi/asm-generic/ioctl.h:88:33: note: in expansion of macro '_IOC'
88 | #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
| ^~~~
include/uapi/linux/nsm.h:186:33: note: in expansion of macro '_IOWR'
186 | #define NSM_IOCTL_RANDOM _IOWR(NSM_MAGIC, 0x7, union nsm_get_random)
| ^~~~~
drivers/misc/nsm.c:1210:11: note: in expansion of macro 'NSM_IOCTL_RANDOM'
1210 | { NSM_IOCTL_RANDOM, _fill_req_get_random, _parse_resp_get_random },
| ^~~~~~~~~~~~~~~~
include/uapi/asm-generic/ioctl.h:70:9: note: (near initialization for 'nsm_ioctls[7].cmd')
70 | (((dir) << _IOC_DIRSHIFT) | \
| ^
include/uapi/asm-generic/ioctl.h:88:33: note: in expansion of macro '_IOC'
88 | #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
| ^~~~
include/uapi/linux/nsm.h:186:33: note: in expansion of macro '_IOWR'
186 | #define NSM_IOCTL_RANDOM _IOWR(NSM_MAGIC, 0x7, union nsm_get_random)
| ^~~~~ drivers/misc/nsm.c:1210:11: note: in expansion of macro 'NSM_IOCTL_RANDOM'
1210 | { NSM_IOCTL_RANDOM, _fill_req_get_random, _parse_resp_get_random },
| ^~~~~~~~~~~~~~~~
vim +70 include/uapi/asm-generic/ioctl.h
8a1ab3155c2ac7 David Howells 2012-10-04 68
8a1ab3155c2ac7 David Howells 2012-10-04 69 #define _IOC(dir,type,nr,size) \ 8a1ab3155c2ac7 David Howells 2012-10-04 @70 (((dir) << _IOC_DIRSHIFT) | \ 8a1ab3155c2ac7 David Howells 2012-10-04 71 ((type) << _IOC_TYPESHIFT) | \ 8a1ab3155c2ac7 David Howells 2012-10-04 72 ((nr) << _IOC_NRSHIFT) | \ 8a1ab3155c2ac7 David Howells 2012-10-04 73 ((size) << _IOC_SIZESHIFT))
8a1ab3155c2ac7 David Howells 2012-10-04 74
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki