Diffusion GnuPG 456a3a8e93ea

gpg: Fix trustdb updates without lock held.

Authored by werner on Mar 26 2018, 4:57 PM.


gpg: Fix trustdb updates without lock held.

* g10/tdbio.c (is_locked): Turn into a counter.
(take_write_lock, release_write_lock): Implement recursive locks.

On trustdb creation we have this call sequence:

init_trustdb                 -> takes lock
       put_record_into_cache -> takes lock
       put_record_into_cache -> releases lock
init_trustdb                 -> releases lock

The second take lock does noting but the first release lock has
already released the lock and the second release lock is a thus a NOP.
This is likely the cause for the corrupted trustdb as reported in

  • GnuPG-bug-id: T3839
  • Signed-off-by: Werner Koch <wk@gnupg.org>