Page MenuHome GnuPG

Recursive call of pinentry
Closed, ResolvedPublic

Description

In gnupg/agent/findkey.c, we have a function try_unprotect_cb.
It is called by agent_askpin as a callback.
But, it may be called with ENTRY_LOCK held.
When try_unprotect_cb calls agent_get_confirmation, recursive lock of ENTRY_LOCK occurs.

Event Timeline

justus triaged this task as Normal priority.Jun 1 2017, 10:45 AM
justus edited projects, added gnupg (gpg22); removed gnupg.

This can be triggered if --max-passphrase-days has been set.

The obvious fix to unlock and relock the pinentry during the callback would have the problem that instead of the confirmation request a pinentry from another connection may pop up. That would be quite confusing.

So, what about checking whether the same connection invokes the pinentry recursive and allow for that? With a counter to detect missing unlocks etc.

OK, I can make reproducible error case:

$ export GNUPGHOME=/tmp/gpg
$ mkdir -m=0700 $GNUPGHOME
$ gpg-agent --faked-system-time=1508900000 --daemon /bin/bash
$ gpg --yes --quick-gen-key "chuji@gniibe.org"
[ ENTERING PASSPHRASE for creation of the key ]
$ exit
$ gpg-agent --max-passphrase-days=1 --daemon /bin/bash
$ touch example.txt
$ gpg --clear-sign example.txt
[ Enter passphrase ]
[ Then, it hang ]

rG3b66a256e376: agent: Allow recursive use of pinentry. fixes the test case above.
I wish it doesn't cause any other issues.

Oh I see you did the Right Thing which back then I was too lazy to do. Thanks.