Skip to contentSkip to conversation

lib: rsa: Add debug message on algo mismatch

PATCH New Sean Anderson 4 participants 5 messages Feb 16, 2021 – Feb 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: rsa: Add debug message on algo mismatch

Currently we fail silently if there is an algorithm mismatch. To help distinguish this failure condition.

---

 lib/rsa/rsa-verify.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/rsa/rsa-verify.c +4 -1
index e34d3293d1..aee76f42d5 100644
@@ -447,8 +447,11 @@ static int rsa_verify_with_keynode(struct image_sign_info *info,
 	}
 
 	algo = fdt_getprop(blob, node, "algo", NULL);
-	if (strcmp(info->name, algo))
+	if (strcmp(info->name, algo)) {
+		debug("%s: Wrong algo: have %s, expected %s", __func__,
+		      info->name, algo);
 		return -EFAULT;
+	}
 
 	prop.num_bits = fdtdec_get_int(blob, node, "rsa,num-bits", 0);
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 lib: rsa: Add debug message on algo mismatch

Dear Sean Anderson,

Quoted 14 lines · In message <[email protected]> you wrote:

Currently we fail silently if there is an algorithm mismatch. To help distinguish this failure condition.

---

 lib/rsa/rsa-verify.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/rsa/rsa-verify.c +0 -0
index e34d3293d1..aee76f42d5 100644

lib/rsa/rsa-verify.c static int rsa_verify_with_keynode(struct image_sign_info *info, · line 454

Quoted 9 lines
lib/rsa/rsa-verify.c +4 -1
@@ -447,8 +447,11 @@ static int rsa_verify_with_keynode(struct image_sign_info *info,
 	}
 
 	algo = fdt_getprop(blob, node, "algo", NULL);
-	if (strcmp(info->name, algo))
+	if (strcmp(info->name, algo)) {
+		debug("%s: Wrong algo: have %s, expected %s", __func__,
+		      info->name, algo);
 		return -EFAULT;
+	}

If this is considered an error, should that not be a printf() then instead of a debug() which users will never see?

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It is impractical for  the  standard  to  attempt  to  constrain  the
behavior  of code that does not obey the constraints of the standard.
                                                          - Doug Gwyn
#2 lore raw

PATCH 1/1 lib: rsa: Add debug message on algo mismatch

Quoted 19 lines · Wolfgang Denk

Dear Sean Anderson,

Quoted 16 lines · In message <[email protected]> you wrote:

Currently we fail silently if there is an algorithm mismatch. To help distinguish this failure condition.

---

  lib/rsa/rsa-verify.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
lib/rsa/rsa-verify.c +0 -0
index e34d3293d1..aee76f42d5 100644
@@ -447,8 +447,11 @@ static int rsa_verify_with_keynode(struct image_sign_info *info,
  	}
 
Quoted 10 lines

lib/rsa/rsa-verify.c static int rsa_verify_with_keynode(struct image_sign_info *info, · line 454

Quoted 7 lines
lib/rsa/rsa-verify.c +4 -1
  	algo = fdt_getprop(blob, node, "algo", NULL);
-	if (strcmp(info->name, algo))
+	if (strcmp(info->name, algo)) {
+		debug("%s: Wrong algo: have %s, expected %s", __func__,
+		      info->name, algo);
  		return -EFAULT;
+	}

If this is considered an error, should that not be a printf() then instead of a debug() which users will never see?

I also thought that, but the much of the rest of this file also uses debug() to report errors. Perhaps there are security implications? Or perhaps it was done to reduce binary size? Simon, can you comment on this?

--Sean

Quoted 5 lines

Best regards,

Wolfgang Denk

#3 lore raw

PATCH 1/1 lib: rsa: Add debug message on algo mismatch

Hi Sean,

Quoted 34 lines · Sean Anderson
Quoted 19 lines · Wolfgang Denk

Dear Sean Anderson,

Quoted 16 lines · In message <[email protected]> you wrote:

Currently we fail silently if there is an algorithm mismatch. To help distinguish this failure condition.

---

  lib/rsa/rsa-verify.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
lib/rsa/rsa-verify.c +0 -0
index e34d3293d1..aee76f42d5 100644
@@ -447,8 +447,11 @@ static int rsa_verify_with_keynode(struct image_sign_info *info,
    }
 
Quoted 10 lines

lib/rsa/rsa-verify.c static int rsa_verify_with_keynode(struct image_sign_info *info, · line 454

Quoted 7 lines
lib/rsa/rsa-verify.c +4 -1
    algo = fdt_getprop(blob, node, "algo", NULL);
-   if (strcmp(info->name, algo))
+   if (strcmp(info->name, algo)) {
+           debug("%s: Wrong algo: have %s, expected %s", __func__,
+                 info->name, algo);
            return -EFAULT;
+   }

If this is considered an error, should that not be a printf() then instead of a debug() which users will never see?

Quoted 4 lines

I also thought that, but the much of the rest of this file also uses debug() to report errors. Perhaps there are security implications? Or perhaps it was done to reduce binary size? Simon, can you comment on this?

In general should not print messages in the bowels of the code, since then there is no way to control what is printed. So long as the error is produced it can be reported and propagated up, and you can document what the different error codes mean. It also bloats the code to include strings everywhere.

I suggest adding logging around the return value as it makes it easy to trace things:

CONFIG_LOG_ERROR_RETURN=y

and return the error with:

return log_msg_ret("algo", -EFAULT)

Regards,
Simon

#4 lore raw

PATCH 1/1 lib: rsa: Add debug message on algo mismatch

In reply to Sean Anderson
Quoted 4 lines · Sean Anderson

Currently we fail silently if there is an algorithm mismatch. To help distinguish this failure condition.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210225/d31f8c43/attachment.sig>