Yubico / libfido2

Provides library functionality for FIDO2, including communication with a device over USB or NFC.
Other
591 stars 152 forks source link

Timeout when reopening a Fido2 device #831

Open chscf opened 1 day ago

chscf commented 1 day ago

Good day,

I'm using libfido2-1.14.0 on linux, and I ran into the following problem: after calling

dev = fido_dev_new();
...
fido_dev_close(dev);
fido_dev_free(&dev);

and then calling

dev = fido_dev_new();
...
fido_dev_open(dev, path);

on the device I closed right before (i.e. with the same device path), fido_dev_open runs into a timeout. The reason is that the calls to flock

while (flock(ctx->fd, LOCK_EX|LOCK_NB) == -1) {

in fido_hid_open (hid_linux.c:259) never succeed.

Adding this

if (flock(ctx->fd, LOCK_UN) == -1)
    fido_log_error(errno, "%s: flock", __func__);

to fido_hid_close in hid_linux.c fixes this for me. Does this make any sense?

Thanks and best regards, Christian

LDVG commented 19 hours ago

Hi,

Could you please provide more information on what operating system you are using, and possibly a reproducing program with debug logging enabled? I cannot reproduce this on any of my machines. My manual pages for flock(2) state that (emphasis mine)

Locks created by flock() are associated with an open file description (see open(2)). This means that duplicate file descriptors (created by, for example, fork(2) or dup(2)) refer to the same lock, and this lock may be modified or released using any of these file descriptors. Furthermore, the lock is released either by an explicit LOCK_UN operation on any of these duplicate file descriptors, or when all such file descriptors have been closed.

Which means that fido_dev_close() should already release the lock.