It is a virtio based RPMB (Replay Protected Memory Block) device.
PATCH v3 1/1 It is a virtio based RPMB (Replay Protected Memory Block) device.
v2 -> v3:
1. Remove conformance changes temporarily
since the draft requires reviews and updates at this phase.
2. Add eMMC, UFS and NVMe as Normative References.
3. Add more details on:
RPMB frame
Request Type/Response Type
4. Add differentiation JEDEC RPMB and NVMe RPMB.
5. Define config layout
6. Illustrate behaviors of all RPMB requests
7. Remove RPMB device ID reservation,
it will be submitted with an independent patch.
--- content.tex | 1 + introduction.tex | 9 ++ virtio-rpmb.tex | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 279 insertions(+) create mode 100644 virtio-rpmb.tex
content.tex +1 -0
@@ -5677,6 +5677,7 @@ \subsubsection{Legacy Interface: Framing Requirements}\label{sec:Device \input{virtio-input.tex} \input{virtio-crypto.tex} \input{virtio-vsock.tex} +\input{virtio-rpmb.tex} \chapter{Reserved Feature Bits}\label{sec:Reserved Feature Bits}
introduction.tex +9 -0
@@ -60,6 +60,15 @@ \section{Normative References}\label{sec:Normative References} \phantomsection\label{intro:SCSI MMC}\textbf{[SCSI MMC]} & SCSI Multimedia Commands, \newline\url{http://www.t10.org/cgi-bin/ac.pl?t=f&f=mmc6r00.pdf}\\ + \phantomsection\label{intro:eMMC}\textbf{[eMMC]} & + eMMC Electrical Standard (5.1), + \newline\url{https://www.jedec.org/standards-documents/docs/jesd84-b51}\\ + \phantomsection\label{intro:UFS}\textbf{[UFS]} & + UNIVERSAL FLASH STORAGE (UFS), Version 3.0, + \newline\url{https://www.jedec.org/standards-documents/docs/jesd220c}\\ + \phantomsection\label{intro:NVMe}\textbf{[NVMe]} & + NVM Express, Revision 1.3 + \newline\url{https://www.nvmexpress.org/wp-content/uploads/NVM_Express_Revision_1.3.pdf}\\ \end{longtable}
virtio-rpmb.tex new file +269 -0
269 lines not on this page · raw message
Signature · 6 lines
2.7.4 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Quoted 45 lines · Huang Yang
Signed-off-by Yang Huang <[email protected]>Reviewed-by Bing Zhu <[email protected]>Reviewed-by Tomas Winkler <[email protected]>v2 -> v3:
1. Remove conformance changes temporarily
since the draft requires reviews and updates at this phase.
2. Add eMMC, UFS and NVMe as Normative References.
3. Add more details on:
RPMB frame
Request Type/Response Type
4. Add differentiation JEDEC RPMB and NVMe RPMB.
5. Define config layout
6. Illustrate behaviors of all RPMB requests
7. Remove RPMB device ID reservation,
it will be submitted with an independent patch.--- content.tex | 1 + introduction.tex | 9 ++ virtio-rpmb.tex | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 279 insertions(+) create mode 100644 virtio-rpmb.texcontent.tex +1
-0@@ -5677,6 +5677,7 @@ \subsubsection{Legacy Interface: Framing Requirements}\label{sec:Device \input{virtio-input.tex} \input{virtio-crypto.tex} \input{virtio-vsock.tex} +\input{virtio-rpmb.tex} \chapter{Reserved Feature Bits}\label{sec:Reserved Feature Bits}introduction.tex +2
-0@@ -60,6 +60,15 @@ \section{Normative References}\label{sec:Normative References} \phantomsection\label{intro:SCSI MMC}\textbf{[SCSI MMC]} & SCSI Multimedia Commands, \newline\url{http://www.t10.org/cgi-bin/ac.pl?t=f&f=mmc6r00.pdf}\\ + \phantomsection\label{intro:eMMC}\textbf{[eMMC]} & + eMMC Electrical Standard (5.1),
introduction.tex \section{Normative References}\label{sec:Normative References} · line 74
Quoted 10 lines
introduction.tex +7
-0+ \newline\url{https://www.jedec.org/standards-documents/docs/jesd84-b51}\\ + \phantomsection\label{intro:UFS}\textbf{[UFS]} & + UNIVERSAL FLASH STORAGE (UFS), Version 3.0, + \newline\url{https://www.jedec.org/standards-documents/docs/jesd220c}\\ + \phantomsection\label{intro:NVMe}\textbf{[NVMe]} & + NVM Express, Revision 1.3 + \newline\url{https://www.nvmexpress.org/wp-content/uploads/NVM_Express_Revision_1.3.pdf}\\ \end{longtable}
At this stage I suggest we avoid nvme. Mix of LE and BE in the frame is just too nasty. And ATM Linux only supports UFS/MMC.
Second, please assess the relevance of anything you copy to virtual devices. Copying things like padding does not buy us anything, and just creates work where we need to zero this out.
The only thing that must match if you are passing through a hardware device is the size and order of keys.
Quoted 34 lines
virtio-rpmb.tex new file +21
-0@@ -0,0 +1,269 @@ +\section{RPMB Device}\label{sec:Device Types / RPMB Device} + +virtio-rpmb is a virtio based RPMB (Replay Protected Memory Block) +device. It is used as a tamper-resistant and anti-replay storage. +The device is driven via requests including read, write, get write +counter and program key, which are submitted via a request queue. +This section relies on definitions from paragraph 6.6.22 of +\hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS} +and 8.10 of \hyperref[intro:NVMe]{NVMe}. +\subsection{Device ID}\label{sec:Device Types / RPMB Device / Device ID} + +28 + +\subsection{Virtqueues}\label{sec:Device Types / RPMB Device / Virtqueues} + +\begin{description} +\item[0] requestq +\end{description} + +\subsection{Feature bits}\label{sec:Device Types / RPMB Device / Feature bits} +
virtio-rpmb.tex line 31
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+None. + +\subsection{Device configuration layout}\label{sec:Device Types / RPMB Device / Device configuration layout} + +All fields of this configuration are always available. + +\begin{lstlisting} +enum virtio_rpmb_type { + RPMB_TYPE_JEDEC, + RPMB_TYPE_NVME,
enum {} has no meaning in spec. any constants must be defined.
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+}; +
Do we have to expose the type? I think we need feature bits for various things so we can split them out later.
virtio-rpmb.tex line 40
Quoted 7 lines
virtio-rpmb.tex new file +7
-0+struct virtio_rpmb_config { + u8 capacity; + u8 max_wr_cnt; + u8 max_rd_cnt; + u8 id; + u8 type; +}
How about adding a key programmed state here?
Quoted 1 line
+\end{lstlisting}
Why not put the counter here?
Are all fields read-only?
virtio-rpmb.tex line 46
Quoted 5 lines
virtio-rpmb.tex new file +5
-0+ +\begin{description} +\item[\field{capacity}] is the capacity of the device (expressed in 128KB units). + The values MUST range between 0x00 and 0x80 inclusive for JEDEC device, and + 0x00 and 0xFF inclusive for NVMe device.
I'd just drop this. u8 so up to 0xff anyway, and I don't think any users care that there are a couple of extra bytes.
Thinking about it, 32Mbytes isn't huge at all. Why not allow larger capacity?
virtio-rpmb.tex line 49
Quoted 3 lines
+\item[\field{max_wr_cnt and
max_rd_cnt}] are the maximum numbers of RPMBvirtio-rpmb.tex new file +2
-0+ block count that can be performed to device in one request. 0 implies + no limitation.
I don't understand what does block count mean in this context.
Quoted 1 line
+\item[\field{id}] is the identifier of RPMB partitions.
What does this mean? what are the partitions? Did you mean of the device?
I suspect what is going on is there's an actual device behind this, and this is its ID. Which again begs the question whether this should just be a part of a blk or scsi device.
Quoted 3 lines
+\item[\field{type}] is the rpmb type that device emulates.
RPMB_TYPE_JEDEC
+ refers to eMMC or UFS whileRPMB_TYPE_NVMErefers to NVMe.
+\end{description}
Does not look like we emulate anything.
virtio-rpmb.tex line 59
Quoted 6 lines
virtio-rpmb.tex new file +6
-0+ +\devicenormative{\subsection}{Device Initialization}{Device Types / RPMB Device / Device Initialization} + +\begin{enumerate} +\item The virtqueue is initialized. +\item The authentication key of device MUST NOT be programmed at the first device initialization.
What is "first device initialization"? The concept does not seem to apply to virtual devices. How about we just have device pre-initialized to some key? Or maybe device can be in two states, key programming and operation?
All conformance clauses belong in conformance sections. here and elsewhere.
Quoted 3 lines
+\item The device capacity MUST be initialized to a multiple of 128Kbytes and up to
+ 16Mbytes/32Mbytes (JEDEC/NVMe device respectively).
+\end{enumerate}
So instead of blindly copying limitations of physical devices, we can just allow hypervisor to set any capacity.
Quoted 14 lines
virtio-rpmb.tex new file +14
-0+ +\subsection{Device Operation}\label{sec:Device Types / RPMB Device / Device Operation} + +The operation of a virtio RPMB device is driven by the requests placed on the virtqueue. + The type of the request can be program key (VIRTIO_RPMB_REQ_PROGRAM_KEY), + get write counter (VIRTIO_RPMB_REQ_GET_WRITE_COUNTER), + write (VIRTIO_RPMB_REQ_DATA_WRITE), and read (VIRTIO_RPMB_REQ_DATA_READ). + A program key or write request can also combine with a + result read (VIRTIO_RPMB_REQ_RESULT_READ) for a returned result. + +\begin{lstlisting} +/* RPMB Request Types */ +#define VIRTIO_RPMB_REQ_PROGRAM_KEY 0x0001 +#define VIRTIO_RPMB_REQ_GET_WRITE_COUNTER 0x0002
virtio-rpmb.tex line 86
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+#define VIRTIO_RPMB_REQ_DATA_WRITE 0x0003 +#define VIRTIO_RPMB_REQ_DATA_READ 0x0004 +#define VIRTIO_RPMB_REQ_RESULT_READ 0x0005 +\end{lstlisting} + +\subsubsection{Device Operation: Request Queue}\label{sec:Device Types / RPMB Device / Device Operation / Device Operation: Request Queue} + +The request information is delivered in RPMB frame. +The frame is in size of 512B for JEDEC RPMB, and in size of 256B plus +multiple 512B for NVMe RPMB depending on the variable data size.
Again this is just messy. Let's come up with a minimal spec. See end of the message pls.
Quoted 16 lines
virtio-rpmb.tex new file +16
-0+ +\begin{lstlisting} +struct virtio_rpmb_frame_jedec { + u8 stuff[196]; + u8 key_mac[32]; + u8 data[256]; + u8 nonce[16]; + be32 write_counter; + be16 address; + be16 block_count; + be16 result; + be16 req_resp; +}; + +struct virtio_rpmb_frame_nvme { + u8 stuff [191];
virtio-rpmb.tex line 112
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+ u8 key_mac[32]; + u8 rpmb_target; + u8 nonce[16]; + le32 write_counter; + le32 address; + le32 block_count; + le16 result; + le16 req_resp; + u8 data[0]; +};
Oh fun, a mix of LE and BE.
Let's make everything consistent.
Why do we need the "stuff" field? It helps align the size to 256 byte boundary - but why do we care?
Quoted 17 lines
virtio-rpmb.tex new file +17
-0+ +/* RPMB Response Types */ +#define VIRTIO_RPMB_RESP_PROGRAM_KEY 0x0100 +#define VIRTIO_RPMB_RESP_GET_COUNTER 0x0200 +#define VIRTIO_RPMB_RESP_DATA_WRITE 0x0300 +#define VIRTIO_RPMB_RESP_DATA_READ 0x0400 + +/* RPMB Operation Results */ +#define VIRTIO_RPMB_RES_OK 0x0000 +#define VIRTIO_RPMB_RES_GENERAL_FAILURE 0x0001 +#define VIRTIO_RPMB_RES_AUTH_FAILURE 0x0002 +#define VIRTIO_RPMB_RES_COUNT_FAILURE 0x0003 +#define VIRTIO_RPMB_RES_ADDR_FAILURE 0x0004 +#define VIRTIO_RPMB_RES_WRITE_FAILURE 0x0005 +#define VIRTIO_RPMB_RES_READ_FAILURE 0x0006 +#define VIRTIO_RPMB_RES_NO_AUTH_KEY 0x0007 +#define VIRTIO_RPMB_RES_WRITE_COUNTER_EXPIRED 0x0080
virtio-rpmb.tex
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+\end{lstlisting} + +\begin{description} +\item[\field{stuff}] Padding for the frame. + +\item[\field{key_mac}] is the authentication key or the message + authentication code (MAC) depending on the request/response type. + If the request is VIRTIO_RPMB_REQ_PROGRAM_KEY, it's used as + authentication key. Otherwise, it's used as MAC. The MAC is calculated + using HMAC SHA-256.
SHA-256 is pretty old. Not being a cryptographer I don't really know whether it's still a good mac to use in 2019.
Generally security considerations should probably be presented with anything dealing with crypto.
In this case, I'd do a feature bit so we can change the crypto down the road.
virtio-rpmb.tex line 146
Quoted 8 lines
It takes as input a key and a message. The key
virtio-rpmb.tex new file +7
-0+ used for the MAC calculation is always the 256 bit RPMB authentication + key. The message used as input to the MAC calculation is the + concatenation of the fields in the RPMB frames excluding stuff bytes + and the MAC itself. + +\item[\field{rpmb_target}] is the exclusive item for NVMe device. It is + the RPMB target to access.
There are multiple targets too?
Quoted 2 lines
+
+\item[\field{data}] is used to be written or read by signed access.
What does signed access mean?
virtio-rpmb.tex
Quoted 5 lines
It's
virtio-rpmb.tex new file +4
-0+ fixed 256B for JEDEC device while variable sized payload + 512 * \field{block_count} for NVMe device. + +\item[\field{nonce}] is a random number
random how? I think it can just be anything.
virtio-rpmb.tex line 160
Quoted 9 lines
generated by user for the read or
virtio-rpmb.tex new file +8
-0+ get write counter requests and copied to the response by device. + +\item[\field{writer_counter}] is the counter value for the total amount of + the successful authenticated data write requests. + +\item[\field{address}] is the address of the data to be written to or read + from the RPMB virtio device. It is the serial number of the accessed + half sector (256B for JEDEC device) or sector (512B for NVMe device).
serial number?
virtio-rpmb.tex line 163
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ +\item[\field{block_count}] is the number of blocks (256B for JEDEC and 512B + for NVMe) requested to be read/written.
can't this be intuited from the buffer size somehow?
I don't really understand how can you both have block_count and a fixed size data. how does this make sense?
virtio-rpmb.tex line 167
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ +\item[\field{result}] includes information about the status of access made + to the device. +
So I am guessing result is written by the device?
And type is written by the driver?
this does not play well with virtio where write
fields are followed by read fields.
Quoted 2 lines
+\item[\field{req_resp}] is the type of request or response, as defined above,
+ to/from the device.
this seems to be the 1st definition. Please avoid "above" and "below", just link to the definition.
virtio-rpmb.tex line 175
Quoted 6 lines
+\end{description}
virtio-rpmb.tex new file +5
-0+ +\devicenormative{\paragraph}{Device Operation: Request Queue}{Device Types / RPMB Device / Device Operation / Device Operation: Request Queue} + +The device MUST parse the request from the request queue and emulate the behaviours described in paragraph +6.6.22 of \hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS} or 8.10 of \hyperref[intro:NVMe]{NVMe}:
If you are going to emulate existing specs, then why not just emulate an existing spec? Why bother with virtio at all? You gain ability to use existing drivers.
If the reason is to make a clean abstraction, then IMHO this falls short of this goal, carrying on all kind of baggage from hardware specs.
virtio-rpmb.tex line 187
Quoted 12 lines
virtio-rpmb.tex new file +12
-0+ +\begin{description} + +\item[VIRTIO_RPMB_REQ_PROGRAM_KEY] If block count has not been set to 1 + then VIRTIO_RPMB_RES_GENERAL_FAILURE is responded. If programming of + authentication key fails then returned result is VIRTIO_RPMB_RES_WRITE_FAILURE. + If some other error occurs then returned result is VIRTIO_RPMB_RES_GENERAL_FAILURE. + The \field{req_resp} value VIRTIO_RPMB_RESP_PROGRAM_KEY corresponds to + the key programming request. + + If VIRTIO_RPMB_REQ_RESULT_READ is requested, the device returns the RPMB frame + with response (VIRTIO_RPMB_RESP_PROGRAM_KEY), the calculated MAC and the result.
I don't see what does VIRTIO_RPMB_REQ_RESULT_READ buy us. I guess it proves key has been programmed - but if someone can snoop on programming then for sure he has the key and won't have trouble faking the mac.
Quoted 39 lines
virtio-rpmb.tex new file +39
-0+ +\item[VIRTIO_RPMB_REQ_GET_WRITE_COUNTE] If the authentication key is not yet + programmed then VIRTIO_RPMB_RES_NO_AUTH_KEY is returned in \field{result}. + If block count has not been set to 1 then VIRTIO_RPMB_RES_GENERAL_FAILURE + SHOULD be responded. + + The device returns the RPMB frame with response (VIRTIO_RPMB_RESP_GET_COUNTER), + the writer counter, a copy of the nonce received in the request, the calculated + MAC and the result. + +\item[VIRTIO_RPMB_REQ_DATA_WRITE] If the authentication key is not yet programmed + then VIRTIO_RPMB_RES_NO_AUTH_KEY is returned in \field{result}. If block count + is zero or greater than \field{max_wr_cnt} then VIRTIO_RPMB_RES_GENERAL_FAILURE + MUST be responded. The device MUST check whether the write counter has expired. + If the write counter is expired then sets the \field{result} to + VIRTIO_RPMB_RES_WRITE_COUNTER_EXPIRED. If there is an error in the address + (out of range) then the \field{result} is set to VIRTIO_RPMB_RES_ADDR_FAILURE. + The device MUST calculate the MAC taking authentication key and frame as input, + and compares this with the MAC in the request. If the two MAC’s are different + then VIRTIO_RPMB_RES_AUTH_FAILURE is returned. + + If the writer counter in the request with is different from the one maintained + by device then VIRTIO_RPMB_RES_COUNT_FAILURE is returned in \field{result}. + If the MAC and write counter comparisons are successful then the write request + is considered to be authenticated. The data from the request are written to the + address indicated in the request and the write counter is incremented by 1. + If write fails then returned result is VIRTIO_RPMB_RES_WRITE_FAILURE. If some + other error occurs during the write procedure then returned result is + VIRTIO_RPMB_RES_GENERAL_FAILURE. + + If VIRTIO_RPMB_REQ_RESULT_READ is requested, the device returns the RPMB data + frame with response (VIRTIO_RPMB_RESP_DATA_WRITE), the incremented counter value, + the data address, the calculated MAC and result. + +\item[VIRTIO_RPMB_REQ_DATA_READ] If the authentication key is not yet programmed + then VIRTIO_RPMB_RES_NO_AUTH_KEY is returned in \field{result}. If block count + has not been set to 1 then VIRTIO_RPMB_RES_GENERAL_FAILURE MUST be responded. + If there is an error in the address (out of range) then the \field{result} is + set to VIRTIO_RPMB_RES_ADDR_FAILURE. If data fetch from addressed location inside
virtio-rpmb.tex
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+ device fails then returned result is VIRTIO_RPMB_RES_READ_FAILURE. If some other + error occurs during the read procedure then returned result is + VIRTIO_RPMB_RES_GENERAL_FAILURE. + + The device returns the RPMB frame with response (VIRTIO_RPMB_RESP_DATA_READ), + the block count, a copy of the nonce received in the request, the address, + the data, the calculated MAC, and the result. + +\item[VIRTIO_RPMB_REQ_RESULT_READ] It is used following with the other request + types for returned result in one or multiple RPMB frames.
So each write request must be followed by a status request. This just seems like a waste. Why not return the result immediately with the operation? Maybe UFS doesn't support this but virtio sure does.
Does device have to maintain the last request in non-volatile memory and persist across resets? You do not list it as being persistent below. So I would just drop this request type
and have driver maintain it in guest memory.
virtio-rpmb.tex line 242
Quoted 7 lines
For
virtio-rpmb.tex new file +6
-0+ VIRTIO_RPMB_REQ_PROGRAM_KEY and VIRTIO_RPMB_REQ_DATA_WRITE, if block count has + not been set to 1 of VIRTIO_RPMB_REQ_RESULT_READ request, then + VIRTIO_RPMB_RES_GENERAL_FAILURE SHALL be indicated. + +\end{description} +If authetication key was programmed successfully, the device SHALL return with a MAC for any operation requests.
Lots of typos above make it pretty hard to figure out.
virtio-rpmb.tex line 246
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ +\drivernormative{\subsubsection}{Device Operation}{Device Types / RPMB Device / Device Operation} + +The driver MUST configure and initialize virtqueue for the requests received.
received where? why isn't it legal to e.g. check feature bits and then reset?
Quoted 14 lines
virtio-rpmb.tex new file +7
-0+ +\devicenormative{\subsubsection}{Device Operation}{Device Types / RPMB Device / Device Operation} + +The virtio-rpmb device could be backed in a number of ways. It SHOULD + keep consistent behaviors with hardware as described in paragraph + 6.6.22 of \hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS} + or 8.10 of \hyperref[intro:NVMe]{NVMe}.Some elements are maintained
virtio-rpmb.tex new file +6
-0+ by the device: +\begin{enumerate} +\item The device maintains an one time programmable authentication key. + It cannot be overwritten, erased or read. The key is used to + authenticate the accesses when MAC is calculated. This key MUST be + kept regardless of device reset or reboot.
virtio-rpmb.tex line 269
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+\item The device maintains a read-only monotonic write counter. It MUST + be initialized to zero and added by one automatically along with + successful write operation. The value cannot be reset. After + the counter has reached its maximum value 0xFFFF FFFF, it will + not be incremented anymore. This counter MUST be kept regardless + of device reset or reboot. +\item The device maintains the data for read/write via authenticated + access. +\end{enumerate} +
What I have gathered from above is really just a counter and a key added to a storage device.
Key: you must have the key to write. It's programmed into the device at some point by manufacturer.
So later, only someone who got key from manufacturer can write. Data is also authenticated with the key, so if you got the key from manufacturer you can verify it's valid.
What if you didn't get the key but you steal the data in transit to storage device somehow? You could replay it to the device and overwrite valid data. To this end device maintains write counter, so you can't.
What if you can pretend write failed, or filter out writes to pretend they succeeded? First write counter will be wrong, but it's tricky for applications to verify the counter: after all an application can crash. So each write is followed by a response and users must validate MAC to make sure write made it to the device.
On the other hand, what if again you didn't get the key but you steal the read response? You could replay that to the application. To this end read requests include a random value and it's copied to the response. Application can put e.g. a counter there.
I think we are coming back full circle and I would
like to ask: so why does it not make sense to add this functionality to a block device, or a scsi device? We'd get lots of goodies such as multiqueue, for free.
If we implement above in a hypervisor in software, we can just ignore all random hardware limitations, and support e.g. arbitrary size of writes, arbitrary hash etc etc.
So I think this is the reason you are making it a separate device and are trying to support so many messy formats is because you are thinking about pass-through.
However, I note that neither driver nor the hypervisor really care about things like order of fields or endian-ness. It's only the MAC calculations that are affected.
So my suggestion is, for now just define a clean minimal interface, with some kind of enumerator for an application to discover the specific MAC used. And when hypervisor is forwarding the data to the device, it can move fields around, swap endian-ness or whatever. Will cost some performance but it does not look like this device is fast path anyway.
And I am guessing most people do trust the hypervisor and so they will happily just use a clean software implementation.
Quoted 2 lines
Signature · 1 line
2.7.4
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Quoted 184 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Michael S. Tsirkin
Sent: Tuesday, August 6, 2019 04:24 AM
To: Huang, Yang <[email protected]>
Cc: [email protected]; [email protected]; Zhu, Bing <[email protected]>; Winkler, Tomas <[email protected]>; Fang, Peter <[email protected]>
Subject: [virtio-dev] Re: [PATCH v3] It is a virtio based RPMB (Replay Protected Memory Block) device.introduction.tex \section{Normative References}\label{sec:Normative
Quoted 39 lines · Huang Yang
Signed-off-by Yang Huang <[email protected]>Reviewed-by Bing Zhu <[email protected]>Reviewed-by Tomas Winkler <[email protected]>v2 -> v3:
1. Remove conformance changes temporarily
since the draft requires reviews and updates at this phase.
2. Add eMMC, UFS and NVMe as Normative References.
3. Add more details on:
RPMB frame
Request Type/Response Type
4. Add differentiation JEDEC RPMB and NVMe RPMB.
5. Define config layout
6. Illustrate behaviors of all RPMB requests 7. Remove RPMB device ID reservation,
it will be submitted with an independent patch.--- content.tex | 1 + introduction.tex | 9 ++ virtio-rpmb.tex | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 279 insertions(+) create mode 100644 virtio-rpmb.texcontent.tex +1
-0@@ -5677,6 +5677,7 @@ \subsubsection{Legacy Interface: Framing Requirements}\label{sec:Device \input{virtio-input.tex} \input{virtio-crypto.tex} \input{virtio-vsock.tex} +\input{virtio-rpmb.tex} \chapter{Reserved Feature Bits}\label{sec:Reserved Feature Bits}introduction.tex index renamed from introduction.tex +0
-0c96acf9..2579bf3 100644
introduction.tex +0
-0@@ -60,6 +60,15 @@ \section{Normative References}\label{sec:NormativeReferences}
introduction.tex \section{Normative References}\label{sec:Normative References}
Quoted 7 lines
introduction.tex +3
-0\phantomsection\label{intro:SCSI MMC}\textbf{[SCSI MMC]} & SCSI Multimedia Commands, \newline\url{http://www.t10.org/cgi-bin/ac.pl?t=f&f=mmc6r00.pdf}\\ + \phantomsection\label{intro:eMMC}\textbf{[eMMC]} & + eMMC Electrical Standard (5.1), + \newline\url{https://www.jedec.org/standards-documents/docs/jesd84-b51}\\
introduction.tex \section{Normative References}\label{sec:Normative References}
Quoted 3 lines
introduction.tex +3
-0+ \phantomsection\label{intro:UFS}\textbf{[UFS]} & + UNIVERSAL FLASH STORAGE (UFS), Version 3.0, + \newline\url{https://www.jedec.org/standards-documents/docs/jesd220c}\\
introduction.tex \section{Normative References}\label{sec:Normative References} · line 73
Quoted 8 lines
introduction.tex +5
-0+ \phantomsection\label{intro:NVMe}\textbf{[NVMe]} & + NVM Express, Revision 1.3 + + \newline\url{https://www.nvmexpress.org/wp-content/uploads/NVM_Expre + ss_Revision_1.3.pdf}\\ \end{longtable}At this stage I suggest we avoid nvme. Mix of LE and BE in the frame is just too nasty. And ATM Linux only supports UFS/MMC.
Second, please assess the relevance of anything you copy to virtual devices. Copying things like padding does not buy us anything, and just creates work where we need to zero this out.
The only thing that must match if you are passing through a hardware device is the size and order of keys.
Quoted 37 lines
virtio-rpmb.tex new file +25
-0@@ -0,0 +1,269 @@ +\section{RPMB Device}\label{sec:Device Types / RPMB Device} + +virtio-rpmb is a virtio based RPMB (Replay Protected Memory Block) +device. It is used as a tamper-resistant and anti-replay storage. +The device is driven via requests including read, write, get write +counter and program key, which are submitted via a request queue. +This section relies on definitions from paragraph 6.6.22 of +\hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS} and +8.10 of \hyperref[intro:NVMe]{NVMe}. +\subsection{Device ID}\label{sec:Device Types / RPMB Device / Device +ID} + +28 + +\subsection{Virtqueues}\label{sec:Device Types / RPMB Device / +Virtqueues} + +\begin{description} +\item[0] requestq +\end{description} + +\subsection{Feature bits}\label{sec:Device Types / RPMB Device / +Feature bits} + +None.virtio-rpmb.tex line 31
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+ +\subsection{Device configuration layout}\label{sec:Device Types / +RPMB Device / Device configuration layout} + +All fields of this configuration are always available. + +\begin{lstlisting} +enum virtio_rpmb_type { + RPMB_TYPE_JEDEC, + RPMB_TYPE_NVME,enum {} has no meaning in spec. any constants must be defined.
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+}; +Do we have to expose the type? I think we need feature bits for various things so we can split them out later.
virtio-rpmb.tex line 40
Quoted 7 lines
virtio-rpmb.tex new file +7
-0+struct virtio_rpmb_config { + u8 capacity; + u8 max_wr_cnt; + u8 max_rd_cnt; + u8 id; + u8 type; +}How about adding a key programmed state here?
Quoted 1 line
+\end{lstlisting}
Why not put the counter here?
Are all fields read-only?
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ +\begin{description} +\item[\field{capacity}] is the capacity of the device (expressed in 128KB units). + The values MUST range between 0x00 and 0x80 inclusive for JEDEC device,and
Quoted 1 line
+
0x00and0xFFinclusive for NVMe device.I'd just drop this. u8 so up to
0xffanyway, and I don't think any users care that there are a couple of extra bytes.Thinking about it, 32Mbytes isn't huge at all. Why not allow larger capacity?
virtio-rpmb.tex line 49
Quoted 3 lines
+\item[\field{max_wr_cnt and
max_rd_cnt}] are the maximum numbers of RPMBvirtio-rpmb.tex new file +2
-0+ block count that can be performed to device in one request. 0 implies + no limitation.
Quoted 5 lines
I don't understand what does block count mean in this context.
Quoted 1 line
+\item[\field{id}] is the identifier of RPMB partitions.
What does this mean? what are the partitions? Did you mean of the device?
if this is for multiple RPMB targets or units in single storage device which are available/supported in real UFS3.0 or NVMe storage device,, I don't think we need to implement this capability in virtio-rpmb device. Because I don't think we will have real usage like that in virtualization environment. So we can just simply emulate a single-RPMB virtual storage. @Tomas, does this make sense?
Quoted 128 lines
I suspect what is going on is there's an actual device behind this, and this is its ID. Which again begs the question whether this should just be a part of a blk or scsi device.
Quoted 3 lines
+\item[\field{type}] is the rpmb type that device emulates.
RPMB_TYPE_JEDEC
+ refers to eMMC or UFS whileRPMB_TYPE_NVMErefers to NVMe.
+\end{description}Does not look like we emulate anything.
virtio-rpmb.tex
Quoted 7 lines
virtio-rpmb.tex new file +7
-0+ +\devicenormative{\subsection}{Device Initialization}{Device Types / +RPMB Device / Device Initialization} + +\begin{enumerate} +\item The virtqueue is initialized. +\item The authentication key of device MUST NOT be programmed at the firstdevice initialization.
What is "first device initialization"? The concept does not seem to apply to virtual devices. How about we just have device pre-initialized to some key? Or maybe device can be in two states, key programming and operation?
All conformance clauses belong in conformance sections. here and elsewhere.
Quoted 1 line
+\item The device capacity MUST be initialized to a multiple of 128Kbytes and
up to
Quoted 2 lines
+ 16Mbytes/32Mbytes (JEDEC/NVMe device respectively).
+\end{enumerate}So instead of blindly copying limitations of physical devices, we can just allow hypervisor to set any capacity.
virtio-rpmb.tex
Quoted 5 lines
virtio-rpmb.tex new file +5
-0+ +\subsection{Device Operation}\label{sec:Device Types / RPMB Device / +Device Operation} + +The operation of a virtio RPMB device is driven by the requests placed on thevirtqueue.
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ The type of the request can be program key +(VIRTIO_RPMB_REQ_PROGRAM_KEY), + get write counter (VIRTIO_RPMB_REQ_GET_WRITE_COUNTER), + write (VIRTIO_RPMB_REQ_DATA_WRITE), and read(
VIRTIO_RPMB_REQ_DATA_READ).Quoted 9 lines
virtio-rpmb.tex new file +9
-0+ A program key or write request can also combine with a + result read (VIRTIO_RPMB_REQ_RESULT_READ) for a returned result. + +\begin{lstlisting} +/* RPMB Request Types */ +#define VIRTIO_RPMB_REQ_PROGRAM_KEY 0x0001 +#define VIRTIO_RPMB_REQ_GET_WRITE_COUNTER 0x0002 +#define VIRTIO_RPMB_REQ_DATA_WRITE 0x0003 +#define VIRTIO_RPMB_REQ_DATA_READ 0x0004virtio-rpmb.tex line 86
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+#define VIRTIO_RPMB_REQ_RESULT_READ 0x0005 +\end{lstlisting} + +\subsubsection{Device Operation: Request Queue}\label{sec:Device +Types / RPMB Device / Device Operation / Device Operation: Request +Queue} + +The request information is delivered in RPMB frame. +The frame is in size of 512B for JEDEC RPMB, and in size of 256B plus +multiple 512B for NVMe RPMB depending on the variable data size.Again this is just messy. Let's come up with a minimal spec. See end of the message pls.
Quoted 16 lines
virtio-rpmb.tex new file +16
-0+ +\begin{lstlisting} +struct virtio_rpmb_frame_jedec { + u8 stuff[196]; + u8 key_mac[32]; + u8 data[256]; + u8 nonce[16]; + be32 write_counter; + be16 address; + be16 block_count; + be16 result; + be16 req_resp; +}; + +struct virtio_rpmb_frame_nvme { + u8 stuff [191];virtio-rpmb.tex line 112
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+ u8 key_mac[32]; + u8 rpmb_target; + u8 nonce[16]; + le32 write_counter; + le32 address; + le32 block_count; + le16 result; + le16 req_resp; + u8 data[0]; +};Oh fun, a mix of LE and BE.
Let's make everything consistent.
Why do we need the "stuff" field? It helps align the size to 256 byte boundary - but why do we care?
Quoted 22 lines
virtio-rpmb.tex new file +22
-0+ +/* RPMB Response Types */ +#define VIRTIO_RPMB_RESP_PROGRAM_KEY 0x0100 +#define VIRTIO_RPMB_RESP_GET_COUNTER 0x0200 +#define VIRTIO_RPMB_RESP_DATA_WRITE 0x0300 +#define VIRTIO_RPMB_RESP_DATA_READ 0x0400 + +/* RPMB Operation Results */ +#define VIRTIO_RPMB_RES_OK 0x0000 +#define VIRTIO_RPMB_RES_GENERAL_FAILURE 0x0001 +#define VIRTIO_RPMB_RES_AUTH_FAILURE 0x0002 +#define VIRTIO_RPMB_RES_COUNT_FAILURE 0x0003 +#define VIRTIO_RPMB_RES_ADDR_FAILURE 0x0004 +#define VIRTIO_RPMB_RES_WRITE_FAILURE 0x0005 +#define VIRTIO_RPMB_RES_READ_FAILURE 0x0006 +#define VIRTIO_RPMB_RES_NO_AUTH_KEY 0x0007 +#define VIRTIO_RPMB_RES_WRITE_COUNTER_EXPIRED 0x0080 +\end{lstlisting} + +\begin{description} +\item[\field{stuff}] Padding for the frame. +
Quoted 8 lines
virtio-rpmb.tex
Quoted 5 lines
+\item[\field{key_mac}] is the authentication key or the message
virtio-rpmb.tex new file +4
-0+ authentication code (MAC) depending on the request/response type. + If the request is VIRTIO_RPMB_REQ_PROGRAM_KEY, it's used as + authentication key. Otherwise, it's used as MAC. The MAC is calculated + using HMAC SHA-256.SHA-256 is pretty old. Not being a cryptographer I don't really know whether it's still a good mac to use in 2019.
Yes, SHA-256 is pretty old, SHA-384 or larger would be good, but actually ^HMAC^ w/ SHA-256 is still safe (at least before year 2030 according to our crypto experts) . also, right now eMMC/UFS only defines HMAC SHA256. NVMe can optionally support higher.
But not sure if it is possible to extend this in the future upgrade.
Quoted 263 lines
Generally security considerations should probably be presented with anything dealing with crypto.
In this case, I'd do a feature bit so we can change the crypto down the road.virtio-rpmb.tex line 146
Quoted 8 lines
It takes as input a key and a message. The key
virtio-rpmb.tex new file +7
-0+ used for the MAC calculation is always the 256 bit RPMB authentication + key. The message used as input to the MAC calculation is the + concatenation of the fields in the RPMB frames excluding stuff bytes + and the MAC itself. + +\item[\field{rpmb_target}] is the exclusive item for NVMe device. It is + the RPMB target to access.There are multiple targets too?
Quoted 2 lines
+
+\item[\field{data}] is used to be written or read by signed access.What does signed access mean?
virtio-rpmb.tex
Quoted 5 lines
It's
virtio-rpmb.tex new file +4
-0+ fixed 256B for JEDEC device while variable sized payload + 512 * \field{block_count} for NVMe device. + +\item[\field{nonce}] is a random numberrandom how? I think it can just be anything.
virtio-rpmb.tex line 160
Quoted 9 lines
generated by user for the read or
virtio-rpmb.tex new file +8
-0+ get write counter requests and copied to the response by device. + +\item[\field{writer_counter}] is the counter value for the total amount of + the successful authenticated data write requests. + +\item[\field{address}] is the address of the data to be written to or read + from the RPMB virtio device. It is the serial number of the accessed + half sector (256B for JEDEC device) or sector (512B for NVMe device).serial number?
virtio-rpmb.tex line 163
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ +\item[\field{block_count}] is the number of blocks (256B for JEDEC and 512B + for NVMe) requested to be read/written.can't this be intuited from the buffer size somehow?
I don't really understand how can you both have
block_countand a fixed size data. how does this make sense?virtio-rpmb.tex line 167
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ +\item[\field{result}] includes information about the status of access made + to the device. +So I am guessing result is written by the device?
And type is written by the driver?
this does not play well with virtio where write fields are followed by read fields.Quoted 2 lines
+\item[\field{req_resp}] is the type of request or response, as defined above,
+ to/from the device.this seems to be the 1st definition. Please avoid "above" and "below", just link to the definition.
virtio-rpmb.tex
Quoted 9 lines
+\end{description}
virtio-rpmb.tex new file +8
-0+ +\devicenormative{\paragraph}{Device Operation: Request Queue}{Device +Types / RPMB Device / Device Operation / Device Operation: Request +Queue} + +The device MUST parse the request from the request queue and emulate +the behaviours described in paragraph +6.6.22 of \hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS} or8.10 of \hyperref[intro:NVMe]{NVMe}:
If you are going to emulate existing specs, then why not just emulate an existing spec? Why bother with virtio at all? You gain ability to use existing drivers.
If the reason is to make a clean abstraction, then IMHO this falls short of this goal, carrying on all kind of baggage from hardware specs.
virtio-rpmb.tex
Quoted 6 lines
virtio-rpmb.tex new file +6
-0+ +\begin{description} + +\item[VIRTIO_RPMB_REQ_PROGRAM_KEY] If block count has not been set to 1 + then VIRTIO_RPMB_RES_GENERAL_FAILURE is responded. If programming of + authentication key fails then returned result is
VIRTIO_RPMB_RES_WRITE_FAILURE.Quoted 1 line
+ If some other error occurs then returned result is
VIRTIO_RPMB_RES_GENERAL_FAILURE.virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ The \field{req_resp} value VIRTIO_RPMB_RESP_PROGRAM_KEY corresponds to + the key programming request. + + If VIRTIO_RPMB_REQ_RESULT_READ is requested, the device returns theRPMB frame
Quoted 1 line
+ with response (
VIRTIO_RPMB_RESP_PROGRAM_KEY), the calculated MAC andthe result.
I don't see what does
VIRTIO_RPMB_REQ_RESULT_READbuy us.
I guess it proves key has been programmed - but if someone can snoop on programming then for sure he has the key and won't have trouble faking the mac.Quoted 2 lines
+
+\item[VIRTIO_RPMB_REQ_GET_WRITE_COUNTE] If the authentication key isnot yet
Quoted 1 line
+ programmed then
VIRTIO_RPMB_RES_NO_AUTH_KEYis returned in\field{result}.
Quoted 1 line
+ If block count has not been set to 1 then
VIRTIO_RPMB_RES_GENERAL_FAILUREvirtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ SHOULD be responded. + + The device returns the RPMB frame with response(
VIRTIO_RPMB_RESP_GET_COUNTER),Quoted 1 line
+ the writer counter, a copy of the nonce received in the request, the
calculated
virtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ MAC and the result. + +\item[VIRTIO_RPMB_REQ_DATA_WRITE] If the authentication key is not yetprogrammed
Quoted 1 line
+ then
VIRTIO_RPMB_RES_NO_AUTH_KEYis returned in \field{result}. If blockcount
Quoted 1 line
+ is zero or greater than \field{max_wr_cnt} then
VIRTIO_RPMB_RES_GENERAL_FAILUREQuoted 1 line
+ MUST be responded. The device MUST check whether the write counter has
expired.
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+ If the write counter is expired then sets the \field{result} to + VIRTIO_RPMB_RES_WRITE_COUNTER_EXPIRED. If there is an error in theaddress
Quoted 1 line
+ (out of range) then the \field{result} is set to
VIRTIO_RPMB_RES_ADDR_FAILURE.Quoted 1 line
+ The device MUST calculate the MAC taking authentication key and frame as
input,
Quoted 1 line
+ and compares this with the MAC in the request. If the two MAC’s are
different
virtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ then VIRTIO_RPMB_RES_AUTH_FAILURE is returned. + + If the writer counter in the request with is different from the onemaintained
Quoted 1 line
+ by device then
VIRTIO_RPMB_RES_COUNT_FAILUREis returned in\field{result}.
Quoted 1 line
+ If the MAC and write counter comparisons are successful then the write
request
Quoted 1 line
+ is considered to be authenticated. The data from the request are written to
the
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+ address indicated in the request and the write counter is incremented by 1. + If write fails then returned result is VIRTIO_RPMB_RES_WRITE_FAILURE. Ifsome
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ other error occurs during the write procedure then returned result is + VIRTIO_RPMB_RES_GENERAL_FAILURE. + + If VIRTIO_RPMB_REQ_RESULT_READ is requested, the device returns theRPMB data
Quoted 1 line
+ frame with response (
VIRTIO_RPMB_RESP_DATA_WRITE), the incrementedcounter value,
virtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ the data address, the calculated MAC and result. + +\item[VIRTIO_RPMB_REQ_DATA_READ] If the authentication key is not yetprogrammed
Quoted 1 line
+ then
VIRTIO_RPMB_RES_NO_AUTH_KEYis returned in \field{result}. If blockcount
Quoted 1 line
+ has not been set to 1 then
VIRTIO_RPMB_RES_GENERAL_FAILUREMUST beresponded.
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+ If there is an error in the address (out of range) then the \field{result} is + set to VIRTIO_RPMB_RES_ADDR_FAILURE. If data fetch from addressedlocation inside
Quoted 1 line
+ device fails then returned result is
VIRTIO_RPMB_RES_READ_FAILURE. Ifsome other
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ error occurs during the read procedure then returned result is + VIRTIO_RPMB_RES_GENERAL_FAILURE. + + The device returns the RPMB frame with response(
VIRTIO_RPMB_RESP_DATA_READ),virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ the block count, a copy of the nonce received in the request, the address, + the data, the calculated MAC, and the result. + +\item[VIRTIO_RPMB_REQ_RESULT_READ] It is used following with the otherrequest
Quoted 1 line
+ types for returned result in one or multiple RPMB frames.
So each write request must be followed by a status request. This just seems like a waste. Why not return the result immediately with the operation? Maybe UFS doesn't support this but virtio sure does.
Does device have to maintain the last request in non-volatile memory and persist across resets? You do not list it as being persistent below. So I would just drop this request type and have driver maintain it in guest memory.
Quoted 2 lines
For
+VIRTIO_RPMB_REQ_PROGRAM_KEYandVIRTIO_RPMB_REQ_DATA_WRITE, ifblock count has
virtio-rpmb.tex
Quoted 5 lines
virtio-rpmb.tex new file +5
-0+ not been set to 1 of VIRTIO_RPMB_REQ_RESULT_READ request, then + VIRTIO_RPMB_RES_GENERAL_FAILURE SHALL be indicated. + +\end{description} +If authetication key was programmed successfully, the device SHALL returnwith a MAC for any operation requests.
Lots of typos above make it pretty hard to figure out.
virtio-rpmb.tex line 246
Quoted 5 lines
virtio-rpmb.tex new file +5
-0+ +\drivernormative{\subsubsection}{Device Operation}{Device Types / +RPMB Device / Device Operation} + +The driver MUST configure and initialize virtqueue for the requests received.received where? why isn't it legal to e.g. check feature bits and then reset?
Quoted 15 lines
virtio-rpmb.tex new file +8
-0+ +\devicenormative{\subsubsection}{Device Operation}{Device Types / +RPMB Device / Device Operation} + +The virtio-rpmb device could be backed in a number of ways. It SHOULD + keep consistent behaviors with hardware as described in paragraph + 6.6.22 of \hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS} + or 8.10 of \hyperref[intro:NVMe]{NVMe}.Some elements are maintained
virtio-rpmb.tex new file +6
-0+ by the device: +\begin{enumerate} +\item The device maintains an one time programmable authentication key. + It cannot be overwritten, erased or read. The key is used to + authenticate the accesses when MAC is calculated. This key MUST be + kept regardless of device reset or reboot.virtio-rpmb.tex line 269
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+\item The device maintains a read-only monotonic write counter. It MUST + be initialized to zero and added by one automatically along with + successful write operation. The value cannot be reset. After + the counter has reached its maximum value 0xFFFF FFFF, it will + not be incremented anymore. This counter MUST be kept regardless + of device reset or reboot. +\item The device maintains the data for read/write via authenticated + access. +\end{enumerate} +What I have gathered from above is really just a counter and a key added to a storage device.
Key: you must have the key to write. It's programmed into the device at some point by manufacturer.
So later, only someone who got key from manufacturer can write. Data is also authenticated with the key, so if you got the key from manufacturer you can verify it's valid.What if you didn't get the key but you steal the data in transit to storage device somehow? You could replay it to the device and overwrite valid data. To this end device maintains write counter, so you can't.
What if you can pretend write failed, or filter out writes to pretend they succeeded? First write counter will be wrong, but it's tricky for applications to verify the counter: after all an application can crash. So each write is followed by a response and users must validate MAC to make sure write made it to the device.
Quoted 5 lines
On the other hand, what if again you didn't get the key but you steal the read response? You could replay that to the application. To this end read requests include a random value and it's copied to the response. Application can put e.g. a counter there.
Right, read uses random value for anti-replay, while write uses counter for anti-replay.
Quoted 10 lines
I think we are coming back full circle and I would like to ask: so why does it not make sense to add this functionality to a block device, or a scsi device? We'd get lots of goodies such as multiqueue, for free.
If we implement above in a hypervisor in software, we can just ignore all random hardware limitations, and support e.g. arbitrary size of writes, arbitrary hash etc etc.
Quoted 6 lines
So I think this is the reason you are making it a separate device and are trying to support so many messy formats is because you are thinking about pass-through.
However, I note that neither driver nor the hypervisor really care about things like order of fields or endian-ness.
It's only the MAC calculations that are affected.
Maybe we can simply this by only supporting one single rpmb, and one single type of rpmb (like UFS) ??
Quoted 16 lines
So my suggestion is, for now just define a clean minimal interface, with some kind of enumerator for an application to discover the specific MAC used. And when hypervisor is forwarding the data to the device, it can move fields around, swap endian-ness or whatever. Will cost some performance but it does not look like this device is fast path anyway.
And I am guessing most people do trust the hypervisor and so they will happily just use a clean software implementation.
Quoted 2 lines
--
2.7.4---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Hi,
I got your points on padding, SHA256, VIRTIO_RPMB_REQ_RESULT_READ etc. But it cannot keep compatibility with native softwares who also runs on hardware RPMB.
Because RPMB frames are packed by other modules who owns RPMB key, but not by virtio driver.
We hope a seamless usage, same APIs, same software to access RPMB under both native or virtualized env. The expectation is to use a same software to access RPMB by calling different drivers obeying same rules in spec.
Quoted 9 lines
Quoted 5 lines
+ \newline\url{https://www.nvmexpress.org/wp-content/uploads/NVM_Expre
+ ss_Revision_1.3.pdf}\\\end{longtable}
At this stage I suggest we avoid nvme. Mix of LE and BE in the frame is just too nasty. And ATM Linux only supports UFS/MMC.
Remove all contents of NVMe RPMB at this phase to simplify the spec?
Quoted 68 lines
Second, please assess the relevance of anything you copy to virtual devices. Copying things like padding does not buy us anything, and just creates work where we need to zero this out.
The only thing that must match if you are passing through a hardware device is the size and order of keys.
Quoted 37 lines
virtio-rpmb.tex new file +25
-0@@ -0,0 +1,269 @@ +\section{RPMB Device}\label{sec:Device Types / RPMB Device} + +virtio-rpmb is a virtio based RPMB (Replay Protected Memory Block) +device. It is used as a tamper-resistant and anti-replay storage. +The device is driven via requests including read, write, get write +counter and program key, which are submitted via a request queue. +This section relies on definitions from paragraph 6.6.22 of +\hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS} and +8.10 of \hyperref[intro:NVMe]{NVMe}. +\subsection{Device ID}\label{sec:Device Types / RPMB Device / Device +ID} + +28 + +\subsection{Virtqueues}\label{sec:Device Types / RPMB Device / +Virtqueues} + +\begin{description} +\item[0] requestq +\end{description} + +\subsection{Feature bits}\label{sec:Device Types / RPMB Device / +Feature bits} + +None.virtio-rpmb.tex line 31
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+ +\subsection{Device configuration layout}\label{sec:Device Types / +RPMB Device / Device configuration layout} + +All fields of this configuration are always available. + +\begin{lstlisting} +enum virtio_rpmb_type { + RPMB_TYPE_JEDEC, + RPMB_TYPE_NVME,enum {} has no meaning in spec. any constants must be defined.
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+}; +Do we have to expose the type? I think we need feature bits for various things so we can split them out later.
Quoted 9 lines
virtio-rpmb.tex line 40
Quoted 7 lines
virtio-rpmb.tex new file +7
-0+struct virtio_rpmb_config { + u8 capacity; + u8 max_wr_cnt; + u8 max_rd_cnt; + u8 id; + u8 type; +}How about adding a key programmed state here?
The state here is not trusted.
User can get this state via read counter/read/write RPMB requests.
If the result is NOT 0007(VIRTIO_RPMB_RES_NO_AUTH_KEY), it implies it has been programmed successfully. And user can authenticate the result by MAC for the case key has been programmed.
Quoted 5 lines
Quoted 2 lines
+\end{lstlisting}
Why not put the counter here?
Same reason. Counter here cannot be trusted.
Quoted 1 line
Are all fields read-only?
Yes. I will add it.
Quoted 4 lines
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ +\begin{description} +\item[\field{capacity}] is the capacity of the device (expressed in 128KB units). + The values MUST range between 0x00 and 0x80 inclusive for JEDEC device,
Quoted 8 lines
and
Quoted 1 line
+
0x00and0xFFinclusive for NVMe device.I'd just drop this. u8 so up to
0xffanyway, and I don't think any users care that there are a couple of extra bytes.Thinking about it, 32Mbytes isn't huge at all. Why not allow larger capacity?
For JEDEC, the address in RPMB frame is 2Bytes. And the data[] (block size) is 256B. It indicates the maximum capacity is 256B * 2^16 = 16MB
For NVMe, I think it's OK. because it's 4B address.
Quoted 8 lines
Quoted 3 lines
+\item[\field{max_wr_cnt and
max_rd_cnt}] are the maximum numbers ofRPMB
virtio-rpmb.tex line 49
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+ block count that can be performed to device in one request. 0 implies + no limitation.I don't understand what does block count mean in this context.
It refers to the number of blocks (256B for JEDEC and 512B for NVMe) requested to be read/written.
Example, if max_wr_cnt is 2 for a eMMC device, it can write RPMB with 2*256B in one request. It can send up to two RPMB write frames (including two data[256]) to device.
Quoted 7 lines
Quoted 1 line
+\item[\field{id}] is the identifier of RPMB partitions.
What does this mean? what are the partitions? Did you mean of the device?
I suspect what is going on is there's an actual device behind this, and this is its ID. Which again begs the question whether this should just be a part of a blk or scsi device.
It's for multiple RPMB regions. RPMB supports up to 4 regions for UFS 3.0 or NVMe 1.3.
Quoted 6 lines
Quoted 4 lines
+\item[\field{type}] is the rpmb type that device emulates.
RPMB_TYPE_JEDEC
+ refers to eMMC or UFS whileRPMB_TYPE_NVMErefers to NVMe.
+\end{description}Does not look like we emulate anything.
Simplify by removing NVMe at current phase.
Quoted 9 lines
virtio-rpmb.tex
Quoted 7 lines
virtio-rpmb.tex new file +7
-0+ +\devicenormative{\subsection}{Device Initialization}{Device Types / +RPMB Device / Device Initialization} + +\begin{enumerate} +\item The virtqueue is initialized. +\item The authentication key of device MUST NOT be programmed at thefirst device initialization.
Quoted 3 lines
What is "first device initialization"? The concept does not seem to apply to virtual devices. How about we just have device pre-initialized to some key? Or maybe device can be in two states, key programming and operation?
I will change the statement.
Device MUST NOT pre-initialized a RPMB key.
The only source of the key is from VIRTIO_RPMB_REQ_PROGRAM_KEY request. Before RPMB is programmed, read/write/read write counter will fail with 0x0007.
Quoted 2 lines
All conformance clauses belong in conformance sections. here and elsewhere.
Thanks. I will add it after the skeleton is stable.
Quoted 7 lines
Quoted 1 line
+\item The device capacity MUST be initialized to a multiple of 128Kbytes and
up to
Quoted 2 lines
+ 16Mbytes/32Mbytes (JEDEC/NVMe device respectively).
+\end{enumerate}So instead of blindly copying limitations of physical devices, we can just allow hypervisor to set any capacity.
As mentioned above, 16MB is limited by 2B address in RPMB frame.
Quoted 114 lines
virtio-rpmb.tex
Quoted 5 lines
virtio-rpmb.tex new file +5
-0+ +\subsection{Device Operation}\label{sec:Device Types / RPMB Device / +Device Operation} + +The operation of a virtio RPMB device is driven by the requests placed on thevirtqueue.
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ The type of the request can be program key +(VIRTIO_RPMB_REQ_PROGRAM_KEY), + get write counter (VIRTIO_RPMB_REQ_GET_WRITE_COUNTER), + write (VIRTIO_RPMB_REQ_DATA_WRITE), and read(
VIRTIO_RPMB_REQ_DATA_READ).Quoted 9 lines
virtio-rpmb.tex new file +9
-0+ A program key or write request can also combine with a + result read (VIRTIO_RPMB_REQ_RESULT_READ) for a returned result. + +\begin{lstlisting} +/* RPMB Request Types */ +#define VIRTIO_RPMB_REQ_PROGRAM_KEY 0x0001 +#define VIRTIO_RPMB_REQ_GET_WRITE_COUNTER 0x0002 +#define VIRTIO_RPMB_REQ_DATA_WRITE 0x0003 +#define VIRTIO_RPMB_REQ_DATA_READ 0x0004virtio-rpmb.tex line 86
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+#define VIRTIO_RPMB_REQ_RESULT_READ 0x0005 +\end{lstlisting} + +\subsubsection{Device Operation: Request Queue}\label{sec:Device +Types / RPMB Device / Device Operation / Device Operation: Request +Queue} + +The request information is delivered in RPMB frame. +The frame is in size of 512B for JEDEC RPMB, and in size of 256B plus +multiple 512B for NVMe RPMB depending on the variable data size.Again this is just messy. Let's come up with a minimal spec. See end of the message pls.
Quoted 16 lines
virtio-rpmb.tex new file +16
-0+ +\begin{lstlisting} +struct virtio_rpmb_frame_jedec { + u8 stuff[196]; + u8 key_mac[32]; + u8 data[256]; + u8 nonce[16]; + be32 write_counter; + be16 address; + be16 block_count; + be16 result; + be16 req_resp; +}; + +struct virtio_rpmb_frame_nvme { + u8 stuff [191];virtio-rpmb.tex line 112
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+ u8 key_mac[32]; + u8 rpmb_target; + u8 nonce[16]; + le32 write_counter; + le32 address; + le32 block_count; + le16 result; + le16 req_resp; + u8 data[0]; +};Oh fun, a mix of LE and BE.
Let's make everything consistent.
Why do we need the "stuff" field? It helps align the size to 256 byte boundary - but why do we care?
Quoted 18 lines
virtio-rpmb.tex new file +17
-0+ +/* RPMB Response Types */ +#define VIRTIO_RPMB_RESP_PROGRAM_KEY 0x0100 +#define VIRTIO_RPMB_RESP_GET_COUNTER 0x0200 +#define VIRTIO_RPMB_RESP_DATA_WRITE 0x0300 +#define VIRTIO_RPMB_RESP_DATA_READ 0x0400 + +/* RPMB Operation Results */ +#define VIRTIO_RPMB_RES_OK 0x0000 +#define VIRTIO_RPMB_RES_GENERAL_FAILURE 0x0001 +#define VIRTIO_RPMB_RES_AUTH_FAILURE 0x0002 +#define VIRTIO_RPMB_RES_COUNT_FAILURE 0x0003 +#define VIRTIO_RPMB_RES_ADDR_FAILURE 0x0004 +#define VIRTIO_RPMB_RES_WRITE_FAILURE 0x0005 +#define VIRTIO_RPMB_RES_READ_FAILURE 0x0006 +#define VIRTIO_RPMB_RES_NO_AUTH_KEY 0x0007 +#define VIRTIO_RPMB_RES_WRITE_COUNTER_EXPIRED 0x0080virtio-rpmb.tex
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+\end{lstlisting} + +\begin{description} +\item[\field{stuff}] Padding for the frame. + +\item[\field{key_mac}] is the authentication key or the message + authentication code (MAC) depending on the request/response type. + If the request is VIRTIO_RPMB_REQ_PROGRAM_KEY, it's used as + authentication key. Otherwise, it's used as MAC. The MAC is calculated + using HMAC SHA-256.SHA-256 is pretty old. Not being a cryptographer I don't really know whether it's still a good mac to use in 2019.
Generally security considerations should probably be presented with anything dealing with crypto.
In this case, I'd do a feature bit so we can change the crypto down the road.virtio-rpmb.tex line 146
Quoted 8 lines
It takes as input a key and a message. The key
virtio-rpmb.tex new file +7
-0+ used for the MAC calculation is always the 256 bit RPMB authentication + key. The message used as input to the MAC calculation is the + concatenation of the fields in the RPMB frames excluding stuff bytes + and the MAC itself. + +\item[\field{rpmb_target}] is the exclusive item for NVMe device. It is + the RPMB target to access.
Quoted 1 line
There are multiple targets too?
Yes.
Quoted 4 lines
Quoted 2 lines
+
+\item[\field{data}] is used to be written or read by signed access.What does signed access mean?
It means read/write is in a authenticated way with MAC. I can add more descriptions.
Quoted 8 lines
virtio-rpmb.tex
Quoted 5 lines
It's
virtio-rpmb.tex new file +4
-0+ fixed 256B for JEDEC device while variable sized payload + 512 * \field{block_count} for NVMe device. + +\item[\field{nonce}] is a random numberrandom how? I think it can just be anything.
I will detail it.
It used by user who request for read/read_write_counter to protect replay attack.
Quoted 12 lines
virtio-rpmb.tex line 160
Quoted 10 lines
generated by user for the read or
virtio-rpmb.tex new file +8
-0+ get write counter requests and copied to the response by device. + +\item[\field{writer_counter}] is the counter value for the total amount of + the successful authenticated data write requests. + +\item[\field{address}] is the address of the data to be written to or read + from the RPMB virtio device. It is the serial number of the accessed + half sector (256B for JEDEC device) or sector (512B for NVMe device).serial number?
Will modify it. Ignore "serial".
Quoted 8 lines
virtio-rpmb.tex line 163
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ +\item[\field{block_count}] is the number of blocks (256B for JEDEC and 512B + for NVMe) requested to be read/written.can't this be intuited from the buffer size somehow?
I don't really understand how can you both have
block_countand a fixed size data. how does this make sense?
The fixed data refer to the size of one block can be read/written.
The block count refers to how many 256 units are requested in one read/write request.
Example, read request on JEDEC RPMB with two blocks (256B*2):
User will send 3 frames, the first is the frame filled by user, with request type, address, nonce etc. The last 2 frames are filled by device with data, MAC, nonce, result etc.
Quoted 11 lines
virtio-rpmb.tex line 167
Quoted 5 lines
virtio-rpmb.tex new file +4
-0+ +\item[\field{result}] includes information about the status of access made + to the device. +So I am guessing result is written by the device?
And type is written by the driver?
this does not play well with virtio where write fields are followed by read fields.
Quoted 5 lines
Quoted 2 lines
+\item[\field{req_resp}] is the type of request or response, as defined above,
+ to/from the device.this seems to be the 1st definition. Please avoid "above" and "below", just link to the definition.
Thanks.
Quoted 11 lines
virtio-rpmb.tex
Quoted 9 lines
+\end{description}
virtio-rpmb.tex new file +8
-0+ +\devicenormative{\paragraph}{Device Operation: Request Queue}{Device +Types / RPMB Device / Device Operation / Device Operation: Request +Queue} + +The device MUST parse the request from the request queue and emulate +the behaviours described in paragraph +6.6.22 of \hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS}or 8.10 of \hyperref[intro:NVMe]{NVMe}:
Quoted 5 lines
If you are going to emulate existing specs, then why not just emulate an existing spec? Why bother with virtio at all? You gain ability to use existing drivers.
If the reason is to make a clean abstraction, then IMHO this falls short of this goal, carrying on all kind of baggage from hardware specs.
Based on the different behaviors.
Or let's discuss it after the skeleton of this device is almost finalized?
Quoted 16 lines
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ +\begin{description} + +\item[VIRTIO_RPMB_REQ_PROGRAM_KEY] If block count has not been set to1
Quoted 1 line
+ then
VIRTIO_RPMB_RES_GENERAL_FAILUREis responded. If programmingof
Quoted 1 line
+ authentication key fails then returned result is
VIRTIO_RPMB_RES_WRITE_FAILURE.Quoted 1 line
+ If some other error occurs then returned result is
VIRTIO_RPMB_RES_GENERAL_FAILURE.Quoted 1 line
+ The \field{req_resp} value
VIRTIO_RPMB_RESP_PROGRAM_KEYcorresponds to
virtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ the key programming request. + + If VIRTIO_RPMB_REQ_RESULT_READ is requested, the device returns the
Quoted 9 lines
RPMB frame
Quoted 1 line
+ with response (
VIRTIO_RPMB_RESP_PROGRAM_KEY), the calculated MACand the result.
I don't see what does
VIRTIO_RPMB_REQ_RESULT_READbuy us.
I guess it proves key has been programmed - but if someone can snoop on programming then for sure he has the key and won't have trouble faking the mac.
Maybe I could add more about it. It's used by write/program_key for a returned frame.
Example, write request on JEDEC RPMB with TWO blocks (256B*2):
User will send 4 frames, the first two are the frames filled by user, with request type, counter, MAC, address, data[] etc.
The third frame is filled with VIRTIO_RPMB_REQ_RESULT_READ request.
And the last is for device to write with MAC, result, etc. If VIRTIO_RPMB_REQ_RESULT_READ is not requested in the 3rd frame, device will not return the result in the 4th frame.
Read/read write counter does not require VIRTIO_RPMB_REQ_RESULT_READ because READ indicates a result frame by default.
Quoted 77 lines
Quoted 2 lines
+
+\item[VIRTIO_RPMB_REQ_GET_WRITE_COUNTE] If the authentication key isnot yet
Quoted 1 line
+ programmed then
VIRTIO_RPMB_RES_NO_AUTH_KEYis returned in\field{result}.
Quoted 1 line
+ If block count has not been set to 1 then
VIRTIO_RPMB_RES_GENERAL_FAILUREvirtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ SHOULD be responded. + + The device returns the RPMB frame with response(
VIRTIO_RPMB_RESP_GET_COUNTER),Quoted 1 line
+ the writer counter, a copy of the nonce received in the request, the
calculated
virtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ MAC and the result. + +\item[VIRTIO_RPMB_REQ_DATA_WRITE] If the authentication key is not yetprogrammed
Quoted 1 line
+ then
VIRTIO_RPMB_RES_NO_AUTH_KEYis returned in \field{result}. Ifblock count
Quoted 1 line
+ is zero or greater than \field{max_wr_cnt} then
VIRTIO_RPMB_RES_GENERAL_FAILUREQuoted 1 line
+ MUST be responded. The device MUST check whether the write counter has
expired.
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+ If the write counter is expired then sets the \field{result} to + VIRTIO_RPMB_RES_WRITE_COUNTER_EXPIRED. If there is an error in theaddress
Quoted 1 line
+ (out of range) then the \field{result} is set to
VIRTIO_RPMB_RES_ADDR_FAILURE.Quoted 1 line
+ The device MUST calculate the MAC taking authentication key and frame as
input,
Quoted 1 line
+ and compares this with the MAC in the request. If the two MAC’s are
different
virtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ then VIRTIO_RPMB_RES_AUTH_FAILURE is returned. + + If the writer counter in the request with is different from the onemaintained
Quoted 1 line
+ by device then
VIRTIO_RPMB_RES_COUNT_FAILUREis returned in\field{result}.
Quoted 1 line
+ If the MAC and write counter comparisons are successful then the write
request
Quoted 1 line
+ is considered to be authenticated. The data from the request are written to
the
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+ address indicated in the request and the write counter is incremented by 1. + If write fails then returned result is VIRTIO_RPMB_RES_WRITE_FAILURE. Ifsome
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ other error occurs during the write procedure then returned result is + VIRTIO_RPMB_RES_GENERAL_FAILURE. + + If VIRTIO_RPMB_REQ_RESULT_READ is requested, the device returns theRPMB data
Quoted 1 line
+ frame with response (
VIRTIO_RPMB_RESP_DATA_WRITE), the incrementedcounter value,
virtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ the data address, the calculated MAC and result. + +\item[VIRTIO_RPMB_REQ_DATA_READ] If the authentication key is not yetprogrammed
Quoted 1 line
+ then
VIRTIO_RPMB_RES_NO_AUTH_KEYis returned in \field{result}. Ifblock count
Quoted 1 line
+ has not been set to 1 then
VIRTIO_RPMB_RES_GENERAL_FAILUREMUST beresponded.
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+ If there is an error in the address (out of range) then the \field{result} is + set to VIRTIO_RPMB_RES_ADDR_FAILURE. If data fetch from addressedlocation inside
Quoted 1 line
+ device fails then returned result is
VIRTIO_RPMB_RES_READ_FAILURE. Ifsome other
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ error occurs during the read procedure then returned result is + VIRTIO_RPMB_RES_GENERAL_FAILURE. + + The device returns the RPMB frame with response(
VIRTIO_RPMB_RESP_DATA_READ),virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ the block count, a copy of the nonce received in the request, the address, + the data, the calculated MAC, and the result. + +\item[VIRTIO_RPMB_REQ_RESULT_READ] It is used following with the otherrequest
Quoted 1 line
+ types for returned result in one or multiple RPMB frames.
Quoted 7 lines
So each write request must be followed by a status request. This just seems like a waste. Why not return the result immediately with the operation? Maybe UFS doesn't support this but virtio sure does.
Does device have to maintain the last request in non-volatile memory and persist across resets? You do not list it as being persistent below. So I would just drop this request type and have driver maintain it in guest memory.
If VIRTIO_RPMB_REQ_RESULT_READ is not request for write/program_key, operation will be performed but no result returned. It’s followed by write/program_key request in most cases. Device does not need to maintain it if user does not request for it. Keeping it for compatibility with hardware does make sense for a unified solution regardless bare metal or virtualization.
Quoted 12 lines
Quoted 2 lines
For
+VIRTIO_RPMB_REQ_PROGRAM_KEYandVIRTIO_RPMB_REQ_DATA_WRITE,if block count has
virtio-rpmb.tex
Quoted 5 lines
virtio-rpmb.tex new file +5
-0+ not been set to 1 of VIRTIO_RPMB_REQ_RESULT_READ request, then + VIRTIO_RPMB_RES_GENERAL_FAILURE SHALL be indicated. + +\end{description} +If authetication key was programmed successfully, the device SHALL returnwith a MAC for any operation requests.
Lots of typos above make it pretty hard to figure out.
Quoted 7 lines
virtio-rpmb.tex line 246
Quoted 5 lines
virtio-rpmb.tex new file +5
-0+ +\drivernormative{\subsubsection}{Device Operation}{Device Types / +RPMB Device / Device Operation} + +The driver MUST configure and initialize virtqueue for the requests received.received where? why isn't it legal to e.g. check feature bits and then reset?
Received from other modules who calls virtio rpmb driver.
Because RPMB frames are not packed by driver.
What driver should do is format the RPMB frames it received and for it to virtqueue, then send to device.
Quoted 73 lines
Quoted 15 lines
virtio-rpmb.tex new file +8
-0+ +\devicenormative{\subsubsection}{Device Operation}{Device Types / +RPMB Device / Device Operation} + +The virtio-rpmb device could be backed in a number of ways. It SHOULD + keep consistent behaviors with hardware as described in paragraph + 6.6.22 of \hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS} + or 8.10 of \hyperref[intro:NVMe]{NVMe}.Some elements are maintained
virtio-rpmb.tex new file +6
-0+ by the device: +\begin{enumerate} +\item The device maintains an one time programmable authentication key. + It cannot be overwritten, erased or read. The key is used to + authenticate the accesses when MAC is calculated. This key MUST be + kept regardless of device reset or reboot.virtio-rpmb.tex line 269
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+\item The device maintains a read-only monotonic write counter. It MUST + be initialized to zero and added by one automatically along with + successful write operation. The value cannot be reset. After + the counter has reached its maximum value 0xFFFF FFFF, it will + not be incremented anymore. This counter MUST be kept regardless + of device reset or reboot. +\item The device maintains the data for read/write via authenticated + access. +\end{enumerate} +What I have gathered from above is really just a counter and a key added to a storage device.
Key: you must have the key to write. It's programmed into the device at some point by manufacturer.
So later, only someone who got key from manufacturer can write. Data is also authenticated with the key, so if you got the key from manufacturer you can verify it's valid.What if you didn't get the key but you steal the data in transit to storage device somehow? You could replay it to the device and overwrite valid data. To this end device maintains write counter, so you can't.
What if you can pretend write failed, or filter out writes to pretend they succeeded? First write counter will be wrong, but it's tricky for applications to verify the counter: after all an application can crash. So each write is followed by a response and users must validate MAC to make sure write made it to the device.
On the other hand, what if again you didn't get the key but you steal the read response? You could replay that to the application. To this end read requests include a random value and it's copied to the response. Application can put e.g. a counter there.
I think we are coming back full circle and I would like to ask: so why does it not make sense to add this functionality to a block device, or a scsi device? We'd get lots of goodies such as multiqueue, for free.
If we implement above in a hypervisor in software, we can just ignore all random hardware limitations, and support e.g. arbitrary size of writes, arbitrary hash etc etc.
So I think this is the reason you are making it a separate device and are trying to support so many messy formats is because you are thinking about pass-through.
However, I note that neither driver nor the hypervisor really care about things like order of fields or endian-ness.
It's only the MAC calculations that are affected.
Quoted 9 lines
So my suggestion is, for now just define a clean minimal interface, with some kind of enumerator for an application to discover the specific MAC used. And when hypervisor is forwarding the data to the device, it can move fields around, swap endian-ness or whatever. Will cost some performance but it does not look like this device is fast path anyway.
And I am guessing most people do trust the hypervisor and so they will happily just use a clean software implementation.
We can simplify the spec by supporting JEDEC only, single RPMB partition. But compatibility with hardware RPMB will benefit developer/user to maintain a same suite of RPMB APIs, structures, operations in both virtualization and bare metal. We can add some feature bits for extended optimization requirements.
Quoted 12 lines · Yang
Hi,
I got your points on padding, SHA256,VIRTIO_RPMB_REQ_RESULT_READetc. But it cannot keep compatibility with native softwares who also runs on hardware RPMB.Because RPMB frames are packed by other modules who owns RPMB key, but not by virtio driver.
We hope a seamless usage, same APIs, same software to access RPMB under both native or virtualized env. The expectation is to use a same software to access RPMB by calling different drivers obeying same rules in spec.Quoted 3 lines
Quoted 3 lines
+ \newline\url{https://www.nvmexpress.org/wp-content/uploads/NVM_Expre
+ ss_Revision_1.3.pdf}\\
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
\end{longtable}
At this stage I suggest we avoid nvme. Mix of LE and BE in the frame is just too nasty. And ATM Linux only supports UFS/MMC.
Remove all contents of NVMe RPMB at this phase to simplify the spec?
Why not.
Quoted 127 lines
Quoted 68 lines
Second, please assess the relevance of anything you copy to virtual devices. Copying things like padding does not buy us anything, and just creates work where we need to zero this out.
The only thing that must match if you are passing through a hardware device is the size and order of keys.
Quoted 37 lines
virtio-rpmb.tex new file +25
-0@@ -0,0 +1,269 @@ +\section{RPMB Device}\label{sec:Device Types / RPMB Device} + +virtio-rpmb is a virtio based RPMB (Replay Protected Memory Block) +device. It is used as a tamper-resistant and anti-replay storage. +The device is driven via requests including read, write, get write +counter and program key, which are submitted via a request queue. +This section relies on definitions from paragraph 6.6.22 of +\hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS} and +8.10 of \hyperref[intro:NVMe]{NVMe}. +\subsection{Device ID}\label{sec:Device Types / RPMB Device / Device +ID} + +28 + +\subsection{Virtqueues}\label{sec:Device Types / RPMB Device / +Virtqueues} + +\begin{description} +\item[0] requestq +\end{description} + +\subsection{Feature bits}\label{sec:Device Types / RPMB Device / +Feature bits} + +None.virtio-rpmb.tex line 31
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+ +\subsection{Device configuration layout}\label{sec:Device Types / +RPMB Device / Device configuration layout} + +All fields of this configuration are always available. + +\begin{lstlisting} +enum virtio_rpmb_type { + RPMB_TYPE_JEDEC, + RPMB_TYPE_NVME,enum {} has no meaning in spec. any constants must be defined.
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+}; +Do we have to expose the type? I think we need feature bits for various things so we can split them out later.
Quoted 9 lines
virtio-rpmb.tex line 40
Quoted 7 lines
virtio-rpmb.tex new file +7
-0+struct virtio_rpmb_config { + u8 capacity; + u8 max_wr_cnt; + u8 max_rd_cnt; + u8 id; + u8 type; +}How about adding a key programmed state here?
The state here is not trusted.
User can get this state via read counter/read/write RPMB requests.
If the result is NOT 0007(VIRTIO_RPMB_RES_NO_AUTH_KEY), it implies it has been programmed successfully. And user can authenticate the result by MAC for the case key has been programmed.Quoted 5 lines
Quoted 2 lines
+\end{lstlisting}
Why not put the counter here?
Same reason. Counter here cannot be trusted.
Quoted 1 line
Are all fields read-only?
Yes. I will add it.
Quoted 4 lines
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ +\begin{description} +\item[\field{capacity}] is the capacity of the device (expressed in 128KB units). + The values MUST range between 0x00 and 0x80 inclusive for JEDEC device,Quoted 8 lines
and
Quoted 1 line
+
0x00and0xFFinclusive for NVMe device.I'd just drop this. u8 so up to
0xffanyway, and I don't think any users care that there are a couple of extra bytes.Thinking about it, 32Mbytes isn't huge at all. Why not allow larger capacity?
For JEDEC, the address in RPMB frame is 2Bytes. And the data[] (block size) is 256B. It indicates the maximum capacity is 256B * 2^16 = 16MB
For NVMe, I think it's OK. because it's 4B address.Quoted 8 lines
Quoted 3 lines
+\item[\field{max_wr_cnt and
max_rd_cnt}] are the maximum numbers ofRPMB
virtio-rpmb.tex line 49
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+ block count that can be performed to device in one request. 0 implies + no limitation.I don't understand what does block count mean in this context.
It refers to the number of blocks (256B for JEDEC and 512B for NVMe) requested to be read/written.
Example, if
max_wr_cntis 2 for a eMMC device, it can write RPMB with 2*256B in one request. It can send up to two RPMB write frames (including two data[256]) to device.Quoted 2 lines
Quoted 1 line
+\item[\field{id}] is the identifier of RPMB partitions.
Quoted 7 lines
Quoted 5 lines
What does this mean? what are the partitions? Did you mean of the device?
I suspect what is going on is there's an actual device behind this, and this is its ID. Which again begs the question whether this should just be a part of a blk or scsi device.
It's for multiple RPMB regions. RPMB supports up to 4 regions for UFS 3.0 or NVMe 1.3.
So a device with 1 region it's always 0?
Quoted 28 lines
Quoted 6 lines
Quoted 4 lines
+\item[\field{type}] is the rpmb type that device emulates.
RPMB_TYPE_JEDEC
+ refers to eMMC or UFS whileRPMB_TYPE_NVMErefers to NVMe.
+\end{description}Does not look like we emulate anything.
Simplify by removing NVMe at current phase.
Quoted 9 lines
virtio-rpmb.tex
Quoted 7 lines
virtio-rpmb.tex new file +7
-0+ +\devicenormative{\subsection}{Device Initialization}{Device Types / +RPMB Device / Device Initialization} + +\begin{enumerate} +\item The virtqueue is initialized. +\item The authentication key of device MUST NOT be programmed at thefirst device initialization.
Quoted 3 lines
What is "first device initialization"? The concept does not seem to apply to virtual devices. How about we just have device pre-initialized to some key? Or maybe device can be in two states, key programming and operation?
I will change the statement.
Device MUST NOT pre-initialized a RPMB key.
The only source of the key is fromVIRTIO_RPMB_REQ_PROGRAM_KEYrequest. Before RPMB is programmed, read/write/read write counter will fail with0x0007.Quoted 1 line
Quoted 3 lines
Quoted 1 line
All conformance clauses belong in conformance sections. here and elsewhere.
Thanks. I will add it after the skeleton is stable.
I'd rather we try to finalize it all in one go, don't have the time to review everything twice :)
Quoted 143 lines
Quoted 7 lines
Quoted 1 line
+\item The device capacity MUST be initialized to a multiple of 128Kbytes and
up to
Quoted 2 lines
+ 16Mbytes/32Mbytes (JEDEC/NVMe device respectively).
+\end{enumerate}So instead of blindly copying limitations of physical devices, we can just allow hypervisor to set any capacity.
As mentioned above, 16MB is limited by 2B address in RPMB frame.
Quoted 114 lines
virtio-rpmb.tex
Quoted 5 lines
virtio-rpmb.tex new file +5
-0+ +\subsection{Device Operation}\label{sec:Device Types / RPMB Device / +Device Operation} + +The operation of a virtio RPMB device is driven by the requests placed on thevirtqueue.
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ The type of the request can be program key +(VIRTIO_RPMB_REQ_PROGRAM_KEY), + get write counter (VIRTIO_RPMB_REQ_GET_WRITE_COUNTER), + write (VIRTIO_RPMB_REQ_DATA_WRITE), and read(
VIRTIO_RPMB_REQ_DATA_READ).Quoted 9 lines
virtio-rpmb.tex new file +9
-0+ A program key or write request can also combine with a + result read (VIRTIO_RPMB_REQ_RESULT_READ) for a returned result. + +\begin{lstlisting} +/* RPMB Request Types */ +#define VIRTIO_RPMB_REQ_PROGRAM_KEY 0x0001 +#define VIRTIO_RPMB_REQ_GET_WRITE_COUNTER 0x0002 +#define VIRTIO_RPMB_REQ_DATA_WRITE 0x0003 +#define VIRTIO_RPMB_REQ_DATA_READ 0x0004virtio-rpmb.tex line 86
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+#define VIRTIO_RPMB_REQ_RESULT_READ 0x0005 +\end{lstlisting} + +\subsubsection{Device Operation: Request Queue}\label{sec:Device +Types / RPMB Device / Device Operation / Device Operation: Request +Queue} + +The request information is delivered in RPMB frame. +The frame is in size of 512B for JEDEC RPMB, and in size of 256B plus +multiple 512B for NVMe RPMB depending on the variable data size.Again this is just messy. Let's come up with a minimal spec. See end of the message pls.
Quoted 16 lines
virtio-rpmb.tex new file +16
-0+ +\begin{lstlisting} +struct virtio_rpmb_frame_jedec { + u8 stuff[196]; + u8 key_mac[32]; + u8 data[256]; + u8 nonce[16]; + be32 write_counter; + be16 address; + be16 block_count; + be16 result; + be16 req_resp; +}; + +struct virtio_rpmb_frame_nvme { + u8 stuff [191];virtio-rpmb.tex line 112
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+ u8 key_mac[32]; + u8 rpmb_target; + u8 nonce[16]; + le32 write_counter; + le32 address; + le32 block_count; + le16 result; + le16 req_resp; + u8 data[0]; +};Oh fun, a mix of LE and BE.
Let's make everything consistent.
Why do we need the "stuff" field? It helps align the size to 256 byte boundary - but why do we care?
Quoted 18 lines
virtio-rpmb.tex new file +17
-0+ +/* RPMB Response Types */ +#define VIRTIO_RPMB_RESP_PROGRAM_KEY 0x0100 +#define VIRTIO_RPMB_RESP_GET_COUNTER 0x0200 +#define VIRTIO_RPMB_RESP_DATA_WRITE 0x0300 +#define VIRTIO_RPMB_RESP_DATA_READ 0x0400 + +/* RPMB Operation Results */ +#define VIRTIO_RPMB_RES_OK 0x0000 +#define VIRTIO_RPMB_RES_GENERAL_FAILURE 0x0001 +#define VIRTIO_RPMB_RES_AUTH_FAILURE 0x0002 +#define VIRTIO_RPMB_RES_COUNT_FAILURE 0x0003 +#define VIRTIO_RPMB_RES_ADDR_FAILURE 0x0004 +#define VIRTIO_RPMB_RES_WRITE_FAILURE 0x0005 +#define VIRTIO_RPMB_RES_READ_FAILURE 0x0006 +#define VIRTIO_RPMB_RES_NO_AUTH_KEY 0x0007 +#define VIRTIO_RPMB_RES_WRITE_COUNTER_EXPIRED 0x0080virtio-rpmb.tex
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+\end{lstlisting} + +\begin{description} +\item[\field{stuff}] Padding for the frame. + +\item[\field{key_mac}] is the authentication key or the message + authentication code (MAC) depending on the request/response type. + If the request is VIRTIO_RPMB_REQ_PROGRAM_KEY, it's used as + authentication key. Otherwise, it's used as MAC. The MAC is calculated + using HMAC SHA-256.SHA-256 is pretty old. Not being a cryptographer I don't really know whether it's still a good mac to use in 2019.
Generally security considerations should probably be presented with anything dealing with crypto.
In this case, I'd do a feature bit so we can change the crypto down the road.virtio-rpmb.tex line 146
Quoted 8 lines
It takes as input a key and a message. The key
virtio-rpmb.tex new file +7
-0+ used for the MAC calculation is always the 256 bit RPMB authentication + key. The message used as input to the MAC calculation is the + concatenation of the fields in the RPMB frames excluding stuff bytes + and the MAC itself. + +\item[\field{rpmb_target}] is the exclusive item for NVMe device. It is + the RPMB target to access.Quoted 1 line
There are multiple targets too?
Yes.
Quoted 4 lines
Quoted 2 lines
+
+\item[\field{data}] is used to be written or read by signed access.What does signed access mean?
It means read/write is in a authenticated way with MAC. I can add more descriptions.
Quoted 7 lines
Quoted 5 lines
It's
virtio-rpmb.tex new file +4
-0+ fixed 256B for JEDEC device while variable sized payload + 512 * \field{block_count} for NVMe device. + +\item[\field{nonce}] is a random number
Quoted 4 lines
Quoted 1 line
random how? I think it can just be anything.
I will detail it.
It used by user who request for read/read_write_counter to protect replay attack.
Oh so if one cares about replay, it needs to be hard to predict.
Quoted 24 lines
Quoted 12 lines
virtio-rpmb.tex line 160
Quoted 10 lines
generated by user for the read or
virtio-rpmb.tex new file +8
-0+ get write counter requests and copied to the response by device. + +\item[\field{writer_counter}] is the counter value for the total amount of + the successful authenticated data write requests. + +\item[\field{address}] is the address of the data to be written to or read + from the RPMB virtio device. It is the serial number of the accessed + half sector (256B for JEDEC device) or sector (512B for NVMe device).serial number?
Will modify it. Ignore "serial".
Quoted 8 lines
virtio-rpmb.tex line 163
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ +\item[\field{block_count}] is the number of blocks (256B for JEDEC and 512B + for NVMe) requested to be read/written.can't this be intuited from the buffer size somehow?
I don't really understand how can you both have
block_countand a fixed size data. how does this make sense?
Quoted 6 lines
The fixed data refer to the size of one block can be read/written.
The block count refers to how many 256 units are requested in one read/write request.Example, read request on JEDEC RPMB with two blocks (256B*2):
User will send 3 frames, the first is the frame filled by user, with request type, address, nonce etc. The last 2 frames are filled by device with data, MAC, nonce, result etc.
So please map this to virtio buffers and document the mapping.
Quoted 30 lines
Quoted 11 lines
virtio-rpmb.tex line 167
Quoted 5 lines
virtio-rpmb.tex new file +4
-0+ +\item[\field{result}] includes information about the status of access made + to the device. +So I am guessing result is written by the device?
And type is written by the driver?
this does not play well with virtio where write fields are followed by read fields.Quoted 5 lines
Quoted 2 lines
+\item[\field{req_resp}] is the type of request or response, as defined above,
+ to/from the device.this seems to be the 1st definition. Please avoid "above" and "below", just link to the definition.
Thanks.
Quoted 11 lines
virtio-rpmb.tex
Quoted 9 lines
+\end{description}
virtio-rpmb.tex new file +8
-0+ +\devicenormative{\paragraph}{Device Operation: Request Queue}{Device +Types / RPMB Device / Device Operation / Device Operation: Request +Queue} + +The device MUST parse the request from the request queue and emulate +the behaviours described in paragraph +6.6.22 of \hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS}or 8.10 of \hyperref[intro:NVMe]{NVMe}:
Quoted 7 lines
Quoted 5 lines
If you are going to emulate existing specs, then why not just emulate an existing spec? Why bother with virtio at all? You gain ability to use existing drivers.
If the reason is to make a clean abstraction, then IMHO this falls short of this goal, carrying on all kind of baggage from hardware specs.
Based on the different behaviors.
I think what you are saying is there's all kind of hardware and it's useful to abstract it away?
Quoted 118 lines
Or let's discuss it after the skeleton of this device is almost finalized?
Quoted 16 lines
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ +\begin{description} + +\item[VIRTIO_RPMB_REQ_PROGRAM_KEY] If block count has not been set to1
Quoted 1 line
+ then
VIRTIO_RPMB_RES_GENERAL_FAILUREis responded. If programmingof
Quoted 1 line
+ authentication key fails then returned result is
VIRTIO_RPMB_RES_WRITE_FAILURE.Quoted 1 line
+ If some other error occurs then returned result is
VIRTIO_RPMB_RES_GENERAL_FAILURE.Quoted 1 line
+ The \field{req_resp} value
VIRTIO_RPMB_RESP_PROGRAM_KEYcorresponds to
virtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ the key programming request. + + If VIRTIO_RPMB_REQ_RESULT_READ is requested, the device returns theQuoted 9 lines
RPMB frame
Quoted 1 line
+ with response (
VIRTIO_RPMB_RESP_PROGRAM_KEY), the calculated MACand the result.
I don't see what does
VIRTIO_RPMB_REQ_RESULT_READbuy us.
I guess it proves key has been programmed - but if someone can snoop on programming then for sure he has the key and won't have trouble faking the mac.Maybe I could add more about it. It's used by write/program_key for a returned frame.
Example, write request on JEDEC RPMB with TWO blocks (256B*2):
User will send 4 frames, the first two are the frames filled by user, with request type, counter, MAC, address, data[] etc.
The third frame is filled withVIRTIO_RPMB_REQ_RESULT_READrequest.
And the last is for device to write with MAC, result, etc. IfVIRTIO_RPMB_REQ_RESULT_READis not requested in the 3rd frame, device will not return the result in the 4th frame.Read/read write counter does not require
VIRTIO_RPMB_REQ_RESULT_READbecause READ indicates a result frame by default.Quoted 81 lines
Quoted 2 lines
+
+\item[VIRTIO_RPMB_REQ_GET_WRITE_COUNTE] If the authentication key isnot yet
Quoted 1 line
+ programmed then
VIRTIO_RPMB_RES_NO_AUTH_KEYis returned in\field{result}.
Quoted 1 line
+ If block count has not been set to 1 then
VIRTIO_RPMB_RES_GENERAL_FAILUREvirtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ SHOULD be responded. + + The device returns the RPMB frame with response(
VIRTIO_RPMB_RESP_GET_COUNTER),Quoted 1 line
+ the writer counter, a copy of the nonce received in the request, the
calculated
virtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ MAC and the result. + +\item[VIRTIO_RPMB_REQ_DATA_WRITE] If the authentication key is not yetprogrammed
Quoted 1 line
+ then
VIRTIO_RPMB_RES_NO_AUTH_KEYis returned in \field{result}. Ifblock count
Quoted 1 line
+ is zero or greater than \field{max_wr_cnt} then
VIRTIO_RPMB_RES_GENERAL_FAILUREQuoted 1 line
+ MUST be responded. The device MUST check whether the write counter has
expired.
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+ If the write counter is expired then sets the \field{result} to + VIRTIO_RPMB_RES_WRITE_COUNTER_EXPIRED. If there is an error in theaddress
Quoted 1 line
+ (out of range) then the \field{result} is set to
VIRTIO_RPMB_RES_ADDR_FAILURE.Quoted 1 line
+ The device MUST calculate the MAC taking authentication key and frame as
input,
Quoted 1 line
+ and compares this with the MAC in the request. If the two MAC’s are
different
virtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ then VIRTIO_RPMB_RES_AUTH_FAILURE is returned. + + If the writer counter in the request with is different from the onemaintained
Quoted 1 line
+ by device then
VIRTIO_RPMB_RES_COUNT_FAILUREis returned in\field{result}.
Quoted 1 line
+ If the MAC and write counter comparisons are successful then the write
request
Quoted 1 line
+ is considered to be authenticated. The data from the request are written to
the
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+ address indicated in the request and the write counter is incremented by 1. + If write fails then returned result is VIRTIO_RPMB_RES_WRITE_FAILURE. Ifsome
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ other error occurs during the write procedure then returned result is + VIRTIO_RPMB_RES_GENERAL_FAILURE. + + If VIRTIO_RPMB_REQ_RESULT_READ is requested, the device returns theRPMB data
Quoted 1 line
+ frame with response (
VIRTIO_RPMB_RESP_DATA_WRITE), the incrementedcounter value,
virtio-rpmb.tex
Quoted 3 lines
virtio-rpmb.tex new file +3
-0+ the data address, the calculated MAC and result. + +\item[VIRTIO_RPMB_REQ_DATA_READ] If the authentication key is not yetprogrammed
Quoted 1 line
+ then
VIRTIO_RPMB_RES_NO_AUTH_KEYis returned in \field{result}. Ifblock count
Quoted 1 line
+ has not been set to 1 then
VIRTIO_RPMB_RES_GENERAL_FAILUREMUST beresponded.
virtio-rpmb.tex
Quoted 2 lines
virtio-rpmb.tex new file +2
-0+ If there is an error in the address (out of range) then the \field{result} is + set to VIRTIO_RPMB_RES_ADDR_FAILURE. If data fetch from addressedlocation inside
Quoted 1 line
+ device fails then returned result is
VIRTIO_RPMB_RES_READ_FAILURE. Ifsome other
virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ error occurs during the read procedure then returned result is + VIRTIO_RPMB_RES_GENERAL_FAILURE. + + The device returns the RPMB frame with response(
VIRTIO_RPMB_RESP_DATA_READ),virtio-rpmb.tex
Quoted 4 lines
virtio-rpmb.tex new file +4
-0+ the block count, a copy of the nonce received in the request, the address, + the data, the calculated MAC, and the result. + +\item[VIRTIO_RPMB_REQ_RESULT_READ] It is used following with the otherrequest
Quoted 1 line
+ types for returned result in one or multiple RPMB frames.
So each write request must be followed by a status request. This just seems like a waste. Why not return the result immediately with the operation? Maybe UFS doesn't support this but virtio sure does.
Quoted 7 lines
Quoted 3 lines
Does device have to maintain the last request in non-volatile memory and persist across resets? You do not list it as being persistent below. So I would just drop this request type and have driver maintain it in guest memory.
If
VIRTIO_RPMB_REQ_RESULT_READis not request for write/program_key, operation will be performed but no result returned. It’s followed by write/program_key request in most cases. Device does not need to maintain it if user does not request for it. Keeping it for compatibility with hardware does make sense for a unified solution regardless bare metal or virtualization.
So what is wrong with driver doing it?
Quoted 20 lines
Quoted 12 lines
Quoted 2 lines
For
+VIRTIO_RPMB_REQ_PROGRAM_KEYandVIRTIO_RPMB_REQ_DATA_WRITE,if block count has
virtio-rpmb.tex
Quoted 5 lines
virtio-rpmb.tex new file +5
-0+ not been set to 1 of VIRTIO_RPMB_REQ_RESULT_READ request, then + VIRTIO_RPMB_RES_GENERAL_FAILURE SHALL be indicated. + +\end{description} +If authetication key was programmed successfully, the device SHALL returnwith a MAC for any operation requests.
Lots of typos above make it pretty hard to figure out.
Quoted 7 lines
virtio-rpmb.tex line 246
Quoted 5 lines
virtio-rpmb.tex new file +5
-0+ +\drivernormative{\subsubsection}{Device Operation}{Device Types / +RPMB Device / Device Operation} + +The driver MUST configure and initialize virtqueue for the requests received.received where? why isn't it legal to e.g. check feature bits and then reset?
Quoted 3 lines
Received from other modules who calls virtio rpmb driver.
Because RPMB frames are not packed by driver.
What driver should do is format the RPMB frames it received and for it to virtqueue, then send to device.
OK pls write this up in the spec.
Quoted 79 lines
Quoted 79 lines
Quoted 15 lines
virtio-rpmb.tex new file +8
-0+ +\devicenormative{\subsubsection}{Device Operation}{Device Types / +RPMB Device / Device Operation} + +The virtio-rpmb device could be backed in a number of ways. It SHOULD + keep consistent behaviors with hardware as described in paragraph + 6.6.22 of \hyperref[intro:eMMC]{eMMC}, 12.4 of \hyperref[intro:UFS]{UFS} + or 8.10 of \hyperref[intro:NVMe]{NVMe}.Some elements are maintained
virtio-rpmb.tex new file +6
-0+ by the device: +\begin{enumerate} +\item The device maintains an one time programmable authentication key. + It cannot be overwritten, erased or read. The key is used to + authenticate the accesses when MAC is calculated. This key MUST be + kept regardless of device reset or reboot.virtio-rpmb.tex line 269
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+\item The device maintains a read-only monotonic write counter. It MUST + be initialized to zero and added by one automatically along with + successful write operation. The value cannot be reset. After + the counter has reached its maximum value 0xFFFF FFFF, it will + not be incremented anymore. This counter MUST be kept regardless + of device reset or reboot. +\item The device maintains the data for read/write via authenticated + access. +\end{enumerate} +What I have gathered from above is really just a counter and a key added to a storage device.
Key: you must have the key to write. It's programmed into the device at some point by manufacturer.
So later, only someone who got key from manufacturer can write. Data is also authenticated with the key, so if you got the key from manufacturer you can verify it's valid.What if you didn't get the key but you steal the data in transit to storage device somehow? You could replay it to the device and overwrite valid data. To this end device maintains write counter, so you can't.
What if you can pretend write failed, or filter out writes to pretend they succeeded? First write counter will be wrong, but it's tricky for applications to verify the counter: after all an application can crash. So each write is followed by a response and users must validate MAC to make sure write made it to the device.
On the other hand, what if again you didn't get the key but you steal the read response? You could replay that to the application. To this end read requests include a random value and it's copied to the response. Application can put e.g. a counter there.
I think we are coming back full circle and I would like to ask: so why does it not make sense to add this functionality to a block device, or a scsi device? We'd get lots of goodies such as multiqueue, for free.
If we implement above in a hypervisor in software, we can just ignore all random hardware limitations, and support e.g. arbitrary size of writes, arbitrary hash etc etc.
So I think this is the reason you are making it a separate device and are trying to support so many messy formats is because you are thinking about pass-through.
However, I note that neither driver nor the hypervisor really care about things like order of fields or endian-ness.
It's only the MAC calculations that are affected.So my suggestion is, for now just define a clean minimal interface, with some kind of enumerator for an application to discover the specific MAC used. And when hypervisor is forwarding the data to the device, it can move fields around, swap endian-ness or whatever. Will cost some performance but it does not look like this device is fast path anyway.
Quoted 8 lines
Quoted 3 lines
And I am guessing most people do trust the hypervisor and so they will happily just use a clean software implementation.
We can simplify the spec by supporting JEDEC only, single RPMB partition. But compatibility with hardware RPMB will benefit developer/user to maintain a same suite of RPMB APIs, structures, operations in both virtualization and bare metal. We can add some feature bits for extended optimization requirements.
I don't know, this picks and chooses hardware parts to copy and I'm not sure what do you base what to emulate on. E.g. doesn't userspace also assume RPMB is part of a storage device?
It would make sense to me if you just emulated encrypted parts.
Signature · 5 lines
MST --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
+ \newline\url{https://www.nvmexpress.org/wp-content/uploads/NVM_E
+ xpre
+ ss_Revision_1.3.pdf}\\\end{longtable}
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
At this stage I suggest we avoid nvme. Mix of LE and BE in the frame is just too nasty. And ATM Linux only supports UFS/MMC.
Remove all contents of NVMe RPMB at this phase to simplify the spec?
Why not.
It's removed in V4.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
+\item[\field{id}] is the identifier of RPMB partitions.
What does this mean? what are the partitions? Did you mean of the device?
I suspect what is going on is there's an actual device behind this, and this is
Quoted 9 lines
its ID.
Quoted 4 lines
Quoted 2 lines
Which again begs the question whether this should just be a part of a blk or scsi device.
It's for multiple RPMB regions. RPMB supports up to 4 regions for UFS 3.0 or
NVMe 1.3.
So a device with 1 region it's always 0?
For the device with only 1 region, no such item required. This is removed in V4 for simplicity.
Quoted 22 lines
Quoted 9 lines
Quoted 9 lines
virtio-rpmb.tex
Quoted 7 lines
+\devicenormative{\subsection}{Device Initialization}{Device Types
virtio-rpmb.tex new file +6
-0+/ RPMB Device / Device Initialization} + +\begin{enumerate} +\item The virtqueue is initialized. +\item The authentication key of device MUST NOT be programmed at +thefirst device initialization.
Quoted 3 lines
Quoted 3 lines
What is "first device initialization"? The concept does not seem to apply to virtual devices. How about we just have device pre-initialized to some key? Or maybe device can be in two states, key
programming and operation?
Quoted 4 lines
I will change the statement.
Device MUST NOT pre-initialized a RPMB key.
The only source of the key is fromVIRTIO_RPMB_REQ_PROGRAM_KEYrequest.
Quoted 1 line
Before RPMB is programmed, read/write/read write counter will fail with
0x0007.Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
All conformance clauses belong in conformance sections. here and
elsewhere.
Quoted 2 lines
Thanks. I will add it after the skeleton is stable.
I'd rather we try to finalize it all in one go, don't have the time to review everything twice :)
Sure. It's added to V4 which had been sent out.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+\item[\field{nonce}] is a random number
random how? I think it can just be anything.
I will detail it.
It used by user who request for read/read_write_counter to protect replayattack.
Oh so if one cares about replay, it needs to be hard to predict.
Yes. This is the responsibility for the caller to fill a random to protect from replay attack.
Quoted 13 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+\item[\field{block_count}] is the number of blocks (256B for JEDEC and
512B
Quoted 9 lines
Quoted 6 lines
Quoted 1 line
+ for NVMe) requested to be read/written.
can't this be intuited from the buffer size somehow?
I don't really understand how can you both have
block_countand a fixed size data. how does this make sense?The fixed data refer to the size of one block can be read/written. The block count refers to how many 256 units are requested in one read/write
request.
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
Example, read request on JEDEC RPMB with two blocks (256B*2):
User will send 3 frames, the first is the frame filled by user, with request type,address, nonce etc.
Quoted 1 line
The last 2 frames are filled by device with data, MAC, nonce, result etc.
So please map this to virtio buffers and document the mapping.
Not included in V4. Will mention it in V5
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
+\item[VIRTIO_RPMB_REQ_RESULT_READ] It is used following with the +other
request
Quoted 1 line
+ types for returned result in one or multiple RPMB frames.
Quoted 7 lines
Quoted 7 lines
So each write request must be followed by a status request. This just seems like a waste. Why not return the result immediately with the operation? Maybe UFS doesn't support this but virtio sure does.
Does device have to maintain the last request in non-volatile memory and persist across resets? You do not list it as being persistent below. So I would just drop this request type and have driver maintain it in
guest memory.
Quoted 2 lines
If
VIRTIO_RPMB_REQ_RESULT_READis not request for write/program_key,operation will be performed but no result returned.
Quoted 8 lines
Quoted 1 line
It’s followed by write/program_key request in most cases. Device does not
need to maintain it if user does not request for it.
Quoted 1 line
Keeping it for compatibility with hardware does make sense for a unified
solution regardless bare metal or virtualization.
So what is wrong with driver doing it?
To answer your previous question firstly:
I don't think the device should maintain the last request in memory and persist across resets.
Because the VIRTIO_RPMB_REQ_RESULT_READ request is sent to the device together with the other requests like VIRTIO_RPMB_REQ_PROGRAM_KEY or VIRTIO_RPMB_REQ_DATA_WRITE. The device can check the VIRTIO_RPMB_REQ_RESULT_READ is requested when it receives the two requests.
No such usage that sending VIRTIO_RPMB_REQ_RESULT_READ at first and VIRTIO_RPMB_REQ_RESULT_READ the second for some time.
Because nobody promises no any new requests operated during the time interval.
For your second question:
The requirement always depends on the caller. This aligns with the native, and make the driver pure. The driver just does one thing: format the request frames to virtqueue but not access the content of the frame.
Quoted 21 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
For
+VIRTIO_RPMB_REQ_PROGRAM_KEYand
VIRTIO_RPMB_REQ_DATA_WRITE,Quoted 9 lines
Quoted 9 lines
if block count has
virtio-rpmb.tex
Quoted 6 lines
virtio-rpmb.tex new file +6
-0+ not been set to 1 of VIRTIO_RPMB_REQ_RESULT_READ request, then + VIRTIO_RPMB_RES_GENERAL_FAILURE SHALL be indicated. + +\end{description} +If authetication key was programmed successfully, the device +SHALL returnwith a MAC for any operation requests.
Quoted 7 lines
Quoted 7 lines
Lots of typos above make it pretty hard to figure out.
Review
Quoted 5 lines
(quoted diff) +5
-0+ +\drivernormative{\subsubsection}{Device Operation}{Device Types / +RPMB Device / Device Operation} + +The driver MUST configure and initialize virtqueue for the requestsreceived.
Quoted 1 line
Quoted 1 line
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
received where? why isn't it legal to e.g. check feature bits and then reset?
Received from other modules who calls virtio rpmb driver. Because RPMB frames are not packed by driver.
What driver should do is format the RPMB frames it received and for it tovirtqueue, then send to device.
OK pls write this up in the spec.
OK. Not included in V4. Will add it to V5.
Quoted 90 lines
Quoted 7 lines
Quoted 7 lines
virtio-rpmb.tex
Quoted 7 lines
virtio-rpmb.tex new file +7
-0+ +\devicenormative{\subsubsection}{Device Operation}{Device Types / +RPMB Device / Device Operation} + +The virtio-rpmb device could be backed in a number of ways. It SHOULD + keep consistent behaviors with hardware as described in paragraph + 6.6.22 of \hyperref[intro:eMMC]{eMMC}, 12.4 of\hyperref[intro:UFS]{UFS}
Quoted 50 lines
Quoted 50 lines
Quoted 8 lines
+ or 8.10 of \hyperref[intro:NVMe]{NVMe}.
Some elements are maintainedvirtio-rpmb.tex new file +6
-0+ by the device: +\begin{enumerate} +\item The device maintains an one time programmable authentication key. + It cannot be overwritten, erased or read. The key is used to + authenticate the accesses when MAC is calculated. This key MUST be + kept regardless of device reset or reboot.virtio-rpmb.tex line 269
Quoted 10 lines
virtio-rpmb.tex new file +10
-0+\item The device maintains a read-only monotonic write counter. It MUST + be initialized to zero and added by one automatically along with + successful write operation. The value cannot be reset. After + the counter has reached its maximum value 0xFFFF FFFF, it will + not be incremented anymore. This counter MUST be kept regardless + of device reset or reboot. +\item The device maintains the data for read/write via authenticated + access. +\end{enumerate} +What I have gathered from above is really just a counter and a key added to a storage device.
Key: you must have the key to write. It's programmed into the device at some point by manufacturer.
So later, only someone who got key from manufacturer can write. Data is also authenticated with the key, so if you got the key from manufacturer you can verify it's valid.What if you didn't get the key but you steal the data in transit to storage device somehow? You could replay it to the device and overwrite valid data. To this end device maintains write counter, so you can't.
What if you can pretend write failed, or filter out writes to pretend they succeeded? First write counter will be wrong, but it's tricky for applications to verify the counter: after all an application can crash. So each write is followed by a response and users must validate MAC to make sure write made it to the device.
On the other hand, what if again you didn't get the key but you steal the read response? You could replay that to the application. To this end read requests include a random value and it's copied to the response. Application can put e.g. a counter there.
Quoted 3 lines
Quoted 3 lines
I think we are coming back full circle and I would like to ask: so why does it not make sense to add this functionality to a block device, or a scsi device? We'd get lots of goodies such as multiqueue, for
free.
Quoted 8 lines
Quoted 8 lines
If we implement above in a hypervisor in software, we can just ignore all random hardware limitations, and support e.g. arbitrary size of writes, arbitrary hash etc etc.
So I think this is the reason you are making it a separate device and are trying to support so many messy formats is because you are thinking
about pass-through.
Quoted 10 lines
Quoted 10 lines
However, I note that neither driver nor the hypervisor really care about things like order of fields or endian-ness.
It's only the MAC calculations that are affected.So my suggestion is, for now just define a clean minimal interface, with some kind of enumerator for an application to discover the specific MAC used. And when hypervisor is forwarding the data to the device, it can move fields around, swap endian-ness or whatever. Will cost some performance but it does not look like this device is fast path
anyway.
Quoted 8 lines
Quoted 4 lines
And I am guessing most people do trust the hypervisor and so they will happily just use a clean software implementation.
We can simplify the spec by supporting JEDEC only, single RPMB partition. But compatibility with hardware RPMB will benefit developer/user to maintain a same suite of RPMB APIs, structures, operations in both
Quoted 9 lines
virtualization and bare metal.
Quoted 1 line
We can add some feature bits for extended optimization requirements.
I don't know, this picks and chooses hardware parts to copy and I'm not sure what do you base what to emulate on.
E.g. doesn't userspace also assume RPMB is part of a storage device?It would make sense to me if you just emulated encrypted parts.
What do you refer to, for the encrypted parts?
HV can be regarded as a part of TCB normally.
So HV emulated rpmb device provides guests with security in some content.
RPMB support depends on the some specified media. If HV could emulates it, it provides great flexibility for the Guest.