Minimal HUK implementation without full CAAM driver#3160
Minimal HUK implementation without full CAAM driver#3160Emantor wants to merge 10 commits intoOP-TEE:masterfrom
Conversation
e182156 to
fe8393e
Compare
jforissier
left a comment
There was a problem hiding this comment.
Reviewing "imx: enable CAAM clocks before accessing registers"
jforissier
left a comment
There was a problem hiding this comment.
Minor comments on "imx_caam: implement tee_otp_get_hw_unique_key".
Please add parentheses to function name in commit subject: tee_otp_get_hw_unique_key()
|
I have a rebased version against the recent master commits and will squash the review commits and suggested changes from @jforissier at the same time on the next push. |
etienne-lms
left a comment
There was a problem hiding this comment.
minor comments for "imx: enable CAAM clocks before accessing registers".
etienne-lms
left a comment
There was a problem hiding this comment.
Acked-by: Etienne Carriere <[email protected]> with minor comment.
etienne-lms
left a comment
There was a problem hiding this comment.
comment for commit "plat-imx: register definitions for CAAM".
etienne-lms
left a comment
There was a problem hiding this comment.
comments on commit "imx_caam: implement tee_otp_get_hw_unique_key"
etienne-lms
left a comment
There was a problem hiding this comment.
For commit "imx_caam: add functions for jr init and reset":
Can remove following sentence from commit message: "Will be used by the tee_otp_get_hw_unique key implementation in the next commit."
The CAAM clocks need to be enabled, otherwise access to the CAAM might result in a bus stall. Signed-off-by: Rouven Czerwinski <[email protected]>
Add __attribute__((packed)) to the CAAM struct definitions to ensure the compiler does not insert padding into the structures. Signed-off-by: Rouven Czerwinski <[email protected]>
Register Definitions in the same style as used by the jobring allocation code, by extending the structure definitions and inserting padding if the registers are undocumented. Signed-off-by: Rouven Czerwinski <[email protected]>
Minimal implementation for tee_otp_get_hw_unique_key using the Master Key Verification Blob (MKVB) produced by the CAAM. Only the first 16 bytes are copied into the hw unique key structure, since the MKVB is 32 bytes long. Signed-off-by: Rouven Czerwinski <[email protected]>
|
I have rebased against latest master and changed to stack allocation. With the alignement within the structure to 64 bytes we should always flush and invalidate the intended date, without hitting stack data above or below. I also tried to incorporated all of the review comments, Thanks @jforissier, @etienne-lms, @jenswi-linaro & @bryanodonoghue. @etienne-lms I did not apply your Ack since I think the code has changed enough to require another review. |
etienne-lms
left a comment
There was a problem hiding this comment.
for commits "plat-imx: pack caam structs", imx: enable CAAM clocks before accessing registers:
Acked-by: Etienne Carriere <[email protected]>.
for commit "imx_caam: implement tee_otp_get_hw_unique_key": see comments.
Address the review comments from @etienne-lms. Signed-off-by: Rouven Czerwinski <[email protected]>
|
I understand that you want to have the HUK generated with the CAAM but I don't see the interest of bypassing all the work we, NXP, are doing to enable the CAAM driver. In your PR you have to enable the CAAM anyway to use the Job Ring. In plus you have missed a condition that is really needed to be full secure. This is the selection of the master key. In the driver we want to add and that has been improved and validated on all i.MX devices (taking care of all boot modes). We are doing the same in a more generic way. Could you explain us what is the added value of your implementation that is a kind of copy of what has been submitted in the PR #3149? |
I am interested in generating the MKVB for use as a HUK. I am not interested in a CAAM driver implementation, since I don't see the use case for it. The CAAM driver adds a lot of code which increases the TCB for my secure OS. For our use cases a full CAAM driver within OP-TEE is not needed, since we don't require hardware acceleration for the crypto primitives.
According to the documentation at hand, the
|
|
I also share similar concerns and needs with @Emantor, so I'm also interested at having just the minimum to derive a HUK instead of having the full CAAM support in place. |
|
@dmcilvaney this may also be relevant to your interests for the Microsoft IOT devices. |
|
@ricardosalveti, @Emantor Thanks for you understanding. |
I tried to find some documentation on which job ring is actually used by the HAB, but all I could find were discussion on the LKML and U-Boot. Do you have more documentation internally that you could share? To be clear: this HUK patch breaks the case where your boot chain is This is a bug in this PR and should consequently be fixed.
With a diffstat of
I'm not restricting you ability to push your changes upstream in any way. I'm just proposing a solution for now which is easier to review and test and has no immediate impact on the kernel. |
|
@MrVan any comments on this pull request? This requires your |
In order to allow a SPL -> OP-TEE -> U-Boot -> HAB authenticate -> Linux boot flow, use job ring two instead of one, since one might be used by the HAB. Signed-off-by: Rouven Czerwinski <[email protected]>
|
I pushed a patch which switches to using job ring two, which is the same ring used as by the full caam implementation for the |
Address review comments from @etienne-lms. Signed-off-by: Rouven Czerwinski <[email protected]>
a0ee937 to
dcb7369
Compare
Handle job ring reset timeouts by passing the return value. Signed-off-by: Rouven Czerwinski <[email protected]>
Those were forgotten in the previous commits, fix them now. Signed-off-by: Rouven Czerwinski <[email protected]>
etienne-lms
left a comment
There was a problem hiding this comment.
comments for the 3 last fixup commits
Fixes the leftover review comments from @etienne-lms. Signed-off-by: Rouven Czerwinski <[email protected]>
|
@etienne-lms, @clementfaure any comments on this? This is a valid minimal implementation which does not require the whole CAAM stack as implemented by NXP, but can be refactored as the necessary NXP commits are added. |
| if (mkvb.jr.outring[0].status != 0) | ||
| ret = TEE_ERROR_SECURITY; | ||
| goto out; | ||
|
|
There was a problem hiding this comment.
Missing { } otherwise it always ends up going to 'goto out'.
There was a problem hiding this comment.
Yes, this is already addressed in my local branch. I plan to rebase onto the CAAM work, but that might take a bit of refactoring to correctly disable the CAAM driver after HUK generation.
There was a problem hiding this comment.
Great, thanks for the heads up.
| uint32_t reg_val = 0; | ||
| uint32_t timeout = 1000; | ||
|
|
||
| io_write32((vaddr_t)&ctrl->jrcfg[MKVB_JR].jrcr, 1); |
There was a problem hiding this comment.
It would be nice that raw value (1 here) at lines 50, 55, 59, ... are replaced with macros, i.e. CAAM_JRCR_xxx BIT(0), CAAM_JRINTR_STATE_MASK GENMASK_32(3, 2), ...
|
|
||
| static TEE_Result caam_get_mkvb(uint8_t *dest) | ||
| { | ||
| struct imx_mkvb mkvb = { 0 }; |
| return ret; | ||
| mkvb_retrieved = true; | ||
| } | ||
| memcpy(&hwkey->data, &stored_key, sizeof(hwkey->data)); |
There was a problem hiding this comment.
prefer add empty line after if() { } block and before last return.
| if (!caam) | ||
| return TEE_ERROR_GENERIC; | ||
|
|
||
| caam_enable_clocks(); |
There was a problem hiding this comment.
add an empty line below.
| do { | ||
| reg_val = io_read32((vaddr_t)&ctrl->jrcfg[MKVB_JR].jrintr); | ||
| reg_val &= 0xc; | ||
| } while ((reg_val & 0x1) && --timeout); |
There was a problem hiding this comment.
1 does not seems the expect value, since mask at line 58.
|
This pull request has been marked as stale because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 5 days. Note, that you can always re-open a closed pull request at any time. |
From pull-request OP-TEE#3160 imx: enable CAAM clocks before accessing registers The CAAM clocks need to be enabled, otherwise access to the CAAM might result in a bus stall. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: pack caam structs Add __attribute__((packed)) to the CAAM struct definitions to ensure the compiler does not insert padding into the structures. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: register definitions for CAAM Register Definitions in the same style as used by the jobring allocation code, by extending the structure definitions and inserting padding if the registers are undocumented. Signed-off-by: Rouven Czerwinski <[email protected]> imx_caam: implement tee_otp_get_hw_unique_key Minimal implementation for tee_otp_get_hw_unique_key using the Master Key Verification Blob (MKVB) produced by the CAAM. Only the first 16 bytes are copied into the hw unique key structure, since the MKVB is 32 bytes long. Signed-off-by: Rouven Czerwinski <[email protected]> Signed-off-by: Ricardo Salveti <[email protected]>
From pull-request OP-TEE#3160 imx: enable CAAM clocks before accessing registers The CAAM clocks need to be enabled, otherwise access to the CAAM might result in a bus stall. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: pack caam structs Add __attribute__((packed)) to the CAAM struct definitions to ensure the compiler does not insert padding into the structures. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: register definitions for CAAM Register Definitions in the same style as used by the jobring allocation code, by extending the structure definitions and inserting padding if the registers are undocumented. Signed-off-by: Rouven Czerwinski <[email protected]> imx_caam: implement tee_otp_get_hw_unique_key Minimal implementation for tee_otp_get_hw_unique_key using the Master Key Verification Blob (MKVB) produced by the CAAM. Only the first 16 bytes are copied into the hw unique key structure, since the MKVB is 32 bytes long. Signed-off-by: Rouven Czerwinski <[email protected]> Signed-off-by: Ricardo Salveti <[email protected]>
From pull-request OP-TEE#3160 imx: enable CAAM clocks before accessing registers The CAAM clocks need to be enabled, otherwise access to the CAAM might result in a bus stall. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: pack caam structs Add __attribute__((packed)) to the CAAM struct definitions to ensure the compiler does not insert padding into the structures. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: register definitions for CAAM Register Definitions in the same style as used by the jobring allocation code, by extending the structure definitions and inserting padding if the registers are undocumented. Signed-off-by: Rouven Czerwinski <[email protected]> imx_caam: implement tee_otp_get_hw_unique_key Minimal implementation for tee_otp_get_hw_unique_key using the Master Key Verification Blob (MKVB) produced by the CAAM. Only the first 16 bytes are copied into the hw unique key structure, since the MKVB is 32 bytes long. Signed-off-by: Rouven Czerwinski <[email protected]> Signed-off-by: Ricardo Salveti <[email protected]>
From pull-request OP-TEE#3160 imx: enable CAAM clocks before accessing registers The CAAM clocks need to be enabled, otherwise access to the CAAM might result in a bus stall. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: pack caam structs Add __attribute__((packed)) to the CAAM struct definitions to ensure the compiler does not insert padding into the structures. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: register definitions for CAAM Register Definitions in the same style as used by the jobring allocation code, by extending the structure definitions and inserting padding if the registers are undocumented. Signed-off-by: Rouven Czerwinski <[email protected]> imx_caam: implement tee_otp_get_hw_unique_key Minimal implementation for tee_otp_get_hw_unique_key using the Master Key Verification Blob (MKVB) produced by the CAAM. Only the first 16 bytes are copied into the hw unique key structure, since the MKVB is 32 bytes long. Signed-off-by: Rouven Czerwinski <[email protected]> Signed-off-by: Ricardo Salveti <[email protected]>
From pull-request OP-TEE#3160 imx: enable CAAM clocks before accessing registers The CAAM clocks need to be enabled, otherwise access to the CAAM might result in a bus stall. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: pack caam structs Add __attribute__((packed)) to the CAAM struct definitions to ensure the compiler does not insert padding into the structures. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: register definitions for CAAM Register Definitions in the same style as used by the jobring allocation code, by extending the structure definitions and inserting padding if the registers are undocumented. Signed-off-by: Rouven Czerwinski <[email protected]> imx_caam: implement tee_otp_get_hw_unique_key Minimal implementation for tee_otp_get_hw_unique_key using the Master Key Verification Blob (MKVB) produced by the CAAM. Only the first 16 bytes are copied into the hw unique key structure, since the MKVB is 32 bytes long. Signed-off-by: Rouven Czerwinski <[email protected]> Signed-off-by: Ricardo Salveti <[email protected]>
From pull-request OP-TEE#3160 imx: enable CAAM clocks before accessing registers The CAAM clocks need to be enabled, otherwise access to the CAAM might result in a bus stall. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: pack caam structs Add __attribute__((packed)) to the CAAM struct definitions to ensure the compiler does not insert padding into the structures. Signed-off-by: Rouven Czerwinski <[email protected]> plat-imx: register definitions for CAAM Register Definitions in the same style as used by the jobring allocation code, by extending the structure definitions and inserting padding if the registers are undocumented. Signed-off-by: Rouven Czerwinski <[email protected]> imx_caam: implement tee_otp_get_hw_unique_key Minimal implementation for tee_otp_get_hw_unique_key using the Master Key Verification Blob (MKVB) produced by the CAAM. Only the first 16 bytes are copied into the hw unique key structure, since the MKVB is 32 bytes long. Signed-off-by: Rouven Czerwinski <[email protected]> Signed-off-by: Ricardo Salveti <[email protected]>
This PR implements a minimal implementation to retrieve a Master Key Verification Blob (MKVB) from the CAAM inside of i.MX processors for use as a Hardware Unique Key (HUK). In contrast to the full CAAM implementation offered by NXP, this only implements the necessary bits to retrieve MKVB once, does not allocate job rings to the secure world and has no conflicts with the linux kernel CAAM driver, since the CAAM is not accessed after the MKVB is retrieved.
Things I'm not sure about:
I followed the style implemented by @bryanodonoghue, it may be more readable to switch to a normal
#definebased register access modelRelated:
#2892 - initial i.MX HUK issue
#3149 - full NXP CAAM driver