Skip to contentSkip to conversation

Check curve_name for null to avoid crash

PATCH In review Bob Wolff 2 participants 2 messages Feb 22, 2024 – Feb 23, 2024

lore
Share & tools
lore

Bob Wolff

author
#0 lore raw

PATCH 1/1 Check curve_name for null to avoid crash

If mixed rsa and ecdsa keys are specified in dtsi, an rsa key can be sent into the ecdsa verify. Without the ecdsa,curve property, this function will crash due to lack of checking the null pointer return.

---

 lib/ecdsa/ecdsa-verify.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/ecdsa/ecdsa-verify.c +5 -0
index 0601700c4f..4d1835b598 100644
@@ -31,6 +31,11 @@ static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
 	int x_len, y_len;
 
 	key->curve_name = fdt_getprop(fdt, node, "ecdsa,curve", NULL);
+	if (!key->curve_name) {
+		debug("Error: ecdsa cannot get 'ecdsa,curve' property from key. Likely not an ecdsa key.\n");
+		return -ENOMSG;
+	}
+
 	key->size_bits = ecdsa_key_size(key->curve_name);
 	if (key->size_bits == 0) {
 		debug("Unknown ECDSA curve '%s'", key->curve_name);
Signature · 1 line
2.39.3 (Apple Git-145)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Bob Wolff

If mixed rsa and ecdsa keys are specified in dtsi, an rsa key can be sent into the ecdsa verify. Without the ecdsa,curve property, this function will crash due to lack of checking the null pointer return.

nit: there should be a blank line here

Quoted 12 lines

---

  lib/ecdsa/ecdsa-verify.c | 5 +++++
  1 file changed, 5 insertions(+)
lib/ecdsa/ecdsa-verify.c +0 -0
index 0601700c4f..4d1835b598 100644
@@ -31,6 +31,11 @@ static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
  	int x_len, y_len;

lib/ecdsa/ecdsa-verify.c static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node) · line 41

Quoted 10 lines
lib/ecdsa/ecdsa-verify.c +5 -0
 
  	key->curve_name = fdt_getprop(fdt, node, "ecdsa,curve", NULL);
+	if (!key->curve_name) {
+		debug("Error: ecdsa cannot get 'ecdsa,curve' property from key. Likely not an ecdsa key.\n");
+		return -ENOMSG;
+	}
+
  	key->size_bits = ecdsa_key_size(key->curve_name);
  	if (key->size_bits == 0) {
  		debug("Unknown ECDSA curve '%s'", key->curve_name);