[Pcsclite-muscle] Race condition with SCardGetStatusChange() when USB Reader is removed

Maximilian Stein maximilian.stein at secunet.com
Mon May 8 10:47:02 UTC 2017


> Yes. It is possible.
> pcsc-lite may contain bugs.

I'm sorry if that sounded offensive. Personally I appreciate the work
and effort you put into this project very much and merely want to
contribute to its further improvement.


> I tried to reproduce the problem with the attached sample code but
> without success.
> I tried using the special reader "\\?PnP?\Notification" and also using
> the current reader name but could not reproduce the problem. Yes, I
> first applied your patch and I get the extra sleep() in pcscd.
> 
> You can change line 52 of my sample code to use the PnP reader or the
> normal one.

On my testing machine (Xubuntu 16.04 python-pyscard installed from
repos) I can reproduce the problem with the python Unit Tests and your
sample code, with any value in line 52. But on another installation of
Ubuntu 16.04 (self compiled pyscard) I can't reproduce it either.

My patch includes a change in the lipcsclite client library which is
very important to provoke the race condition. This change should produce
debug output ("Waiting 2s to provoke...") when executing the test
programs with env variable PCSCLITE_DEBUG=0.

Did you get this additional client side debug output?

On the Ubuntu 16.04 machine I don't get the additional debug output, so
it seems like the pyscard Python module is not using the currently
installed libpcsclite. This is very strange because there is only the
self compiled libpcsclite installed. And with a test program written in
C, the problem is reproducible (including debug output) on both systems.


> Can you provide a/your sample code to reproduce the problem?
> 

My test program in C is attached and should compile like this:
$ gcc -I/usr/local/include/PCSC/ SCardGetStatusChange_Disconnect.c -o
SCardGetStatusChange_Disconnect -lpcsclite

There has to be exactly one reader connected before starting the
program. SCardGetStatusChange is called 2 times with reader states for
both the PnP Notification and the connected reader. First call is to get
the current reader state. The second call is blocking waiting for
events. This call stays blocked even if the observed reader is removed.


Thanks for you efforts. I'm sorry that I didn't include a sample code
for reproduction in the first place. I could reproduce it using the
provided Unit tests (e.g. SCardGetStatusChange_PnP.py) and considered
this should be enough.

Best regards
Maximilian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SCardGetStatusChange_Disconnect.c
Type: text/x-csrc
Size: 5045 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pcsclite-muscle/attachments/20170508/97028aea/attachment.c>


More information about the Pcsclite-muscle mailing list