From: Andrew Davis <afd@ti.com>
To: Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
<u-boot@lists.denx.de>
Cc: Andrew Davis <afd@ti.com>
Subject: [PATCH 4/4] arm: mach-k3: security: Remove certificate if detected on GP device
Date: Fri, 15 Jul 2022 11:34:35 -0500 [thread overview]
Message-ID: <20220715163435.1725-4-afd@ti.com> (raw)
In-Reply-To: <20220715163435.1725-1-afd@ti.com>
If the device is a GP and we detect a signing certificate then remove it.
It would fail to authenticate otherwise as the device is GP and has no
secure authentication services in SYSFW.
This shouldn't happen often as trying to boot signed images on GP devices
doesn't make much sense, but if we run into a signed image we should at
least try to ignore the certificate and boot the image anyway. This could
help with users of GP devices who only have HS images available.
If this does happen, print a nice big warning.
Signed-off-by: Andrew Davis <afd@ti.com>
---
arch/arm/mach-k3/security.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-k3/security.c b/arch/arm/mach-k3/security.c
index add7f413a4..d8d41ec515 100644
--- a/arch/arm/mach-k3/security.c
+++ b/arch/arm/mach-k3/security.c
@@ -30,10 +30,19 @@ static bool ti_secure_cert_detected(void *p_image)
((u8 *)p_image)[4] == 0x30 && ((u8 *)p_image)[5] == 0x82);
}
+/* Primitive certificate length, assumes one 2-Octet sized SEQUENCE */
+static size_t ti_secure_cert_length(void *p_image)
+{
+ size_t seq_length = be16_to_cpu(readw_relaxed(p_image + 2));
+ /* Add 4 for the SEQUENCE tag length */
+ return seq_length + 4;
+}
+
void ti_secure_image_post_process(void **p_image, size_t *p_size)
{
struct ti_sci_handle *ti_sci = get_ti_sci_handle();
struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
+ size_t cert_length;
u64 image_addr;
u32 image_size;
int ret;
@@ -41,9 +50,28 @@ void ti_secure_image_post_process(void **p_image, size_t *p_size)
image_addr = (uintptr_t)*p_image;
image_size = *p_size;
- if (!image_size || get_device_type() == K3_DEVICE_TYPE_GP)
+ if (!image_size)
return;
+ if (get_device_type() == K3_DEVICE_TYPE_GP) {
+ if (ti_secure_cert_detected(*p_image)) {
+ printf("Warning: Detected image signing certificate on GP device. "
+ "Skipping certificate to prevent boot failure. "
+ "This will fail if the image was also encrypted\n");
+
+ cert_length = ti_secure_cert_length(*p_image);
+ if (cert_length > *p_size) {
+ printf("Invalid signing certificate size\n");
+ return;
+ }
+
+ *p_image += cert_length;
+ *p_size -= cert_length;
+ }
+
+ return;
+ }
+
if (get_device_type() != K3_DEVICE_TYPE_HS_SE &&
!ti_secure_cert_detected(*p_image)) {
printf("Warning: Did not detect image signing certificate. "
--
2.36.1
next prev parent reply other threads:[~2022-07-15 16:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-15 16:34 [PATCH 1/4] arm: mach-k3: Add support for device type detection Andrew Davis
2022-07-15 16:34 ` [PATCH 2/4] arm: mach-k3: security: Allow signing bypass if type is HS-FS Andrew Davis
2022-08-04 20:52 ` Tom Rini
2022-07-15 16:34 ` [PATCH 3/4] arm: mach-k3: security: Bypass image signing at runtime for GP devices Andrew Davis
2022-08-04 20:52 ` Tom Rini
2022-07-15 16:34 ` Andrew Davis [this message]
2022-07-18 12:08 ` [PATCH 4/4] arm: mach-k3: security: Remove certificate if detected on GP device Tom Rini
2022-08-04 20:52 ` Tom Rini
2022-07-18 12:08 ` [PATCH 1/4] arm: mach-k3: Add support for device type detection Tom Rini
2022-07-25 16:57 ` Tom Rini
2022-07-26 1:29 ` Andrew Davis
2022-08-04 20:51 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220715163435.1725-4-afd@ti.com \
--to=afd@ti.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox