diff mbox series

Check curve_name for null to avoid crash

Message ID 20240227235704.48386-1-bob.wolff68@gmail.com
State Accepted
Commit 9522956605205d23fe99142547ca3227574d418a
Delegated to: Tom Rini
Headers show
Series Check curve_name for null to avoid crash | expand

Commit Message

Bob Wolff Feb. 27, 2024, 11:57 p.m. UTC
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.

Signed-off-by: Bob Wolff <bob.wolff68@gmail.com>
---

 lib/ecdsa/ecdsa-verify.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Bob Wolff March 6, 2024, 10:55 p.m. UTC | #1
Hey all,
I think I addressed the nit of the missing blank line in my last email on
this thread. Wondering if there's more action to be had on my part or if
this just gets accepted etc.

Thanks!
Bob Wolff

On Tue, Feb 27, 2024 at 3:57 PM Bob Wolff <bob.wolff68@gmail.com> wrote:

> 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.
>
> Signed-off-by: Bob Wolff <bob.wolff68@gmail.com>
> ---
>
>  lib/ecdsa/ecdsa-verify.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/lib/ecdsa/ecdsa-verify.c b/lib/ecdsa/ecdsa-verify.c
> index 0601700c4f..4d1835b598 100644
> --- a/lib/ecdsa/ecdsa-verify.c
> +++ b/lib/ecdsa/ecdsa-verify.c
> @@ -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);
> --
> 2.39.3 (Apple Git-145)
>
>
Tom Rini March 7, 2024, 5:12 p.m. UTC | #2
On Tue, Feb 27, 2024 at 03:57:03PM -0800, Bob Wolff wrote:

> 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.
> 
> Signed-off-by: Bob Wolff <bob.wolff68@gmail.com>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/lib/ecdsa/ecdsa-verify.c b/lib/ecdsa/ecdsa-verify.c
index 0601700c4f..4d1835b598 100644
--- a/lib/ecdsa/ecdsa-verify.c
+++ b/lib/ecdsa/ecdsa-verify.c
@@ -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);