safesign (libaetpkss.so) hangs the process which uses it

Bug #647545 reported by Magosányi Árpád
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
pcsc-lite (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

It happens above libpcsclite1_1.4.102

Any process using libaetpkss.so as a pkcs#11 provider hangs at the end of smart card session.
It is caused by the pcsclite library (I don't know if it is called in the correct way, as the Safesign pkcs#11 library is closed source).

The cause of it is an open on a fifo which hangs as no one at the other end.

Patch (please notify upstream as well):

--- pcsc-lite-1.5.3.orig/src/utils.c
+++ pcsc-lite-1.5.3/src/utils.c
@@ -170,7 +170,7 @@
        (void)snprintf(filename, sizeof(filename), "%s/event.%d.%ld",
                PCSCLITE_EVENTS_DIR, SYS_GetPID(), hContext);
        (void)mkfifo(filename, 0644);
- fd = SYS_OpenFile(filename, O_WRONLY, 0);
+ fd = SYS_OpenFile(filename, O_WRONLY|O_NONBLOCK, 0);

        if (fstat(fd, &fstat_buf))
        {

Revision history for this message
Ludovic Rousseau (ludovic-rousseau-gmail) wrote :

Interesting patch. But I (as upstream maintainer) can't apply it before I understand the problem.

If you can write a small sample to reproduce the problem without using a proprietary software I will have a look.

If it is not possible I have some questions:
- does the FIFO the code is trying to open exists or not?
- can you follow [1] and generate a pcscd log?

[1] http://pcsclite.alioth.debian.org/ccid.html#support

Revision history for this message
Magosányi Árpád (mag-magwas) wrote :

I don't know what the heck libaetpkss does, as it is closed source.
I assure you I am not happy to use proprietary code. It kept a lot of my packages downgraded because this bug, and it took me a day to figure out at last what is the problem.
It is possible that safesign calls linpcsc-lite in the wrong way.
But it is a good custom of open source software to work around bugs in other software.
In the other hand open() without O_NONBLOCK definitely hangs on a fifo if there is no process at the other side.
My patch could definitely be improved to have a timeout to wait if pcscd comes up.
But it does work without that, at least for me.

Revision history for this message
Ludovic Rousseau (ludovic-rousseau-gmail) wrote :

The latest pcsc-lite 1.6.x do not use a fifo anymore. So the patch would only be for the 1.5.x branch.

If I can't reproduce/understand the bug myself I will not apply the patch, even if it works for you.
I note you have not replied to the 2 questions in my previous message.

Revision history for this message
Magosányi Árpád (mag-magwas) wrote :

I confirm that 1.6.x does not have this problem (I have installed it from debian pool), so I have lost interest in patching an old version, so I will be happy with a WONTFIX.

The answer to your questions:
- no, there is no one at the other end of the pipe
- I could generate a pcscd log, but I think it would not bring us closer.

Revision history for this message
Paul Moran (paulm) wrote :

Also seen this problem with the 1.5 libs. However upgrading to 1.6.4 causes other issues: the hanging problem goes away but now the usb token is never detected.

It could be a problem with libaetpkss.so since its closed source and we can't tell if its correct or not.

Revision history for this message
Jan Rochat (rochat) wrote :

Below a program that shows the problem out of the context of SafeSign (libaetpkss.so). The program runs fine on Windows (XP), and hangs on Ubuntu with
PCSC-Lite 1.5.3

#! /usr/bin/env python

from smartcard.scard import *

try:
     hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
     if hresult != SCARD_S_SUCCESS:
         raise Exception('Failed to establish context : ' +
                         SCardGetErrorMessage(hresult))
     print 'Context established!'

     try:

         hresult = SCardCancel(hcontext)
         if hresult != SCARD_S_SUCCESS:
             raise Exception('Failed to cancel context : ' +
                             SCardGetErrorMessage(hresult))
         print 'context canceled'

     finally:
         hresult = SCardReleaseContext(hcontext)
         if hresult != SCARD_S_SUCCESS:
             raise Exception('Failed to release context: ' +
                             SCardGetErrorMessage(hresult))
         print 'Released context.'

except Exception, message:
     print "Exception:", message

Cheers,

Jan

BTW If you encounter problems with SafeSign you can always send a bug report to <email address hidden>

Revision history for this message
Ludovic Rousseau (ludovic-rousseau-gmail) wrote :

I have no problem on Linux using pcsc-lite 1.6.5 and your Python sample.

$ ./SCardCancel2.py Context established!
context canceled
Exception: Failed to release context: Command cancelled.

PCSC-Lite 1.5.3 is an old version. You should at least try with version 1.5.5.

Revision history for this message
Jan Rochat (rochat) wrote :

Hi Ludovic,

I can not force ubuntu to update to 1.6.5., maybe you should tell them to. Furthermore the example above gives no exception when running on windows 7 or windows xp. (release context does return success instead of cancel)

Jan

Revision history for this message
Ludovic Rousseau (ludovic-rousseau-gmail) wrote :

Your Python sample exposed a bug in pcsc-lite. It is now fixed un revision 5344.

I now have:
$ ./SCardCancel2.py
Context established!
context canceled
Released context.

Revision history for this message
Ludovic Rousseau (ludovic-rousseau-gmail) wrote :

Naty has pcsc-lite version 1.7.0 so the bug should be fixed.
Closing the bug report.

Changed in pcsc-lite (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.