KASAN: slab-out-of-bounds Read in x509_process_extension (keyUsage / basicConstraints)
A message that is not in the archive (sent off-list or not yet received): CALPOzVkz5dzdOTJyWGGNyQOuSG9d2fhjdL2cLSvAOFXFA80bLw@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Ignat Korchagin
Reviewed-byQuoted 30 lines · Lukas Wunner
Quoted 11 lines · Willy Tarreau
Quoted 5 lines · Leo Lin
An out-of-bounds read exists in
x509_process_extension()incrypto/asymmetric_keys/x509_cert_parser.c. When parsing the keyUsage (and basicConstraints) X.509 extension, v[0] is dereferenced before vlen is validated, so a crafted certificate with an empty extnValue triggers a 1-byte OOB read past a slab object.Please note that 6.12 is not the latest LTS and is more than one year old, 6.18 is the latest LTS, 6.19 is the latest stable, and 7.0-rc is under development. If you could confirm that current versions are still affected, it would be nice.
I hereby confirm that current versions are still affected.
Patch is below, in case Leo doesn't want to craft a patch of their own.
Thanks,
Lukas
-- >8 --
Subject: [PATCH] X.509: Fix out-of-bounds access when parsing extensions
Leo reports an out-of-bounds access when parsing a certificate with empty Basic Constraints or Key Usage extension because the first byte of the extension is accessed before checking its length. Fix it.
Quoted 5 lines
Fixes 30eae2b037af ("KEYS: X.509: Parse Basic Constraints for CA")Fixes 567671281a75 ("KEYS: X.509: Parse Key Usage")Reported-by Leo Lin <[email protected]>Signed-off-by Lukas Wunner <[email protected]>Cc [email protected] # v6.4+
Quoted 38 lines
--- crypto/asymmetric_keys/x509_cert_parser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)crypto/asymmetric_keys/x509_cert_parser.c +4
-5@@ -584,10 +584,10 @@ int x509_process_extension(void *context, size_t hdrlen,* 0x04 is where keyCertSign lands in this bit string * 0x80 is where digitalSignature lands in this bit string */ -if (v[0 ] !=ASN1_BTS ) -return -EBADMSG ;if (vlen <4 )return -EBADMSG ; +if (v[0 ] !=ASN1_BTS ) +return -EBADMSG ;if (v[2 ] >=8 )return -EBADMSG ;if (v[3 ] &0x80 )@@ -620,10 +620,10 @@ int x509_process_extension(void *context, size_t hdrlen,* (Expect 0xFF if the CA is TRUE) * vlen should match the entire extension size */ -if (v[0 ] != (ASN1_CONS_BIT |ASN1_SEQ )) -return -EBADMSG ;if (vlen <2 )return -EBADMSG ; +if (v[0 ] != (ASN1_CONS_BIT |ASN1_SEQ )) +return -EBADMSG ;if (v[1 ] != vlen -2 )return -EBADMSG ;/* Empty SEQUENCE means CA:FALSE (default value omitted per DER) */ --2.51.0