Page MenuHome GnuPG

dirmngr: Crash when CRL signature check fails
Closed, ResolvedPublic

Description

Somehow I have a failed signature verification in dirmngr. While this may be a bug dirmngr crashes after the failure (happend to me on a windows test system).

Last debug messages before the crash are:
2017-11-17 10:14:00 dirmngr[2332] DBG: rsa_verify => Falsche Unterschrift
2017-11-17 10:14:00 dirmngr[2332] DBG: gcry_pk_verify: Falsche Unterschrift
2017-11-17 10:14:00 dirmngr[2332] Signaturprüfung der CRL ist fehlgeschlagen: Falsche Unterschrift

This looks like a double free. Through debug output I confirmed that the crashing function is abort_sig_check.
And that is because "finish_sig_check" already closes the gcry_md_hd_t (freeing memory)
But on error md is not null and so it's double freed in the cleanup of crl_parse_insert.

Proposed fix for the 2.2 branch:

diff --git a/dirmngr/crlcache.c b/dirmngr/crlcache.c
index 248ad9ad4..a4bb6a2ac 100644
--- a/dirmngr/crlcache.c
+++ b/dirmngr/crlcache.c
@@ -1842,13 +1842,13 @@ crl_parse_insert (ctrl_t ctrl, ksba_crl_t crl,
               }
 
             err = finish_sig_check (crl, md, algo, crlissuer_cert);
+            md = NULL;
             if (err)
               {
                 log_error (_("CRL signature verification failed: %s\n"),
                            gpg_strerror (err));
                 goto failure;
               }
-           md = NULL;
 
             err = validate_cert_chain (ctrl, crlissuer_cert, NULL,
                                        (VALIDATE_FLAG_TRUST_CONFIG

Details

Version
master

Event Timeline

Oh that is not good. A passed arg should not be closed by the called fucntion unless that fucntion is documented as gaining ownership of it. Let me check.

werner claimed this task.

Okay, I took your suggestion but also improved the documentation. Fixed in 2.2