Skip to contentSkip to conversation

device/virtio-nsm: Support string data for extendPCR

PATCH Applied Dorjoy Chowdhury 3 participants 10 messages Nov 9, 2024 – Dec 13, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 device/virtio-nsm: Support string data for extendPCR

NSM device in AWS Nitro Enclaves supports extending with both bytestring and string data.

---
 hw/virtio/virtio-nsm.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
hw/virtio/virtio-nsm.c +14 -7
index a3db8eef3e..6830fcfe17 100644
@@ -444,7 +444,7 @@ static bool handle_describe_pcr(VirtIONSM *vnsm, struct iovec *request,
  *       key = String("index"),
  *       value = Uint8(pcr),
  *       key = String("data"),
- *       value = Byte_String(data),
+ *       value = Byte_String(data) || String(data),
  *     }
  *   }
  * }
@@ -504,14 +504,21 @@ static enum NSMResponseTypes get_nsm_extend_pcr_req(uint8_t *req, size_t len,
 
         if (cbor_string_length(pair[i].key) == 4 &&
             memcmp(str, "data", 4) == 0) {
-            if (!cbor_isa_bytestring(pair[i].value)) {
+            if (cbor_isa_bytestring(pair[i].value)) {
+                str = cbor_bytestring_handle(pair[i].value);
+                if (!str) {
+                    goto cleanup;
+                }
+                nsm_req->data_len = cbor_bytestring_length(pair[i].value);
+            } else if (cbor_isa_string(pair[i].value)) {
+                str = cbor_string_handle(pair[i].value);
+                if (!str) {
+                    goto cleanup;
+                }
+                nsm_req->data_len = cbor_string_length(pair[i].value);
+            } else {
                 goto cleanup;
             }
-            str = cbor_bytestring_handle(pair[i].value);
-            if (!str) {
-                goto cleanup;
-            }
-            nsm_req->data_len = cbor_bytestring_length(pair[i].value);
             /*
              * nsm_req->data_len will be smaller than NSM_REQUEST_MAX_SIZE as
              * we already check for the max request size before processing
Signature · 1 line
2.39.5
#1 lore raw

Hey Dorjoy,

Thanks a lot for the patch! Would you mind to send to the ML so it can go through the normal review + apply cycle? :)

Same comment for the other patches.

Alex

Quoted 51 lines · Dorjoy Chowdhury

NSM device in AWS Nitro Enclaves supports extending with both bytestring and string data.

---
  hw/virtio/virtio-nsm.c | 21 ++++++++++++++-------
  1 file changed, 14 insertions(+), 7 deletions(-)
hw/virtio/virtio-nsm.c +14 -8
index a3db8eef3e..6830fcfe17 100644
@@ -444,7 +444,7 @@ static bool handle_describe_pcr(VirtIONSM *vnsm, struct iovec *request,
   *       key = String("index"),
   *       value = Uint8(pcr),
   *       key = String("data"),
- *       value = Byte_String(data),
+ *       value = Byte_String(data) || String(data),
   *     }
   *   }
   * }
@@ -504,14 +504,21 @@ static enum NSMResponseTypes get_nsm_extend_pcr_req(uint8_t *req, size_t len,
 
          if (cbor_string_length(pair[i].key) == 4 &&
              memcmp(str, "data", 4) == 0) {
-            if (!cbor_isa_bytestring(pair[i].value)) {
+            if (cbor_isa_bytestring(pair[i].value)) {
+                str = cbor_bytestring_handle(pair[i].value);
+                if (!str) {
+                    goto cleanup;
+                }
+                nsm_req->data_len = cbor_bytestring_length(pair[i].value);
+            } else if (cbor_isa_string(pair[i].value)) {
+                str = cbor_string_handle(pair[i].value);
+                if (!str) {
+                    goto cleanup;
+                }
+                nsm_req->data_len = cbor_string_length(pair[i].value);
+            } else {
                  goto cleanup;
              }
-            str = cbor_bytestring_handle(pair[i].value);
-            if (!str) {
-                goto cleanup;
-            }
-            nsm_req->data_len = cbor_bytestring_length(pair[i].value);
              /*
               * nsm_req->data_len will be smaller than NSM_REQUEST_MAX_SIZE as
               * we already check for the max request size before processing
--
Quoted 2 lines

2.39.5

Amazon Web Services Development Center Germany GmbH Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597

#2 lore raw

Hey Alex,

Quoted 7 lines · Alexander Graf

Hey Dorjoy,

Thanks a lot for the patch! Would you mind to send to the ML so it can go through the normal review + apply cycle? :)

Same comment for the other patches.

I don't understand. I sent them to the mailing list too, no? I see the cc's on the patches.

Regards,
Dorjoy

Quoted 1 line
#3 lore raw

Hey Dorjoy,

Quoted 11 lines · Dorjoy Chowdhury

Hey Alex,

On Tue, Nov 12, 2024, 6:14 PM Alexander Graf <[email protected]> wrote:

Hey Dorjoy,

Thanks a lot for the patch! Would you mind to send to the ML so it can
go through the normal review + apply cycle? :)

Quoted 5 lines

Same comment for the other patches.

I don't understand. I sent them to the mailing list too, no? I see the cc's on the patches.

You did indeed - I'm just blind :). Let me have another look at the actual contents of the patches!

Alex

Amazon Web Services Development Center Germany GmbH Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597

#5 lore raw
Quoted 3 lines · Dorjoy Chowdhury

Ping.

Ping...
This is a small one that can be reviewed and picked up for merging. Thanks!

Regards,
Dorjoy

#6 lore raw
Quoted 9 lines · Dorjoy Chowdhury
Quoted 3 lines · Dorjoy Chowdhury

Ping.

Ping...
This is a small one that can be reviewed and picked up for merging. Thanks!

Gentle ping.

Regards,
Dorjoy

Reviewed-by on v1 1/1
#7 lore raw
In reply to Dorjoy Chowdhury
Quoted 4 lines · Dorjoy Chowdhury

NSM device in AWS Nitro Enclaves supports extending with both bytestring and string data.

Alex

Quoted 46 lines
---
  hw/virtio/virtio-nsm.c | 21 ++++++++++++++-------
  1 file changed, 14 insertions(+), 7 deletions(-)
hw/virtio/virtio-nsm.c +14 -8
index a3db8eef3e..6830fcfe17 100644
@@ -444,7 +444,7 @@ static bool handle_describe_pcr(VirtIONSM *vnsm, struct iovec *request,
   *       key = String("index"),
   *       value = Uint8(pcr),
   *       key = String("data"),
- *       value = Byte_String(data),
+ *       value = Byte_String(data) || String(data),
   *     }
   *   }
   * }
@@ -504,14 +504,21 @@ static enum NSMResponseTypes get_nsm_extend_pcr_req(uint8_t *req, size_t len,
 
          if (cbor_string_length(pair[i].key) == 4 &&
              memcmp(str, "data", 4) == 0) {
-            if (!cbor_isa_bytestring(pair[i].value)) {
+            if (cbor_isa_bytestring(pair[i].value)) {
+                str = cbor_bytestring_handle(pair[i].value);
+                if (!str) {
+                    goto cleanup;
+                }
+                nsm_req->data_len = cbor_bytestring_length(pair[i].value);
+            } else if (cbor_isa_string(pair[i].value)) {
+                str = cbor_string_handle(pair[i].value);
+                if (!str) {
+                    goto cleanup;
+                }
+                nsm_req->data_len = cbor_string_length(pair[i].value);
+            } else {
                  goto cleanup;
              }
-            str = cbor_bytestring_handle(pair[i].value);
-            if (!str) {
-                goto cleanup;
-            }
-            nsm_req->data_len = cbor_bytestring_length(pair[i].value);
              /*
               * nsm_req->data_len will be smaller than NSM_REQUEST_MAX_SIZE as
               * we already check for the max request size before processing
--
Quoted 2 lines

2.39.5

Amazon Web Services Development Center Germany GmbH Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597