Skip to contentSkip to conversation

pkcs7: Remove the [2] form of the signed attributes from the grammar

RFC PATCH New Dan Carpenter 1 participant 1 message Dec 2

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

RFC PATCH 1/1 pkcs7: Remove the [2] form of the signed attributes from the grammar

Hi David,

At Pereq we're doing formal verification work and our tools flagged signed attributes with a [2] tag. The issue is that the [2] tag leaves attributes out of the signature check. So for example, someone who can modify the message could change the signingTime and make a correctly signed message be refused. It's obviously not the end of the world, but it's the sort of invariant violation that formal verification will complain about.

The thing is that it looks like [2] was included by mistake. Can we just remove it? I don't think anything relies on it. The kernel only parses SignedData and nothing in the kernel produces the [2] form; openssl cms always uses the [0] tag.

It's not clear that [3] should be included either but the kernel ignores them so the tool doesn't complain.

-- >8 --

RFC 2315 section 9.2 and RFC 5652 section 5.3 give the signed attributes only the [0] tag, and the signature is made over them. pkcs7.asn1 also accepts a [2] tag, as an EXPLICIT SEQUENCE. Only the
[0] alternative has the pkcs7_sig_note_set_of_authattrs() action, which records the attributes for the signature check, so with the [2] tag the signature is checked over the content alone. pkcs7_verify_one() still compares the unsigned signingTime with the signer's validity.

Remove the [2] alternative from the grammar, so that the ASN.1 decoder refuses it. The kernel only parses SignedData and nothing in the kernel produces the [2] form; openssl cms always uses the [0] tag.

Fixes 2e3fadbf730f ("PKCS#7: Implement a parser [RFC 2315]")

---

---
 crypto/asymmetric_keys/pkcs7.asn1 | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
crypto/asymmetric_keys/pkcs7.asn1 +2 -8
index 28e1f4a41c14..5e57288b4509 100644
@@ -78,14 +78,8 @@ SignerInfo ::= SEQUENCE {
 	version			INTEGER ({ pkcs7_note_signerinfo_version }),
 	sid			SignerIdentifier, -- CMS variant, not PKCS#7
 	digestAlgorithm		DigestAlgorithmIdentifier ({ pkcs7_sig_note_digest_algo }),
-	authenticatedAttributes	CHOICE {
-		aaSet		[0] IMPLICIT SetOfAuthenticatedAttribute
-					({ pkcs7_sig_note_set_of_authattrs }),
-		aaSequence	[2] EXPLICIT SEQUENCE OF AuthenticatedAttribute
-			-- Explicit because easier to compute digest on
-			-- sequence of attributes and then reuse encoded
-			-- sequence in aaSequence.
-	} OPTIONAL,
+	authenticatedAttributes	[0] IMPLICIT SetOfAuthenticatedAttribute OPTIONAL
+				({ pkcs7_sig_note_set_of_authattrs }),
 	digestEncryptionAlgorithm
 				DigestEncryptionAlgorithmIdentifier ({ pkcs7_sig_note_pkey_algo }),
 	encryptedDigest		EncryptedDigest,

---
base-commit: b30891102b2099aac3dee3ce4cc9b5c0539b6ccd
change-id: 20261202-signed_attr2-2ce3c1e4253c

Best regards,

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