author | Stephen Gaul Jr <steve.gaul@oracle.com> |
Wed, 11 Jan 2017 14:23:48 -0800 | |
changeset 7563 | 328fee062f83 |
permissions | -rw-r--r-- |
7563
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
1 |
Upstream patch/fix that was included in the next release of pcsclite: |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
2 |
https://anonscm.debian.org/cgit/pcsclite/PCSC.git/patch/?id=697fe05967af7ea215bcd5d5774be587780c9e22 |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
3 |
patch by Peter Wu <[email protected]> 2016-12-25 22:31:24 (GMT) |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
4 |
committed by Ludovic Rousseau <[email protected]> 2016-12-30 16:18:39 (GMT) |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
5 |
|
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
6 |
Once MSGRemoveContext is invoked (via SCARD_RELEASE_CONTEXT), cardsList is freed. |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
7 |
A repeated invocation of SCARD_RELEASE_CONTEXT (with an empty context handle) |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
8 |
results in a use-after-free followed by a double-free. After MSGRemoveContext, |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
9 |
invocation of SCardEstablishContext enable further use-after-free of cardsList in |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
10 |
MSGCheckHandleAssociation, MSGRemoveContext, MSGAddHandle, MSGRemoveHandle. |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
11 |
|
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
12 |
To avoid this problem, destroy the list only when the client connection is terminated. |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
13 |
|
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
14 |
This patch was based on the above and modified to work with our v1.8.14 of the pcsc-lite source code |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
15 |
and named accordingly to build with our existing Solaris pcsc-lite userland patch layout. |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
16 |
|
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
17 |
--- a/src/winscard_svc.c 2017-01-09 14:27:56.897972773 -0500 |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
18 |
+++ b/src/winscard_svc.c 2017-01-09 14:26:46.043849006 -0500 |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
19 |
@@ -868,7 +868,6 @@ |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
20 |
UNREF_READER(rContext) |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
21 |
} |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
22 |
(void)pthread_mutex_unlock(&threadContext->cardsList_lock); |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
23 |
- list_destroy(&threadContext->cardsList); |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
24 |
|
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
25 |
/* We only mark the context as no longer in use. |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
26 |
* The memory is freed in MSGCleanupCLient() */ |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
27 |
@@ -979,6 +978,11 @@ |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
28 |
(void)MSGRemoveContext(threadContext->hContext, threadContext); |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
29 |
} |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
30 |
|
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
31 |
+ |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
32 |
+ (void)pthread_mutex_lock(&threadContext->cardsList_lock); |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
33 |
+ list_destroy(&threadContext->cardsList); |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
34 |
+ (void)pthread_mutex_unlock(&threadContext->cardsList_lock); |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
35 |
+ |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
36 |
Log3(PCSC_LOG_DEBUG, |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
37 |
"Thread is stopping: dwClientID=%d, threadContext @%p", |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
38 |
threadContext->dwClientID, threadContext); |
328fee062f83
25366898 pcsclite SCardReleaseContext can result in a double-free of cardslist
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff
changeset
|
39 |