Skip to contentSkip to conversation

crypto: ecrdsa - fix unknown OID check in ecrdsa_param_curve

PATCH In review Thorsten Blum 4 participants 4 messages May 2 – May 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: ecrdsa - fix unknown OID check in ecrdsa_param_curve

The ->curve_oid check in ecrdsa_param_curve() rejects the valid enum value 0 (OID_id_dsa_with_sha1), but look_up_OID() returns OID__NR on lookup failure. Compare ->curve_oid with OID__NR instead to ensure that only unknown OIDs return -EINVAL.

Fixes 0d7a78643f69 ("crypto: ecrdsa - add EC-RDSA (GOST 34.10) algorithm")
---
 crypto/ecrdsa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/ecrdsa.c +1 -1
index 2c0602f0cd40..0cd7eb367604 100644
@@ -145,7 +145,7 @@ int ecrdsa_param_curve(void *context, size_t hdrlen, unsigned char tag,
 	struct ecrdsa_ctx *ctx = context;
 
 	ctx->curve_oid = look_up_OID(value, vlen);
-	if (!ctx->curve_oid)
+	if (ctx->curve_oid == OID__NR)
 		return -EINVAL;
 	ctx->curve = get_curve_by_oid(ctx->curve_oid);
 	return 0;
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Thorsten Blum

The ->curve_oid check in ecrdsa_param_curve() rejects the valid enum value 0 (OID_id_dsa_with_sha1), but look_up_OID() returns OID__NR on lookup failure. Compare ->curve_oid with OID__NR instead to ensure that only unknown OIDs return -EINVAL.

Fixes 0d7a78643f69 ("crypto: ecrdsa - add EC-RDSA (GOST 34.10) algorithm")

crypto/ecrdsa.c int ecrdsa_param_curve(void *context, size_t hdrlen, unsigned char tag, · line 151

Quoted 10 lines

+++ b/crypto/ecrdsa.c

crypto/ecrdsa.c +1 -1
@@ -145,7 +145,7 @@ int ecrdsa_param_curve(void *context, size_t hdrlen, unsigned char tag,
 	struct ecrdsa_ctx *ctx = context;
 
 	ctx->curve_oid = look_up_OID(value, vlen);
-	if (!ctx->curve_oid)
+	if (ctx->curve_oid == OID__NR)
 		return -EINVAL;
 	ctx->curve = get_curve_by_oid(ctx->curve_oid);
 	return 0;

This is a fairly harmless logic bug: OID_id_dsa_with_sha1 is not a valid curve and so get_curve_by_oid() returns NULL, which is assigned to ctx->curve.

The function you're changing, ecrdsa_param_curve(), is called from the ecrdsa_params ASN.1 parser, which is invoked from ecrdsa_set_pub_key(). That function does perform a NULL pointer check for ctx->curve right after the ASN.1 parser returns.

Your patch will change the return value for an unknown OID from -ENOPKG to -EINVAL, but that probably doesn't matter much.

Thanks,

Lukas

Reviewed-by
#2 lore raw

Lukas,

Quoted 26 lines · Lukas Wunner
Quoted 7 lines · Thorsten Blum

The ->curve_oid check in ecrdsa_param_curve() rejects the valid enum value 0 (OID_id_dsa_with_sha1), but look_up_OID() returns OID__NR on lookup failure. Compare ->curve_oid with OID__NR instead to ensure that only unknown OIDs return -EINVAL.

Fixes 0d7a78643f69 ("crypto: ecrdsa - add EC-RDSA (GOST 34.10) algorithm")

crypto/ecrdsa.c int ecrdsa_param_curve(void *context, size_t hdrlen, unsigned char tag, · line 151

Quoted 10 lines

+++ b/crypto/ecrdsa.c

crypto/ecrdsa.c +1 -1
@@ -145,7 +145,7 @@ int ecrdsa_param_curve(void *context, size_t hdrlen, unsigned char tag,
 	struct ecrdsa_ctx *ctx = context;
 
 	ctx->curve_oid = look_up_OID(value, vlen);
-	if (!ctx->curve_oid)
+	if (ctx->curve_oid == OID__NR)
 		return -EINVAL;
 	ctx->curve = get_curve_by_oid(ctx->curve_oid);
 	return 0;

This is a fairly harmless logic bug: OID_id_dsa_with_sha1 is not a valid curve and so get_curve_by_oid() returns NULL, which is assigned to ctx->curve.

Quoted 7 lines

The function you're changing, ecrdsa_param_curve(), is called from the ecrdsa_params ASN.1 parser, which is invoked from ecrdsa_set_pub_key(). That function does perform a NULL pointer check for ctx->curve right after the ASN.1 parser returns.

Your patch will change the return value for an unknown OID from -ENOPKG to -EINVAL, but that probably doesn't matter much.

Great review, thanks. Basically, the check is redundant.

Thanks,

Quoted 4 lines

Thanks,

Lukas

maintainer
#3 lore raw
In reply to Thorsten Blum
Quoted 10 lines · Thorsten Blum

The ->curve_oid check in ecrdsa_param_curve() rejects the valid enum value 0 (OID_id_dsa_with_sha1), but look_up_OID() returns OID__NR on lookup failure. Compare ->curve_oid with OID__NR instead to ensure that only unknown OIDs return -EINVAL.

Fixes 0d7a78643f69 ("crypto: ecrdsa - add EC-RDSA (GOST 34.10) algorithm")
---
 crypto/ecrdsa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt