Skip to contentSkip to conversation

pkcs7: Reject signed attributes with an indefinite length

PATCH New Dan Carpenter 1 participant 1 message Dec 2

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

PATCH 1/1 pkcs7: Reject signed attributes with an indefinite length

RFC 5652 section 5.3 requires the signed attributes to be DER encoded, so refuse signed attributes with an indefinite length instead of digesting them.

Indefinite length attributes always fail in practice anyway since the length of the attributes is included in the signed bytes. Also the kernel truncates away the 00 00 end-of-contents octets.

This patch is about correctness. It doesn't affect real life.

Fixes 2e3fadbf730f ("PKCS#7: Implement a parser [RFC 2315]")
---
 crypto/asymmetric_keys/pkcs7_parser.c | 6 ++++++
 1 file changed, 6 insertions(+)
crypto/asymmetric_keys/pkcs7_parser.c +6 -0
index 7f00e45a33cf..cafb4541e2ae 100644
@@ -633,6 +633,12 @@ int pkcs7_sig_note_set_of_authattrs(void *context, size_t hdrlen,
 		return -EBADMSG;
 	}
 
+	/* Signed attributes must be DER [RFC5652 5.3]: no indefinite length */
+	if (*((const u8 *)value - hdrlen + 1) == 0x80) {
+		pr_warn("Indefinite-length AuthAttrs not permitted\n");
+		return -EBADMSG;
+	}
+
 	/* We need to switch the 'CONT 0' to a 'SET OF' when we digest */
 	sinfo->authattrs = value - hdrlen;
 	sinfo->authattrs_len = vlen + hdrlen;

---
base-commit: a9c48428cbd8d96b26f92631d0db6f8519c5fcc5
change-id: 20261202-signed_attr-5e5329676a53

Best regards,

Signature · 1 line
Dan Carpenter <[email protected]>