Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using 'select' in libpcsclite can be problematic for application opening a large number of file descriptors #51

Closed
kamengopin opened this issue Dec 14, 2018 · 4 comments

Comments

@kamengopin
Copy link

kamengopin commented Dec 14, 2018

Hi Ludovic,

Currently, libpcsclite uses select + non-blocking IO when communicating to the PCSC daemon.
However, select can be used only on file descriptors whose value does not exceed FD_SETSIZE. Quote from Linux man page for select:

fd_set is a fixed size buffer. Executing FD_CLR() or FD_SET() with a value of fd that is negative or is equal to or larger than FD_SETSIZE will result in undefined behavior.

More often that not, this undefined behavior will come in the form of a stack corruption.

This means that an application which uses libpcsclite is forced to have no more than FD_SETSIZE (1024) open file descriptors at any given moment. Depending on the use-case this limit can be problematic for the application.

There are other I/O event notification mechanisms which do not have this limitation:
poll, epoll on Linux, kqueue on Mac and BSD, IO completion ports on Windows, etc
Have you considered using any of the above?

@LudovicRousseau
Copy link
Owner

Good remark.
No, I have not considered an alternative. You are the first one to report this problem.

@LudovicRousseau
Copy link
Owner

Do you plan to propose a patch?
What do you expect from me?

@kamengopin
Copy link
Author

Yeah, I planned to propose a patch but I am not sure when I will have the time for that (probably after the holidays). For now I just wanted to bring the issue to your attention.

LudovicRousseau pushed a commit that referenced this issue Nov 8, 2019
From [Pcsclite-muscle] select()-induced crashes (and attached tentative fix)
http:https://lists.infradead.org/pipermail/pcsclite-muscle/2019-November/001199.html

" Hello all,
we tracked down some crashes in Firefox [1] to the use of select() and
its related macros in the libpcslite library. Recent versions of glibc
added checks to ensure that the values of the file descriptors passed to
the FD_SET(), FD_CLR() and FD_ISSET() macros have values lower than the
FD_SETSIZE constant. If the file descriptor value is found to be higher
than FD_SETSIZE then abort() gets called which is ultimately what we're
seeing in Firefox.

I have attached a patch that replaces the select() calls with poll()
which does not suffer from this problem. Unfortunately I don't have a
smartcard reader on hand so I can't test the patch myself.

Cheers,

 Gabriele Svelto

[1] select() crashes in libpcslite
    https://bugzilla.mozilla.org/show_bug.cgi?id=1591876
"

Fixes github issue #51
"Using 'select' in libpcsclite can be problematic for application opening a large number of file descriptors #51"
@LudovicRousseau
Copy link
Owner

Fixed in 20385ef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants